Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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(&not_a_repo, Some(&worktree)));
}

#[test]
fn repository_is_gone_keeps_subdirectory_of_live_repo() {
let temp = tempfile::tempdir().unwrap();
Expand Down
Loading