Skip to content

feat: add minimum quota reserve and account cooldown#584

Open
steel-code-agent wants to merge 2 commits intodecolua:masterfrom
SteelMorgan:feat/quota-reserve-cooldown
Open

feat: add minimum quota reserve and account cooldown#584
steel-code-agent wants to merge 2 commits intodecolua:masterfrom
SteelMorgan:feat/quota-reserve-cooldown

Conversation

@steel-code-agent
Copy link
Copy Markdown

Summary

  • Minimum Quota Reserve: per-connection setting that blocks account routing when remaining quota drops below a configurable threshold (default 15%). Prevents draining accounts to zero before switching to the next one.
  • Account Cooldown: per-connection setting that keeps an account unavailable for N minutes (default 30) after its quota resets. Prevents immediately re-using freshly-reset accounts.
  • Background quota monitor (60s polling interval) checks quota for enabled connections and manages state transitions in-memory — zero disk writes on each tick.
  • Account selection filter in auth.js — pure in-memory lookup with zero latency impact.
  • UI: "Quota Management" section in Edit Connection modal (only for OAuth providers with quota support), orange "Reserve limit" and blue "Cooldown" badges with live countdown on Quota Tracker cards.
  • Russian i18n translations included.

New files

File Purpose
src/shared/utils/quotaPercent.js Compute min remaining % from raw provider usage response
src/shared/services/quotaReserveState.js In-memory state store (global singleton)
src/shared/services/credentialRefresh.js Extracted credential refresh logic (shared between usage route and monitor)
src/shared/services/quotaMonitorService.js Background 60s polling service
src/app/api/quota-reserve/route.js GET endpoint exposing reserve states to frontend

Modified files

File Change
src/sse/services/auth.js Add isConnectionReserveBlocked() filter in account selection
src/app/api/providers/[id]/route.js Accept minReserveEnabled, minReservePercent, cooldownEnabled, cooldownMinutes
src/app/api/usage/[connectionId]/route.js Refactored to use shared credentialRefresh service
src/shared/services/initializeApp.js Register startQuotaMonitor()
src/shared/components/EditConnectionModal.js "Quota Management" section with toggles and inputs
src/app/(dashboard)/dashboard/usage/components/ProviderLimits/index.js Reserve/cooldown badges on Quota Tracker cards
public/i18n/literals/ru.json Russian translations

Test plan

  • Open Edit modal on OAuth provider (Claude, GitHub, etc.) — "Quota Management" section visible
  • Open Edit modal on API key provider — section hidden
  • Enable Minimum Reserve (15%), save — settings persist after page reload
  • Background monitor detects low quota — orange "Reserve limit" badge appears on Quota Tracker
  • Account with reserve-blocked status is skipped during request routing
  • After quota resets, blue "Cooldown" badge appears with live countdown timer
  • Cooldown expires — badge disappears, account becomes available again
  • Build passes (next build --webpack)

🤖 Generated with Claude Code

SteelMorgan and others added 2 commits April 13, 2026 18:38
Per-connection settings to prevent draining accounts to zero and to
rest them after quota resets:

- Minimum Reserve: block account when remaining quota drops below a
  configurable threshold (default 15%)
- Cooldown on Reset: keep account unavailable for N minutes (default 30)
  after quota refreshes, preventing immediate re-use

Architecture:
- Background monitor service (60s polling) checks quota for enabled
  connections and manages state transitions in-memory
- auth.js filters out reserve-blocked and cooling-down connections
  during account selection (zero-latency in-memory lookup)
- GET /api/quota-reserve exposes state to frontend
- Edit modal shows Quota Management section for OAuth providers
- Quota Tracker cards show orange "Reserve limit" and blue "Cooldown"
  badges with live countdown
- Russian i18n translations included

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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