fix: distinguish stale-stream from APIConnectionError in fallback gate (#69186) - #69419
Closed
aurorabotticus-svg wants to merge 1 commit into
Closed
aurorabotticus-svg wants to merge 1 commit into
aurorabotticus-svg wants to merge 1 commit into
Conversation
Contributor
Contributor
Author
|
Closing — duplicate of existing PR. Apologies for the noise. |
19 tasks
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.
Fixes #69186
Problem
The eager fallback gate groups two materially different failure sources:
FailoverReason.timeoutcovers both stale-stream kills (expensive, each retry costs minutes) and ordinaryAPIConnectionError(DNS failure, TCP reset — returns in milliseconds). Two fast connection failures trigger fallback beforeapi_max_retriesis exhausted, skipping_try_recover_primary_transport()entirely.Fix
Use the stale-stream detector's own counter (
agent._consecutive_stale_streams) to distinguish the two cases:Ordinary
APIConnectionErrornow flows through: retry →_try_recover_primary_transport()(client/pool rebuild, retry_count reset) → fresh retry cycle → fallback only if recovered primary still fails.What stays unchanged:
rate_limit,billing,upstream_rate_limit— still eageroverloaded— still eager atretry_count >= 2retry_count >= 1(fallback chain not activated on stream-stall timeouts (15+ min silent hang on degraded primary) #22277 fix preserved)Verification
py_compileAST parse passes_consecutive_stale_streamsattribute is only set by the stale-stream detector inchat_completion_helpers.py— fastAPIConnectionErrordoes not bump it, so the gate cleanly separates the two cases