From b6539d49b16a29751ac112851168a498bf219a71 Mon Sep 17 00:00:00 2001 From: "posthog[bot]" <206114724+posthog[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 03:18:18 +0000 Subject: [PATCH] fix(daemon): stop reporting rewrite synthesis failures for a deleted worktree An agent can delete a temporary worktree before the daemon handles the git command. Rewrite synthesis then fails in find_repository, and the error-level log sent the benign race to error tracking with the temporary path in the message. The outer vanished-repo guard already skipped the side effect, but the inner log ran first. Now the rewrite synthesis error arm checks is_vanished_repo_error first. When it is true, the daemon logs at debug level and returns the error as before, so the outer guard still runs. Other rewrite synthesis failures still log at error level. Add a unit test that runs find_repository on a deleted worktree. Generated-By: PostHog Desktop Task-Id: 272e438d-f425-4b6f-bda6-6a9b8eb02ab8 --- src/daemon.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/daemon.rs b/src/daemon.rs index 7f32444..c939435 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -8930,6 +8930,19 @@ impl ActorDaemonCoordinator { let rewrite_events = match self.rewrite_events_from_semantic_events(cmd, events) { Ok(rewrite_events) => rewrite_events, + // A repository deleted before the daemon handled the command (e.g. an + // agent's temporary worktree) is a benign race. Log at debug level + // and let the caller's vanished-repo guard skip the side effect. + Err(error) if is_vanished_repo_error(&error, cmd.worktree.as_deref()) => { + tracing::debug!( + command = ?cmd.primary_command, + root_sid = %cmd.root_sid, + ?family, + %error, + "strict rewrite synthesis skipped: repository no longer exists (benign race)" + ); + return Err(error); + } Err(error) => { tracing::error!( component = "daemon", @@ -12787,6 +12800,32 @@ mod tests { )); } + #[test] + fn vanished_repo_error_detects_find_repository_on_deleted_worktree() { + // Rewrite synthesis calls `find_repository` for the command's worktree. + // An agent can delete a temporary worktree before the daemon handles + // the command. + let temp = tempfile::tempdir().unwrap(); + let worktree = temp.path().join("wt"); + init_fake_repo(&worktree); + fs::remove_dir_all(&worktree).unwrap(); + + let error = match find_repository_in_path(&worktree.to_string_lossy()) { + Ok(_) => panic!("find_repository must fail for a deleted worktree"), + Err(error) => error, + }; + assert!(is_vanished_repo_error(&error, Some(&worktree))); + + // The shape git reports on Windows for the same race. + let not_a_repo = AutterError::GitCliError { + code: Some(128), + stderr: "fatal: not a git repository (or any of the parent directories): .git" + .to_string(), + args: vec!["rev-parse".to_string(), "--show-toplevel".to_string()], + }; + assert!(is_vanished_repo_error(¬_a_repo, Some(&worktree))); + } + #[test] fn repository_is_gone_keeps_subdirectory_of_live_repo() { let temp = tempfile::tempdir().unwrap();