fix: kill stale cargo processes before running acceptance gates

The completion handler now pgrep+kills any cargo processes targeting
the worktree's Cargo.toml before running gates. This prevents the
run_tests MCP child from holding the build lock and blocking gates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dave
2026-04-12 00:25:56 +00:00
parent 8ae6ca3eb8
commit b43e7cf752
@@ -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())) .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::<i32>() {
crate::slog!(
"[agents] Killing stale cargo process (pid {pid}) for '{story_id}' before running gates"
);
unsafe { libc::kill(pid, libc::SIGKILL); }
}
}
}
}
// Run acceptance gates. // Run acceptance gates.
let (gates_passed, gate_output) = if let Some(wt_path) = worktree_path { let (gates_passed, gate_output) = if let Some(wt_path) = worktree_path {
let path = wt_path; let path = wt_path;