Skip to content

fix: RevertBanner UI shows no changes after successful file revert#8121

Merged
marius-kilocode merged 4 commits intoKilo-Org:mainfrom
IamCoder18:fix/vscode-revert-file-changes
Apr 2, 2026
Merged

fix: RevertBanner UI shows no changes after successful file revert#8121
marius-kilocode merged 4 commits intoKilo-Org:mainfrom
IamCoder18:fix/vscode-revert-file-changes

Conversation

@IamCoder18
Copy link
Copy Markdown
Contributor

Context

IMPORTANT: The revert button was reverting changes correctly, it just didn't convey that in the banner, causing confusion.

The "Revert to here" button in the VS Code extension sidebar appears to not revert file changes — after clicking it, messages disappear but the RevertBanner shows no file change information. This gives the impression that only chat messages are reverted and not the associated git/file changes. In reality, Snapshot.revert(patches) was always reverting files correctly. The actual bug is that the diff data never reaches the webview, so the RevertBanner is always empty after revert.

Closes #8048

Two bugs contribute to this:

  1. computeDiff() called after file revertSessionSummary.computeDiff() was called after Snapshot.revert(patches). By that point files on disk already matched the revert.snapshot baseline, so Snapshot.diffFull(from, to) compared identical states and returned an empty diff.

  2. Diffs not persisted to the databaseSession.setRevert() stored summary_additions, summary_deletions, and summary_files but not summary_diffs. The column exists in the schema but was never written. The webview reads session.summary()?.diffs for the RevertBanner, which was always undefined.

Additionally, revert does not work in repositories with no commits (e.g., git init but no commits yet) because the snapshot system's initial git rev-list --max-parents=0 --all returns empty, causing the project to be stored without git VCS tracking. This is a pre-existing limitation, not addressed in this PR.

Implementation

Two files changed:

packages/opencode/src/session/revert.ts

  • Compute diffs before reverting files: Moved SessionSummary.computeDiff() to execute before Snapshot.revert(patches). The diff captures changes being undone while files on disk still reflect the AI's modifications. Snapshot.revert itself was not changed — it was always working correctly.

  • Include diffs in the summary: The setRevert call now passes diffs in the summary so it propagates through sessionToWebview to the webview's RevertBanner.

packages/opencode/src/session/index.ts

  • Persist summary_diffs in setRevert: Added summary_diffs: input.summary?.diffs ?? null to the Drizzle .set() call. The summary_diffs column already exists in the schema but was never written during revert operations.

Screenshots

before after
before after

How to Test

  1. Open a git-initialized project with existing files (must have at least one commit)
  2. Ask the AI to modify a file (e.g., "add a comment to the top of README.md")
  3. Wait for the AI to complete and verify the file was modified
  4. Click the revert arrow on your user message
  5. Verify:
    • The file on disk is reverted to its previous state (this already worked before this fix)
    • The RevertBanner now shows the file changes (additions, deletions, file names) — this is the fix
    • Any files you edited independently are NOT reverted
  6. Click "Redo" and verify the changes are restored

Get in Touch

My discord is @iamcoder18 and I am in the Kilo Code discord server.

When reverting a session, the diff was computed after files were already
reverted to their pre-change state, producing an empty or wrong diff.
By computing the diff before restoring files, the revert summary now
correctly reflects what was actually undone for the user.
summary_additions: input.summary?.additions,
summary_deletions: input.summary?.deletions,
summary_files: input.summary?.files,
summary_diffs: input.summary?.diffs ?? null,
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.

WARNING: Persisting raw summary.diffs here stores every file's full before/after contents in the session row and republishes them on Session.Event.Updated. We already strip summary.diffs off user messages because these payloads can grow very large, and the RevertBanner only needs file names plus add/delete counts. Consider storing a metadata-only shape here and keeping the full diff bodies in session_diff storage / diff events.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The issue has been resolved.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 2, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • packages/opencode/src/session/index.ts
  • packages/opencode/src/session/revert.ts
  • packages/opencode/src/session/session.sql.ts
  • packages/sdk/js/src/v2/gen/types.gen.ts
  • packages/sdk/openapi.json

Reviewed by gpt-5.4-20260305 · 1,445,338 tokens

Full file contents were being stored in the session summary diffs,
causing unnecessary database bloat. The webview RevertBanner only
needs file path, line counts, and status — not the full diff content.
@marius-kilocode
Copy link
Copy Markdown
Collaborator

Hi @IamCoder18, thanks for contributing. Could you please add kilocode_change markers around all non-generated changes, thanks!

@marius-kilocode marius-kilocode self-requested a review April 2, 2026 07:35
@marius-kilocode
Copy link
Copy Markdown
Collaborator

@IamCoder18 I added the change marker, thanks for the fix!

@marius-kilocode marius-kilocode merged commit 2e3b9a2 into Kilo-Org:main Apr 2, 2026
13 checks passed
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.

Bug: 'Revert to here' button does not revert git changes (file history)

2 participants