Skip to content

fix(opencode): restore session diff summary#37542

Open
ergs0204 wants to merge 1 commit into
anomalyco:devfrom
ergs0204:session-diff-summary
Open

fix(opencode): restore session diff summary#37542
ergs0204 wants to merge 1 commit into
anomalyco:devfrom
ergs0204:session-diff-summary

Conversation

@ergs0204

Copy link
Copy Markdown

Issue for this PR

Closes #30877
Closes #32852
Closes #17797

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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 aggregate session.diff event. 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 30000
  • bun typecheck from packages/opencode
  • Repository pre-push bun turbo typecheck across all packages
  • Prettier check for the changed files

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings July 17, 2026 18:33
@github-actions

Copy link
Copy Markdown
Contributor

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:
This PR (37542) explicitly mentions #33444 in its description as an overlapping PR that identified the same root cause and proposed the same general direction. According to the description, PR #33444 has been waiting without review and lacks automated regression coverage. This PR (37542) is presented as an alternative implementation that includes better test coverage while addressing the same issue.

Both PRs aim to restore the session-level diff projection from per-turn diffs computed by SessionSummary.summarize, and both reference issues #30877, #32852, and #17797.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-message summary.diffs and republish the aggregate session.diff event.
  • 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.

Comment on lines +126 to +136
// 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(),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants