Skip to content

fix(session): cap per-message summary diff size to prevent OOM bloat - #2062

Open
YOMXXX wants to merge 1 commit into
XiaomiMiMo:mainfrom
YOMXXX:fix/summary-diffs-cap
Open

fix(session): cap per-message summary diff size to prevent OOM bloat#2062
YOMXXX wants to merge 1 commit into
XiaomiMiMo:mainfrom
YOMXXX:fix/summary-diffs-cap

Conversation

@YOMXXX

@YOMXXX YOMXXX commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1854 (part of it). message.summary.diffs grow unbounded — single messages reach tens–hundreds of MB because Snapshot.FileDiff.patch holds the full file content (diffFull uses full context). On resume, JSON → V8 heap ×copies → 10–20 GB process commit → OOM / Windows Event 2004.

Root cause: packages/opencode/src/session/summary.ts summarize() stores the full per-message diff into the message summary with no size cap.

Fix: cap the per-message summary diff at MAX_SUMMARY_DIFF_BYTES (1 MB):

  • capSummaryDiffs() slices each FileDiff.patch to the remaining byte budget and drops entries once exhausted, so a single huge patch can never bloat a message beyond ~1 MB.
  • Applied only to the message-embedded copy. The full session diff (session_diff) and the revert path are untouched — they use the unbounded diff.

Test Plan

  • New tests: huge patch capped to budget; small diffs unchanged; budget exhaustion drops entries.
  • bun test test/session/summary-diffs-cap.test.ts — 3 pass; full session suite 913 pass no regression.
  • bun typecheck — clean.

Notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process OOM 10–20GB commit: unbounded message.summary.diffs + prune skipped while checkpoint-writer + history.backfill (related #1351)

1 participant