fix: limit git object size in code review diff to prevent multi-GB heap growth
Description
Fixes an excessive memory usage issue in the code review diff panel. When loading diffs, the app reads the full content of every changed file via git show HEAD:{file} (and git show {commit}:{file}) to populate the base content for the diff editor. These strings are accumulated simultaneously across all files in the diff. For users with many large or generated files in their diff (e.g. lock files, minified bundles, large data files), this causes the heap to grow to multi-GB levels.
Root cause from heap profile (Sentry issue 7259255054, 9.97 GB total):
- 9.75 GB (97.77%) allocated in
LocalDiffStateModel::load_diffs_for_repo→get_file_content_at_head→warp_util::git::run_git_command→async_process::Command::output(reading stdout intoVec<u8>) - The buffers from all files accumulate simultaneously in the
Vec<FileDiffAndContent>returned by the diff state
Fix: Add a MAX_CONTENT_AT_HEAD_SIZE = 20 MB limit (matching the existing limit in num_lines_in_file_if_non_binary) to both get_file_content_at_head and get_file_content_at_commit. Before calling git show, we check the git object size via git cat-file -s <object>, which is a fast metadata-only query. Files exceeding the limit return None, which is already handled gracefully by the UI (it skips setting the base content for the diff editor).
Linked Issue
Sentry: https://sentry.io/organizations/warpdotdev/issues/7259255054/events/e7537d51424e4012be9d8c77012d8b37/
Testing
- [ ] I have manually tested my changes locally with
./script/run
Manual testing: Open code review panel on a repo with large generated files (e.g. lock files, bundle.js) — the panel should still render correctly for those files without the base content, and won't OOM.
Agent Mode
- [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode
Conversation: https://staging.warp.dev/conversation/383bcd45-9017-4781-92e9-e9d33de932e4 Run: https://oz.staging.warp.dev/runs/019e6c43-d727-74b4-b775-956ef16436ba
This PR was generated with Oz.