diff --git a/server/src/agents/pool/pipeline/completion.rs b/server/src/agents/pool/pipeline/completion.rs index 38c314b7..182ad145 100644 --- a/server/src/agents/pool/pipeline/completion.rs +++ b/server/src/agents/pool/pipeline/completion.rs @@ -199,6 +199,25 @@ pub(in crate::agents::pool) async fn run_server_owned_completion( .and_then(|a| a.worktree_info.as_ref().map(|wt| wt.path.clone())) }; + // Kill any in-flight cargo test processes for this worktree so they don't + // hold the build lock while gates try to run. + if let Some(wt_path) = worktree_path.as_ref() { + if let Ok(output) = std::process::Command::new("pgrep") + .args(["-f", &format!("--manifest-path {}/Cargo.toml", wt_path.display())]) + .output() + { + let pids = String::from_utf8_lossy(&output.stdout); + for pid_str in pids.lines() { + if let Ok(pid) = pid_str.trim().parse::() { + crate::slog!( + "[agents] Killing stale cargo process (pid {pid}) for '{story_id}' before running gates" + ); + unsafe { libc::kill(pid, libc::SIGKILL); } + } + } + } + } + // Run acceptance gates. let (gates_passed, gate_output) = if let Some(wt_path) = worktree_path { let path = wt_path;