ag-ui-protocol / ag-ui-protocol/ag-ui
[Bug]: [langgraph/typescript] Text content dropped when tool_call_chunk arrives in the same chunk; text↔tool stream transitions lose events
- Lingua principale
- Python
- Stelle
- 15.9k
- Fork
- 1.4k
- Merge medio
- 1g 17h
- PR unite (30g)
- 163
Descrizione
## Description
The TypeScript `OnChatModelStream` handler uses mutually-exclusive boolean flags and an `if/break` ladder, which causes three related silent-drop bugs when a chunk carries mixed payloads or the stream type changes mid-sequence.
### Bug A — Interleaved text + tool in one chunk
Some providers (e.g. Anthropic) emit a single chunk with both `content` text and a `tool_call_chunk`. The guard:
```ts
const isMessageContentEvent = Boolean(!toolCallData && messageContent);
```
evaluates to `false` whenever `toolCallData` is present. Text is silently dropped; only the tool event is routed.
```ts
// chunk: { content: "Looking that up", tool_call_chunks: [{ id: "tc-1", name: "search" }] }
// Actual: TOOL_CALL_START only
// Expected: TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, TEXT_MESSAGE_END, TOOL_CALL_START
```
### Bug B — text→tool transition: TOOL_CALL_START is lost along with all subsequent arg chunks
When a text message is open and the next chunk opens a new tool call:
```ts
const isToolCallStartEvent = !hasCurrentStream && toolCallData?.name;
// → false, because hasCurrentStream is true (text message open)
```
`TEXT_MESSAGE_END` fires and breaks. The tool call is never opened, so every subsequent arg chunk is also dropped (no `toolCallId` was ever recorded).
### Bug C — tool→text transition: text content dropped
When a tool call is open and a chunk arrives with text but no `tool_call_chunk`, `isToolCallEndEvent` fires and breaks. Any text content on the same chunk is dropped.
## Root cause
All three bugs share the same design: the handler picks **at most one** payload kind per chunk via an early-break ladder. A chunk that carries multiple payload kinds cannot be correctly handled.
## Affected component
`integrations/langgraph/typescript`
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.