/** * 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(); 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; }