Native WebSocket rejects response.interrupt from Codex, ending turns with unsupported_websocket_event
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
- Forward
response.interruptto the upstream socket carrying the active response. - Always answer. Codex waits for
response.interrupt.acceptedorresponse.interrupt.failedwith a matchingresponse_id, including after the response has completed. With no upstream socket (HTTP recovery, or the response just ended), a localacceptedis safe because the response just runs to its end. - Treat
response.incompletewithincomplete_details.reason === "interrupted"likeresponse.completedwhen remembering the chain. Codex continues it withprevious_response_id. - Handle
response.output_item.interruptedinResponseOutputHistory. The discarded partial item otherwise stays incomplete, sofinish()returnsundefinedand 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.
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.
Fixed on main by two PRs:
- #749 (
6714f244): the native WebSocket now forwardsresponse.interruptto the upstream socket that owns the response, always answers withresponse.interrupt.accepted/failed, and keeps late acknowledgements separate from the next response. - #755 (
d5878830):response.incompletewithincomplete_details.reason: "interrupted"is remembered likeresponse.completedforprevious_response_idcontinuations, andresponse.output_item.interrupteddrops the discarded partial item from the output history.
Thanks @thatdaveguy1 for the detailed analysis and the real-upstream test notes.