Skip to content

Fix Codex stream recovery when terminal output is empty - #33091

Closed
AslanJ wants to merge 3 commits into
NousResearch:mainfrom
AslanJ:fix/codex-stream-empty-output
Closed

Fix Codex stream recovery when terminal output is empty#33091
AslanJ wants to merge 3 commits into
NousResearch:mainfrom
AslanJ:fix/codex-stream-empty-output

Conversation

@AslanJ

@AslanJ AslanJ commented May 27, 2026

Copy link
Copy Markdown

Summary

Fixes Codex Responses streaming recovery when the OpenAI SDK encounters a terminal response with output=None.

Changes include:

  • handle the SDK TypeError: 'NoneType' object is not iterable during Responses stream parsing
  • retry once, then fall back to responses.create(stream=True)
  • synthesize/backfill final output from collected stream events or text deltas
  • guard output_text fallback access in normalization and validation paths
  • add regression coverage for the empty-output stream case

Testing

venv/bin/pytest tests/run_agent/test_run_agent_codex_responses.py -k 'codex_stream or codex_empty_output' tests/run_agent/test_codex_xai_oauth_recovery.py

AslanJ added 3 commits May 22, 2026 23:54
Separate Kimi Code and Moonshot China provider mappings so the model picker does not show duplicate or misleading Kimi rows.

Kimi Code uses api.kimi.com/coding and exposes kimi-for-coding. Moonshot China uses api.moonshot.cn/v1 and exposes K2/Kimi models.
…rate_limit

The function is defined in run_agent.py but conversation_loop.py
called it as a bare name. Since the module is only imported lazily
inside _ra(), the symbol was not available in the local namespace.

Use _ra()._pool_may_recover_from_rate_limit() so the call goes
through the lazy reference, matching the pattern used elsewhere.

Fixes: NameError when rate-limit fallback logic is triggered.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/openai OpenAI / Codex Responses API provider/kimi Kimi / Moonshot labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

The Codex null-output stream recovery portion overlaps with merged #32963 and open test-only #33003. The Kimi/Moonshot provider rebrand changes (models_dev.py, auth.py, models.py, providers.py, setup.py, model_switch.py) are unrelated to stream recovery and should be a separate PR.

@teknium1

Copy link
Copy Markdown
Contributor

Closing as obsolete — same reason as #33103. PR #33042 (commit cb38ce2) eliminates the SDK's responses.stream(...) helper from both Codex call sites; the TypeError: 'NoneType' object is not iterable it would have raised on terminal output=None cannot fire anymore because the SDK never gets to do the typed reconstruction. The synthesize/backfill logic this PR added on top of the helper is now redundant. Thanks for the work.

@teknium1 teknium1 closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists provider/kimi Kimi / Moonshot provider/openai OpenAI / Codex Responses API type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants