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>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
/**
|
|
* Rooms whose Claude work is parked while a rejected OAuth token is being
|
|
* refreshed through a transient outage (see token-refresh.ts). Parking works
|
|
* like the usage-limit pause: the paired task, its failure count and the
|
|
* unconsumed messages stay as they were. Once the token recovers, every
|
|
* parked room is re-queued so the same turn runs again without user input.
|
|
*/
|
|
|
|
import { logger } from './logger.js';
|
|
|
|
const parkedRooms = new Set<string>();
|
|
|
|
export function parkRoomForClaudeAuthRecovery(chatJid: string): void {
|
|
parkedRooms.add(chatJid);
|
|
}
|
|
|
|
/** Remove and return every parked room. */
|
|
export function takeRoomsParkedForClaudeAuthRecovery(): string[] {
|
|
const rooms = [...parkedRooms];
|
|
parkedRooms.clear();
|
|
return rooms;
|
|
}
|
|
|
|
/** Re-queue parked rooms; rooms without a binding are skipped. */
|
|
export function resumeRoomsAfterClaudeAuthRecovery(deps: {
|
|
resolveIpcDir: (chatJid: string) => string | null;
|
|
enqueueMessageCheck: (chatJid: string, ipcDir: string) => void;
|
|
}): string[] {
|
|
const resumed: string[] = [];
|
|
for (const chatJid of takeRoomsParkedForClaudeAuthRecovery()) {
|
|
const ipcDir = deps.resolveIpcDir(chatJid);
|
|
if (!ipcDir) {
|
|
logger.warn(
|
|
{ chatJid },
|
|
'Skipped resuming a room parked for Claude auth recovery without a room binding',
|
|
);
|
|
continue;
|
|
}
|
|
deps.enqueueMessageCheck(chatJid, ipcDir);
|
|
resumed.push(chatJid);
|
|
}
|
|
if (resumed.length > 0) {
|
|
logger.info(
|
|
{ rooms: resumed },
|
|
'Claude OAuth recovered; resumed parked rooms',
|
|
);
|
|
}
|
|
return resumed;
|
|
}
|