GeezerVison is showing github.com — fix(session): store turn summaries as names and counts, compute patches on request by lihaokun · Pull Request #57 · lihaokun/opencode
Conversation
lihaokun
commented
Oct 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Base branch: dev. The default branch main only takes promotion PRs from dev.
Issue for this PR
No issue of ours; found while diagnosing an earlyoom kill (opencode at 47 GB RSS) and a 52 GB opencode-dev.db. The same defect is open upstream as anomalyco#43551, anomalyco#42748, anomalyco#48641, anomalyco#46833, anomalyco#50089 and anomalyco#48616; three upstream fixes (anomalyco#48245, anomalyco#49715, anomalyco#50106) were closed unmerged. The clock-ordering problem met during review is tracked separately as #56.
Type of change
What does this PR do?
Every turn, SessionSummary.summarize diffed the two workspace snapshots and stored the full-context patch of every changed file in the user message's summary.diffs. The durable message.updated event copied the whole message on each write. On a session where the agents regenerated ~1,400 tracked log files per compile, one turn's summary was 1,264 files / 244 MB; the message row was 249 MB, two of them were rewritten in the four minutes before the kill, and event.data held 41 GB of message.updated.1 rows. The model never sees this field; it is UI metadata.
Summaries now store names and counts. Snapshot.diffStat runs git diff --name-status and --numstat and nothing else: no file content enters the process. summarize stores {file, additions, deletions, status}, writes the turn's aggregate into the session-level summary, and publishes the list on session.diff (previously an empty array, so the TUI sidebar's "Modified Files" was always empty). File names are unquoted so stored rows, the event and the endpoint agree.
Patches are computed on request. GET /session/:id/diff recomputes diffFull from the turn's step-start/step-finish snapshot hashes when a client asks. Files over 1 MB on either side get counts only; once a response's patches reach 8 MB the rest get counts only; if cat-file --batch-check cannot report sizes, every file gets counts only. Without a messageID the endpoint returns the latest turn's stored list, which is what the TUI asks on opening a session. Messages that still carry stored patches keep serving them. Snapshot objects are pruned after 7 days, so a turn older than that shows names and counts only — the documented trade-off (Claude Code keeps 100 checkpoints / 30 days; ZCode records only the agent's own edits; neither stores workspace-wide patches).
Writes are bounded. The processor schedules one summary per step and releases them together; they are now coalesced per message (one running, at most one waiting) and a result equal to the stored one is not written again, while a turn that changed nothing still writes once so the counts reset. A git failure during comparison is a Snapshot.DiffError that writes nothing, instead of an empty list that would read as "nothing changed".
FileDiff.patch was already optional in the schema: no schema or SDK change, no TUI change. Desktop app and cli export already guard a missing patch.
Design, upstream comparison (table), review record and the three test layers: docs/fixes/session-fix-summary-diff-size.md.
README (second commit, folded in from #58). The fork notice at the top of README.md becomes a positioning section: an independent branch that no longer submits changes upstream and merges upstream updates selectively; the Agent management tools and TUI surface; the session-layer stability work with its fix documents; the branch and release model; the development workflow. Feature and stability differences only. Translated READMEs untouched.
How did you verify your code works?
- Basic/edge:
test/session/summary.test.ts (10 cases: large file never enters the message and the message stays under 2 KB; patches recomputed on request with the per-file cap; legacy stored patches served; latest turn without a message id; a quiet turn resets counts and clears the list; six concurrent summaries write once; quoted file names; no snapshots) and test/snapshot/snapshot.test.ts (+3: diffStat vs diffFull, per-file cap, per-response cap).
- Random (seeded, cross-checked against git numstat): 12 random change sets (
diffStat equals diffFull minus patch; patch withheld iff over cap; patch +/- line counts equal numstat), 8 random turns (stored equals diffStat, message size bounded by file count, aggregate correct, diff() does not write back, idempotent), 6 random multi-turn sessions (latest turn vs named turn).
- Independent review (doc + diff, then code): 5 findings, 4 fixed, 1 accepted; recorded in the doc.
- Regression:
test/session, test/snapshot, test/server — 942 pass; the 14 httpapi-sdk.test.ts failures reproduce on unmodified dev (local 503/health), 2 concurrency timeouts pass alone. bun typecheck clean.
- The random multi-turn test flaked under load until its clock was replaced with a counter: this machine's clock steps backwards (journald "Time jumped backwards"), which also makes ascending ids and message order go backwards in product code — ascending ids and message order go backwards when the system clock steps back #56.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…es on request
Each turn's summary embedded the full-context patch of every file that
changed in the workspace, and the durable message.updated event copied it
on every write. One turn that regenerated a thousand tracked logs produced
a 249 MB user message; the process reached 47 GB and was killed, and the
event table grew to 44 GB. Upstream carries the same code and six open
issues for it; three fixes there were closed unmerged.
The summary now stores file names, line counts and status from git
numstat; nothing is read into memory. The diff endpoint computes patches
from the turn's snapshot hashes when asked, with a per-file and a
per-response size limit. Summaries scheduled for the same message are
coalesced and written once; a result equal to what is stored is not
written again, while a turn that changed nothing still writes once to
reset the session's counts. Session-level counts and the session.diff
event now carry the turn's file list. A git failure during comparison is
an error that writes nothing, not an empty change set. Stored file names
are unquoted, matching the endpoint.
Design, upstream comparison, review record and test layers are in
docs/fixes/session-fix-summary-diff-size.md.
|
Thanks for your contribution!
This PR doesn't have a linked issue. All PRs must reference an existing issue.
Please:
- Open an issue describing the bug/feature (if one doesn't exist)
- Add
Fixes #<number> or Closes #<number> to this PR description
See CONTRIBUTING.md for details.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The following comment was made by an LLM, it may be inaccurate:
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
The fork notice becomes a section: what the fork is, that it no longer
submits changes upstream and merges upstream updates selectively, the
Agent management tools and TUI surface that replace the task tool, the
session-layer stability work with its fix documents, the branch and
release model, and the development workflow. Feature and stability
differences only; the upstream README follows unchanged.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 12, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|