🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(hetero): keep messages sent after a text-only wake-up visible (#22597)
Arvin Xu483f6a015d1c
diff --git a/packages/conversation-flow/src/transformation/FlatListBuilder.ts b/packages/conversation-flow/src/transformation/FlatListBuilder.tsindex 91b87b6e11d..a896ab0a268 100644--- a/packages/conversation-flow/src/transformation/FlatListBuilder.ts+++ b/packages/conversation-flow/src/transformation/FlatListBuilder.ts@@ -618,8 +618,8 @@ export class FlatListBuilder {processedIds: Set<string>,allMessages: Message[],): FlatListWork {- // A text-only wake-up never hosts a follow-up, so a run ending on one is- // continued from the step before it.+ // A text-only wake-up never hosts the run's next step, so a run ending on+ // one is continued from the step before it.const lastAssistant =assistantChain.findLast((assistant) => !isToollessSignalTurn(assistant)) ??assistantChain.at(-1);@@ -630,7 +630,7 @@ export class FlatListBuilder {yield this.continueGroupMemberReplies(assistantChain, flatList, processedIds, allMessages);const parentIds = [- ...(lastAssistant ? [lastAssistant.id] : []),+ ...this.messageCollector.collectFollowUpHostIds(assistantChain, lastAssistant),...allToolMessages.map((toolMessage) => toolMessage.id),];diff --git a/packages/conversation-flow/src/transformation/MessageCollector.ts b/packages/conversation-flow/src/transformation/MessageCollector.tsindex a68d6cc630c..5dae7c7664d 100644--- a/packages/conversation-flow/src/transformation/MessageCollector.ts+++ b/packages/conversation-flow/src/transformation/MessageCollector.ts@@ -561,6 +561,17 @@ export class MessageCollector {return blocks;}+ /**+ * Chain steps whose children continue the conversation after the group: the+ * step the run ended on, plus every text-only wake-up. A wake-up is the last+ * thing the user saw when it closes a run, so their next message hangs off it.+ */+ collectFollowUpHostIds(assistantChain: Message[], lastAssistant?: Message): string[] {+ return assistantChain+ .filter((assistant) => assistant === lastAssistant || isToollessSignalTurn(assistant))+ .map((assistant) => assistant.id);+ }+/*** User turns that interrupted a folded group at `assistant`, an intermediate* step whose next step in the chain is `next`. Branch selection among them@@ -849,8 +860,9 @@ export class MessageCollector {* Return the final same-agent assistant that belongs inside this group and* can host what follows it. The child selected after that assistant can be* either a tool-hosted legacy continuation or a direct non-tool continuation- * in the current storage form. A text-only wake-up never hosts a follow-up,- * so a run ending on one keeps the step before it.+ * in the current storage form. A text-only wake-up never hosts the run's next+ * step, so a run ending on one keeps the step before it, unless the user+ * replied to that wake-up.*/private findLastAssistantNodeInGroup(idNode: IdNode, groupAgentId?: string): IdNode {// Iterative: a group's chain can be thousands of steps long.@@ -859,12 +871,21 @@ export class MessageCollector {let nextNode = this.findChainContinuationNode(current, groupAgentId, pending);while (nextNode) {const nextMessage = this.messageMap.get(nextNode.id);- if (!nextMessage || !isToollessSignalTurn(nextMessage)) current = nextNode;+ if (!nextMessage || !isToollessSignalTurn(nextMessage) || this.hasUserReply(nextNode)) {+ current = nextNode;+ }nextNode = this.findChainContinuationNode(nextNode, groupAgentId, pending);}return current;}+ private hasUserReply(idNode: IdNode): boolean {+ return idNode.children.some((child) => {+ const message = this.messageMap.get(child.id);+ return message?.role === 'user' && !message.threadId;+ });+ }+/*** Resolve the first node after an AssistantGroup without applying* `activeBranchIndex` to tool children. Persisted branch indexes count onlydiff --git a/packages/conversation-flow/src/transformation/__tests__/signalTurnWithTools.pipeline.test.ts b/packages/conversation-flow/src/transformation/__tests__/signalTurnWithTools.pipeline.test.tsindex c1c007bef77..1d9bacaaee3 100644--- a/packages/conversation-flow/src/transformation/__tests__/signalTurnWithTools.pipeline.test.ts+++ b/packages/conversation-flow/src/transformation/__tests__/signalTurnWithTools.pipeline.test.ts@@ -173,6 +173,65 @@ describe('signal turn that emits tools — spine promotion (tpc_aGIggi9N8DpK)',* (STALE). The final answer was missing from the UI in the STALE shape, and the* closing reply was missing in both.*/+describe('user replies anchored on a text-only wake-up that ends the run', () => {+ const step = (id: string, parentId: string, createdAt: number, extra: Partial<Message> = {}) =>+ ({+ agentId: 'a',+ content: id,+ createdAt,+ id,+ parentId,+ role: 'assistant',+ updatedAt: createdAt,+ ...extra,+ }) as Message;+ const user = (id: string, parentId: string, createdAt: number) =>+ ({ content: id, createdAt, id, parentId, role: 'user', updatedAt: createdAt }) as Message;++ const run: Message[] = [+ { content: 'go', createdAt: 0, id: 'u1', role: 'user', updatedAt: 0 },+ step('RUN', 'u1', 100, { tools: toolArr('bash') }),+ {+ content: 'ok',+ createdAt: 110,+ id: 'tool',+ parentId: 'RUN',+ role: 'tool',+ tool_call_id: 'bash',+ updatedAt: 110,+ } as Message,+ step('REPLY', 'RUN', 120),+ step('WAKE', 'tool', 130, {+ metadata: {+ signal: { sourceToolCallId: 'bash', sourceToolName: 'Bash', type: 'task-completion' },+ } as any,+ }),+ ];++ it('keeps the conversation that continues from the wake-up', () => {+ const { contextTree, flatList } = parse([+ ...run,+ user('u2', 'WAKE', 200),+ step('a2', 'u2', 210),+ ]);++ expect(flatList.map((m) => m.id)).toEqual(['u1', 'RUN', 'u2', 'a2']);+ expect(contextTree.map((node) => node.id)).toEqual(['u1', 'RUN', 'u2', 'a2']);+ });++ it('renders both turns when a later send forks on the same wake-up', () => {+ const { flatList } = parse([+ ...run,+ user('u2', 'WAKE', 200),+ step('a2', 'u2', 210),+ user('u3', 'WAKE', 300),+ step('a3', 'u3', 310),+ ]);++ expect(flatList.map((m) => m.id)).toEqual(['u1', 'RUN', 'u2', 'a2', 'u3', 'a3']);+ });+});+describe('wake-up turns that call tools after a toolless closing reply', () => {const wakeUpScenario = (parentOfWake2: 'toolRead1' | 'toolWait'): Message[] => [{ content: 'go', createdAt: 0, id: 'u1', role: 'user', updatedAt: 0 },