Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): large file edits no longer store their full diff twice #19316

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/19316/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Part 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_eventsorchestration_v2_projection_turn_items
main (test fails)2,551,144 B2,551,144 B
this PR35,979 B35,979 B
  • vp test run src/orchestration-v2/ProviderEventIngestor.test.ts src/orchestration-v2/WireProjection.test.ts: 47 passed.
  • Server tsc --noEmit clean. 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

    2. juliusmarminge added labelsmacroscope-review

    3. Approvability

      Verdict: Approved at 3a347f2

      Macroscope'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).
    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/server/src/orchestration-v2/ProviderEventIngestor.ts
      • apps/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.ts
      boundFileChangeForStorage truncates defined diffStr, oldStr, and newStr values 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.ts
      Turn-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: Passed 2 · Failed 2
      Failed Failed checks: 2 warnings
      Check nameStatusExplanationResolution
      Linked Issues checkWarningThe PR bounds diffStr, oldStr, and newStr for turn-item.updated file-change items before persistence. The new test verifies bounded payloads in orchestration_events and `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 checkWarningThe 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 Passed checks: 2 passed
      Check nameStatusExplanation
      Out of Scope Changes checkPassedThe 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 checkPassedThe 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, and newStr for turn-item.updated file-change items before persistence. The new test verifies bounded payloads in orchestration_events and orchestration_v2_projection_turn_items. Issue #12758 requires the Codex lifecycle activity path to stop storing full diffs in lifecycle rows and in both activity stores. This diff does not change CodexAdapter, ProviderRuntimeIngestion, tool.started/tool.completed, or projection_thread_activities. The PR also explicitly does not repair oversized rows that already exist, while #12758 requires 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
      Comment `@coderabbitai help` to get the list of available commands.
    5. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB−24 B (−0.5%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB−24 B (−2.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB−41 B (−0.2%)29.3 KiB✅
      ClaudeLive turn messages21−1 (−50.0%)8✅

      Baseline: acb9027 · PR result: 3a347f2 · Source CI: success

      Scenario 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.

Sign in to join this conversation.