Abort kills claude_cli process group and cancels pending plan/ask dialogs
- claude -p runs in its own process group; dropping the stream kills the group (its Bash children survived kill_on_drop) - reader task stops when the stream is dropped - exit_plan/AskUserQuestion race the question against abort - TUI clears choose/doc/perm popups when a run ends - fix abort_during_tool_round test (tu() always built echo calls, slow never ran)
This commit is contained in:
1 parent
7e428dfb39
commit
fd0b0a77dc
4 files changed
+105
-10
No files matched your search
@@ -1140,7 +1140,18 @@ mod tests {
|
||||
async fn abort_during_tool_round_stops_it_and_answers_the_calls() {
|
||||
let p = Arc::new(Script(
|
||||
Mutex::new(vec![
|
||||
asst(vec![tu("1", "slow"), tu("2", "slow")]),
|
||||
asst(vec![
|
||||
ContentBlock::ToolUse {
|
||||
id: "1".into(),
|
||||
name: "slow".into(),
|
||||
input: json!({}),
|
||||
},
|
||||
ContentBlock::ToolUse {
|
||||
id: "2".into(),
|
||||
name: "slow".into(),
|
||||
input: json!({}),
|
||||
},
|
||||
]),
|
||||
asst(vec![ContentBlock::Text { text: "ok".into() }]),
|
||||
]),
|
||||
Mutex::new(vec![]),
|
||||
|
||||
@@ -200,6 +200,19 @@ pub async fn serve(path: &Path, cx: ToolCtx, bus: Bus, mode: Unanswered) -> std:
|
||||
}
|
||||
}
|
||||
|
||||
async fn choose_or_abort(
|
||||
cx: &ToolCtx,
|
||||
q: crate::Question,
|
||||
) -> Result<Option<Vec<String>>, &'static str> {
|
||||
match cx.state.abort.get().cloned() {
|
||||
Some(mut rx) => tokio::select! {
|
||||
r = cx.state.choose(q) => r,
|
||||
_ = async { rx.wait_for(|a| *a).await.is_ok() } => Ok(None),
|
||||
},
|
||||
None => cx.state.choose(q).await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn exit_plan(cx: &ToolCtx, plan: &str) -> Result<(), String> {
|
||||
let q = crate::Question {
|
||||
text: "Implement this plan?".into(),
|
||||
@@ -214,7 +227,7 @@ async fn exit_plan(cx: &ToolCtx, plan: &str) -> Result<(), String> {
|
||||
other: true,
|
||||
plan: Some(plan.into()),
|
||||
};
|
||||
match cx.state.choose(q).await {
|
||||
match choose_or_abort(cx, q).await {
|
||||
Ok(Some(v)) if v.first().is_some_and(|s| s == "Implement") => {
|
||||
cx.state
|
||||
.allow
|
||||
@@ -239,17 +252,18 @@ async fn ask(cx: &ToolCtx, input: &Value) -> Option<Value> {
|
||||
let s = |k| o[k].as_str().unwrap_or_default().to_string();
|
||||
(s("label"), s("description"))
|
||||
});
|
||||
let r = cx
|
||||
.state
|
||||
.choose(crate::Question {
|
||||
let r = choose_or_abort(
|
||||
cx,
|
||||
crate::Question {
|
||||
text: text.into(),
|
||||
options: options.collect(),
|
||||
multi: q["multiSelect"].as_bool().unwrap_or(false),
|
||||
other: true,
|
||||
plan: None,
|
||||
})
|
||||
.await
|
||||
.ok()??;
|
||||
},
|
||||
)
|
||||
.await
|
||||
.ok()??;
|
||||
answers.insert(text.into(), r.join(", ").into());
|
||||
}
|
||||
let mut out = input.clone();
|
||||
|
||||
Reference in new issue
Block a user