AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

V3 Streaming: Tool-Call Block-Delta Events Are Snapshots Causing Quadratic Size Growth

In langchain-core v3 streaming, tool-call argument deltas are emitted as full snapshots of accumulated state, leading to O(n^2) event sizes for large arguments. This causes severe performance degradation and memory overhead in LangGraph Server and any consumer of the event stream.

highConfidence 95%LangchainAffected V1.6.6

Origin Analysis

The compat bridge (chunks_to_events/achunks_to_events) builds tool-call block-delta events from per-index accumulated state instead of the incoming chunk, sending a full snapshot of name, id, and all argument characters on every chunk. Text and data deltas correctly send only the new slice. This mismatch causes quadratic growth: n characters of arguments streamed in chunks of c produce about n²/(2c) characters in events.
Run the provided reproduction script with langchain-core 1.6.6. It streams a fake model with tool_call_chunks of increasing argument sizes and measures the total serialized size of content-block-delta events. Text deltas grow linearly; tool-call deltas grow quadratically (e.g., 64k chars → 0.42MB text vs 128.82MB tool-call).

Fixing Code Block

Edge Case Audit

This changes the public event stream schema: tool-call content-block-delta events will no longer contain a full snapshot of args. Any external consumer that relies on receiving the complete accumulated args in each event will break. Rollback: revert to snapshot emission and shallow-merge consumer. Version compatibility: the patch must be applied consistently to both the bridge and all consumers; mixing old and new versions within the same deployment will cause incorrect tool-call argument reconstruction. Concurrency: ensure thread-safety of any shared accumulated state when patching async versions.

Ecosystem Topology