fix(server): release oversized pull request diff cache entries #12523
main fromrefs/pull/12523/head·merged by juliusmarminge View on GitHubLarge pull-request diff slices remained strongly referenced by both the normal diff cache and its stale fallback after the request finished. Those caches admitted up to 128 results without accounting for patch size.
Skip retention when a patch exceeds 512 KiB of estimated UTF-16 storage. Return the complete patch and pagination metadata unchanged, retain caching for small results, and guard invalidation against removing a replacement entry. Each persistent cache is consequently limited to 64 MiB of patch text. Repeated server requests for oversized slices fetch them again.
Before/after evidence against this PR's main base: an isolated GC check through the actual service read 16 synthetic diff results totaling 8 MiB. The base retained all 16 after GC (54 MiB heap); this revision retained zero (46 MiB heap). This demonstrates this retention defect; it does not establish the retaining root of the separately observed 3.86 GiB backend crash.
Validation: 165 focused PullRequestService tests passed, including large regular, paginated, and commit slices and small replacements; server package typecheck, scoped lint, formatting, and diff checks passed. The shared service applies to all source-control providers and web, desktop, and mobile connections without a contract change.
Prepared with Codex.
Summary by CodeRabbit#
- Bug Fixes
- Improved diff caching behavior for very large responses.
- Large diffs are still returned when requested but are no longer retained in the cache.
- Smaller diff responses continue to be cached and reused.
- Updated viewed-file handling to preserve cached diffs when file marks are invalidated.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 13.5 KiB 13.5 KiB +2 B (+0.0%) 15.1 KiB ✅ Codex Thread snapshot wire 7.1 KiB 7.1 KiB +7 B (+0.1%) 7.3 KiB ✅ Codex Live turn WebSocket wire 6.4 KiB 6.4 KiB −5 B (−0.1%) 7.8 KiB ✅ Codex Live turn WebSocket decoded 56.2 KiB 56.2 KiB 0 B (0.0%) 66.4 KiB ✅ Codex Live turn messages 9 9 0 (0.0%) 21 ✅ Claude Total thread wire 13.5 KiB 13.5 KiB −4 B (−0.0%) 15.1 KiB ✅ Claude Thread snapshot wire 7.1 KiB 7.1 KiB −4 B (−0.1%) 7.3 KiB ✅ Claude Live turn WebSocket wire 6.4 KiB 6.4 KiB 0 B (0.0%) 7.8 KiB ✅ Claude Live turn WebSocket decoded 57.0 KiB 57.0 KiB 0 B (0.0%) 66.4 KiB ✅ Claude Live turn messages 9 9 0 (0.0%) 21 ✅ Baseline:
e74c668· PR result:04bbab1· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 113.9 KiB
- Claude decoded thread snapshot: 114.6 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved at
04bbab1Macroscope's review found this PR approvable — This is a small, isolated cache-retention fix that preserves complete diff responses and existing small-diff caching while preventing oversized patches from remaining in either cache. Focused tests cover regular, paginated, and commit diff paths, including replacement behavior.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Team
Run ID:
69db5a83-0161-4829-8ccc-67d7a3ea9c26📥 Commits
Reviewing files that changed from the base of the PR and between e74c668d786ffc14f40a9540cd3aede02ba5d62e and 04bbab1d8219ad93be0f3aa130fb2a042301fd06.
📒 Files selected for processing (2)
apps/server/src/pullRequest/PullRequestService.test.tsapps/server/src/pullRequest/PullRequestService.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough#
The pull request limits cached diffs to 512 KiB of UTF-16 storage. Oversized diffs are returned but not retained. Matching oversized cached values are invalidated, and tests cover repeated large responses and later small cached responses.
Changes#
Diff cache handling
Layer / File(s) Summary Cache size policy
apps/server/src/pullRequest/PullRequestService.tsThe service permits caching only diffs within the 512 KiB UTF-16 limit and skips oversized values during diff recording. Oversized read behavior
apps/server/src/pullRequest/PullRequestService.ts,apps/server/src/pullRequest/PullRequestService.test.tsDiff reads invalidate matching oversized cached values before stale-diff handling. Tests cover repeated large responses, later small-response reuse, and cached diffs remaining after file-mark invalidation. Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix
Suggested reviewers:
maria-rcks🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the primary change: releasing oversized pull-request diff cache entries. Description check ✅ Passed The description explains the problem, the caching change, expected behavior, validation, and scope. It does not use the template headings or checklist, but it provides the required information and is … Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. ✨ Finishing Touches
📝 Generate docstrings
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge merged thiscb3d95c
juliusmarminge closed this
Sign in to join this conversation.
All clear
Posted via Macroscope — Effect Service Conventions