Repository navigation
fix(codex): make tools work on gpt-5.6 — additional_tools + custom-tool round-trip (#4231) - #57
Merged
Merged
Conversation
Codex 0.145+ (gpt-5.6 family) no longer sends tools at the top level of a
/responses request — it carries them inside an `additional_tools` item in
`input`. The Responses translator dropped that item, so the model reached
Copilot tool-less and could only narrate its tool calls as text ("I'm unable
to access a shell tool"). Every real Codex task on gpt-5.6 was dead.
Proven against a live `codex exec -m gpt-5.6-luna`: top-level tools=0, tools
ride an additional_tools item {role:"developer", tools:[custom exec, function
wait, function request_user_input]}.
Fix (mirrors agent-maestro #208):
- collectTools() merges additional_tools[].tools with the top-level tools
before the existing function/custom/hosted filter.
- itemToMessage() now maps custom_tool_call / custom_tool_call_output so a
multi-turn custom-tool (Codex's exec) session keeps its history; a custom
tool's `input` is a raw string, wrapped as {input:<string>}.
Tests: unit (additional_tools extraction, top-level+additional merge, custom
history) + hermetic e2e EP-42/EP-43 + a golden http-e2e round-trip + a real
cli-e2e case pinning gpt-5.6 that drives a shell tool loop (SKIPs if the model
is absent from the account).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… (#4231)
The additional_tools extraction (prior commit) made the model START calling
tools, but driving the REAL codex CLI revealed it was necessary-not-sufficient:
Codex's primary tool `exec` is a `custom` tool (freeform-string input), and we
flattened custom -> function. That made the model emit empty {} and Codex reject
the reply with "tool exec invoked with incompatible payload".
Probed live: Copilot /responses NATIVELY accepts {type:"custom"} tools and
returns a custom_tool_call. So the fix is a round-trip, not a flatten:
- canonical: CanonicalTool.custom + ToolUseBlock.custom + tool_use_start.custom
- inbound (responses-inbound.ts): keep custom tools as {custom:true}; map
custom_tool_call/_output history as raw-string tool_use; the ResponsesSSE
emitter serializes a custom tool_use as custom_tool_call +
custom_tool_call_input.delta/.done (NOT function_call), and
canonicalToResponsesResponse does the same on the non-stream path.
- outbound (responses-upstream.ts): emit {type:"custom"} for custom tools;
serialize a custom tool_use as custom_tool_call; parse custom_tool_call output
items + response.custom_tool_call_input.delta/.done stream events back to a
canonical tool_use{custom:true} with raw-string input.
Verified end-to-end against live Copilot with `codex exec -m gpt-5.6-luna`:
a real shell tool loop now runs through the proxy (single-step file write AND
multi-step create->read-back), filesystem as oracle. Before: tool-less text
narration, then an incompatible-payload crash loop. After: DONE + correct file.
+7 unit/e2e tests (custom tool body/parse/stream both ways, custom SSE emitter).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Using codex with a gpt-5.6 model, all tools are unavailable — the model can see the workspace but calls nothing; it narrates tool calls as text and says "I'm unable to access a shell tool." Matches router-for-me/CLIProxyAPI#4231 (gpt-5.6 broken, gpt-5.5 fine).
Root cause (proven by tapping a live
codex exec -m gpt-5.6-luna)Two distinct bugs, both on the
/openai/responsespath:Tools were dropped. Codex 0.145+ (gpt-5.6 family) sends no top-level
tools— they ride inside anadditional_toolsitem ininput.responses-inbound.tsdidn't know that item type and dropped it, so the canonical request reached Copilot with zero tools.Custom tools were mistranslated. Codex's primary tool
execis acustomtool (freeform-string input, not JSON). We flattenedcustom → function, so the model emitted empty{}and Codex rejected the reply with "tool exec invoked with incompatible payload." Probed live: Copilot/responsesnatively accepts{type:"custom"}tools and returns acustom_tool_call— so the fix is a round-trip, not a flatten.Fix
responses-inbound.ts):collectTools()mergesadditional_tools[].toolswith top-level tools;customtools kept as{custom:true};custom_tool_call/custom_tool_call_outputhistory mapped (raw-string input); theResponsesSSEemitter + non-stream builder serialize a custom tool ascustom_tool_call+custom_tool_call_input.delta/.done(neverfunction_call).responses-upstream.ts): emit{type:"custom"}for custom tools; serialize a customtool_useascustom_tool_call; parsecustom_tool_calloutput items +response.custom_tool_call_input.delta/.donestream events back to canonicaltool_use{custom:true}.CanonicalTool.custom,ToolUseBlock.custom,tool_use_start.custom.extractAdditionalTools+ theisCustomoutput branch).Verification
codex exec -m gpt-5.6-luna: a real shell tool loop now runs through the proxy — single-step file write (CODEX56_OK) and multi-step create→read-back (MULTI99), filesystem as oracle. Before: text narration → incompatible-payload crash loop. After:DONE+ correct file.cli-e2ecase pinning gpt-5.6 (SKIPs if the model is absent from the account) + a goldenhttp-e2eround-trip.The docker cli-e2e image could not be built in my environment —
npm ciinside the container fails at the network layer (registry.npmjs.orgreturns HTTP 000 / SSL handshake failure from both host and Docker VM; corporate egress block). This is environmental, not a code/Dockerfile issue. I validated the exact fix at higher fidelity by driving the realcodexCLI against live Copilot on the host (what cli-e2e wraps). Please run the docker cli-e2e once on a machine with npm-registry access before merging, per the repo's pre-merge mandate.🤖 Generated with Claude Code