fix(server): large file edits no longer store their full diff twice #19316
main fromrefs/pull/19316/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubPart of #12758: this stops new oversized writes. Rows that are already stored are not rewritten here (see the end of this description), so the issue stays open.
The issue names the V1 path (CodexAdapter and ProviderRuntimeIngestion writing tool.started and tool.completed). That code is gone. In V2, Codex writes the diff only once per edit, as the file_change turn item on item/completed, and this PR bounds that item.
A provider file change stores its full diff in turn-item.updated, and SQLite keeps it twice: once in orchestration_events and once in orchestration_v2_projection_turn_items. A single edit to a large or generated file can store tens of MB. The issue's install held 5.2 GiB of diff text in each table and crashed when it read them back. Clients never get this text. projectTurnItemForWire strips it, except a failed edit's error, which it cuts to 32 KB.
Fix#
ProviderEventIngestor now bounds a file change's diffStr, oldStr, and newStr to the same 32 KB detail limit before it commits the item. It does this in the same place it already strips unserved tool image bytes. Because the bound applies before commit, both tables get the bounded copy, for every provider.
- No contract or wire change. Web, desktop, mobile, and older builds get the same file-change items as before.
- Small diffs are stored unchanged.
- Full diffs still come from checkpoint diffs.
- One change: agents reading a thread over MCP (
turnItemText) now see at most 32 KB of a diff, with a truncation marker.
Proof#
New test: stores a bounded copy of a large file-change diff in both SQLite tables in ProviderEventIngestor.test.ts. It ingests a 2.25 MB diff and a small one, then reads the raw payload_json bytes from both tables.
orchestration_events | orchestration_v2_projection_turn_items | |
|---|---|---|
main (test fails) | 2,551,144 B | 2,551,144 B |
| this PR | 35,979 B | 35,979 B |
vp test run src/orchestration-v2/ProviderEventIngestor.test.ts src/orchestration-v2/WireProjection.test.ts: 47 passed.- Server
tsc --noEmitclean. Scoped lint and format clean.
Not covered: rows already stored. This PR does not rewrite existing rows. Reclaiming that space stays with the compaction work in #19249.
Created with Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code
- 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
juliusmarminge added labelsmacroscope-review
Approvability#
Verdict: Approved at
3a347f2Macroscope's review found this PR approvable — This is a narrowly scoped server fix that bounds oversized file-change text before it is written to either SQLite table, preventing duplicate multi-megabyte storage while preserving small diffs and the existing checkpoint diff path. Database-level tests cover truncation and unchanged small-file behavior; the only intentional runtime difference is bounded MCP text for large diffs.
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: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
9fd45916-7a3f-4ebe-89cc-ec642db00a2f
📥 Commits
-
Reviewing files that changed from the base of the PR and between acb90279e2adad19a63586944543fe7346499467 and 3a347f28ef871ca79478f4c6a304346344ce9ee0.
📒 Files selected for processing: 3
-
apps/server/src/orchestration-v2/ProviderEventIngestor.test.tsapps/server/src/orchestration-v2/ProviderEventIngestor.tsapps/server/src/orchestration-v2/WireProjection.ts
Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 10 reviews per hour.
-
📝 Walkthrough
-
Turn-item normalization now bounds file-change text before storage. A test checks serialized event and projection payload sizes, confirms the large diff retains its prefix, and verifies that a small diff remains unchanged.
Changes: Bounded file-change storage
Layer / File(s) Summary Bound file-change text
apps/server/src/orchestration-v2/WireProjection.tsboundFileChangeForStoragetruncates defineddiffStr,oldStr, andnewStrvalues on file-change items. Other item types remain unchanged. The file-change projection comment now describes bounded text in storage.Apply bounds during ingestion and verify persistence
apps/server/src/orchestration-v2/ProviderEventIngestor.ts,apps/server/src/orchestration-v2/ProviderEventIngestor.test.tsTurn-item normalization applies the bounds after stripping unserved tool-output image bytes. The test checks event and projection payload sizes, the retained prefix of a large diff, and an unchanged small diff. Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
Merge Risk: ⚪ Minimal · up to
3a347-
No demonstrated issue blocks merging after normal checks.
Pre-merge checks:
2 · 2-
Failed checks: 2 warningsCheck name Status Explanation Resolution Linked Issues check The PR bounds diffStr,oldStr, andnewStrforturn-item.updatedfile-change items before persistence. The new test verifies bounded payloads inorchestration_eventsand `orchestration_v2_pro…Apply the bound or bounded-metadata transformation to the Codex lifecycle activity persistence path, including both lifecycle rows and both activity stores. Add regression coverage for that path. Provide a supported repair or migration for … Description check The description clearly covers the problem, fix, scope limitations, verification results, and agent attribution. It does not provide the required explicit maintainer approval comment or explain the ex… Add a Scope and approval section. Link the triaged issue or approval discussion and include the explicit maintainer approval comment. If no approval is required, explain why this focused fix qualifies as an obvious bug fix under the reposit… Passed checks: 2 passed-
Check name Status Explanation Out of Scope Changes check The changed production code bounds provider file-change text before event and projection persistence. The changed test verifies the bound in both affected turn-item SQLite tables and verifies that sma… Title check The title clearly and concisely describes the main change: preventing large file edits from storing the full diff twice.
Full details: Linked Issues check
-
Explanation
The PR bounds
diffStr,oldStr, andnewStrforturn-item.updatedfile-change items before persistence. The new test verifies bounded payloads inorchestration_eventsandorchestration_v2_projection_turn_items. Issue#12758requires the Codex lifecycle activity path to stop storing full diffs in lifecycle rows and in both activity stores. This diff does not changeCodexAdapter,ProviderRuntimeIngestion,tool.started/tool.completed, orprojection_thread_activities. The PR also explicitly does not repair oversized rows that already exist, while#12758requires a supported repair or migration.Resolution
Apply the bound or bounded-metadata transformation to the Codex lifecycle activity persistence path, including both lifecycle rows and both activity stores. Add regression coverage for that path. Provide a supported repair or migration for oversized existing rows, or link a reviewed implementation that is part of this PR.
Full details: Description check
-
Explanation
The description clearly covers the problem, fix, scope limitations, verification results, and agent attribution. It does not provide the required explicit maintainer approval comment or explain the exemption under the scope and approval requirements.
Resolution
Add a Scope and approval section. Link the triaged issue or approval discussion and include the explicit maintainer approval comment. If no approval is required, explain why this focused fix qualifies as an obvious bug fix under the repository policy.
-
- Fix all pre-merge checks with AI
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB −24 B (−0.5%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB −24 B (−2.0%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB −41 B (−0.2%) 29.3 KiB ✅ Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅ Baseline:
acb9027· PR result:3a347f2· 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: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes