Skip to content

[Bug] Codex APIConnectionError retry rate ~8x higher post-v0.13.0; persists with #12953 applied; suspected commit 5533ad764 strict stream-timeout enforcement #22986

Closed as not planned

Description

@QuarkAssistant

Summary

After upgrading to v0.13.0 (v2026.5.7), the APIConnectionError: Connection error. retry rate against chatgpt.com/backend-api/codex increased ~8x against the same workload. The retries persist even with PR #12953 (custom keepalive transport bypass) cherry-picked locally. Suspect commit 5533ad764 fix(auxiliary): enforce Codex Responses stream timeout is a contributing cause via a too-tight 120s default.

Environment

Empirical data

Logs counted across ~/.hermes/logs/agent.log, ~/.hermes/profiles/*/logs/agent.log, and ~/.hermes/kanban/logs/t_*.log:

  • 2026-05-08 (pre-upgrade, full day): 21 retries.
  • 2026-05-09 12:00–22:00 CDT (post-upgrade): 171+ retries.
  • Same user, same workload class (Telegram-driven agent interactions plus an internal multi-agent workload), same network/IP.

Hourly post-upgrade peaks: 33–48 retries/hour. Pre-upgrade comparable: 0–2 retries/hour.

Symptom

Every retry signature in the post-upgrade window:

⚠️  API call failed (attempt 1/3): APIConnectionError
   🔌 Provider: openai-codex  Model: gpt-5.5
   🌐 Endpoint: https://chatgpt.com/backend-api/codex
   📝 Error: Connection error.
   ⏱️  Elapsed: 0.13–0.5s  Context: varies
⏳ Retrying in 2-5s (attempt 1/3)...

Sub-second elapsed means TLS-handshake-time RST. ~95%+ of retries succeed within 1–3 attempts (no max-retries-exhausted events).

Hypothesis

Commit 5533ad764 enforces a hard total-elapsed timeout on the Codex Responses auxiliary stream. The default auxiliary.compression.timeout: 120s is too tight for compression workloads where 200K+ token sessions on gpt-5.4-mini routinely take 60–180s. Pre-commit, slow streams completed; post-commit, they timeout at 120s, raise TimeoutError, classify as retryable, and the outer agent loop fires a retry cycle that often surfaces as a transport-level APIConnectionError due to the forcible client.close() in _close_client_on_timeout.

Workaround

In ~/.hermes/config.yaml:

auxiliary:
  compression:
    timeout: 300   # was 120

load_config() is mtime-cached so no restart needed. Reduces the compression-driven retry class. Connection-class retries (covered by #12952) are separate.

Related

This issue is for the post-v0.13.0 amplification specifically, not the underlying transport instability that pre-existed.

Asks

  1. Confirm 5533ad764's 120s default is intended for production Codex-OAuth-on-ChatGPT-account workloads or should be tuned higher.
  2. Consider exposing a per-call override or auto-scaling the deadline based on observed stream throughput.
  3. Either way, document the workaround for users hitting the regression.

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    P2Medium — degraded but workaround exists
    on May 10, 2026
  2. QuarkAssistant commented on May 21, 2026

    @QuarkAssistant
    Author

    Follow-up: v0.14.0 (v2026.5.16) upgrade — pattern recurs, but not in the auxiliary-timeout class

    Filing as the original reporter. 11 days of clean operation followed by a same-day spike post-v0.14.0 upgrade.

    Updated retry-count timeline

    Same workload class, same network, same provider config (openai-codex / ChatGPT Codex OAuth / gpt-5.5):

    Date Hermes version Connection-error retries (full day, agent.log)
    2026-05-09 pre-C23 cherry-pick (v0.13.0) 37
    2026-05-10 — 2026-05-17 v0.13.0 + PR #12953 cherry-pick + PR #19485 cherry-pick (no auxiliary.compression.timeout workaround applied) 0 across 11 days
    2026-05-18 same (v0.13.0 + cherry-picks) 4 (single cron-driven burst, see below)
    2026-05-19, 5-20 same 0
    2026-05-21 (post-upgrade to v2026.5.16) v0.14.0 + same two cherry-picks rebased 40+ by 16:20 CDT, hourly distribution 12=2, 13=6, 14=2, 15=30, 16=8

    PR #12953's local cherry-pick (_is_chatgpt_codex_backend helper + _create_openai_client keepalive bypass) was sufficient to eliminate the v0.13.0 retry baseline entirely between 5/10 and 5/17 — confirming the original transport diagnosis was correct for that period. The 11-day zero-error window also held WITHOUT the auxiliary.compression.timeout: 300 workaround, suggesting the original 8x amplification is not load-bearing for our specific workload (relatively small contexts, ChatGPT Codex OAuth lane).

    Today's spike — direct code inspection rules out a new bypass

    Read-only audit of the v2026.5.16 source tree (PR #12953 cherry-pick rebased onto the v0.14.0 base):

    • _is_chatgpt_codex_backend defined at run_agent.py:6754 (PR fix(codex): avoid custom keepalive transport on chatgpt backend #12953 helper, intact).
    • _create_openai_client keepalive-transport injection at run_agent.py:6864 is properly gated by the helper (if "http_client" not in client_kwargs and not self._is_chatgpt_codex_backend(self.provider, client_kwargs.get("base_url")):). Verified the only other _build_keepalive_http_client() call site at run_agent.py:6824 is inside the is_native_gemini_base_url(base_url) branch — Gemini-native path, never reached for chatgpt-codex.
    • agent/auxiliary_client.py has separate OpenAI(...) constructors but they emit different log strings (Codex auxiliary Responses API call failed) and are not the codex_stream_request reason-string we see on today's failures.
    • agent/codex_responses_adapter.py and agent/transports/codex.py consume rather than construct clients.
    • Editable install pointer (__editable___hermes_agent_0_14_0_finder.py) confirms the gateway loads from the tree on disk — no shadow snapshot.

    So today's failures are NOT due to a new v0.14.0 client construction site that bypasses PR #12953's bypass.

    Failure signature

    Identical to the original #12952/#12953 transport-shape, ~240ms client lifetime then clean close → immediate APIConnectionError:

    WARNING run_agent: OpenAI client created (codex_stream_request, shared=False) provider=openai-codex base_url=https://chatgpt.com/backend-api/codex model=gpt-5.5
    WARNING run_agent: OpenAI client closed (request_complete, shared=False, tcp_force_closed=0) ...
    WARNING run_agent: API call failed (attempt 1/3) error_type=APIConnectionError ... summary=Connection error.
    

    tcp_force_closed=0 means clean shutdown — not the socket-RST class the keepalive bypass fixed. The 120-240ms create→close→error pattern with provider=openai-codex / chatgpt.com base_url suggests TLS-handshake-then-error on the upstream side (ChatGPT-codex backend rejecting or RSTing after handshake completes), not local transport misconfiguration.

    Concurrent factor: live OpenAI status incident

    status.openai.com shows an active incident "Elevated error rates on ChatGPT paid plans" — ongoing for ~7h at time of writing, overlapping the entire 12:00-16:00 CDT spike window. This is a plausible direct cause for the surge, layered on top of:

    1. v0.14.0's 5533ad764 strict stream-timeout enforcement classifying timeouts as APIConnectionError (raises visibility of stalls that pre-upgrade may have been silent).
    2. Heavy concurrent workload today (3 multi-agent investigations + 13-query x_search batch) increasing the probability of any individual stream tripping the new timeout enforcement during an upstream slowdown.

    Refined ask

    • (1) The 11-day zero-error window with PR fix(codex): avoid custom keepalive transport on chatgpt backend #12953 alone is evidence that PR fix(codex): avoid custom keepalive transport on chatgpt backend #12953 is complete and effective for the v0.13.0 transport class. Worth merging.
    • (2) If 5533ad764 is converting previously-silent stream stalls into APIConnectionError-classified retries (rather than just raising TimeoutError), that may be a separate observability issue — consider distinguishing "stream timeout, retryable" from "transport error, retryable" in the retry-loop classifier so users can filter noise during upstream incidents.
    • (3) Confirm whether v0.14.0 changed the behavior of _close_client_on_timeout such that a force-close races with the OpenAI SDK's response-stream parse, producing the 240ms-then-APIConnectionError shape we're seeing.

    Will continue measuring through the OpenAI incident resolution and re-report if the pattern persists past that.

  3. miguelmanlyx commented on May 21, 2026

    @miguelmanlyx

    Probably OpenAI timeout conditions. A quick npx ai-doctor run can flag missing timeout guards and unprotected requests.

  4. teknium1 commented on Jul 13, 2026

    @teknium1
    Collaborator

    Thanks for the detailed measurements and follow-up separating the timeout and transport classes.

    Automated hermes-sweeper review found this specific compression-timeout regression is implemented on current main:

    • Commit 370a489fb4adb7268f6510439e25e8213bddb624 (fix(auxiliary): floor compression timeout so reasoning models don't fall back to marker, shipped in v2026.7.7) applies a bounded 300-second floor to config-derived compression timeouts.
    • agent/auxiliary_client.py:6065-6068 limits that behavior to compression and preserves explicit per-call deadlines.
    • tests/agent/test_auxiliary_compression_timeout_floor.py:77-189 covers the former 120-second path plus sync/async, explicit-override, and scope boundaries.
    • agent/auxiliary_client.py:1137-1140 reports an enforced stream deadline as TimeoutError, while agent/auxiliary_client.py:6575-6581 avoids repeating a full-budget same-provider compression timeout.

    The later upstream/transport retry observations are distinct from the 120-second compression deadline addressed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointsweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions