Repository navigation
Conversation
This was referenced Nov 27, 2026
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
An upstream stream can deliver a tool call whose
argumentstext is damaged: a bare quote inside a value, a trailing comma, prose appended after the object, a string cut mid-value by the output limit, or a second same-name call that reusesindex: 0. Before this change the gateway either failed the whole round (arguments is invalid JSON) or merged two calls into one.Change
internal/translate/toolargs.go: repair formatting damage first (trailing commas, bare quotes, appended prose), then drop the trailing incomplete member so only fields the model finished writing remain, and use{}as the last resort. The repair never pads a value cut mid-string, sorm -rf /tmp/focannot turn intorm -rf /tmp/foo.internal/gateway/compat_stream.go/openai_stream.go/anthropic.go: keep same-tool calls separate when the upstream reusesindex: 0, and stream only normalized, complete argument fragments instead of raw damaged deltas.internal/gateway/openai_tool_normalizer.go: shared normalizer used by the OpenAI, Anthropic and Responses paths.Well-formed calls are byte-identical to before.
Trade-off to review
A truncated call is emitted with the fields that were complete (possibly
{}), so the client may invoke a tool the model did not finish writing. Dropping the unfinished field was chosen over inventing it, but this is a behavior change and worth a separate decision: an opt-out that fails the round instead is possible if maintainers prefer the old hard failure.Tests
go test ./internal/gateway ./internal/translatepasses.toolargs_stream_test.go,toolargs_test.go,toolargs_normalize_test.go).