feat(credential-pool): mark revoked/invalidated credentials as permanently dead#33904
Open
zccyman wants to merge 1 commit into
Open
feat(credential-pool): mark revoked/invalidated credentials as permanently dead#33904zccyman wants to merge 1 commit into
zccyman wants to merge 1 commit into
Conversation
…ently dead Credential pool previously treated all 401 errors as transient exhausted (5min cooldown → re-enter rotation). token_invalidated and token_revoked errors are permanent — the key will never work again — but the pool kept cycling them every 5 minutes. Changes: - credential_pool.py: Add STATUS_DEAD terminal state. Permanent auth failures (revoked, invalidated, deactivated keys) get marked as DEAD with no cooldown. _available_entries() permanently skips DEAD entries. User can still revive via reset_statuses(). - error_classifier.py: 401 messages containing token_revoked, invalid_api_key, etc. now classify as auth_permanent instead of auth, giving downstream code the signal to skip refresh attempts. - agent_runtime_helpers.py: auth_permanent path skips the OAuth refresh attempt entirely and goes straight to mark-as-dead + rotate. Tests: 33 new tests covering pattern detection, dead state lifecycle, exhaustion fallback, error classifier integration, and manual reset. Fixes: NousResearch#32849
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
Fixes #32849 — credential pool treats
token_invalidated/token_revokederrors as temporary exhaustion (5min cooldown → re-enter rotation) instead of permanently removing the credential.Problem
The credential pool has only two states:
STATUS_OKandSTATUS_EXHAUSTED. All 401 errors get a 5-minute cooldown, after which the credential re-enters rotation. For permanently invalid credentials (revoked keys, deactivated accounts), this creates an infinite retry cycle:token_revoked→ markedexhausted(TTL=5min)Solution
Three-layer defense:
error_classifier.pytoken_revoked,invalid_api_key,key has been deactivated, etc. →FailoverReason.auth_permanent(instead ofauth)credential_pool.pySTATUS_DEAD = "dead"terminal state._mark_exhausted()usesSTATUS_DEADfor permanent failures (noreset_at)._available_entries()permanently skips DEAD entries.reset_statuses()can still revive (manual user action).agent_runtime_helpers.pyauth_permanentpath skips the OAuth refresh attempt entirely and goes straight to mark-as-dead + rotate.Testing
test_credential_pool_dead_state.pytest_error_classifier.pytests all pass (zero regression)Test coverage
_is_permanent_auth_failure(): pattern matching for 15 message variants_mark_exhausted(): permanent → DEAD, transient → EXHAUSTED, 429 → EXHAUSTED_available_entries(): DEAD entries never returned, never resurrect after timemark_exhausted_and_rotate(): integration test with rotationerror_classifier:token_revoked→auth_permanent, transient 401 staysauthreset_statuses(): manual reset can revive DEAD entriesChecklist