What: follow-up to Edward4226's joinToolRuns (previous commit), after review
against Codex rust-v0.162.1 and the code around it.
- An item carrying a call_id is never moved, whatever its type. Before, only
function_call/custom_tool_call/tool_search_call counted as calls, so a
local_shell_call (or any call type Codex adds) inside a run was moved after
results, its own output's among them.
- Before the run's first result, what the model wrote between its own calls
(reasoning, assistant text, a hosted tool's call) stays where it is. Before,
[call_a, reasoning, call_b, out_a, out_b] sent the reasoning after the
results, where it reads as the next step's: DeepSeek, whose step must lead
with its reasoning (reasonFirst, f4cc7459), would get a step that isn't.
Anything else there (a subagent's agent_message, a note) still moves after
the run, so TestGrokGetsAgentMessageAsUser's expectation from the previous
commit stands.
- A call opens a run only when a result after it answers it. Before, a result
written before its call (an odd replay) left the run open for the rest of
the request, and every later message was moved to its end.
Where it happens, checked in Codex's source: prepare_response_items
(core/src/image_preparation.rs) pushes the developer <image_resize_notice>
right after each function_call_output / custom_tool_call_output whose image
it resized, so a batch of two image results has it between them, as #1822's
rollout shows (lines 347-349).
Routes: joinToolRuns sits in attempt before every destination, so the
Responses relay, plugins (relayed through passthrough) and translations all
get it. Translations rebuilt the order themselves for a developer or user
item (the developer one is lifted into the system prompt, user turns merge
and results go first), but an assistant message between two results closed
the chat exchange: pairToolMessages answered the second call with the
synthetic "unavailable" result and sent the real one as user text
(TestTranslatedToolRunKeepsItsRealResults, red without the call site).
Docs: gateway-routing.md says what attempt mends in a Responses request's
tool exchanges (joinToolRuns, orphanedToolOutputs, pairToolItems).
Run:
- TestRelayedCodexImageBatchKeepsItsResultsTogether (#1822's call ids, two
view_image results, the notice between; the fake answers DeepSeek's "No
tool output found for tool call …") and TestTranslatedToolRunKeepsItsRealResults
fail with the call site removed (400 / synthetic result) and pass with it.
TestJoinToolRunsOnlyMovesWhatBreaksARun fails on the previous commit's
joinToolRuns (reasoning moved, local_shell_call moved, a request rewritten
for a result before its call) and passes now.
- go test -tags nogui -count=1 ./internal/gateway/ under a sandbox HOME with
a private GOCACHE: ok (376s). gofmt -l: nothing. go vet (darwin),
GOOS=linux go vet -tags nogui, GOOS=windows go vet on ./internal/gateway/:
clean.
- Real DeepSeek (api.deepseek.com/v1/responses, deepseek-v4-flash), direct:
a developer note between the two results 400 "No tool output found for
tool call call_01_x2"; the same note after the results 200. Through a
sandbox magpie (own HOME, :3591, only the deepseek provider), streamed and
whole: origin/main's build 400 with that refusal, this build 200. The
<image_resize_notice> text itself between the results is answered 200 by
DeepSeek directly, before and after, with text results.
Not tried: OpenCode Go (this account's workspace isn't set to Global
regions, so every request there is refused before the model); the
reporter's image results and full-length history; Volcengine; a real Grok
subscription for the agent_message's new place.
Co-authored-by: Edward4226 <234070868+Edward4226@users.noreply.github.com>