fix: park rooms during a transient Claude auth outage instead of failing
ff76d04 told the room about a transient refresh failure but still failed
the execution (completeImmediately 'failed'), which bumps
owner_failure_count and can hand the task to the arbiter after two blips.
- reportClaudeAuthRecovering now parks the turn like the usage-limit
pause: releaseForClaudeUsagePause (lease released, no failure count, no
follow-up) plus markRunPausedForClaudeUsage (messages stay unconsumed).
The room is told once per incident; later blips park silently.
- token-refresh fires setOnClaudeAuthRecovered once a rejected token is
replaced (deferred so the new token is in memory first); index.ts
re-queues every parked room so the same turn runs without user input.
- Real-DB test: two parked owner runs leave owner_failure_count/status/
arbiter_requested_at unchanged (control: a failed run does count).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,14 @@ let authFailure: AuthFailureState | null = null;
|
||||
let rejectedAccessToken: string | null = null;
|
||||
// Bumped for each newly rejected token, so rooms are told once per incident.
|
||||
let authRecoveryIncident = 0;
|
||||
// Called once a rejected token has been replaced by a working one.
|
||||
let onAuthRecovered: (() => void) | null = null;
|
||||
const AUTH_RECOVERED_RESUME_DELAY_MS = 1_000;
|
||||
|
||||
/** Register the hook that resumes rooms parked during an auth outage. */
|
||||
export function setOnClaudeAuthRecovered(fn: (() => void) | null): void {
|
||||
onAuthRecovered = fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current token was rejected and refreshing failed for a transient reason;
|
||||
@@ -107,8 +115,28 @@ export function isReloginRequired(): boolean {
|
||||
|
||||
/** Clear failure tracking once a valid token is observed again. */
|
||||
function recordAuthSuccess(accessToken?: string): void {
|
||||
if (accessToken && accessToken !== rejectedAccessToken) {
|
||||
if (
|
||||
accessToken &&
|
||||
rejectedAccessToken !== null &&
|
||||
accessToken !== rejectedAccessToken
|
||||
) {
|
||||
rejectedAccessToken = null;
|
||||
logger.info('Claude OAuth token replaced after a rejection — resuming');
|
||||
// Deferred: the caller still has to write the new token to disk and into
|
||||
// memory, and a resumed run must not start with the rejected one.
|
||||
const hook = onAuthRecovered;
|
||||
if (hook) {
|
||||
setTimeout(() => {
|
||||
try {
|
||||
hook();
|
||||
} catch (err) {
|
||||
logger.warn(
|
||||
{ err: getErrorMessage(err) },
|
||||
'Resuming rooms after Claude auth recovery failed',
|
||||
);
|
||||
}
|
||||
}, AUTH_RECOVERED_RESUME_DELAY_MS);
|
||||
}
|
||||
}
|
||||
if (
|
||||
authFailure?.deadAccessToken &&
|
||||
|
||||
Reference in New Issue
Block a user