Repository navigation
fix(ai): route response events by output index - #45013
Merged
Merged
Conversation
3 of 6 tasks
jinhuang712
pushed a commit
to jinhuang712/opencode
that referenced
this pull request
Sep 26, 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.
Summary
response.output_item.addedand route subsequent text, refusal, reasoning, and function-argument events by authoritativeoutput_indexitem_idrouting for compatible providers that omit output indexes and preserve validation of missing required item IDsBefore and after
Responses events identify an output slot with
output_index; subsequent events also includeitem_id, but the official accumulator routes through the output slot:{ "type": "response.output_item.added", "output_index": 1, "item": { "type": "function_call", "id": "fc_1", "call_id": "call_1", "name": "first" } } { "type": "response.output_item.added", "output_index": 3, "item": { "type": "function_call", "id": "fc_2", "call_id": "call_2", "name": "second" } } { "type": "response.function_call_arguments.delta", "output_index": 1, "item_id": "fc_2", "delta": "{\"a\":" } { "type": "response.function_call_arguments.delta", "output_index": 3, "item_id": "fc_1", "delta": "{\"b\":" }Before: OpenCode ignored
output_index, so the argument fragments were associated with the wrong tool calls.After: Registered output slots are authoritative: the first fragment belongs to
call_1and the second belongs tocall_2, matching the official Responses accumulator. Streams without registered output indexes continue using their existingitem_idbehavior.Verification
bun test test/partial-json.test.ts test/tool-stream.test.ts test/provider/openai-responses.test.ts test/provider/openai-compatible-responses.test.ts test/provider/openai-responses-websocket.recorded.test.ts test/provider/openai-chat.test.ts test/provider/anthropic-messages.test.ts test/provider/bedrock-converse.test.ts test/provider/xai-responses.test.ts test/response.test.ts test/tool-runtime.test.ts --timeout 30000 --only-failures(363 passing)RECORDED_PREFIX=openai-responses bun test test/provider/golden.recorded.test.ts --timeout 30000 --only-failuresbun typecheckfrompackages/aibunx prettier --check packages/ai/src/protocols/open-responses.ts packages/ai/src/protocols/openai-responses.ts packages/ai/test/provider/openai-responses.test.ts packages/ai/test/provider/openai-compatible-responses.test.ts packages/ai/test/provider/xai-responses.test.ts