Skip to content

fix: add file size limit to FileModel to prevent multi-GB allocations#12060

Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
oz/fix-memory-unbounded-file-read
Draft

fix: add file size limit to FileModel to prevent multi-GB allocations#12060
warp-dev-github-integration[bot] wants to merge 1 commit into
masterfrom
oz/fix-memory-unbounded-file-read

Conversation

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

Summary

Adds a 256 MB file size limit to FileModel to prevent multi-gigabyte memory allocations when opening or reloading very large files.

Problem

Sentry issue 7259255054 shows 24.18 GB of in-use memory with 99.27% from async_fs::read_to_string via the blocking::Executor thread pool. The heap profile shows the allocation path:

blocking::Executor::main_loop
  → async_fs::read_to_string<&PathBuf>
    → std::fs::read_to_string::inner
      → alloc::raw_vec::RawVecInner::finish_grow  (24 GB)

FileModel::open(), read_content_for_file(), and reload_file_paths() all use async_fs::read_to_string without any size check. When a user opens or the file-watcher detects changes to a very large file (logs, binaries, database dumps, etc.), the entire content is read into memory as a String.

Changes

  • warp_util/src/file.rs: Added FileTooLarge { size, limit } variant to FileLoadError
  • warp_files/src/lib.rs:
    • Added MAX_READABLE_FILE_SIZE constant (256 MB)
    • Added check_file_size() async helper
    • Guarded FileModel::open() with size check before read_to_string
    • Guarded FileModel::read_content_for_file() with size check
    • Guarded FileModel::reload_file_paths() with size check (logs warning and skips)
  • app/src/ai/blocklist/action_model/execute.rs: Added FileTooLarge arm to exhaustive match in read_binary_file_context

Validation

  • cargo check --workspace passes
  • cargo clippy -p warp_files -p warp_util -- -D warnings passes

CHANGELOG-BUG-FIX: Fixed excessive memory usage when opening very large files by adding a 256 MB file size limit

Conversation: https://staging.warp.dev/conversation/99f355e9-9bd4-4dbf-ae68-c81bc1db01ae
Run: https://oz.staging.warp.dev/runs/019e8793-6d32-723a-bbc1-75d4c4694915
This PR was generated with Oz.

FileModel::open(), read_content_for_file(), and reload_file_paths() all
use async_fs::read_to_string without any size check. When a user opens
or the file-watcher detects changes to a very large file (logs, binaries,
database dumps, etc.), the entire content is read into memory as a String.

Sentry issue 7259255054 shows 24 GB of in-use memory with 99.27% from
async_fs::read_to_string via the blocking::Executor thread pool.

This change:
- Adds a FileTooLarge variant to FileLoadError
- Adds a MAX_READABLE_FILE_SIZE constant (256 MB) and check_file_size()
  helper to FileModel
- Guards all three async_fs::read_to_string call sites with a file size
  check before reading
- Updates the exhaustive match in read_binary_file_context to handle the
  new error variant

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

Co-Authored-By: Oz <oz-agent@warp.dev>
@cla-bot cla-bot Bot added the cla-signed label Jun 2, 2026
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