fix(core): refuse checkpoint workspace restore when HEAD moved past the checkpoint (#13626)
* fix(core): refuse checkpoint workspace restore when HEAD moved past the checkpoint Restoring a checkpoint runs git reset --hard, which moves the current branch pointer. If commits were made after the checkpoint (by the user or by the agent), the reset silently knocked them off the branch, leaving them reachable only through the reflog. Guard the reset: if HEAD no longer matches the commit the checkpoint was created on, throw a descriptive error (including how many commits would be dropped) instead of destroying history. Chat-only restore is unaffected, and users who really want to discard the commits can reset the branch manually first. Fixes #13550 Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com> * fix(core): close the guard-to-reset race with an atomic ref update The moved-HEAD guard read HEAD, ran further git commands, then reset unconditionally, so a commit landing in that window could still be knocked off the branch. Replace the reset's branch move with git's native compare-and-swap (git update-ref HEAD <new> <old>), which fails if HEAD no longer points at the verified commit, and follow with a bare reset --hard to sync the index and worktree to the already-moved HEAD. Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com> --------- Co-authored-by: Saoud Rizwan <saoudrizwan@users.noreply.github.com>
S
Saoud Rizwan committed
89c2efa970a115d0815942e4eb69f1a74f9d3b5e
Parent: f753a01
Committed by GitHub <noreply@github.com>
on 8/27/2026, 8:47:50 PM