Skip to content

feat(quota): pause accounts below a remaining-credit floor - #13

Merged
peach0x33a merged 1 commit into
peach0x33a:masterfrom
HardeNNN:pr/quota-credit-pause
Nov 16, 2026
Merged

peach0x33a merged 1 commit into
peach0x33a:masterfrom
HardeNNN:pr/quota-credit-pause

Conversation

@HardeNNN

Copy link
Copy Markdown
Contributor

Adds an optional per-account pause_below_credits guard so the gateway stops routing to an account that is nearly exhausted, instead of exhausting it and hitting 429s.

  • pause_below_credits is read from config.yaml, exposed on the admin API (paused, pause_below_credits) and patchable via PATCH /admin/api/accounts/{id}. It is counted in plan credits, the unit the quota endpoints report.
  • QuotaService.RefreshAccount feeds the latest remaining monthly credits into the account; at or below the floor the account is parked. Lowering or clearing the floor re-evaluates immediately.
  • AccountPool.Acquire skips parked accounts. If every enabled account is parked, CCClient.Send returns 503 quota_paused (with the earliest cooldown when one exists) instead of a misleading rate-limit error.
  • QuotaService.ApplyCached seeds the pause state from persisted snapshots at startup, so a restart does not route to an account that was already parked.
  • Docs (en/zh) cover the config field and the API behaviour; tests cover the pool state machine, the admin PATCH (including negative rejection and persistence) and the cached-restore path.

No WebUI changes in this PR. Tested with go test ./... and go vet ./....

Add an optional per-account pause_below_credits floor. The quota refresh feeds
the latest remaining monthly credits into the account, Acquire skips parked
accounts, and a persisted snapshot restores the pause state on startup so the
first request is not routed to an exhausted account. When every enabled account
is parked the client receives 503 quota_paused.
@peach0x33a
peach0x33a merged commit de1fc3d into peach0x33a:master Nov 16, 2026
3 checks passed
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.

2 participants