-
Notifications
You must be signed in to change notification settings - Fork 6.1k
feat(auth): OAuth Marathon - multi-account credential rotation #8590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate FoundPR #5754: auth: multi-account OAuth subscription failover Why it's related: This PR appears to address the same core functionality - multi-account OAuth credential failover. Both PRs are designed to handle credential rotation when one account fails (rate limits, auth errors). The current PR (#8590) seems to be an evolution or reimplementation of this concept with the "OAuth Marathon" feature set, including automatic rotation on 429/401/403 errors and cooldown tracking. You should verify:
|
|
This supersedes #5754 with a simpler, more maintainable approach:
|
OAuth Marathon 🏃
Keep running when you hit the wall. This PR adds automatic credential rotation for OAuth providers - when one account hits rate limits or auth errors, opencode seamlessly switches to your next available credential within the same provider.
Closes #8591
Works for all OAuth providers — both core providers and plugins.
The Problem
Using OAuth providers with personal subscriptions often means hitting rate limits mid-session. Currently, when this happens, your request fails and you're stuck waiting.
The Solution
Register multiple OAuth accounts for the same provider, and opencode will automatically:
How to Add Multiple Accounts
Run
opencode auth loginmultiple times for the same provider:Architecture Overview
flowchart TD A[Provider.getSDK] --> B[createOAuthRotatingFetch] B --> C{fetchFn} C -->|429 Rate Limit| D[moveToBack + notifyFailover] C -->|401/403 Auth| E[markAccessExpired + retry] C -->|Network Error| F[recordOutcome + notifyFailover] C -->|200 OK| G[recordOutcome success] D --> H[Try Next Credential] E -->|Still fails| H F --> H H --> CDemo
Configuration (Optional)
Per-provider settings in
opencode.json. Sensible defaults are used if omitted:{ "provider": { "openai": { "oauth": { "maxAttempts": 3, // default: number of accounts "rateLimitCooldownMs": 60000, // default: 30000 "authFailureCooldownMs": 300000, // default: 300000 "toastDurationMs": 5000 // default: 8000 } } } }Changes
src/auth/rotating-fetch.ts- Core rotation logicsrc/auth/context.ts- AsyncLocalStorage for request scopingsrc/auth/credential-manager.ts- Toast notificationssrc/auth/index.ts- OAuth pool management & persistencesrc/config/config.ts- Newoauthconfig schematest/auth/oauth-rotation.test.ts- 10 test casesVerification
How I tested:
Test Coverage