fix(chat-bridge): keep index-less streamed tool-call fragments in one block - #264
Open
dex0shubham wants to merge 1 commit into
Open
fix(chat-bridge): keep index-less streamed tool-call fragments in one block#264dex0shubham wants to merge 1 commit into
dex0shubham wants to merge 1 commit into
Conversation
… block The Chat Completions SSE translator keyed tool-call deltas by `tc.index ?? state.calls.size`. Some OpenAI-compatible providers (the exact upstreams this bridge targets) omit `index` on continuation deltas and split a tool call's arguments across chunks. With `index` absent, each continuation fragment was keyed by the growing map size and opened a brand-new tool_use block, so Claude Code saw a truncated first block plus a spurious empty-named duplicate instead of one call. Disambiguate the way the OpenAI stream shape does: a delta carrying an id or name opens a new call; an args-only delta continues the most recent one (tracked via lastToolKey). Conformant streams that always send `index` are unaffected.
dex0shubham
force-pushed
the
fix/chat-bridge-toolcall-index
branch
from
September 2, 2026 07:14
57059c1 to
daedc8f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Chat Completions SSE translator (
chatStreamEventinmessages-chat-bridge.ts) keyed streamed tool-call deltas by:Some OpenAI-compatible upstreams — the arbitrary providers this bridge exists to support (Cloudflare Workers AI, Kimi, etc.) — omit
indexon tool-call deltas and split a single call'sargumentsacross chunks. Withindexabsent, each continuation fragment was keyed by the growingcalls.size, socalls.get(key)missed and a newtool_useblock was opened per fragment.Result for a two-chunk
{"q":+"cats"}call: a first block with truncated, invalid JSON plus a spurious second block with an empty name and duplicate id — instead of onetool_usewith{"q":"cats"}. The entire streamed-tool-call branch was untested.Fix
Disambiguate the way the OpenAI stream shape already signals it: a delta carrying an
idornameopens a new call; an args-only delta continues the most recent call (tracked via a newlastToolKeyon the stream state). Strictly-conformant streams that always sendindextake the unchanged path.Added a streaming regression test (index-less, split-arguments) — it opens two blocks on the old code and one on the fix.
Full suite green (1207/1207);
typecheckclean.