Repository navigation
Commit 03626b2
committed
gateway: an item a batch's tool results were interrupted by goes after them, so strict Responses upstreams stop refusing the relayed request
What: the normalization a relayed Responses request goes through before it
leaves (gateway.go, attempt) gains joinToolRuns beside orphanedToolOutputs
and pairToolItems: an item that sits inside a run of tool calls and results
- between a call and the result that answers it - is moved to the end of
that run. A run is open while one of its calls has been seen and the result
answering it is still ahead, so an item between two whole exchanges stays
where it is. Codex writes such an item itself: when a tool returned an
image it resized, its <image_resize_notice> goes between one batch's two
results (the report from the Codex app on Windows, one assistant step with
view_image and exec_command).
Before, the run reached the upstream with the item inside it and a strict
one refused the whole request with 400: Volcengine's Agent Plan "An
assistant message with 'tool_calls' must be followed by tool messages
responding to each 'tool_call_id'", OpenCode Zen/Go "No tool output found
for tool call <id>" - both naming a result that is in the request. After,
the results follow the calls, the item goes after them, and both answer
200. This is the rule the chat path has had since yetone#1275 (pairToolMessages
closes a run with its results, interrupted ones included, before another
message) and the same family as yetone#1341 (pairToolItems, a call nothing
answers), and it is applied before the request is relayed or translated,
so every destination whose own form is strict gets it in the same change.
The item's own bytes, its role and its order among the other non-tool items
are as they were. A request with no tool items, one whose exchanges are each
whole, and a body that is not a Responses request come back byte for byte
(TestJoinToolRunsLeavesWholeExchangesAlone). One expectation changed on
purpose: TestGrokGetsAgentMessageAsUser's turn holds a subagent's reply
between the send_message call and its output, and Grok is now given that
reply after the run. Its conversion is unchanged (same user message, same
"From <author> to <recipient>" header, same text and images) and only its
place moved, the way every other item Grok is handed keeps the place magpie
gave it; a review that knows Grok's backend needs the reply in place can
narrow the rule to messages other than agent_message.
Run:
- go test -tags nogui ./internal/gateway/: 2 failures, both red on
origin/main 6c1c0a7 as well and neither from this change -
TestClaudeAsRootEnv (a Linux-only expectation with no Windows guard) and
TestSweepBridgeProjectsTakesOnlyTheBridgesFolders (needs a symlink
privilege this Windows box doesn't hold). Everything else passes,
TestQueuedStreamKeptAliveOnceSentToItsVendor among them (that one failed
once on main under load; it is the queued-stream timing in the standards).
- the same run under a temporary HOME with GOPATH/GOMODCACHE/GOCACHE pinned
from go env: the same two failures.
- gofmt -l on the four changed files: nothing. go vet ./..., GOOS=linux go
vet -tags nogui ./..., GOOS=windows go vet ./...: clean. go build,
GOOS=windows go build, GOOS=linux go build -tags nogui: ok.
- without the change: with the one call-site line taken out,
TestResponsesRelayKeepsAToolRunTogether prints
`status 400: ... "Fake: An assistant message with 'tool_calls' must be
followed by tool messages responding to each 'tool_call_id'."`; the line
back, it passes.
- real upstreams, the reporter's shape (two parallel calls, an image
result, Codex's <image_resize_notice>, the second result), the same build
with the line and without it, streamed the way Codex sends it:
Volcengine Agent Plan / deepseek-v4.1-flash - run whole 200/200; the
notice between the results 400 "insufficient tool messages following
tool_calls message" then 200; any other note there 400 then 200.
OpenCode Zen/Go / deepseek-v4.1-flash - run whole 200/200; a note between
the results 400 "No tool output found for tool call call_b" then 200; the
notice between them 200/200, their gateway recognizing that one item.
- the reporter's own rebuilt turn (1399 items, from their rollout) to
Volcengine: refused "insufficient tool messages following tool_calls
message" without the change, past that check with it (what is left is the
input's length, 1.7M tokens, over the model's limit).
Not tried: a real Grok subscription - the reply's new place is unverified
against xAI's backend, though its conversion is unchanged and its plugin
(community plugins packages/grok) converts in place the same way; a real
ChatGPT (native Codex account) destination, which takes standalone tool
outputs itself and is left as it came; the Windows GUI. The OpenCode Zen/Go
400 of the original report is not reproduced by the reporter's own bytes:
with both results and the notice between them that gateway answers 200
before and after this change, so the report's refusal may be the follow-up
body assembled before the batch's last output was in it
(openai/codex#44604).
Refs: yetone#1341, yetone#1275. Reported as anomalyco/opencode#54698 and
openai/codex#44604.1 parent d0c587a commit 03626b2
4 files changed
Lines changed: 266 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2908 | 2908 | | |
2909 | 2909 | | |
2910 | 2910 | | |
| 2911 | + | |
2911 | 2912 | | |
2912 | 2913 | | |
2913 | 2914 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | 42 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
484 | 578 | | |
485 | 579 | | |
486 | 580 | | |
| |||
602 | 696 | | |
603 | 697 | | |
604 | 698 | | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
| 699 | + | |
611 | 700 | | |
612 | 701 | | |
613 | 702 | | |
| |||
0 commit comments