🤯 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(chat): drop subagent-tagged events from the main gateway stream handler (#15814)
Arvin Xu8ee5f1c80623
diff --git a/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts b/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.tsindex d4eadeb1c6e..63a7d111c36 100644--- a/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts+++ b/src/store/chat/slices/aiChat/actions/__tests__/gatewayEventHandler.test.ts@@ -246,6 +246,44 @@ describe('createGatewayEventHandler', () => {expect(store.internal_dispatchMessage).not.toHaveBeenCalled();});++ it('should DROP subagent-tagged tool chunks so they do not leak into the main bubble', async () => {+ // Regression: on a live gateway / remote-CC stream, a subagent (Agent/Task)+ // inner tool chunk is tagged with `data.subagent`. It belongs to an+ // isolation Thread, not the main assistant. If dispatched here it appends+ // to the MAIN assistant's tools[] until the terminal DB refetch corrects it+ // ("流式时漏出来、结束后正常"). It must be dropped before any dispatch.+ const store = createMockStore();+ const handler = createHandler(store);++ handler(+ makeEvent('stream_chunk', {+ chunkType: 'tools_calling',+ subagent: { parentToolCallId: 'toolu_agent', subagentMessageId: 'sub-1' },+ toolsCalling: [{ id: 'inner-1' }],+ }),+ );+ await flush();++ // Not dispatched onto the main assistant, and no tool-calling spinner.+ expect(store.internal_dispatchMessage).not.toHaveBeenCalled();+ expect(store.internal_toggleToolCallingStreaming).not.toHaveBeenCalled();+ });++ it('should still dispatch a NON-subagent tool chunk (drop is scoped to subagent)', async () => {+ const store = createMockStore();+ const handler = createHandler(store);++ handler(+ makeEvent('stream_chunk', { chunkType: 'tools_calling', toolsCalling: [{ id: 'm-1' }] }),+ );+ await flush();++ expect(store.internal_dispatchMessage).toHaveBeenCalledWith(+ { id: 'msg-initial', type: 'updateMessage', value: { tools: [{ id: 'm-1' }] } },+ { operationId: 'op-1' },+ );+ });});describe('reasoning operation lifecycle', () => {diff --git a/src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts b/src/store/chat/slices/aiChat/actions/gatewayEventHandler.tsindex ddf5d4c0e0c..cdb0dc4a7be 100644--- a/src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts+++ b/src/store/chat/slices/aiChat/actions/gatewayEventHandler.ts@@ -267,6 +267,13 @@ export const createGatewayEventHandler = (return (event: AgentStreamEvent) => {if (terminalState) return;+ // Subagent (`Agent`/`Task`) inner-tool events are tagged `data.subagent` and+ // belong to an isolation Thread. This handler is main-agent-only, so+ // dispatching them leaks the subagent's tools into the parent bubble+ // mid-stream until the terminal fetch corrects it. The local executor drops+ // them before forwarding; the gateway path doesn't. (DB is unaffected.)+ if ((event.data as { subagent?: unknown } | undefined)?.subagent) return;+if (event.type === 'agent_runtime_end' || event.type === 'error') {terminalState = event.type === 'error' ? 'error' : 'completed';}