fix(opencode): restore session diff summary#37542
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Perfect! I found a related PR: Potential Duplicate PR Found:
Why it's related: Both PRs aim to restore the session-level diff projection from per-turn diffs computed by |
There was a problem hiding this comment.
Pull request overview
Restores the session-level “diff summary” projection used by the TUI/app “Modified Files” surfaces by aggregating already-computed per-turn diffs, avoiding the expensive full-session snapshot diff that was removed in #30127.
Changes:
- Rebuild
session.summary(files/additions/deletions + stored diffs) by aggregating user-messagesummary.diffsand republish the aggregatesession.diffevent. - Add a focused regression test ensuring aggregation happens without recomputing a full-session diff (only the current turn’s snapshot range is diffed).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/opencode/src/session/summary.ts | Restores session-level diff projection by aggregating persisted per-turn diffs and publishing the resulting session.diff event. |
| packages/opencode/test/session/summary.test.ts | Adds regression coverage validating aggregation behavior and the “diff only current turn snapshots” performance invariant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Rebuild the session projection from stored turn diffs without diffing the full snapshot history. | ||
| const diffs = Array.from( | ||
| new Map( | ||
| all | ||
| .filter( | ||
| (message): message is SessionV1.WithParts & { info: SessionV1.User } => message.info.role === "user", | ||
| ) | ||
| .flatMap((message) => (message.info.summary ? message.info.summary.diffs : [])) | ||
| .map((item, index) => [item.file ?? index, item] as const), | ||
| ).values(), | ||
| ) |
Issue for this PR
Closes #30877
Closes #32852
Closes #17797
Type of change
What does this PR do?
#30127 removed the expensive full-session snapshot diff and intentionally left the session-level diff projection empty. Per-turn diffs remained available on user message summaries, but the TUI sidebar and session diff endpoint still consume the session-level projection, so Modified Files disappeared.
This restores that projection from the per-turn diffs already computed and persisted by
SessionSummary.summarize. It deduplicates files by path, updates the session summary counts and stored diffs, and publishes the aggregatesession.diffevent. It does not recompute a full-session snapshot diff.This overlaps with #33444, which identified the same root cause and proposed the same general direction. I opened this alternative because that PR has been waiting without review and currently has no automated regression coverage. This version includes a focused test that verifies both the restored aggregate and the performance invariant that only the current turn's snapshot range is diffed. Credit to @aic0d3r for the diagnosis and original fix proposal.
How did you verify your code works?
bun test test/session/summary.test.ts test/session/snapshot-tool-race.test.ts test/server/session-diff-missing-patch.test.ts --timeout 30000bun typecheckfrompackages/opencodebun turbo typecheckacross all packagesChecklist