Skip to content

fix: guard float infinity in stale timeout display and truncate codex cache key (#65746, #66045) - #66050

Closed
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/moa-infinity-stale-timeout-crash
Closed

fix: guard float infinity in stale timeout display and truncate codex cache key (#65746, #66045)#66050
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/moa-infinity-stale-timeout-crash

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

Two production crash fixes in agent/:

1. chat_completion_helpers.py — OverflowError on infinite stale timeout (#65746)

MoA/local calls set non-stream stale timeout to float("inf"). When the 30-second heartbeat fires, int(_deadline) raises OverflowError: cannot convert float infinity to integer. The retry loop then mislabels the healthy local request as an API failure and retries 5 times.

Fix: Guard with math.isinf() and display "∞" in the wait notice and timeout error messages. Three call sites protected: the heartbeat display (line ~620), and both timeout error paths (lines ~780, ~786).

2. transports/codex.py — prompt_cache_key > 64 chars causes HTTP 400 on every turn (#66045)

When _content_cache_key() returns None (no static content to hash), the fallback is session_id. Cron jobs and long session IDs produce keys > 64 chars. The Codex backend (chatgpt.com/backend-api/codex) rejects any prompt_cache_key over 64 characters with HTTP 400. The failure is masked by the fallback chain, making the primary provider appear unused.

Fix: Truncate cache_key to 64 characters before setting the kwarg. Content-addressed keys (pck_<sha256[:24]>) are 28 chars and unaffected; only the session_id fallback is truncated.

Testing

  • python3 -m py_compile passes for both files
  • math.isinf(float("inf")) returns True (tested locally)
  • Truncation preserves cache routing semantics (first 64 chars still unique per session)

Fixes #65746
Fixes #66045

… cache key

Two production crashes fixed:

1. MoA/local calls with non-stream stale timeout of float("inf") crash
   with OverflowError when the 30s heartbeat formats int(_deadline).
   Guard with math.isinf() and display "∞" instead. (NousResearch#65746)

2. Codex transport emits prompt_cache_key longer than 64 chars when the
   fallback to session_id produces a long key (e.g. cron_<id>_<ts>).
   The Codex backend rejects >64 chars with HTTP 400 on every turn,
   causing silent fallback. Truncate to 64 chars. (NousResearch#66045)

Fixes NousResearch#65746
Fixes NousResearch#66045
@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 provider/openai OpenAI / Codex Responses API P2 Medium — degraded but workaround exists sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) duplicate This issue or pull request already exists labels Jul 17, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

The bundled Codex prompt_cache_key truncation duplicates #24273. Its separate stale-timeout display guard is related to broader open #65594 rather than a duplicate.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: LGTM / Comment

Small, targeted fix that guards against float infinity (math.inf) causing display issues in stale timeout UI. Adds isinf check before formatting. No security concerns. Clean and well-scoped.

@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded in both parts:

Thank you for responding quickly to both reports.

@teknium1 teknium1 closed this Jul 17, 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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/openai OpenAI / Codex Responses API sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) type/bug Something isn't working

Projects

None yet

4 participants