Retry transient transport errors in native LLM client - #128
Merged
Conversation
Rename `_with_rate_limit_retries` -> `_with_retries` and broaden it to retry transient transport failures (reqwest connection/send errors, stalled/aborted streams) in addition to rate limits. These failures never reached a response, so retrying them can't double-bill; they share the rate-limit backoff schedule and retry cap. Also: - Add `_is_transient_transport_error` / `_TRANSPORT_ERROR_MARKERS` and `_is_definitely_unbilled_transport_error` / `_PRE_RESPONSE_TRANSPORT_MARKERS`. - Allow the aiohttp OpenAI fallback to run even under budget enforcement when the transport error provably preceded generation (connection refused, DNS, TLS, "error sending request"). - Treat definitely-unbilled transport errors as unbilled in the spend ledger. - Log call/stream failures at WARNING with `_format_exc_chain` so the nested reqwest cause is visible, not just the terse top-level message. - Drop "glm" from the reasoning_effort-unsupported patterns. Preserves main's existing reasoning_effort and max_output_tokens retry branches, now routed through the broadened `_with_retries`.
ropoctl
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Broadens the native LLM client's retry handling to cover transient transport failures, not just rate limits.
_with_rate_limit_retries→_with_retriesand retries transient transport errors (reqwest connection/send failures, stalled/aborted streams) alongside rate limits. These never reached a response, so retrying can't double-bill; they share the existing backoff schedule andrate_limit_max_retriescap._is_transient_transport_error/_TRANSPORT_ERROR_MARKERS— retryable transport failures._is_definitely_unbilled_transport_error/_PRE_RESPONSE_TRANSPORT_MARKERS— the subset that provably precede generation (connection refused, DNS, TLS, handshake, "error sending request")._achat_with_provider_policyand the streaming path)._is_definitely_unbilled_error).WARNINGvia_format_exc_chain, surfacing the nested reqwest cause instead of the terse top-level message."glm"from_REASONING_EFFORT_UNSUPPORTED_PATTERNS.Main's existing
reasoning_effortandmax_output_tokensrejection-retry branches are preserved and now route through the broadened_with_retries.Context
These changes originated from local edits made against an older
master; this PR reconciles them with main's newermax_output_tokensretry work (the two overlapped). Pricing-table (telemetry.py) changes from the same local batch are intentionally not included here.Test plan
python -m py_compile clearwing/llm/native.pyruff check clearwing/llm/native.pypython -m pytest— LLM/native/provider suite: 112 passed (test_llm_openai_fallback, test_llm_spend_budget, test_native_reasoning_effort, test_providers, test_providers_env)