responses: the tool contract is not carried over WebSocket sessions

Author: hrygoCreated Sep 29, 2026Updated Sep 29, 2026

Is it a request payload issue? [x] Yes, this is a request payload issue. I am using a client/cURL to send a request payload, but I received an unexpected error. [ ] No, it's another issue.

If it's a request payload issue, you MUST know Reproduce over a downstream WebSocket connection rather than HTTP. The request bodies are identical; what differs is that the WebSocket handler reuses the session, so the second turn of a task arrives on a connection that already carries the first turn's tool state. request-log: true plus the client's own transcript shows the divergence between the two turns.

Describe the bug

Summary

The Codex client uses a WebSocket session for /v1/responses and treats the session as a live duplex channel rather than a sequence of independent requests. A per-request tool-protocol attempt therefore has no natural lifetime on that path: the connection persists, the conversation state persists, and the handler must decide per turn whether the session's incremental context is still valid. Nothing carries the tool contract across the session, so bridged tool state is lost or silently reused across turns.

Observed behavior

  • A bridged tool call made in turn 1 is not resolvable in turn 2 on the same WebSocket session, because the contract that produced it was scoped to the HTTP request and did not survive the session boundary.
  • The handler cannot tell whether a given frame needs the full tool contract or whether the session already established it, so it either replays the full contract on every turn (re-defeating the point of deferring tools) or skips it and breaks the loop.
  • The decision depends on the route, so the handler needs the provider, the upstream model, and the credential before it can choose a mode — information it does not have at frame-receive time in the current code shape.
  • Control frames in the session are not distinguished from tool-protocol frames, so a replay decision can be triggered by a frame that carries no tool state.

CLI Type All providers reachable over a downstream WebSocket session.

Model Name All.

LLM Client Codex desktop client over WebSocket.

Request Information

The two frames that decide the mode — a control frame that must not trigger a replay, and a turn that does carry protocol state:

jsonc
// control frame — carries no tool state, must not trigger a contract replay
{ "type": "response.cancel" }

// turn that does carry protocol state
{ "type": "response.create", "response": { "tools": [ /* tool protocol items */ ] } }

Expected behavior

  • The handler decides per turn whether the session requires a tool-contract replay, and it distinguishes control frames from protocol frames before deciding.
  • The decision uses the route, resolved from the payload, the client model, the provider, and the credential — so the mode matches the one the executor will actually use, rather than assuming the session's first-turn mode.
  • The check is cheap when the feature is off or the route cannot be bridged: it consults a "may this route need the bridge at all" predicate before parsing anything.
  • The native passthrough path is preserved, including live duplex steering, for routes that forward the protocol unchanged.
  • The executor input the handler builds for a WebSocket turn is identical to the HTTP turn's, so a session and a plain request cannot diverge.

Screenshots N/A.

OS Type

  • OS: macOS
  • Version: 26.x / arm64 (not platform specific)

Additional context

Scope in this issue

  • The WebSocket handler's tool-mode resolution: whether a replay is required, for a route, and for a specific client model and credential.
  • Control-frame detection, kept separate from the "does this payload use the tool protocol" predicate so a cancel or a keepalive cannot trigger a replay.
  • Construction of the executor input for a WebSocket turn, aligned with the HTTP path.
  • The feature-off and route-cannot-be-bridged short circuits, so the cost when the feature is disabled is a predicate call and not a payload parse.

Out of scope

Upstream WebSocket transport, the Codex websocket liveness deadlines, and the relay session deadlines. Those are unchanged.

Invariants

  • A turn on a WebSocket session and the same turn sent over HTTP are handled identically.
  • A frame carrying no tool state never triggers a contract replay.
  • Native passthrough, including duplex steering, is unchanged for routes that forward the protocol.

Related issues

Depends on the integration seam. The "may this route need the bridge" predicate comes from the capability-declaration issue, and the "does this payload use the tool protocol" predicate from the contract issue.

Source: router-for-me/CLIProxyAPI