Skip to content

fix(codex): make tools work on gpt-5.6 — additional_tools + custom-tool round-trip (#4231) - #57

Merged
wangcansunking merged 2 commits into
masterfrom
worktree-codex-additional-tools
Jul 25, 2026
Merged

wangcansunking merged 2 commits into
masterfrom
worktree-codex-additional-tools

Conversation

@wangcansunking

Copy link
Copy Markdown
Owner

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/responses path:

  1. Tools were dropped. Codex 0.145+ (gpt-5.6 family) sends no top-level tools — they ride inside an additional_tools item in input. responses-inbound.ts didn't know that item type and dropped it, so the canonical request reached Copilot with zero tools.

  2. Custom tools were mistranslated. Codex's primary tool exec is a custom tool (freeform-string input, not JSON). We flattened custom → function, so the model emitted empty {} and Codex rejected 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.

Fix

  • Inbound (responses-inbound.ts): collectTools() merges additional_tools[].tools with top-level tools; custom tools kept as {custom:true}; custom_tool_call / custom_tool_call_output history mapped (raw-string input); the ResponsesSSE emitter + non-stream builder serialize a custom tool as custom_tool_call + custom_tool_call_input.delta/.done (never function_call).
  • 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 canonical tool_use{custom:true}.
  • Canonical: CanonicalTool.custom, ToolUseBlock.custom, tool_use_start.custom.
  • Mirrors agent-maestro's approach (#208 extractAdditionalTools + the isCustom output branch).

Verification

  • 697 unit/e2e tests pass (+7 new: additional_tools extraction, custom-tool body/parse/stream both ways, custom SSE emitter, EP-42/EP-43).
  • Live end-to-end against real Copilot with 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.
  • Added a cli-e2e case pinning gpt-5.6 (SKIPs if the model is absent from the account) + a golden http-e2e round-trip.

⚠️ Pre-merge gate note

The docker cli-e2e image could not be built in my environment — npm ci inside the container fails at the network layer (registry.npmjs.org returns 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 real codex CLI 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

wangcansunking and others added 2 commits July 25, 2026 12:09
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>
@wangcansunking
wangcansunking merged commit 7bbb699 into master Jul 25, 2026
6 checks passed
@wangcansunking
wangcansunking deleted the worktree-codex-additional-tools branch July 25, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant