Skip to content

fix: recover Codex max-output truncation - #28062

Closed
eliteworkstation94-ai wants to merge 1 commit into
NousResearch:mainfrom
eliteworkstation94-ai:fix/codex-max-output-truncation
Closed

fix: recover Codex max-output truncation#28062
eliteworkstation94-ai wants to merge 1 commit into
NousResearch:mainfrom
eliteworkstation94-ai:fix/codex-max-output-truncation

Conversation

@eliteworkstation94-ai

@eliteworkstation94-ai eliteworkstation94-ai commented May 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treat Codex Responses status=incomplete / incomplete_details.reason=max_output_tokens as a resumable Codex incomplete turn instead of the generic chat-completions length failure path.
  • Add a pre-API request pressure check during every tool-loop iteration so long tool-heavy turns compact before they consume the entire context window and leave no output budget.
  • Add regressions for both the max-output continuation path and mid-turn compaction after large tool results.

Test plan

  • python -m pytest tests/run_agent/test_run_agent.py tests/run_agent/test_run_agent_codex_responses.py -q -o 'addopts='
  • python -m py_compile agent/conversation_loop.py tests/run_agent/test_run_agent.py tests/run_agent/test_run_agent_codex_responses.py
  • git diff --check -- agent/conversation_loop.py tests/run_agent/test_run_agent_codex_responses.py

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels May 18, 2026
@eliteworkstation94-ai
eliteworkstation94-ai force-pushed the fix/codex-max-output-truncation branch from 514f413 to 030a87d Compare May 25, 2026 02:34
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused fix. I verified the premise against current main and did not find a blocking correctness issue in the patch.

Suggested changes

  • If this is salvaged, keep both behaviors: the PR's Codex max-output reroute in agent/conversation_loop.py and the current-main final-answer safeguards in agent/codex_responses_adapter.py:1257-1260. They cover different Responses states: max-output incomplete turns vs completed final_answer items on a top-level incomplete response.
  • Consider tying the new pre-API pressure gate's attempt cap to the existing max_compression_attempts local (agent/conversation_loop.py:875) instead of adding a second literal 3, so future changes to the compression retry budget stay in one place.

Current main still maps Codex status=incomplete / incomplete_details.reason=max_output_tokens to finish_reason="length" at agent/conversation_loop.py:1359-1360, and that generic length path can return Response truncated due to output length limit at agent/conversation_loop.py:1708-1723. The Codex continuation path only runs for finish_reason == "incomplete" at agent/conversation_loop.py:3615, so the PR is aimed at a real branch distinction.

Automated hermes-sweeper review.

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Merged via #58155 — your commit was cherry-picked with authorship preserved (author eliteworkstation94-ai on 1f430e1a on main).

Both fixes landed:

  • The Codex status=incomplete / max_output_tokens reroute to finish_reason="incomplete" (routes into the existing Codex continuation path instead of the generic "Response truncated due to output length limit" rollback).
  • The per-iteration pre-API context-pressure compaction.

Two follow-up commits on top (ours): the mid-turn compaction now re-baselines the flush cursor via conversation_history_after_compression() so it doesn't double-persist under the default in-place compaction, and the trigger is gated through the turn-prologue preflight guard chain (should_defer_preflight_to_real_usage → compression-failure cooldown → should_compress) so it reuses the canonical threshold_tokens and honors the anti-thrash / cooldown / defer guards.

Thanks for the fix! #58155

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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants