Skip to content

Commit 050de8e

Browse files
committed
remove unused fallbacks
1 parent 35c490d commit 050de8e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

apps/sim/lib/copilot/request/go/stream.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,21 @@ export async function runStreamLoop(
396396
if (isPendingPause) {
397397
return
398398
}
399-
if (context.subAgentParentStack.length > 0) {
400-
context.subAgentParentStack.pop()
399+
// Pop by id, not by position: parallel subagents can end out of
400+
// order, and a positional pop would otherwise remove the wrong
401+
// parent and leave subAgentParentToolCallId pointing at the
402+
// just-ended lane. Every subagent_end carries a toolCallId in
403+
// current protocol; if one ever doesn't, prefer leaving the stack
404+
// intact over guessing the wrong parent.
405+
if (toolCallId) {
406+
const idx = context.subAgentParentStack.lastIndexOf(toolCallId)
407+
if (idx >= 0) {
408+
context.subAgentParentStack.splice(idx, 1)
409+
} else {
410+
logger.warn('subagent end without matching start', { toolCallId })
411+
}
401412
} else {
402-
logger.warn('subagent end without matching start')
413+
logger.warn('subagent end missing toolCallId')
403414
}
404415
context.subAgentParentToolCallId =
405416
context.subAgentParentStack.length > 0

0 commit comments

Comments
 (0)