OpenProgram Docs

LLM-call fault tolerance

SituationPolicy
Rate limit, overload, server, timeout, networkRetried: 5 attempts, jittered exponential backoff, 2 s base, 30 s cap
Retry-After (ms, seconds, HTTP date)Honoured as a lower bound up to 300 s. Longer: fails at once, flagged exhausted, hint kept, so a fallback, credential switch or the user can act.
Auth, invalid request, context overflow, policyNot retried
Refused for its shapeMended and resent
Long silence on a streamFails after 10 min with no bytes or 15 min with no real data; no total limit
Dead connection30 s connect, TCP keepalive notices in about 60 s
Break after contentCodex keeps the partial reply as stop_reason="length". Other providers re-send the whole request on a transport failure and void the partial, see Re-sending a failed reply.
Network unreachableWaits for it
Another modelOff by default; before the first token only
Still failingStructured error in the UI

Why read timeouts are generous

A reasoning stream must not carry a tight read timeout: a single timeout=120 caps the body read and fires over a buffering proxy, killing a healthy stream. Codex uses Timeout(connect=30, read=660, write=30, pool=30).

BudgetReset byCatches
SSE_IDLE_TIMEOUT_S 600Any line, pings includedA dead connection. Codex's own client allows 5 min; 10 leaves room for a buffering proxy.
Stream idle bound 300Parsed events onlyA reply that stops while the connection stays open, pings included; retried. Every provider, see Idle bound
OPENPROGRAM_SSE_TOTAL_TIMEOUT_S 0NothingPositive values opt into a deadline

Transport and recovery

PartBehaviour
utils/http_transport/timeouts.pyThe one timeout source, with context-scaling helpers
utils/http_transport/http_client.pyKeepalive, per OS. Force-IPv4 binds an IPv4 source, since httpx has no Happy Eyeballs. get_shared_async_client is loop-keyed, so Codex reuses TLS across turns. Proxy through httpx proxy=.
utils/http_transport/rate_limit.pyParses x-ratelimit-*, anthropic-ratelimit-*; Codex warns when a bucket is low
retry_after_beyond_capOne rule for the stream retry and Runtime.exec
Partial recovery, openai_codex.pyA transient break after content finalizes the turn; permanent failures still fail
openai-completions retryAfter EventStart, before content: a retryable APIError, including xAI's status-less Internal error during token generation, reopens on the same model. Otherwise the outer handler records cooldown and re-raises.
gemini_cliSame client and timeouts

Failover

utils/failures/failover.py and stream_with_failover try each fallback on a failover-worthy failure before content, forwarding events and suppressing the duplicate start.

model_fallback.modeTriesCrosses providers
off (default)None; a 429 shows that error–
same-providerUp to two other enabled models of the provider, in config-row order, reusing the credentialno
listmodel_fallback.models, provider/model ids in orderyes

Settings → Model services → Behavior, or openprogram config. OPENPROGRAM_FALLBACK_MODELS overrides it. A fallback reply records what was skipped in AssistantMessage.failover. Each switch also goes to the route_events table the routing overview reads.

Environment variables

