core-agent-ide/codex-rs/codex-api/src
Josh McKinney bba5e5e0d4
fix(codex-api): handle Chat Completions DONE sentinel (#8708)
Context
- This code parses Server-Sent Events (SSE) from the legacy Chat
Completions streaming API (wire_api = "chat").
- The upstream protocol terminates a stream with a final sentinel event:
data: [DONE].
- Some of our test stubs/helpers historically end the stream with data:
DONE (no brackets).

How this was found
- GitHub Actions on Windows failed in codex-app-server integration tests
with wiremock verification errors (expected multiple POSTs, got 1).

Diagnosis
- The job logs included: codex_api::sse::chat: Failed to parse
ChatCompletions SSE event ... data: DONE.
- eventsource_stream surfaces the sentinel as a normal SSE event; it
does not automatically close the stream.
- The parser previously attempted to JSON-decode every data: payload.
The sentinel is not JSON, so we logged and skipped it, then continued
polling.
- On servers that keep the HTTP connection open after emitting the
sentinel (notably wiremock on Windows), skipping the sentinel meant we
never emitted ResponseEvent::Completed.
- Higher layers wait for completion before progressing (emitting
approval requests and issuing follow-up model calls), so the test never
reached the subsequent requests and wiremock panicked when its
expected-call count was not met.

Fix
- Treat both data: [DONE] and data: DONE as explicit end-of-stream
sentinels.
- When a sentinel is seen, flush any pending assistant/reasoning items
and emit ResponseEvent::Completed once.

Tests
- Add a regression unit test asserting we complete on the sentinel even
if the underlying connection is not closed.
2026-01-05 09:29:42 -08:00
..
endpoint Refresh on models etag mismatch (#8491) 2026-01-01 11:41:16 -08:00
requests fix: chat multiple tool calls (#8556) 2026-01-05 10:37:43 +00:00
sse fix(codex-api): handle Chat Completions DONE sentinel (#8708) 2026-01-05 09:29:42 -08:00
auth.rs chore: proper client extraction (#6996) 2025-11-25 18:06:12 +00:00
common.rs Refresh on models etag mismatch (#8491) 2026-01-01 11:41:16 -08:00
error.rs chore: proper client extraction (#6996) 2025-11-25 18:06:12 +00:00
lib.rs Add models endpoint (#7603) 2025-12-04 12:57:54 -08:00
provider.rs chore: proper client extraction (#6996) 2025-11-25 18:06:12 +00:00
rate_limits.rs fix: taking plan type from usage endpoint instead of thru auth token (#7610) 2025-12-04 23:34:13 -08:00
telemetry.rs chore: proper client extraction (#6996) 2025-11-25 18:06:12 +00:00