Fixing followup after termination of agent turn

This commit is contained in:
Ryan Ward
2026-08-18 17:20:13 -05:00
parent 0ffd1181d1
commit 87080c8086
+11
View File
@@ -6319,7 +6319,17 @@ impl BlocklistAIController {
}; };
slot.turn_control = None; slot.turn_control = None;
let cancellation_reason = slot.cancellation_reason; let cancellation_reason = slot.cancellation_reason;
// A cancellation reason is set as soon as the user cancels, but the coordinator may
// already have reached its terminal `Done` outcome (e.g. the in-flight model turn was
// cancelled and the run transitioned straight to `Cancelled`). In that case we must fall
// through to the normal `Done` handling below so `finish_active_provider_run` runs and
// frees this conversation's slot. Otherwise this would unconditionally re-drive an
// already-terminal run: `next_step()` immediately returns `Done` again, which lands back
// here and loops forever, so `active_provider_runs` never empties and any follow-up
// queued behind this generation (see `start_next_queued_provider_run`) never starts.
let reached_terminal_outcome = matches!(result, Ok(ProviderRunBlock::Done(_)));
if let Some(reason) = cancellation_reason { if let Some(reason) = cancellation_reason {
if !reached_terminal_outcome {
if !run.coordinator.run().is_terminal() { if !run.coordinator.run().is_terminal() {
let _ = run.coordinator.run_mut().cancel(reason.to_string()); let _ = run.coordinator.run_mut().cancel(reason.to_string());
} }
@@ -6330,6 +6340,7 @@ impl BlocklistAIController {
self.drive_active_provider_run(conversation_id, ctx); self.drive_active_provider_run(conversation_id, ctx);
return; return;
} }
}
let block = match result { let block = match result {
Ok(block) => block, Ok(block) => block,
Err(message) => { Err(message) => {