fix: abort stops running tool calls and kills bash process group

Race the tool round against abort, check abort before starting tools,
answer pending calls with an aborted result, deny permission prompts on
abort, and kill the bash process group on drop.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
johannesandClaude Sonnet 5.5 committed 2026-11-21 18:58:42 +01:00
1 parent 951b69837a
commit 8f0de9465d
3 files changed
+120 -9

No files matched your search

+28 -7
View File
@@ -366,6 +366,19 @@ impl Tool for ExitPlan {
const LIVE_TAIL: usize = 2048;
#[cfg(unix)]
struct KillGroup(Option<u32>);
#[cfg(unix)]
impl Drop for KillGroup {
fn drop(&mut self) {
if let Some(pid) = self.0 {
let _ = std::process::Command::new("kill")
.args(["-KILL", &format!("-{pid}")])
.status();
}
}
}
pub struct Bash;
#[async_trait]
impl Tool for Bash {
@@ -396,6 +409,8 @@ impl Tool for Bash {
Err(e) => return ToolResult::err(format!("spawn: {e}")),
};
let pid = child.id();
#[cfg(unix)]
let mut group = KillGroup(pid);
let mut so = child.stdout.take().expect("piped");
let live = &cx.state.live;
let run = async {
@@ -420,15 +435,21 @@ impl Tool for Bash {
let res = tokio::time::timeout(Duration::from_secs(secs), run).await;
live.lock().unwrap_or_else(|e| e.into_inner()).remove(cmd);
let (out, code) = match res {
Ok(Ok((o, st))) => (o, st.code()),
Ok(Err(e)) => return ToolResult::err(format!("wait: {e}")),
Err(_) => {
Ok(Ok((o, st))) => {
#[cfg(unix)]
if let Some(pid) = pid {
let _ = std::process::Command::new("kill")
.args(["-KILL", &format!("-{pid}")])
.status();
{
group.0 = None;
}
(o, st.code())
}
Ok(Err(e)) => {
#[cfg(unix)]
{
group.0 = None;
}
return ToolResult::err(format!("wait: {e}"));
}
Err(_) => {
return ToolResult::err(format!("timed out after {secs}s"));
}
};