AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] Setting account state to "ready" (PUT /api/accounts/{id}/state) clears all per-model quota cooldowns (runtimeState.Cooldowns)

Open photobrand opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Summary

In v0.3.13, switching an account's state back to ready via the new account state dropdown (PUT /api/accounts/{id}/state with {"state":"ready"}) clears all entries in runtimeState.Cooldowns, including long-running per-model quota cooldowns (套餐限额 / 每日限额).

Minimal Reproduction

  1. Have an account with an active model quota cooldown in runtime-state.json (e.g. gemini-4-neon in 套餐限额 until 10:59).
  2. Have that account become restricted (e.g. 403 verification on another request), auth_required (401), or manually disabled.
  3. In the Accounts page state dropdown, change the account state to Ready (就绪).
  4. Check Requests -> Model cooldowns (GET /api/cooldowns) or runtime-state.json.

Expected vs Observed

  • Expected: Changing account state to Ready clears account-level blocking states (Restricted, AccountAuthRequired, disabled, stateMessage — and at most non-quota global * cooldowns), while preserving per-model upstream quota cooldowns (套餐限额, 每日限额, etc.), which already have their own per-scope clear button (DELETE /api/accounts/{id}/cooldowns/{scope}).
  • Observed: All per-model quota cooldowns on the account are wiped immediately, causing the scheduler to route requests for exhausted models back to that account.

Root Cause Pointer (verified in v0.3.13 / c77dd89)

  • internal/app/admin.go (restoreAccount) calls admin.pool.ClearAccountState(accountID).
  • internal/aistudio/accounts.go (ClearAccountState) unconditionally runs:
    runtimeState.Restricted = ""
    clear(runtimeState.Cooldowns)
    
    
    

Note that ClearPageCooldownIfGeneration (internal/aistudio/accounts.go) already uses keepQuota = true (quotaCooldownReason) specifically to avoid clearing upstream quota cooldowns during recovery/sync, whereas ClearAccountState clears the entire Cooldowns map.

###Suggested Fix In ClearAccountState, keep entries where quotaCooldownReason(cooldown.Reason) is true (or only clear Restricted / auth_required / non-quota global * cooldowns), leaving per-model quota cooldowns manageable via the existing DELETE /api/accounts/{id}/cooldowns/{scope} endpoint.

版本 / Version

v0.3.13

photobrand avatar Nov 20 '26 23:11 photobrand