mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 22:30:21 +00:00
fix(auth): reset cooldown error counters on expiry to prevent infinite escalation (#41028)
Merged via squash.
Prepared head SHA: 89bd83f09a
Co-authored-by: zerone0x <39543393+zerone0x@users.noreply.github.com>
Co-authored-by: altaywtf <9790196+altaywtf@users.noreply.github.com>
Reviewed-by: @altaywtf
This commit is contained in:
@@ -400,9 +400,19 @@ function computeNextProfileUsageStats(params: {
|
||||
params.existing.lastFailureAt > 0 &&
|
||||
params.now - params.existing.lastFailureAt > windowMs;
|
||||
|
||||
const baseErrorCount = windowExpired ? 0 : (params.existing.errorCount ?? 0);
|
||||
// If the previous cooldown has already expired, reset error counters so the
|
||||
// profile gets a fresh backoff window. clearExpiredCooldowns() does this
|
||||
// in-memory during profile ordering, but the on-disk state may still carry
|
||||
// the old counters when the lock-based updater reads a fresh store. Without
|
||||
// this check, stale error counts from an expired cooldown cause the next
|
||||
// failure to escalate to a much longer cooldown (e.g. 1 min → 25 min).
|
||||
const unusableUntil = resolveProfileUnusableUntil(params.existing);
|
||||
const previousCooldownExpired = typeof unusableUntil === "number" && params.now >= unusableUntil;
|
||||
|
||||
const shouldResetCounters = windowExpired || previousCooldownExpired;
|
||||
const baseErrorCount = shouldResetCounters ? 0 : (params.existing.errorCount ?? 0);
|
||||
const nextErrorCount = baseErrorCount + 1;
|
||||
const failureCounts = windowExpired ? {} : { ...params.existing.failureCounts };
|
||||
const failureCounts = shouldResetCounters ? {} : { ...params.existing.failureCounts };
|
||||
failureCounts[params.reason] = (failureCounts[params.reason] ?? 0) + 1;
|
||||
|
||||
const updatedStats: ProfileUsageStats = {
|
||||
|
||||
Reference in New Issue
Block a user