Skip to content

fix(cli): keep session reverts atomic - #12587

Merged
marius-kilocode merged 3 commits into
mainfrom
reproduce-and-fix-revert-file-rollback-bug
Jul 28, 2026
Merged

fix(cli): keep session reverts atomic#12587
marius-kilocode merged 3 commits into
mainfrom
reproduce-and-fix-revert-file-rollback-bug

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Revert currently records a conversation rewind even when an individual snapshot checkout fails. A locked or unwritable path can therefore leave only part of the workspace restored while the UI reports the entire checkpoint as reverted.

Snapshot restoration now validates checkpoint trees before mutation and treats checkout, restore, and deletion failures as fatal. Revert, replacing an existing revert, and Unrevert all run as compensated transitions: they capture a durable baseline, restore only the checkpoint patch paths through the snapshot service, and preserve both the original and rollback failure causes. Conversation state is persisted only after every affected file reaches the requested checkpoint.

Fixes #11864

Comment thread packages/opencode/src/kilocode/session/revert.ts Outdated
Comment thread packages/opencode/src/kilocode/session/revert.ts Outdated
Comment thread packages/opencode/src/kilocode/session/revert.ts Outdated
Comment thread packages/opencode/src/session/revert.ts Outdated
Comment thread packages/opencode/src/session/revert.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

All issues from the previous review round were addressed in this update: KiloSessionRevert.restore now delegates path/file resolution to snap.revert() (worktree-relative resolution, no more Instance.directory mismatch, and no more per-restore full-tree track()), the pre-restore step in revert() and the restore in unrevert() are now wrapped by KiloSessionRevert.apply's baseline compensation, and rollback failures are combined with Cause.combine so the original failure cause is preserved. New tests cover the replace-revert and unrevert failure paths and a nested worktree-subdirectory restore scenario.

Files Reviewed (3 files)
  • packages/opencode/src/kilocode/session/revert.ts
  • packages/opencode/src/session/revert.ts
  • packages/opencode/test/kilocode/session/revert.test.ts
Previous Review Summary (commit 16f8e7e)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 16f8e7e)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

CRITICAL

File Line Issue
packages/opencode/src/kilocode/session/revert.ts 25 Resolves worktree-relative diff paths against Instance.directory instead of Instance.worktree, which can silently skip or mis-target file deletion when they differ

WARNING

File Line Issue
packages/opencode/src/kilocode/session/revert.ts 22 New full-tree snap.track() call added to every restore() invocation, increasing cost of every revert/unrevert
packages/opencode/src/session/revert.ts 89 Pre-restore step (undo previous revert) has no baseline compensation on failure, unlike the new patch-apply path
packages/opencode/src/session/revert.ts 127 unrevert() restore has no compensation/rollback on partial failure, same bug class this PR fixes for revert()

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/session/revert.ts 16 Original revert failure cause is dropped if the compensating restore also fails
Files Reviewed (5 files)
  • .changeset/atomic-session-revert.md
  • packages/opencode/src/kilocode/session/revert.ts - 3 issues
  • packages/opencode/src/session/revert.ts - 2 issues
  • packages/opencode/src/snapshot/index.ts
  • packages/opencode/test/kilocode/session/revert.test.ts

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5 · Input: 40 · Output: 19K · Cached: 1.2M

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode disabled auto-merge July 28, 2026 08:45
@marius-kilocode
marius-kilocode merged commit b20986b into main Jul 28, 2026
29 checks passed
@marius-kilocode
marius-kilocode deleted the reproduce-and-fix-revert-file-rollback-bug branch July 28, 2026 09:58
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…ert-file-rollback-bug

fix(cli): keep session reverts atomic
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.

[Critical Bug] Revert Function Does Not Undo All Changes — Partial Revert Leaves Codebase in Inconsistent State

2 participants