VariableDefaultMeaning
OPENPROGRAM_SSE_IDLE_TIMEOUT_S600No bytes
OPENPROGRAM_STREAM_IDLE_TIMEOUT_S300No event; 0 turns the bound off
OPENPROGRAM_SSE_DATA_STALL_TIMEOUT_Sthe idle boundNo real data, Codex only
OPENPROGRAM_SSE_TOTAL_TIMEOUT_S0One-stream deadline; 0 is none
OPENPROGRAM_HTTPX_CONNECT_TIMEOUT_S30Connect
OPENPROGRAM_HTTPX_WRITE_TIMEOUT_S, _POOL_TIMEOUT_S30Write, pool
OPENPROGRAM_HTTPX_READ_TIMEOUT_Sidle + 60Read backstop
OPENPROGRAM_PROVIDER_STREAM_RETRIES5Attempts per stream
OPENPROGRAM_PROVIDER_STREAM_BACKOFF_S2.0Backoff base
OPENPROGRAM_PROVIDER_STREAM_BACKOFF_MAX_S30.0Exponential cap
OPENPROGRAM_RETRY_AFTER_CAP_S300Longest wait sat through; 0 lifts it
OPENPROGRAM_NETWORK_WAIT_MAX_S1800Waiting for the network; 0 disables
OPENPROGRAM_MAX_RETRIES3Runtime.exec attempts
OPENPROGRAM_EXEC_TIMEOUT_S0exec deadline; 0 is none
OPENPROGRAM_TCP_KEEPALIVE1Dead-peer detection
OPENPROGRAM_TCP_KEEPIDLE_S, _KEEPINTVL_S, _KEEPCNT30, 10, 3Probe timing
OPENPROGRAM_FORCE_IPV40IPv4 source, for broken-IPv6 VPNs
OPENPROGRAM_PARTIAL_RECOVERY1Keep partial output
OPENPROGRAM_FALLBACK_MODELSempty, the settingsame-provider, a list, or off/none
Comparison with peer frameworks
Dimensionopenclawopencodehermes-agentpi-ai (codex)OpenProgram
Attempts3 (+2 inner)2335
Backoff base300 ms500 ms5 s1 s2 s
Backoff cap30 s10 s120 snone30 s
Jittersymmetric, positive±20%decorrelatednonesymmetric, positive
Retryable status408, 409, 429, 5xx429, 503, 504, 529429, 5xx, 524429, 5xx429, 5xx, body patterns
Retry-Afterms, s, datems, s, date (cap 10 s)nonenonems, s, date (cap 300 s)
Idle timeout30 min any bytenone; WS 5 min180 s stale, scalednone10 min any byte, 15 min data
Connect timeoutundici defaultnone; WS 15 sSDK defaultnone30 s
First-byte guard30 s (Azure)n/a120 s (codex)noneidle and read
HTTP versionforced 1.1defaultauto (h2)n/ahttpx default (1.1)
IPv6autoSelectFamilynonon/aforce-IPv4 switch
TCP keepaliveundici defaultno30/10/3n/a30/10/3
Connection reusekeep-aliveWS pool, 55 min recycleshared, rebuilt when stalen/ashared, loop-keyed
Key rotationyesnopool, cooldownsn/apool, cooldowns
Model failoveryesWS to HTTP onlychainn/achain, off by default
Break after first tokenerrorerrorpartial, continueerrorpartial, continue (Codex); re-send (others)
OAuth refreshn/an/aper-request providerper callper call
Rate-limit headersn/ayesNousn/ayes
Classificationyestagged unionyesbasicErrorReason
What each project contributes
ProjectPatterns
openclaw (references/openclaw, TS)30 min stream timeout on the undici dispatcher, reset by any byte. Forced HTTP/1.1 and Happy Eyeballs avoid h2 resets and broken IPv6. Two-tier retry. Key rotation with per-key transient retry. Failover categories as regex groups. Positive-only jitter with Retry-After; x-should-retry.
hermes-agent (Python, closest)Keepalive socket injection and forced TCP close against CLOSE_WAIT. Decorrelated backoff seeded from time_ns. Stale timeout scaled by context, off for local providers. Separate first-byte and inter-event timeouts. Credential pool with cooldowns (401 5 min, 429/402 1 h, dead 24 h). Per-request OAuth hook. Partial reply with finish_reason=length.
opencode (TS)No HTTP body timeout. WS: 15 s connect, 5 min idle, 55 min recycle, HTTP after 5 failures. Rate-limit headers into a structured object. Tagged-union errors.
pi-ai (TS, source of our Codex provider)3 retries, 1 s base, 429/5xx and body patterns, no read timeout
claude-code (partial bundle)HTTP behaviour is the Anthropic SDK's

Implementation status

StatusItems
ImplementedClassifier, retry and backoff, timeouts, shared client, keepalive, IPv4 switch, rate-limit parsing, opt-in failover, pre-content retry for Codex, OpenAI Responses and completions. The SDKs' own retries are off (max_retries=0); the credential layer retries and switches keys. Partial recovery: Codex only.
CredentialsEvery request goes through auth/selection.py: a limited or refused credential is held and the next is tried. A sole credential cools like any other; the request waits up to 60 s for it with a notice, else fails saying when it is back.
Not builtPer-request OAuth hook: Codex already resolves and refreshes the bearer per call.
Last updated · 2026-11-25