Skip to content

fix: checkpoint uncommitted work before restoring a checkpoint - #209

Merged
currentbits merged 1 commit into
mainfrom
coder/restorecheckpoint-hard-resets-the-worktr-ec44a0
Aug 17, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/restorecheckpoint-hard-resets-the-worktr-ec44a0

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Fixes #132.

Problem

restoreCheckpoint in electron/worktrees.js ran git reset --hard <sha> as soon as the sha passed validation. Any uncommitted work in the thread worktree was destroyed by one click on an older checkpoint, with no way back:

  • manual edits made directly in the worktree folder
  • changes from a run whose post-turn checkpoint silently failed (that path is best-effort by design)

maybeCreateCheckpoint already existed and is exactly the right safety net — it just was not being called here.

Change

await maybeCreateCheckpoint(store, threadId) immediately before the reset. It sits after the sha validation, so it cannot influence which checkpoint resolves.

The fix is in the shared function, so it covers every restore entry point — the ThreadView undo bar and the AgentsPanel checkpoint list both route through it.

maybeCreateCheckpoint no-ops on a clean worktree, so the ordinary restore (nothing uncommitted) behaves exactly as before.

Known limitation

The safety commit is off-HEAD after the reset, so it drops out of listCheckpoints and is not visible in the UI. Recovery is git reflog in the worktree. That turns unrecoverable loss into recoverable loss, which is what the issue asked for; surfacing it in the checkpoint list is a separate change and is marked with a ponytail: comment at the call site.

Tests

Two cases added to electron/test/checkpoints.test.js:

  • dirty restore — an edit to a tracked file plus an untracked file, then a restore; asserts the reset happened and that both pieces of work are retrievable from the safety commit via the reflog
  • clean restore — asserts no stray commit is created when there is nothing to save

electron/test/checkpoints.test.js 12/12 and electron/test/worktrees.test.js 34/34 pass.

  • PR created by the Claude Code agent

restoreCheckpoint ran `git reset --hard` straight away, so any uncommitted
work in the thread worktree — manual edits, or changes from a run whose
best-effort post-turn checkpoint failed — was destroyed by one click on an
older checkpoint.

maybeCreateCheckpoint now runs first. It no-ops on a clean worktree, so the
common restore is unchanged. The safety commit is off-HEAD after the reset
and drops out of listCheckpoints; recovery is `git reflog` in the worktree.

Co-Authored-By: Claude Opus 5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@currentbits
currentbits merged commit 4c50ef1 into main Aug 17, 2026
1 check passed
@currentbits
currentbits deleted the coder/restorecheckpoint-hard-resets-the-worktr-ec44a0 branch October 3, 2026 16:07
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.

restoreCheckpoint hard-resets the worktree with no safety checkpoint first

1 participant