Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ function parseBlocks(blocks: ContentBlock[]): MessageSegment[] {
segments.push({ ...nextGroup, isOpen })
}

const lastSubagentBlockIndex = new Map<string, number>()
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i]
if (block.type === 'subagent' && block.content) {
lastSubagentBlockIndex.set(block.content, i)
}
}
const hasSubagentBlockAfter = (name: string, index: number): boolean => {
const last = lastSubagentBlockIndex.get(name)
return last !== undefined && last > index
}

for (let i = 0; i < blocks.length; i++) {
const block = blocks[i]

Expand Down Expand Up @@ -267,6 +279,9 @@ function parseBlocks(blocks: ContentBlock[]): MessageSegment[] {
const isDispatch = SUBAGENT_KEYS.has(tc.name) && !tc.calledBy

if (isDispatch) {
if (hasSubagentBlockAfter(tc.name, i)) {
continue
}
if (!group || group.agentName !== tc.name) {
if (group) {
pushGroup(group)
Expand Down
27 changes: 12 additions & 15 deletions apps/sim/lib/copilot/request/go/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,29 +361,26 @@ export async function runStreamLoop(
flushSubagentThinkingBlock(context)
flushThinkingBlock(context)
if (spanEvt === MothershipStreamV1SpanLifecycleEvent.start) {
const lastParent = context.subAgentParentStack[context.subAgentParentStack.length - 1]
const lastBlock = context.contentBlocks[context.contentBlocks.length - 1]
if (toolCallId) {
if (lastParent !== toolCallId) {
if (!context.subAgentParentStack.includes(toolCallId)) {
context.subAgentParentStack.push(toolCallId)
}
context.subAgentParentToolCallId = toolCallId
context.subAgentContent[toolCallId] ??= ''
context.subAgentToolCalls[toolCallId] ??= []
}
if (
subagentName &&
!(
lastParent === toolCallId &&
lastBlock?.type === 'subagent' &&
lastBlock.content === subagentName
if (subagentName) {
const alreadyOpen = context.contentBlocks.some(
(b) =>
b.type === 'subagent' && b.content === subagentName && b.endedAt === undefined
)
Comment thread
icecrasher321 marked this conversation as resolved.
) {
context.contentBlocks.push({
type: 'subagent',
content: subagentName,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parallel same-name subagents collapse into single block

Medium Severity

The alreadyOpen check for subagent blocks incorrectly dedupes by subagentName without considering toolCallId. This results in only one subagent block being created for parallel instances sharing a name. Consequently, the first subagent's end event prematurely closes the shared block, causing visual inconsistencies where lanes finish early and subsequent text attaches to an ended block.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 340c154. Configure here.

timestamp: Date.now(),
})
if (!alreadyOpen) {
context.contentBlocks.push({
type: 'subagent',
content: subagentName,
timestamp: Date.now(),
})
}
}
return
}
Expand Down
Loading