fix: recover auto chat mode when quota state stalls#472
Open
double2tea wants to merge 1 commit intochenyme:mainfrom
Open
fix: recover auto chat mode when quota state stalls#472double2tea wants to merge 1 commit intochenyme:mainfrom
double2tea wants to merge 1 commit intochenyme:mainfrom
Conversation
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
AUTOtoFASTand thenEXPERTwhen chat quota state is staleNo available accountsProblem
Some deployments can get stuck returning
No available accounts for this model tierfor chat requests usingAUTOmodels even though quota becomes available again after a manual refresh or a process restart.In practice there were two missing recovery paths:
AUTOas a hard mode and did not try other chat windows that were still availableThis makes the service dependent on long periodic refresh intervals or manual intervention.
What This Changes
1. Chat-mode fallback
For chat models whose public mode is
AUTO, account selection now tries:AUTOFASTEXPERTThis behavior is enabled by default and guarded by:
features.auto_chat_mode_fallback = true2. Empty-pool refresh retry
If account selection still finds no candidate, the service now:
refresh_on_demand()This behavior is enabled by default and guarded by:
features.on_empty_retry_enabled = true3. Shared implementation
The recovery logic is centralized in a shared products-layer helper so OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages stay consistent.
Why This Is Safe
Verification
./.venv/bin/python -m unittest tests.test_account_selection./.venv/bin/python -m py_compile app/products/_account_selection.py tests/test_account_selection.py app/products/openai/chat.py app/products/openai/responses.py app/products/anthropic/messages.pyNotes
I observed this against a live deployment where:
AUTOquota had stalled at zeroFAST/EXPERTquota was still availableAUTOThis patch addresses both the stale-state case and the no-self-recovery case.