Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(group): surface supervisor reply when it parents to any council member (#16188)

Arvin Xueae5c5b91a37
diff --git a/packages/conversation-flow/src/__tests__/parse.test.ts b/packages/conversation-flow/src/__tests__/parse.test.ts
index ef1030e9834..6d361f79df8 100644
--- a/packages/conversation-flow/src/__tests__/parse.test.ts
+++ b/packages/conversation-flow/src/__tests__/parse.test.ts
@@ -434,6 +434,44 @@ describe('parse', () => {
expect(serializeParseResult(result)).toEqual(outputs.agentCouncil.withSupervisorReply);
});
+
+ // Regression: the supervisor's post-council reply must surface no matter which council
+ // member it parents to. Broadcast agents finish near-simultaneously (tied createdAt), so
+ // the writer's createdAt-last member can differ from the array order; previously the reader
+ // only walked the last member and stranded the reply, making the supervisor message vanish.
+ it.each([['msg-agent-backend-1'], ['msg-agent-devops-1'], ['msg-agent-architect-1']])(
+ 'should surface supervisor final reply when it parents to council member %s',
+ (memberId) => {
+ const messages = inputs.agentCouncil.withSupervisorReply.map((message) =>
+ message.id === 'msg-supervisor-summary'
+ ? { ...message, parentId: memberId }
+ : message,
+ );
+
+ const result = parse(messages);
+ const summary = result.flatList.find((m) => m.id === 'msg-supervisor-summary');
+
+ expect(summary).toBeDefined();
+ expect(summary!.role).toBe('supervisor');
+ // No duplication regardless of which member carries the reply
+ expect(result.flatList.filter((m) => m.id === 'msg-supervisor-summary')).toHaveLength(1);
+
+ // contextTree must stay in agreement with flatList β€” the reply has to surface in
+ // both exported views, otherwise a contextTree consumer still sees the chain vanish.
+ const collectIds = (nodes: any[], acc: string[] = []): string[] => {
+ for (const node of nodes) {
+ if (node.id) acc.push(node.id);
+ if (Array.isArray(node.members)) collectIds(node.members, acc);
+ if (Array.isArray(node.children)) collectIds(node.children, acc);
+ if (Array.isArray(node.columns)) collectIds(node.columns, acc);
+ }
+ return acc;
+ };
+ const contextIds = collectIds(result.contextTree as any[]);
+ expect(contextIds).toContain('msg-supervisor-summary');
+ expect(contextIds.filter((id) => id === 'msg-supervisor-summary')).toHaveLength(1);
+ },
+ );
});
describe('Assistant Group Scenarios', () => {
diff --git a/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts b/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts
index ec83dfe800d..f7f5ce88c9f 100644
--- a/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts
+++ b/packages/conversation-flow/src/transformation/ContextTreeBuilder.ts
@@ -101,12 +101,18 @@ export class ContextTreeBuilder {
const agentCouncilNode = this.createAgentCouncilNodeFromChildren(message, idNode);
contextTree.push(agentCouncilNode);
- // Continue processing children of the last member (for supervisor final reply)
- // The supervisor's reply has parentId pointing to the last agent's message
- const lastChild = idNode.children.at(-1);
- if (lastChild && lastChild.children.length > 0) {
- // Process the first child of the last agent (supervisor's reply)
- this.transformToLinear(lastChild.children[0], contextTree);
+ // Continue from every member to surface the supervisor's post-council reply.
+ // The reply attaches to exactly ONE member, but which member is non-deterministic:
+ // broadcast agents finish near-simultaneously so their createdAt values tie, and the
+ // writer anchors the reply to the createdAt-last member while the tree preserves
+ // input-array order β€” the two can disagree. Walking only children.at(-1) would strand
+ // the reply. Only the member carrying it has children, so iterating every member emits
+ // it exactly once and keeps contextTree in agreement with flatList (FlatListBuilder
+ // applies the same all-member continuation).
+ for (const child of idNode.children) {
+ if (child.children.length > 0) {
+ this.transformToLinear(child.children[0], contextTree);
+ }
}
return;
}
diff --git a/packages/conversation-flow/src/transformation/FlatListBuilder.ts b/packages/conversation-flow/src/transformation/FlatListBuilder.ts
index d3f70e48397..6b4526bbae4 100644
--- a/packages/conversation-flow/src/transformation/FlatListBuilder.ts
+++ b/packages/conversation-flow/src/transformation/FlatListBuilder.ts
@@ -74,11 +74,16 @@ export class FlatListBuilder {
);
flatList.push(agentCouncilMessage);
- // Continue processing children of the last member (for supervisor final reply)
- // The last member's children should be processed next
- const lastMemberId = children.at(-1);
- if (lastMemberId) {
- this.buildFlatListRecursive(lastMemberId, flatList, processedIds, allMessages);
+ // Continue from each member's children to surface the supervisor's post-council reply.
+ // The reply attaches to exactly ONE member, but which member is non-deterministic:
+ // broadcast agents finish near-simultaneously so their createdAt values tie, and the
+ // writer anchors the reply to the createdAt-last member while childrenMap preserves
+ // input-array order β€” the two can disagree. Walking only children.at(-1) would strand
+ // the reply (and everything after it) whenever they disagree. Members are already in
+ // processedIds, so recursing into every member only emits the reply chain; the
+ // processedIds guard keeps it from duplicating anything.
+ for (const memberId of children) {
+ this.buildFlatListRecursive(memberId, flatList, processedIds, allMessages);
}
return;
}