Skip to content

fix: live cumulative diff during multi-step turns - #184

Merged
jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/179-files-changed-cumulative-diff
Aug 11, 2026
Merged

fix: live cumulative diff during multi-step turns#184
jeonghun-jj-lee merged 1 commit into
local/amicodefrom
fix/179-files-changed-cumulative-diff

Conversation

@jeonghun-jj-lee

Copy link
Copy Markdown
Contributor

Follow-up to #181 — fixes the Files Changed panel going stale during live multi-step workflows.

Problem

After #181, the cumulative diff worked at turn boundaries but broke mid-turn:

  1. The query only refetched on session status transitions (idle↔busy), not between individual edits
  2. Session.diff() used a stale lastStepFinish snapshot as the diff endpoint instead of tracking the live working tree
  3. Files outside the workspace root (e.g., editing opencode source from an Altissimo workspace) produced no diff at all — the snapshot system only tracks the workspace worktree

Fixes

A. Prefer live working tree (session.ts)

// Before (stale during live turns):
const to = lastStepFinish ?? (yield* snapshot.track())
// After:
const to = (yield* snapshot.track()) ?? lastStepFinish

B. Refetch diff query on each completed edit (packages/app)

Added a diff_version counter per session that bumps when a file-editing tool completes (via SSE message.part.updated). The query key includes this counter → refetch after every edit (~100-250ms, acceptable at edit frequency).

C. External file support (snapshot/index.ts + session.ts)

For files outside the tracked worktree:

  • Resolve ../ relative paths to absolute
  • Find the file's own git repo (git rev-parse --show-toplevel)
  • Look up what commit was HEAD at session start (git rev-list -1 --before=<time>)
  • Diff that committed state against current disk
  • Display with ~/ prefix (not the broken ../../../ path)

Falls back to tool-metadata accumulation for files not in any git repo.

Files changed

Package File Change
opencode src/session/session.ts Fix A + C: track() priority, external file splitting
opencode src/snapshot/index.ts Fix C: diffExternalFiles(files, startTime)
app src/pages/session.tsx Fix B: diff_version in query key
app src/context/global-sync/event-reducer.ts Fix B: bump on completed edit parts
app src/context/global-sync/types.ts Fix B: diff_version field
app src/context/server-session.ts Fix B: store init
app src/context/global-sync/child-store.ts Fix B: store init
app src/context/directory-sync.ts Fix B: session field list
app src/context/global-sync/session-cache.ts Fix B: cache cleanup
app tests Fix B: fixture updates

Two fixes for the Files Changed panel showing stale/last-edit-only diffs
during a live workflow:

Fix A — prefer live working tree over stale snapshot:
  Session.diff() now calls snapshot.track() first (captures current disk
  state including in-progress edits), falling back to lastStepFinish only
  when tracking is unavailable. Previously it used lastStepFinish when set,
  which is stale during a live turn.

Fix B — refetch diff query when tool edits complete mid-turn:
  Added a diff_version counter per session that bumps in the event reducer
  when a completed file-editing tool part (edit/write/patch/apply_patch)
  with filediff metadata arrives via SSE. The sessionDiffQuery key includes
  this version, so each completed edit triggers a server refetch — giving
  the panel the real cumulative diff (~100-250ms) instead of relying on the
  client-side accumulateDiffs fallback (which only keeps the last patch).
@jeonghun-jj-lee
jeonghun-jj-lee merged commit 556b7fd into local/amicode Aug 11, 2026
1 of 4 checks passed
@jeonghun-jj-lee
jeonghun-jj-lee deleted the fix/179-files-changed-cumulative-diff branch August 11, 2026 08:36
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.

1 participant