Repository navigation
Conversation
Google's OpenAI-compatible endpoint streams each parallel tool call as a whole chunk with a unique id and no index. The capture in testdata comes from gemini-4-neon through the Coder AI gateway. These tests fail until the stream accumulator stops keying such calls on the decoded index, which is 0 for every call.
Stream tool calls were keyed by index. A delta without an index decodes as 0, so every parallel call from Google's OpenAI-compatible endpoint merged into one call with concatenated arguments. A delta without an index now starts a new call when it carries a new id, or a name without an id after the previous call's arguments are complete JSON. Other unindexed deltas continue the latest call. Indexed deltas are handled as before.
Replace draft comment markers with brief rationale on the unindexed tool-call helpers and the streaming test fixture.
Reviewers found shapes the index-less rule mishandles: an index 0 opener continued by unindexed fragments, interleaved fragments correlated only by id, a whitespace fragment after complete arguments, a name change on a call without arguments, and an explicit index that lands on a key a synthetic call already took. collectCalls now also checks the per-call part sequence and names.
The previous rule compared each unindexed delta only with the latest unindexed call and allocated keys as latest+1, so interleaved ids split, an indexed opener lost its unindexed fragments, and a later explicit index could overwrite a synthetic call. Unindexed deltas now continue the call with the same id, or the most recently touched call when they carry no id and do not look like a new call. Fresh keys never collide: an explicit index whose key is taken maps to a fresh key. Streams with only indexed deltas keep key equal to wire index. Skipped empty deltas no longer move any state.
Replace draft comment markers on toolCallKeys and collectCalls, and update the tool-call finalization comment to reflect key ordering for synthetic and remapped calls.
This comment has been minimized.
This comment has been minimized.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
|
Chat: Review posted | View chat Review history
deep-review v0.13.1 | Round 12 | Last posted: Round 12, 16 findings (8 P2, 8 P3), APPROVE. Review Finding inventoryFinding inventory: #89Findings
Contested and acknowledgedCRF-5 (P2, providers/openai/language_model.go:192) -
|
| Reviewer | Focus |
|---|---|
| Bisky | tests |
| Chopper | ops/errors |
| Churn-guard | change verification |
| Ging | language modernization |
| Gon | naming |
| Hisoka | edge cases |
| Killua | perf |
| Kite | change integrity |
| Knov | contracts |
| Knuckle | SQL |
| Komugi | flake/determinism |
| Kurapika | security |
| Law | decomposition |
| Leorio | docs |
| Luffy | product |
| Mafu-san | process |
| Mafuuu | contracts |
| Melody | dispatch/pairing |
| Meruem | structural |
| Nami | frontend |
| Netero | mechanical checks |
| Pariston | premise testing |
| Pen-botter | product gaps |
| Razor | verification |
| Robin | duplication |
| Ryosuke | Go arch |
| Takumi | concurrency |
| Zoro | shape |
🤖 Managed by Coder Agents.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
This PR assigns streamed tool calls without a wire index to their own keys by id, then by name and argument shape. 1 P2 and 2 P3 findings; as requested, the review is limited to P0 to P2 plus closely related P3.
Out of scope (needs a ticket or explicit acceptance by a human):
providers/kronk/language_model.go:396: streamed tool calls are keyed bytc.Indexalone, so unindexed or same-index parallel calls merge into one call with concatenated arguments.providers/openai/language_model.go:701:tool_calls[].extra_content.google.thought_signature, present in the Gemini fixture, is not read or sent back, so Gemini models that require signed function calls may reject the follow-up request (unverified against the live endpoint).agent.go:1707: Gemini ends tool turns withfinish_reason: "stop", soAgent.Streamdoes not run the now-separated calls, andAgent.Generateruns them and then ends the loop atagent.go:638without sending the results to the model.providers/openai/language_model.go:574:toolCallsandcallKeysare shared across allchunk.Choices, so withn > 1calls from different choices share keys andlatest.providers/openai/language_model.go:811: the key collection and sort could beslices.Sorted(maps.Keys(toolCalls)); behavior is the same.
🤖 This review was automatically generated with Coder Agents.
Adds rows for an unindexed opener continued by indexed deltas with the same id, an unindexed delta continuing an indexed call by id, and a same-name delta with empty arguments after complete arguments.
An unindexed opener followed by a continuation that carries the same
id and an index took a fresh key, so the call split into two calls
with the same id. A wire index seen for the first time now binds to an
existing call with the delta's id, as long as no wire index already
maps to that call. Indexed-only streams never match, so their keys
stay equal to the wire index.
A same-name delta with empty arguments after complete arguments also
started a phantom call dispatched with "{}". Only non-empty arguments
that start with "{" or "[" now open a new same-name call.
Update toolCallKeys, forWireIndex, and opensArguments comments to match wire-index binding by id and the non-empty opening-arguments rule.
This comment has been minimized.
This comment has been minimized.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
This comment has been minimized.
This comment has been minimized.
coder/coder chatd fails closed on a duplicate tool use id, so a second call that reuses an id must reach it as its own call. Adds rows for a named delta reusing the id of a complete or incomplete unindexed call, with and without a new wire index, and for a different id at a bound wire index. collectCalls now tracks calls that share an id separately.
d01fedb bound a first-seen wire index to any unindexed call with the same id, so a named second call with a duplicate id merged into the first and chatd no longer saw the collision. A wire index now binds only for a nameless continuation. An unindexed named delta whose id matches a call with complete arguments starts a second call with that id. A delta with a different non-empty id at a bound wire index now starts a new call, which separates parallel calls that Ollama and LiteLLM send on index 0. Spec streams send the id only on the first delta or repeat it, so their keys are unchanged.
Update toolCallKeys and collectCalls comments for nameless id binding, bound-index id changes, duplicate-id separation, and per-call lifecycle tracking.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
…openers Gemini's OpenAI-compatible endpoint is reported to sometimes send parallel calls with an empty id, so two whole id-less calls must stay two calls. An indexed opener continued by an index-less fragment must stay one call, as on coder_2_33.
A named index-less delta with an empty id continued the latest call, merging id-less parallel calls into invalid JSON, and an index-less fragment after an indexed opener started a separate nameless call. A named index-less delta now starts a new call unless its id equals the latest call's id. A nameless one continues the latest call of either kind, so the latest key now follows indexed calls too.
Update unindexedToolCallKey, fallbackNumber, and latestKey comments for starting new index-less calls on a function name and continuing the latest call of either kind on nameless deltas.
This comment has been minimized.
This comment has been minimized.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
This comment has been minimized.
This comment has been minimized.
Id-less fragments that repeat the function name before the arguments complete, alone or after an opener with an id, must stay one call as on coder_2_33.
…gments An id-less delta with a function name always started a new index-less call, splitting fragments that repeat the name into calls with unparseable input. Such a delta now continues the latest call while that call's arguments are non-empty and not yet valid JSON.
Update unindexedToolCallKey comment to note that an id-less named delta continues latest while latest's arguments are non-empty and incomplete JSON.
This comment has been minimized.
This comment has been minimized.
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
An id-less named delta for tool g after an unfinished call to f must start its own call, so f never runs with g's arguments.
…alls An id-less named delta continued any unfinished call, so a call to a different tool could append its arguments to the previous one. It now continues only when the name matches. The JSON check also moves behind the name and id checks, so nameless fragments no longer re-parse the accumulated arguments on every delta.
Update unindexedToolCallKey comment to reflect that id-less unfinished continuation requires the same tool name.
|
@codex review
|
|
/coder-agents-review Please limit the review to P0, P1, P2 issues only. Include only highly relevant P3 issues.
|
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
This round returns early for nameless index-less deltas before the JSON check and requires the same tool name before an id-less delta continues an unfinished call. A 100 KB call streamed in 10,000 index-less fragments now parses in about the same time as the indexed stream (0.67 s vs 0.61 s, was 2.35 s), a call to another tool after an unfinished call stays separate, and the other shapes the review tracks are unchanged. No new findings at P0 to P2 or closely related P3.
Still awaiting a human decision from earlier rounds: the index-reuse merge listed under Known limits has no linked ticket. File one or explicitly accept the gap.
🤖 This review was automatically generated with Coder Agents.
Relates to CODAGT-1658
Google's OpenAI-compatible Chat Completions endpoint streams each parallel tool call whole in its own chunk and omits
tool_calls[].index. The Go SDK decodes an absent index as0, andproviders/openai/language_model.gokeys accumulated calls bytoolCallDelta.Index, so every parallel call in a turn merged into key0with concatenated arguments like{..}{..}.To fix, only deltas with
!toolCallDelta.JSON.Index.Valid()take a new path; indexed deltas take the existingcoder_2_33path unchanged (key = wire index):math.MinInt64, staying far below any wire index providers send so they finalize before indexed calls in arrival order. The next slot advances only after a call is stored there, so skipped empty deltas allocate nothing.idequal to the latest call's id, or it has no id with the same tool name while the latest call's arguments are non-empty and not yet valid JSON. A nameless index-less delta continues the latest call of either kind (indexed or index-less), or starts one when none exists.latestKeyfollows the latest call of either kind touched by a delta with a name or arguments.tool-call-Nfallback id numbers new index-less calls from0instead of exposing the negative map key.An index-less stream that ends at clean EOF without a finish reason after whole calls now has those calls dispatched, following the same rule indexed streams already use; before, the merged arguments failed to parse and the step retried.
Known limits: streams that reuse one wire index across several calls (such as Ollama or LiteLLM on
index: 0) still merge as before. A same-name index-less delta with empty arguments after a complete call starts a second call; no provider is known to send that shape.providers/kronk/language_model.goalso keys streamed tool calls by index and is left untouched.Verified with
go test ./providers/openaicompat/ -run Unindexed -count=1:TestStream_UnindexedGeminiParallelToolCalls: replays a captured three-call stream from Google's OpenAI-compatible endpoint.TestStream_UnindexedToolCallShapes: id-less fragments, repeated id and name, nameless fragments with a fresh id each, two calls in one chunk, id-less whole calls start one call each, id-less fragments repeating the name before the arguments complete, opener with an id continued by id-less named fragments, id-less named call for another tool after an unfinished call, indexed opener continued by an index-less fragment, indexed deltas unchanged, and indexed plus index-less calls in one stream not colliding.Implementation plan and decision log
An earlier revision of this PR added a unified tracker for mixed indexed/unindexed streams and index-reuse shapes raised during review. We cut it back to this minimal change because no provider we target sends those mixed shapes and the broader heuristic altered behavior on indexed streams.
stopfinish mapping: unchanged. Google reportsstopon tool-call turns;chatdcollects tool calls regardless of finish reason, Coder does not use fantasy'sAgentstream loop, and remappingstopwould affect every provider.id(Chat Completions streaming merges parallel tool calls when deltas have noindexopenai/openai-agents-js#2116), so a named index-less delta opens a new call unless its non-emptyidmatches the latest call's id or it has no id with the same tool name while the latest call's arguments are non-empty and not yet valid JSON. A nameless index-less fragment continues the latest call of either kind (indexed or index-less), preserving base behavior for an indexed opener followed by index-less fragments.math.MinInt64upward): stays far below any wire index providers send (including negative indexes such as Bedrock's-1) without a separate tracking map, keeps index-less calls in arrival order on key sort, and keeps fallback IDs zero-based for new index-less calls viatoolCallDelta.Index - firstUnindexedToolCallKey.