Skip to content

fix: add 50 MB file size limit in code editor to prevent OOM from large files#12125

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/large-file-oom-code-editor-APP-XXXX
Draft

fix: add 50 MB file size limit in code editor to prevent OOM from large files#12125
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
fix/large-file-oom-code-editor-APP-XXXX

Conversation

@warp-dev-github-integration
Copy link
Copy Markdown

@warp-dev-github-integration warp-dev-github-integration Bot commented Jun 3, 2026

Description

Adds a 50 MB file size limit in FileModel::open to prevent extreme memory usage when the code editor opens a very large file.

Root cause: When a large file is loaded in the code editor:

  1. Buffer::replace_all materializes the entire file as Vec<StyledBufferBlock> — proportional to file size (3.15 GB in the Sentry event)
  2. CodeEditorModel::handle_content_model_event clones the EditDelta containing all styled blocks (1.52 GB)
  3. SyntaxTreeState::update_internal_state_with_delta parses the entire content with tree-sitter (2.87 GB)

Together these consumed 7.6 GB of heap for a single file open (Sentry issue 7259255054, warp-client-beta-stable, MacBookPro18,2 w/ M1 Max, mac_stable_release).

Fix: A new read_file_with_size_limit helper in FileModel::open checks async_fs::metadata before reading. Files larger than MAX_EDITOR_FILE_SIZE_BYTES (50 MB) emit FailedToLoad instead of being read into memory. The code editor shows the standard load-failure toast.

Changes:

  • crates/warp_util/src/file.rs — Add FileLoadError::FileTooLarge { size_bytes, limit_bytes } variant
  • crates/warp_files/src/lib.rs — Add MAX_EDITOR_FILE_SIZE_BYTES constant (50 MB), read_file_with_size_limit async helper, wire it into FileModel::open
  • app/src/ai/blocklist/action_model/execute.rs — Add FileTooLarge arm to exhaustive match

Linked Issue

Sentry: https://sentry.io/organizations/warpdotdev/issues/7259255054/

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Testing

  • I have manually tested my changes locally with ./script/run

The affected code path is tested by: attempting to open a file larger than 50 MB in the code editor — it should show the "failed to load" toast instead of consuming gigabytes of RAM.

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Conversation: https://staging.warp.dev/conversation/1f7b5e5a-c53a-4576-9bae-c8ec63d3c68f
Run: https://oz.staging.warp.dev/runs/019e8bd0-5b45-7040-aaab-09e52b40bf93
This PR was generated with Oz.

Linear Issue

APP-4519

…ge files

When a very large file is opened in the code editor, the buffer
materializes the entire content as Vec<StyledBufferBlock>, which is
then cloned in CodeEditorModel::handle_content_model_event, and
tree-sitter also parses the complete content. Together these operations
can consume many gigabytes of RAM for large files — a real-world Sentry
event (issue 7259255054) showed 7.6 GB of live heap from a single file
load (3.15 GB in SumTree, 1.52 GB from delta clone, 2.87 GB tree-sitter).

Add FileLoadError::FileTooLarge and a MAX_EDITOR_FILE_SIZE_BYTES (50 MB)
limit in FileModel::open via a new read_file_with_size_limit helper.
Files exceeding this threshold emit FailedToLoad, which the code editor
handles by showing the standard load-failure toast.

The existing read_content_for_file (used by discard_unsaved_changes and
tests) is left unchanged since those paths are intentional and bounded
by user action rather than background auto-load.

Fixes Sentry issue: https://sentry.io/organizations/warpdotdev/issues/7259255054/

Co-Authored-By: Oz <oz-agent@warp.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant