fix(engine): drain late sub-agent completions before turn break (#1961)

Before the turn breaks at the thinking-only checkpoint, drain
any sub-agent completions that arrived between the last hold
check and now. If a child finished while we were running the
final status check, surface its sentinel immediately rather
than delaying it to the next turn.
This commit is contained in:
Hunter Bown
2026-05-24 04:21:21 -05:00
parent 805ec668f2
commit af59f7a732
+25
View File
@@ -1096,6 +1096,31 @@ impl Engine {
// code fell straight through to this `break`, emitting nothing
// and leaving the UI spinner hung. Surface a status now —
// safe because the turn can no longer resume.
// #1961: Before breaking, drain any sub-agent completions that
// arrived between the last hold check and now. If a child finished
// while we were running the thinking-only check, surface its
// sentinel rather than delaying it to the next turn.
let mut late_completions: Vec<crate::tools::subagent::SubAgentCompletion> =
Vec::new();
while let Ok(c) = self.rx_subagent_completion.try_recv() {
late_completions.push(c);
}
if !late_completions.is_empty() {
let count = late_completions.len();
for c in late_completions {
self.add_session_message(subagent_completion_runtime_message(&c.payload))
.await;
}
let _ = self
.tx_event
.send(Event::status(format!(
"Resuming turn with {count} late sub-agent completion(s)"
)))
.await;
turn.next_step();
continue;
}
if thinking_only_no_sendable {
let holding_for_subagents = {
let running = {