feat: pause room work on the Claude usage limit and resume after reset

Before, a Claude run that hit the account usage limit closed the open
paired task as claude_usage_limit, posted the reset time and consumed the
user's messages, so the work was lost and had to be re-requested.

Now the room is paused instead:
- The failed turn is released without touching the paired task (no
  failure count, no status change, no follow-up) and the queue keeps the
  human messages unconsumed, so the same turn can run again.
- The room is recorded in router_state `claude_usage_pause` with the reset
  time (error text, else cached usage API reset, else a 10 min retry). A
  banner time that just passed is read as "now", not tomorrow.
- While the limit lasts, paused rooms run nothing and any other room's
  Claude turn pauses that room without spawning a run (the limit is
  account-wide). A stop request still goes through and drops the room
  from the resume list.
- The scheduler tick clears the pause 1 min after the reset, posts a
  resume notice and re-queues the rooms; the pending turn or the kept
  messages then run again. The state survives restarts.

Safety refusals keep closing the task as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-13 13:14:56 +09:00
parent 1167023a13
commit aed7371cfa
19 changed files with 893 additions and 90 deletions

View File

@@ -36,7 +36,12 @@ import {
RELOGIN_REQUIRED_MESSAGE,
} from './token-refresh.js';
import { findChannel, formatMessages } from './router.js';
import { stopRoomWorkIfRequested, type RoomStopResult } from './room-stop.js';
import {
findStopRequest,
stopRoomWorkIfRequested,
type RoomStopResult,
} from './room-stop.js';
import { isRoomPausedForClaudeUsage } from './claude-usage-pause.js';
import { reopenReviewSkippedTaskForReview } from './review-request-gate.js';
import { createScopedLogger, logger } from './logger.js';
import type { GroupQueue, GroupRunContext } from './group-queue.js';
@@ -269,6 +274,18 @@ async function processMissedMessages(
args.failureFinalText,
);
// A stop request still goes through, so the user can drop paused work.
if (
isRoomPausedForClaudeUsage(runtime.chatJid) &&
!findStopRequest(missedMessages)
) {
runtime.log.info(
{ pendingMessages: missedMessages.length },
'Room is paused by the Claude usage limit; leaving its work for the resume',
);
return true;
}
if (missedMessages.length === 0) {
return handleNoMissedMessages(args, runtime, rawMissedMessages);
}