From a360607fad351ae0e46379889cbe77a8840eafcf Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 2 Apr 2026 17:35:17 -0400 Subject: [PATCH] fix stale process count after interrupt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't abort the tokio task when killing processes — let SIGTERM'd processes exit normally so run_bash sees the exit and unregisters them from the tracker. Only abort the turn when no processes are running (e.g. interrupting a streaming response). Co-Authored-By: Proof of Concept --- src/bin/poc-agent.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/bin/poc-agent.rs b/src/bin/poc-agent.rs index 2767d5f..df43697 100644 --- a/src/bin/poc-agent.rs +++ b/src/bin/poc-agent.rs @@ -547,14 +547,18 @@ impl Session { for p in &procs { self.process_tracker.kill(p.pid).await; } - if let Some(handle) = self.turn_handle.take() { - handle.abort(); - self.turn_in_progress = false; - self.dmn = dmn::State::Resting { - since: Instant::now(), - }; - self.update_status(); - let _ = self.ui_tx.send(UiMessage::Activity(String::new())); + // Only abort the turn if no processes are running — let SIGTERM'd + // processes exit normally so run_bash can unregister them. + if procs.is_empty() { + if let Some(handle) = self.turn_handle.take() { + handle.abort(); + self.turn_in_progress = false; + self.dmn = dmn::State::Resting { + since: Instant::now(), + }; + self.update_status(); + let _ = self.ui_tx.send(UiMessage::Activity(String::new())); + } } self.pending_input = None; let killed = procs.len();