mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:51:25 +00:00
fix: keep auth-profile cooldown windows immutable in-window (#23536) (thanks @arosstale)
This commit is contained in:
@@ -287,25 +287,29 @@ function computeNextProfileUsageStats(params: {
|
||||
baseMs: params.cfgResolved.billingBackoffMs,
|
||||
maxMs: params.cfgResolved.billingMaxMs,
|
||||
});
|
||||
const newDisabledUntil = params.now + backoffMs;
|
||||
// Only advance disabledUntil — never shorten an existing window.
|
||||
// A retry that fires while the profile is already disabled must not reset
|
||||
// the deadline to an earlier time; it may extend it if the new backoff is longer.
|
||||
if (!params.existing.disabledUntil || newDisabledUntil > params.existing.disabledUntil) {
|
||||
updatedStats.disabledUntil = newDisabledUntil;
|
||||
}
|
||||
const existingDisabledUntil = params.existing.disabledUntil;
|
||||
const hasActiveDisabledWindow =
|
||||
typeof existingDisabledUntil === "number" &&
|
||||
Number.isFinite(existingDisabledUntil) &&
|
||||
existingDisabledUntil > params.now;
|
||||
// Keep active disable windows immutable so retries within the window cannot
|
||||
// extend recovery time indefinitely.
|
||||
updatedStats.disabledUntil = hasActiveDisabledWindow
|
||||
? existingDisabledUntil
|
||||
: params.now + backoffMs;
|
||||
updatedStats.disabledReason = "billing";
|
||||
} else {
|
||||
const backoffMs = calculateAuthProfileCooldownMs(nextErrorCount);
|
||||
const newCooldownUntil = params.now + backoffMs;
|
||||
// Only advance cooldownUntil — never shorten an existing window.
|
||||
// When the backoff saturates (60 min) and retries fire every 30 min, each
|
||||
// retry was resetting cooldownUntil to now+60m, preventing the profile from
|
||||
// ever recovering. We only write a new deadline when it is strictly later
|
||||
// than the one already in the store.
|
||||
if (!params.existing.cooldownUntil || newCooldownUntil > params.existing.cooldownUntil) {
|
||||
updatedStats.cooldownUntil = newCooldownUntil;
|
||||
}
|
||||
const existingCooldownUntil = params.existing.cooldownUntil;
|
||||
const hasActiveCooldownWindow =
|
||||
typeof existingCooldownUntil === "number" &&
|
||||
Number.isFinite(existingCooldownUntil) &&
|
||||
existingCooldownUntil > params.now;
|
||||
// Keep active cooldown windows immutable so retries within the window
|
||||
// cannot push recovery further out.
|
||||
updatedStats.cooldownUntil = hasActiveCooldownWindow
|
||||
? existingCooldownUntil
|
||||
: params.now + backoffMs;
|
||||
}
|
||||
|
||||
return updatedStats;
|
||||
|
||||
Reference in New Issue
Block a user