Skip to content

feat(rotation): add multi-account support with automatic model rotation#78

Open
deuriib wants to merge 9 commits into
jenslys:mainfrom
deuriib:feat/multi-account-rotation
Open

feat(rotation): add multi-account support with automatic model rotation#78
deuriib wants to merge 9 commits into
jenslys:mainfrom
deuriib:feat/multi-account-rotation

Conversation

@deuriib

@deuriib deuriib commented May 23, 2026

Copy link
Copy Markdown

Problem

Using a single Gemini account often leads to immediate rate limits and capacity exhaustion (429 errors) when handling complex coding sessions or multi-model agents. This affects users on both free and premium plans, particularly with high-reasoning models like Gemini Pro and Flash.

Solution

This PR implements comprehensive Multi-Account Profile and Automatic Model Rotation Support. The plugin dynamically distributes API requests across multiple configured accounts in an account pool, tracking their health status, remaining quotas, and rate-limit cooldowns. When an account experiences transient errors or capacity limits, the pool automatically rotates to the next healthiest available account.

Closes #25
Closes #30

PR Type

  • New feature
  • Bug fix
  • Documentation only
  • Code refactoring
  • Maintenance/tooling
  • Breaking change

Summary

  • Account Pool Management (src/plugin/account-pool.ts, src/plugin/account-manager.ts): Manages multiple accounts loaded from configured provider options or user login profiles. Supports dynamic pool selection and status reporting.
  • Account Health & Selection (src/plugin/health.ts, src/plugin/rotation.ts): Ranks accounts by availability, success history, and quota. Employs priority sorting, ties breaking via LRU, and weighted random selection for low-quota states.
  • Network Retries & Cooldowns (src/plugin/retry/index.ts): Retries transient connection issues, handles Retry-After headers, and automatically triggers cooling-off periods for models experiencing 429 errors.
  • Aggregated Quotas (src/plugin/quota.ts): Provides terminal formatting for multi-account usage checks, grouping limits by model version and displaying comprehensive usage/remaining percentages.

Changes Table

File Change
src/plugin/account-pool.ts Manages the rotation pool, usage counts, failure reporting, and mutex refresh locks.
src/plugin/health.ts Formulates the health metrics based on successes, failures, and quota utilization.
src/plugin/rotation.ts Implements account selection logic with priority and tie-breaking algorithms.
src/plugin/retry/index.ts Orchestrates transparent request retries and coordinates cooldowns for exhausted models.
src/plugin/token.ts Provides on-demand OAuth access token refresh with lock-based deduplication.
src/plugin/quota.ts Formats and displays aggregate quota and usage information across accounts.

Test Plan

  • Unit and Integration Tests: bun test passes successfully for all 140 tests.
  • Manual verification of multi-account rotation, fallback, and health-based routing.

Contributor Checklist

  • Linked an approved issue
  • Added exactly one type:* label
  • Conventional commit format
  • No Co-Authored-By trailers

deuriib added 9 commits May 21, 2026 06:39
Shows consumed quota per model when remainingFraction and
remainingAmount are both available, calculated as
total = remaining / fraction, used = total - remaining.
The Code Assist quota API returns remainingFraction but not
remainingAmount, so absolute 'used' counts cannot be calculated.
Fall back to showing used percentage (100% - remaining%) instead
of 'unknown' when only fraction data is available.
- Introduce AccountPool for managing multiple accounts
- Implement health-weighted rotation strategy with quota fallback
- Add AccountManager for dynamic account addition/removal
- Persist dynamic accounts to ~/.config/opencode/gemini-auth.json
- Make retry cooldowns, auth caches, and project contexts per-account
- Update quota tool to display per-account and aggregate summaries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Too many request alert [Bug]: Error 429 on gemini 3 pro and flash

1 participant