Repository navigation
fix: Auto-expire auth profile cooldowns when timestamp expires - #3607
bergcb322-clawd wants to merge 1 commit into
Conversation
Fixes openclaw#3604 Auth profiles were getting stuck in cooldown even after the cooldownUntil timestamp had expired. This happened because the cooldown check only happened during profile selection, but expired cooldowns were never cleared from the store. Changes: - Added auto-expiry logic in profile ordering (both explicit and round-robin paths) - When now >= cooldownUntil, clear both cooldownUntil and disabledUntil - Ensures profiles become available immediately after cooldown expires Tested by manually setting expired cooldown and verifying it clears on next profile resolution attempt.
| // Auto-expire cooldowns that have passed | ||
| if (stats && cooldownUntil > 0 && now >= cooldownUntil) { | ||
| stats.cooldownUntil = undefined; | ||
| stats.disabledUntil = undefined; |
There was a problem hiding this comment.
[P1] Clearing disabledUntil when only cooldownUntil expired can re-enable profiles prematurely.
In the explicit-order path, cooldownUntil is computed as max(cooldownUntil, disabledUntil) (via resolveProfileUnusableUntil). If disabledUntil is still in the future, now >= cooldownUntil is false, so this block doesn’t run. But if disabledUntil is past and cooldownUntil is also past, both get cleared even though disabledUntil might represent a billing disable reason that you may want to preserve until it truly expires (or preserve disabledReason/counters). Consider expiring each field independently (clear cooldownUntil only if now >= cooldownUntil, and clear disabledUntil only if now >= disabledUntil) to avoid unintended state changes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/auth-profiles/order.ts
Line: 104:107
Comment:
[P1] Clearing `disabledUntil` when only `cooldownUntil` expired can re-enable profiles prematurely.
In the explicit-order path, `cooldownUntil` is computed as `max(cooldownUntil, disabledUntil)` (via `resolveProfileUnusableUntil`). If `disabledUntil` is still in the future, `now >= cooldownUntil` is false, so this block doesn’t run. But if `disabledUntil` is past and `cooldownUntil` is also past, both get cleared even though `disabledUntil` might represent a billing disable reason that you may want to preserve until it truly expires (or preserve `disabledReason`/counters). Consider expiring each field independently (clear `cooldownUntil` only if `now >= cooldownUntil`, and clear `disabledUntil` only if `now >= disabledUntil`) to avoid unintended state changes.
How can I resolve this? If you propose a fix, please make it concise.| for (const profileId of order) { | ||
| const stats = store.usageStats?.[profileId]; | ||
| if (stats) { | ||
| const unusableUntil = resolveProfileUnusableUntil(stats); | ||
| // Auto-expire cooldowns that have passed | ||
| if (unusableUntil && unusableUntil > 0 && now >= unusableUntil) { | ||
| stats.cooldownUntil = undefined; | ||
| stats.disabledUntil = undefined; | ||
| } | ||
| } | ||
|
|
||
| if (isProfileInCooldown(store, profileId)) { |
There was a problem hiding this comment.
[P3] Duplicated cooldown-expiry logic diverges from isProfileInCooldown behavior.
resolveProfileUnusableUntil/expiry logic is now implemented in two places here and separately in src/agents/auth-profiles/usage.ts. This increases the chance of future drift (e.g., if disabledReason/other fields start mattering). It may be simpler/safer to centralize “expire stats if unusableUntil passed” in a shared helper in usage.ts and call it from both ordering paths.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/auth-profiles/order.ts
Line: 155:166
Comment:
[P3] Duplicated cooldown-expiry logic diverges from `isProfileInCooldown` behavior.
`resolveProfileUnusableUntil`/expiry logic is now implemented in two places here and separately in `src/agents/auth-profiles/usage.ts`. This increases the chance of future drift (e.g., if `disabledReason`/other fields start mattering). It may be simpler/safer to centralize “expire stats if unusableUntil passed” in a shared helper in `usage.ts` and call it from both ordering paths.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.bfc1ccb to
f92900f
Compare
|
Closing in favor of #17853 as it has more tests |
Fixes #3604
Problem
Auth profiles were getting stuck in cooldown even after the
cooldownUntiltimestamp had expired, blocking the agent from making API calls indefinitely.Root Cause
The cooldown check only happened during profile selection (
isProfileInCooldown), but expired cooldowns were never cleared from the store. Profiles remained marked as unavailable even whenDate.now() >= cooldownUntil.Solution
Added auto-expiry logic in
resolveAuthProfileOrder(both explicit and round-robin paths):now >= unusableUntil, clear bothcooldownUntilanddisabledUntilTesting
Manually tested by:
Evidence
Before fix:
After fix:
Greptile Overview
Greptile Summary
This PR updates auth profile ordering (
src/agents/auth-profiles/order.ts) to auto-expire cooldown/disable timestamps when they’re already in the past, preventing profiles from remaining stuck as “in cooldown” indefinitely. The logic is applied in both the explicit-order path and the round-robin ordering path so thatresolveAuthProfileOrderreturns available profiles immediately after expiry.Confidence Score: 3/5
cooldownUntilanddisabledUntiltogether, which could unintentionally re-enable a profile if those fields are meant to expire independently.(2/5) Greptile learns from your feedback when you react with thumbs up/down!