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

Abierto
#2,008 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug Integration
Lenguaje dominante
Python
Estrellas
15.9k
Forks
1.4k
Merge medio
1 d 17 h
PR fusionados (30 d)
163

Descripción

## 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`

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.