responses: the client tool contract has no canonical representation — deferred tools, discovered names and custom tools cannot survive a proxy hop
Is it a request payload issue? [ ] Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error. [x] No, it's another issue.
If it's a request payload issue, you MUST know
N/A — this is not a single malformed request. Every turn of every task on a bridged route is affected. Reproduction needs a client that speaks the client-executed tool_search protocol, not a cURL.
Describe the bug
Summary
The Responses client tool protocol has two client-executed shapes — tool_search discovery and custom (free-form, optionally grammar-constrained) tools — and neither maps onto a plain function tool list. The proxy currently only forwards the declared tool list, so on any upstream that does not natively implement this protocol the round trip is broken in four independent ways at once. This issue covers the structural root cause: there is no representation of the client tool contract at all.
Observed behavior
- Deferred tools are expanded before the client ever searched. Codex-style clients only defer tool definitions when the selected model advertises
supports_search_tool. When it does not, the client falls back to injecting the whole tool surface — the top-leveltoolsarray andinput.additional_tools— into the first request of every turn. Measured on 2026-09-26 with the Codex 0.156.1 desktop client on non-OpenAI routes, that fallback put roughly 120K input tokens into the opening request of a task, almost all of it tool definitions the model never called. The cost is paid on every turn: latency, a prefix cache miss, and per-request spend. - Discovered tool names come back renamed. The model can only emit a flattened name (and upstream caps function names at 64 characters), so
fs.readunder namespacefsand a flat tool literally namedfs_readare indistinguishable on the wire. - The model's search call and the client's search result stop matching. A
tool_search_callitem and thetool_search_outputthe client answers with are protocol items; an upstream that only understandsfunction/function_call_outputeither rejects them or silently drops the pairing, so the loop never closes. customcalls are rejected by upstreams that accept only strict function schemas.
Root cause chain
internal/runtime/executor/*andinternal/translator/*treattoolsas an opaque list that is copied through. Nothing parses it, so nothing can act on it.- There is no canonical identity for a declared tool. A tool is only a name string, so namespace, local name and protocol kind cannot be distinguished, and a flattened name cannot be mapped back.
- Because there is no model of the contract, the proxy cannot know which tools the client declared as deferred, which ones a discovery round actually returned, or which items in the conversation history were produced by a tool call.
- Because there is no identity, any adaptation (flattening, capping, translating to a chat-shaped tool list) is irreversible.
CLI Type
codex (also affects meta and xai, which speak the same Responses wire format through the same translator, and every chat-shaped upstream: claude, gemini, vertex, aistudio, kimi, antigravity, openai-compatible-*).
Model Name Any. The blow-up is worst on aliases with large tool surfaces (filesystem, shell, MCP catalogs).
LLM Client
Codex 0.156.1 desktop client. Any client implementing client-executed tool_search / custom is affected.
Request Information
Not a cURL reproduction — the trigger is a client that declares the protocol, e.g. a first turn that carries deferred declarations instead of a materialized tool list:
// POST /v1/responses — shape the client emits when the model advertises
// supports_search_tool. A proxy that cannot close the loop gets the fallback
// shape instead: the full tool surface inlined into the first request.
{
"model": "gpt-5.6",
"input": [
{ "type": "message", "role": "user", "content": [{ "type": "input_text", "text": "read the config" }] }
],
"tools": [
{ "type": "tool_search", "execution": "client", "parameters": { "type": "object", "properties": { "queries": { "type": "array", "items": { "type": "string" } } } } }
],
"additional_tools": [ /* deferred declarations, never searched yet */ ]
}With request-log: true in config.yaml the inflated first request is directly observable: compare the tools + additional_tools byte size of turn 1 against turn 2 of the same task.
Expected behavior
The proxy parses the client tool contract once per request into a canonical model that carries, for every declaration: its namespace, its local name, its protocol kind (function / custom / tool_search), whether it was declared upfront or learned from a discovery round, and the activation alias minted for it. That model is the single place that knows which tools are deferred and which are already activated, and it is what every later adaptation (search bridge, custom bridge, history replay, response restore) must be derived from.
Screenshots N/A.
OS Type
- OS: macOS
- Version: 26.x / arm64 (reproduced on Linux and macOS; not platform specific)
Additional context
Scope in this issue
- A new core package that depends only on the Go standard library — never on auth, Gin, the plugin host, or network transport.
- The protocol field and item names the contract recognises:
tool_search,custom,custom_tool_call,custom_tool_call_output,tool_search_call,tool_search_output,additional_tools, nested namespace containers, and theexecutionfield. Only the names that need a single definition across the package are constants today (tool_search, the namespace container type, and the deferred-entry key); the remaining item names are literals at their use sites, so a reviewer should expect to find them in several files rather than in one table. ToolIdentity{Namespace, Name, Kind}as the canonical identity, with deterministic flattening (RawQualifiedToolName,JoinNamespace,CapToolNamefor the 64-character upstream limit,HashedToolAliasfor collision-resistant activation aliases) and a normalized form (NormalizeToolName) for fuzzy matching.- Parsing of a raw request body into a
ToolContract, returningnilwhen the body carries no tool metadata so unmatched routes pay no JSON parse. PayloadUsesToolProtocolso a caller can decide whether a turn needs rewriting at all — required by the WebSocket replay gate.- A fixed error taxonomy (
ToolCompatibilityError+Reasonconstants) that never attaches payloads, prompts, grammars or credentials, and that reports request-scoped failures as availability-neutral so credential rotation and cooldown are never triggered by a client-shape problem.
Out of scope
No behavior change. This issue lands the representation only; every route still passes requests through byte-for-byte. Wiring, strategy resolution, and the actual bridges are separate issues.
Invariants
- Two declarations that differ in namespace, local name, or kind are distinct tools even when their flattened upstream names collide.
- Ambiguity is never resolved by guessing: an ambiguous display name must fail rather than pick one.
- Pure computation only. No network, no tool execution, no global state.
Related issues
This is the foundation for the bridge, custom-tool, identity-fidelity, budget, and capability-declaration issues in this series.
Source: router-for-me/CLIProxyAPI