From 4759adda4b383904d90264fc584ad9556b1a004d Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 6 Apr 2026 16:19:36 -0400 Subject: [PATCH] Wire up original_commit_hash in archive and restore flows persist_worktree_state: - Read HEAD SHA before creating WIP commits as original_commit_hash - Pass it to create_archived_worktree restore_worktree_via_git: - Pre-restore: verify original_commit_hash exists via resolve_commit; abort with user-facing error if the git history is gone - Worktree-already-exists: check for .git file to detect if path is a real git worktree; if not, call repair_worktrees to adopt it - Resilient WIP resets: track success of mixed and soft resets independently; if either fails, fall back to mixed reset directly to original_commit_hash - Post-reset HEAD verification: confirm HEAD landed at original_commit_hash after all resets - Branch restoration: after switching, verify branch points at original_commit_hash; if it doesn't, reset and create a fresh branch --- crates/agent_ui/src/thread_worktree_archive.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/agent_ui/src/thread_worktree_archive.rs b/crates/agent_ui/src/thread_worktree_archive.rs index 795dd0ba700e1df275ac487bc21fcc08597fb356..c43bc48aa79765c6e2b5c250f4d7b9c223103df8 100644 --- a/crates/agent_ui/src/thread_worktree_archive.rs +++ b/crates/agent_ui/src/thread_worktree_archive.rs @@ -1115,7 +1115,9 @@ pub async fn restore_worktree_via_git( // Check if the branch exists and points at original_commit_hash. // If it does, switch to it. If not, create a new branch there. let rx = wt_repo.update(cx, |repo, _cx| repo.change_branch(branch_name.clone())); - if matches!(rx.await, Ok(Ok(()))) { + let switched = matches!(rx.await, Ok(Ok(()))); + + if switched { // Verify the branch actually points at original_commit_hash after switching let head_after_switch = wt_repo .update(cx, |repo, _cx| repo.head_sha())