codex-multi-auth icon indicating copy to clipboard operation
codex-multi-auth copied to clipboard

Native WebSocket rejects response.interrupt from Codex, ending turns with unsupported_websocket_event

Open thatdaveguy1 opened this issue 1 month ago • 2 comments

Problem

With codex-multi-auth 2.24.0 and Codex CLI 0.166.0 over the native WebSocket transport, a turn can end with:

{"type":"error","status":400,"error":{"type":"invalid_request_error","code":"unsupported_websocket_event","message":"The local WebSocket request could not be served."}}

It happens when a multi-agent v2 sub-agent message reaches the parent while the parent is mid-response (seen twice, each within about 2 seconds of a sub-agent finishing).

Cause

Codex sends this on the open socket (codex-rs/codex-api/src/endpoint/responses_websocket.rs):

{"type":"response.interrupt","response_id":"...","mode":"discard_partial_items"}

dist/lib/runtime/responses-websocket.js accepts only response.create and response.cancel, so anything else gets unsupported_websocket_event.

What a fix needs

  1. Forward response.interrupt to the upstream socket carrying the active response.
  2. Always answer. Codex waits for response.interrupt.accepted or response.interrupt.failed with a matching response_id, including after the response has completed. With no upstream socket (HTTP recovery, or the response just ended), a local accepted is safe because the response just runs to its end.
  3. Treat response.incomplete with incomplete_details.reason === "interrupted" like response.completed when remembering the chain. Codex continues it with previous_response_id.
  4. Handle response.output_item.interrupted in ResponseOutputHistory. The discarded partial item otherwise stays incomplete, so finish() returns undefined and the chain is lost.

Upstream's handling of late acknowledgements is an assumption: a late one should be dropped so it is not read as the next response's first event.

I have this working as a local patch of the built files, tested against a stand-in upstream, and can share the diff.

thatdaveguy1 avatar Oct 30 '26 23:10 thatdaveguy1

Update from testing against the real upstream with a ChatGPT account (model gpt-6-luna): forwarding response.interrupt returned response.interrupt.failed with code interrupt_not_supported ("Mid-item interruption is not enabled for this response"), and the response then ran to response.completed. Continuing with previous_response_id on the same socket worked.

The turn survives this because the main Codex turn loop uses drain mode, which does not validate or wait for the answer. interrupt.Cancel callers do treat a refusal as an error, the same as they would without the relay.

Three real codex exec runs with a sub-agent finishing mid-response then completed with no errors.

thatdaveguy1 avatar Oct 30 '26 23:10 thatdaveguy1

Fixed on main by two PRs:

  • #749 (6714f244): the native WebSocket now forwards response.interrupt to the upstream socket that owns the response, always answers with response.interrupt.accepted/failed, and keeps late acknowledgements separate from the next response.
  • #755 (d5878830): response.incomplete with incomplete_details.reason: "interrupted" is remembered like response.completed for previous_response_id continuations, and response.output_item.interrupted drops the discarded partial item from the output history.

Thanks @thatdaveguy1 for the detailed analysis and the real-upstream test notes.

ndycode avatar Oct 31 '26 10:10 ndycode