feat(middleware): retry with rotated auth key on rate-limit errors (#423)#434
Merged
alexey-pelykh merged 1 commit intomainfrom Mar 8, 2026
Merged
feat(middleware): retry with rotated auth key on rate-limit errors (#423)#434alexey-pelykh merged 1 commit intomainfrom
alexey-pelykh merged 1 commit intomainfrom
Conversation
) When an agent has multiple auth profiles configured, rate-limit or auth errors now trigger automatic retry with the next key in the rotation. Each key is tried at most once per message. - Add isAuthRotatableError() to error-classifier — detects rate-limit (429, quota exceeded, resource exhausted) and auth failures (401, unauthorized, invalid key) that may benefit from key rotation - Add resolveAuthProfileCount() to env-injection — returns the number of auth profiles configured for an agent - Add withAuthKeyRetry() orchestrator in auth-key-retry.ts — wraps execute callbacks with automatic retry on rotatable errors, capped at one attempt per configured key - Integrate withAuthKeyRetry in agent-runner-execution.ts — replaces direct resolveAuthEnv + bridge creation with retry-aware wrapper Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
auth: ["key1", "key2"]), rate-limit or auth errors now trigger automatic retry with the next key in the rotationauth: falseagents execute once with no retry (existing behavior preserved)Changes
src/middleware/error-classifier.ts— AddisAuthRotatableError()detecting rate-limit (429, quota exceeded, resource exhausted, too many requests) and auth failures (401, unauthorized, invalid key)src/auth/env-injection.ts— AddresolveAuthProfileCount()returning the number of configured auth profiles for an agentsrc/middleware/auth-key-retry.ts(new) —withAuthKeyRetry()orchestrator wrapping execute callbacks with automatic retry on rotatable errors, capped at one attempt per keysrc/auto-reply/reply/agent-runner-execution.ts— Replace directresolveAuthEnv+ bridge creation withwithAuthKeyRetrywrapperTest plan
auth: false→ no retry attemptedCloses #423
🤖 Generated with Claude Code