From 210657c51657aa8a09f39666ae2078a1f2d98939 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 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/agent_ui/src/thread_worktree_archive.rs b/crates/agent_ui/src/thread_worktree_archive.rs index 97a6053f4ce352e692e5316a84218e602ff3dea5..2d577e62b92d30b0e24b27b7c5525dd5cdbc6fc7 100644 --- a/crates/agent_ui/src/thread_worktree_archive.rs +++ b/crates/agent_ui/src/thread_worktree_archive.rs @@ -1041,7 +1041,11 @@ pub async fn restore_worktree_via_git( let soft_reset_ok = if mixed_reset_ok { let rx = wt_repo.update(cx, |repo, cx| { - repo.reset(row.original_commit_hash.clone(), ResetMode::Soft, cx) + repo.reset( + row.original_commit_hash.clone(), + ResetMode::Soft, + cx, + ) }); match rx.await { Ok(Ok(())) => true, @@ -1067,7 +1071,11 @@ pub async fn restore_worktree_via_git( row.original_commit_hash ); let rx = wt_repo.update(cx, |repo, cx| { - repo.reset(row.original_commit_hash.clone(), ResetMode::Mixed, cx) + repo.reset( + row.original_commit_hash.clone(), + ResetMode::Mixed, + cx, + ) }); match rx.await { Ok(Ok(())) => {} @@ -1126,7 +1134,11 @@ pub async fn restore_worktree_via_git( row.original_commit_hash ); let rx = wt_repo.update(cx, |repo, cx| { - repo.reset(row.original_commit_hash.clone(), ResetMode::Mixed, cx) + repo.reset( + row.original_commit_hash.clone(), + ResetMode::Mixed, + cx, + ) }); let _ = rx.await; // Delete the old branch and create fresh