Repository navigation
[checkpoints] Prevent data loss when restoring a missing checkpoint - #22
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the problem?
Restoring a checkpoint deleted untracked workspace files before checking whether the saved commit existed. If the checkpoint repository was deleted, recreated, pruned, or damaged, cleanup succeeded but the reset failed, permanently losing uncommitted user work.
How does this PR solve the problem?
Checks that the target commit exists before any workspace-mutating command. A missing commit now raises an error explaining that the checkpoint no longer exists and that no files were changed. Existing logging, error events, and rethrow behavior are preserved. Valid restores retain their existing behavior.
The supplied audit found that restoreCheckpoint is the only path running destructive Git commands against commit hashes from saved task messages. Branch deletion already validates branch names with branchLocal() and leaves core.worktree unset. Diff/show paths are read-only. The core checkpoint restore wrapper and webview edit/delete-message flows delegate to restoreCheckpoint and are protected transitively.
Only the checkpoint service and its two new tests are included. No unrelated files or changeset are included; no mandatory changeset requirement was found in this fork.
How did you test the PR?
Implementation-session result supplied with this change: exit 0, 2 test files, 40/40 tests passed. Tests cover preserving untracked files and tracked edits when the commit is missing, and restoring a valid commit normally. Tests were not rerun during PR preparation. The commit hook passed all 10 lint tasks.
Agent notes
Base: 4bf5874 (simurg79/Roo-Code main).
Preflight uses git cat-file -e ^{commit} before git clean -f -d -f and git reset --hard.
The patch is submitted unchanged.