Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.169.0 (the latest release; codex-rs/codex-api on main at 65a5410 reads the same way)
What subscription do you have?
None for this report: a custom model provider with wire_api = "responses". The reproduction uses a local scripted provider.
Which model were you using?
Any. The reproduction names a placeholder model, probe-model.
What platform is your computer?
Darwin 27.2.0 arm64 arm
What terminal emulator and version are you using (if applicable)?
Not applicable: codex exec.
Codex doctor report
Not included. The reproduction runs in a new CODEX_HOME whose whole configuration is shown below.
What issue are you seeing?
A provider ends a Responses stream with the error event that the streaming reference documents, with code and message beside type:
event: response.created
event: response.in_progress
event: error
data: {"type": "error", "code": "validation_error", "message": "web search is not supported for this request", "param": "", "sequence_number": 2}
Codex does not act on the event. It reports the end of the stream as a disconnection and sends the same request six times in all:
Reconnecting... 1/5 (stream disconnected before completion: stream closed before response.completed)
…
Reconnecting... 5/5 (stream disconnected before completion: stream closed before response.completed)
stream disconnected before completion: stream closed before response.completed
The provider's code and message never reach the user, and a request that the provider refused as invalid is retried five times.
What steps can reproduce the bug?
- Save this as
upstream.pyand runpython3 upstream.py 18961. It answers everyPOSTwithresponse.created,response.in_progressand one ending, ends the chunked body, and prints one line per request.
"""A scripted Responses provider. Usage: python3 upstream.py <port> [flat|nested|nested-known|failed]"""
import http.server, json, sys
PORT, SHAPE = int(sys.argv[1]), (sys.argv[2] if len(sys.argv) > 2 else "flat")
MESSAGE = "web search is not supported for this request"
RESPONSE = {"id": "resp_1", "object": "response", "status": "in_progress", "model": "probe-model", "output": []}
FAILED = RESPONSE | {"status": "failed", "error": {"code": "validation_error", "message": MESSAGE}}
ENDINGS = {
"flat": {"type": "error", "code": "validation_error", "message": MESSAGE, "param": ""},
"nested": {"type": "error", "error": {"code": "validation_error", "message": MESSAGE}},
"nested-known": {"type": "error", "error": {"code": "context_length_exceeded", "message": MESSAGE}},
"failed": {"type": "response.failed", "response": FAILED},
}
EVENTS = [
{"type": "response.created", "response": RESPONSE},
{"type": "response.in_progress", "response": RESPONSE},
ENDINGS[SHAPE],
]
class Handler(http.server.BaseHTTPRequestHandler):
protocol_version = "HTTP/1.1"
def do_POST(self):
self.rfile.read(int(self.headers.get("Content-Length") or 0))
print("POST", self.path, flush=True)
self.send_response(200)
self.send_header("Content-Type", "text/event-stream")
self.send_header("Transfer-Encoding", "chunked")
self.end_headers()
for number, event in enumerate(EVENTS):
body = json.dumps(event | {"sequence_number": number})
data = f"event: {event['type']}\ndata: {body}\n\n".encode()
self.wfile.write(b"%x\r\n%s\r\n" % (len(data), data))
self.wfile.write(b"0\r\n\r\n")
def log_message(self, *args):
pass
http.server.ThreadingHTTPServer(("127.0.0.1", PORT), Handler).serve_forever()- In a new directory, write
config.toml:
model = "probe-model"
model_provider = "probe"
[model_providers.probe]
name = "probe"
base_url = "http://127.0.0.1:18961/v1"
wire_api = "responses"- Run one turn with that directory as
CODEX_HOME:
CODEX_HOME=<that directory> codex exec --skip-git-repo-check --json -c features.memories=false "Reply with the word ready."Result: the server prints six POST /v1/responses lines, Codex prints five Reconnecting... events, and the turn fails with exit status 1.
The second argument of the script selects other endings. Measured with the same command:
| The stream ends with | Requests | Codex's last message |
|---|---|---|
flat: error, code validation_error beside type |
6 | stream closed before response.completed |
nested: error, code validation_error in an error member |
6 | stream closed before response.completed |
nested-known: error, code context_length_exceeded in an error member |
1 | Codex ran out of room in the model's context window. … |
failed: response.failed, code validation_error in response.error |
6 | stream disconnected before completion: web search is not supported for this request |
What is the expected behavior?
An error event that carries code and message beside type ends the turn with that code and message, as nested-known does today for a nested, known code. A refusal such as a validation error is shown to the user and not retried five times.
Additional information
Where the event is read, at the tag rust-v0.169.0:
process_responses_eventincodex-rs/codex-api/src/sse/responses.rshandles"error"withparse_terminal_provider_error(event.error.as_ref(), None).ResponsesStreamEventhas anerrormember and no top-levelcodeormessage, so the documented shape yields nothing.parse_terminal_provider_errorincodex-rs/codex-api/src/error.rsreturns an error only for a fixed list of codes. Any other code falls through, and the end of the stream then reads as "stream closed before response.completed", which is retried.
Where it was met: a third-party Responses provider refuses a request that carries a web_search tool for a model without web search, with the event above. With features.memories on, a new Codex home starts a memory import thread whose request carries that tool, so each such thread costs six refused requests beside the turn that the user asked for.
Follow-up, 15 November 2026
Thanks @r266-tech for running the additional cases. Their 0.169.0 binary results, with retries disabled, show:
After response.failed(validation_error) |
Result |
|---|---|
| EOF | Original provider error, exit 1 |
| Held-open stream | Idle timeout replaces the provider error |
response.completed |
False success, exit 0 |
These are scripted cases, not evidence of the same event sequence in production. The held-open failure is already tracked in #43140.
I rechecked current main at ee344ca9. The parser still saves unclassified failures for EOF; timeout and completion bypass that saved error. The flat error decoding gap in this report also remains.
Acceptance should cover both: expose the documented flat error's code/message and avoid retrying an invalid request; end a response immediately on response.failed so timeout or later completion cannot replace it. The outer request retry policy must retain genuine transient retries. The existing success and recognized-error controls should remain unchanged. I have not rerun the binary here.
Native stream test follow-up, 15 November 2026
Thanks @r266-tech for the native regression tests. They report five failures on main ee344ca9 and 214 passing library tests after terminating the stream on the decoded response.failed event. The checks cover held-open bodies, later completion, transport errors and malformed failure fields; completion-first and transient retry controls still pass.
That gives maintainers a tested fix for the terminality part of #43140. The two gaps in this report remain: decode the documented flat error, and stop retrying a request refused as invalid. I rechecked the same main source; I have not run their tests or built the CLI. Their library result does not establish production recovery.
Activity
Nakagawa-master commentedon Nov 14, 2026
A second acceptance boundary is visible in current Codex source (source review only; I have not run the reporter's Codex fixture).
The report correctly separates the documented flat
errorshape from nestedresponse.failed. Fixing only the flat JSON decoding would still leave the retry classification problem:ResponsesStreamEvent, the"error"branch passesevent.erroronly. The top-levelcode/messagefields in the reported official event are not represented, so that event is currently ignored.parse_terminal_provider_error, an unfamiliarvalidation_errorreturnsNone; theresponse.failedfallback instead maps an unclassified error toApiError::Retryable(currentresponses_error.rs:100-103). A successful flat-shape parse alone therefore need not prevent the repeated POSTs.process_ssestores non-whitelisted errors inresponse_errorfor EOF, but emitsResponseEvent::Completedimmediately if a laterresponse.completedarrives. A stream withresponse.failed(validation_error)followed byresponse.completedcan therefore appear successful rather than failed. I have not reproduced this exact sequence with the binary; it follows from the current branches.A focused regression matrix could run the existing scripted provider's flat and nested
validation_errorcases and assert one POST + visible provider message, then feedresponse.failed(validation_error) -> response.completedand assert error wins, no Completed. Opposite controls: a known deliberate retryable condition such asrate_limit_exceededretains its configured retry behavior; ordinary transport disconnects remain distinguishable from explicit provider rejection; a genuinely successful stream still completes. Existingterminal_failure_with_retry_header_ends_stream_immediatelytests only a recognized set of terminal codes, so it does not exercise the unrecognized-code branch.The implementation choice is to normalize both documented error shapes and classify an explicit provider-declared terminal failure separately from a transport disconnect; treating every unknown error as a retryable disconnect is what the two boundaries have in common. This is a source-based proposed test and classification, not a claim of running the integration suite.
r266-tech commentedon Nov 14, 2026
I ran the failed-then-completed case from the preceding comment against the released codex-cli 0.169.0 on macOS arm64. It does report success. This is also related to the already-tested terminality defect in #43140; I am not claiming a new underlying bug.
Using a scripted loopback Responses provider, isolated
CODEX_HOME, no credentials,stream_max_retries=0, andstream_idle_timeout_ms=500:response.createdresponse.completedturn.completedresponse.failed(validation_error)→ EOFturn.failed, original fixture message preservedresponse.completedturn.completed; failure message absentidle timeout waiting for SSE; failure message absentresponse.failed(context_length_exceeded)→response.completedturn.completedFor the success-after-failure row, append this event after the reporter's existing
failedending, then end the chunked body:For the held-open row, send only the failure, flush, and leave the chunked body unfinished beyond the configured idle timeout. These are deliberately scripted transport cases: the two-terminal-events sequence is inconsistent provider output, not evidence that a production provider emits it.
The current source at
81b995a6c9a4c978f399775cfa5ce50702368749still stores unhandled errors, returns a new error on idle timeout, and emits a later completion without consulting that saved error. The relevant control flow also exists in the release source.AI-only offline verification: 16 shape/EOF/completion/hold-open cases, one unauthenticated localhost POST each; no model service requests, current-main build, or production-incident attribution. This turns the earlier source prediction into an executable release-level observation; #43140 already describes the broader immediate-terminal-failure requirement.
r266-tech commentedon Nov 15, 2026
I checked the event-kind boundary already proposed in #43140 against current
main ee344ca9458351a6ea102795fa73110ad3ede5dc, using nativespawn_response_streamtests rather than only the error parser.response.failed(validation_error)response.completedCompletedCompletedThe new native fixture has 3 passes / 5 failures on unmodified main; all 206 existing library tests pass. Including
event.kind == "response.failed"in the existing send-error-and-return condition gives 214 passes / 0 failures. A decoded failed event with malformed error fields also terminates withresponse.failed event received. Completion-first and ordinary transport-error controls stay unchanged.The transient controls pass through
map_api_error: bothrate_limit_exceededandserver_is_overloadedretainRetry-After: 3andretry_delay(1) == Some(3s). This tests stream termination separately from request retry policy.validation_errorstill has its current retryable classification; the documented flaterrorshape and invalid-request retry suppression remain unresolved.Rust 1.99.1, macOS arm64. I reduced the local workspace to this crate's path-dependency closure to avoid unrelated V8 fetches; every selected package's version/source/checksum matches the upstream lock. These are native library checks, not a current-main CLI build or production-provider verification. AI-assisted local verification; no model/provider calls.
Native regression fixture and commands
Add this test module beside
error_testsincodex-rs/codex-api/src/sse/responses.rs:Save the following as
codex-rs/codex-api/src/sse/responses_terminal_tests.rs:From
codex-rs, the focused baseline command is:cargo +1.99.1 test --locked --profile dev-small -p codex-api --lib terminal_tests -- --nocaptureAfter the local event-kind change, the full library command is:
cargo +1.99.1 test --locked --profile dev-small -p codex-api --libThalrion commentedon Nov 21, 2026
A loopback-only regression check on Linux x86_64 narrows the release boundary for a policy-error variant of this issue. The fixture returns HTTP 200 with
Content-Type: text/event-stream, sendsevent: errorwith{"type":"error","sequence_number":0,"error":{"code":"cyber_policy","type":"invalid_request","message":"Synthetic terminal policy refusal"}}, and closes.request_max_retries = 0,stream_max_retries = 2, emptyCODEX_HOME, no credentials or external inference.0.156.1and stable0.171.0: 3 POSTs (initial + 2 retries), terminalstream closed before response.completedrather than the refusal.0.173.0-alpha.4: 1 POST, process exits nonzero and reports the synthetic policy refusal.response.failedwith the same error and ordinary HTTP 400 stop after one POST; an empty SSE stream still retries.This is consistent with the terminal handling in #62354 / #62356. No change to policy enforcement is requested. Please retain this statusless nested-error case in stable-release coverage; the released stable client still treats it like a disconnect.
HengYangDS commentedon Nov 25, 2026
Thanks for the release comparison. I checked the current stable tag,
rust-v0.172.0. It includes #62356. The tagged decoder still has a nestederrorfield, and the event handler still reads that field for anerrorevent. The documented flat event from the opening report therefore still lacks a decoding path in this source. I have not run a new CLI reproduction for this tag.Please keep the original acceptance case alongside the nested-event coverage. A flat provider validation error should surface its original message and end the turn without retries. A genuinely transient response should retain its retry behavior.