Skip to content

fix(streaming): deduplicate tool call emissions during streaming#9292

Merged
mudler merged 1 commit into
masterfrom
fix/streaming-tool-dedup
Apr 9, 2026
Merged

fix(streaming): deduplicate tool call emissions during streaming#9292
mudler merged 1 commit into
masterfrom
fix/streaming-tool-dedup

Conversation

@mudler

@mudler mudler commented Apr 9, 2026

Copy link
Copy Markdown
Owner

The Go-side incremental JSON parser was emitting the same tool call on every streaming token because it lacked the len > lastEmittedCount guard that the XML parser had. On top of that, the post-streaming default: case re-emitted all tool calls from index 0, duplicating everything.

This produced duplicate delta.tool_calls events causing clients to accumulate arguments as "{args}{args}" — invalid JSON.

Fixes:

  • JSON incremental parser: add len(jsonResults) > lastEmittedCount guard and loop from lastEmittedCount (matching the XML parser pattern)
  • Post-streaming default: case: skip i < lastEmittedCount entries that were already emitted during streaming
  • JSON parser: use blocking channel send (matching XML parser behavior)

Supersedes #9286

@mudler mudler added the bug Something isn't working label Apr 9, 2026
The Go-side incremental JSON parser was emitting the same tool call on
every streaming token because it lacked the len > lastEmittedCount guard
that the XML parser had. On top of that, the post-streaming default:
case re-emitted all tool calls from index 0, duplicating everything.

This produced duplicate delta.tool_calls events causing clients to
accumulate arguments as "{args}{args}" — invalid JSON.

Fixes:
- JSON incremental parser: add len(jsonResults) > lastEmittedCount guard
  and loop from lastEmittedCount (matching the XML parser pattern)
- Post-streaming default: case: skip i < lastEmittedCount entries that
  were already emitted during streaming
- JSON parser: use blocking channel send (matching XML parser behavior)
@mudler mudler force-pushed the fix/streaming-tool-dedup branch from 8b8a19d to cdbadc9 Compare April 9, 2026 19:57
@mudler mudler merged commit e1a6010 into master Apr 9, 2026
36 checks passed
@mudler mudler deleted the fix/streaming-tool-dedup branch April 9, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

1 participant