fix(codex): recover null-output Responses turns - #33296
Conversation
…easoning models
Two related failures broke the Telegram gateway (every agent turn errored,
then surfaced "model provider failed after retries"):
1. codex/gpt-5.5 null output. The chatgpt.com/backend-api/codex backend sends
`response.completed` with `output: null` while streaming the real content
via incremental events. The OpenAI SDK's parse_response() does
`for output in response.output:` and raises "'NoneType' object is not
iterable" inside the `.stream()` helper's loop. The existing backfill only
handled an empty *list*, not None, so neither the main path nor the
create(stream=True) fallback recovered — turns came back empty / crashed.
- run_codex_create_stream_fallback: backfill when output is None (not just
[]), reusing the collected output_item.done items / text deltas. This is
the path that actually recovers the text (verified live: returns the
streamed content with a valid output list).
- run_codex_stream: on the null-output TypeError, skip the retry (re-streaming
reproduces the same null output deterministically) and go straight to the
create(stream=True) fallback, which reads raw events without parse_response.
- Both backfill sites also leave output=[] when there's nothing to recover so
downstream `.output` iteration never re-raises.
2. gpt-4.1 fallback 400. When the codex primary fails and the chain falls back
to a direct-OpenAI target (custom / api.openai.com) the Responses transport
added `reasoning` + `include: ["reasoning.encrypted_content"]` for every
model. gpt-4.1 (non-reasoning) rejects this with HTTP 400 "Encrypted content
is not supported with this model."
- Add model_metadata.openai_responses_supports_reasoning() (codex/gpt-5/o1/
o3/o4 prefixes), mirroring _AZURE_FOUNDRY_RESPONSES_PREFIXES.
- codex transport now gates reasoning/include on
`is_codex_backend or openai_responses_supports_reasoning(model)`: the codex
OAuth backend always gets them (contract requires reasoning replay), the
direct OpenAI endpoint gets them only for reasoning models. gpt-4.1 / gpt-4o
now omit them.
Tests: update the null-output fallback test to assert no wasted retry
(call_count == 1); add direct-OpenAI gpt-4.1 (omit) and gpt-5.4 (include)
gate tests. codex transport + recovery suites green.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Late duplicate of merged #32963 (canonical Codex null-output fix). The null-output TypeError guard in |
ea2ef83 to
a20d2bd
Compare
|
Thanks for this — closing as already fixed on The Codex null-output crash (
Your fix targets the same path that's now hardened upstream, so there's nothing left to merge here. Your authorship is preserved in your branch; I'm crediting your report in the umbrella issue #33932 (now closed). Appreciate the contribution. |
Summary
Test Plan
🤖 Generated with Hermes Agent