Make stream reconnect delay/backoff configurable in config.toml
Hard-coded exponential backoff for retryable stream reconnects makes some provider setups unusable.
Today Codex exposes stream_max_retries, but not the reconnect delay strategy. The outer reconnect loop uses a fixed exponential backoff starting around 200ms and doubling on each retry, so by the time a session reaches the low teens it is already waiting many minutes between attempts.
That is a poor fit for providers / gateways that frequently fail with retryable transient errors but often recover after a few quick retries. One concrete case is OpenAI-compatible upstreams that may briefly return 403 Forbidden with an "insufficient balance / quota" message and then succeed again shortly afterward once the upstream gateway refreshes state or routes to a healthy backend.
In that setup, users can already raise stream_max_retries, but they cannot express the retry cadence they actually need. By retry 10+ the built-in exponential backoff dominates and the CLI can end up waiting far longer than the upstream outage itself.
Proposed behavior:
- Keep the current default behavior for existing users.
- Add provider-scoped TOML settings so users can choose the reconnect delay behavior explicitly.
- Support at least:
- a configurable base delay in milliseconds
- a configurable backoff mode (
exponentialorfixed)
Example desired config:
[model_providers.custom]
stream_max_retries = 100
stream_retry_delay_ms = 500
stream_retry_backoff = "fixed"
That would allow the common "retry every 500ms" workflow without requiring a local patch.
I have a PR ready that implements exactly this shape while preserving the current default behavior.
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
I have the patch implemented here:
What it adds:
I attempted to open the upstream PR as well, but GitHub's fork API is currently failing for
openai/codexfrom this account (502 Server Error, followed byRepository is already being forked). As soon as GitHub successfully creates the canonical fork, I'll open the upstream PR and link it here.This feature hasn't received enough upvotes, so closing.
Request for reconsideration: support the built-in OpenAI provider, not only custom providers
Please reconsider reopening this issue, or explicitly track this requirement as part of #19821.
The scope is now broader than the original custom-provider use case. On the current macOS Codex Desktop bundle (
codex-cli 0.144.2) using ChatGPT authentication and the built-in OpenAI provider, transient network interruptions still produce the user-visibleReconnecting... 1/5through5/5sequence. The five attempts can be consumed too quickly to survive ordinary Wi-Fi, VPN, proxy, sleep/wake, or route transitions.The documented retry controls do not solve this for normal Desktop users:
stream_max_retries,request_max_retries, andstream_idle_timeout_msare provider-scoped.openaiprovider ID is reserved and cannot be overridden.model_providers.openai.stream_max_retriesis rejected with:Built-in providers cannot be overridden.That leaves the mainstream ChatGPT-authenticated Desktop path with a hard-coded retry budget and cadence, even though the same knobs exist for custom providers.
Since this issue was closed for insufficient upvotes, #19821 has accumulated additional reports across platforms showing the same practical failure mode: Codex spends the complete
1/5–5/5budget on a failing WebSocket path before a working HTTP/SSE fallback. This is evidence of an unresolved resilience and configurability gap, not merely a niche custom-gateway preference.Requested behavior
Retry-Afterwhen presentA larger retry count without backoff risks hammering the same failing path. Exponential backoff without a cap or user-visible timing can make Codex appear hung. The reliable policy needs all three: a configurable retry budget, bounded backoff with jitter, and adaptive transport fallback.
Suggested acceptance criteria
The request is not for unlimited retries. It is for a resilient, bounded, observable retry policy that standard Codex Desktop users can actually configure.