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

@@ -74,7 +74,7 @@ ANTHROPIC_BASE_URL=
- `CLAUDE_CODE_OAUTH_TOKEN`: runner에 주입하는 Claude 토큰. 예전 `CLAUDE_CODE_OAUTH_TOKENS`(쉼표 구분)가 남아 있으면 첫 번째 값만 씁니다
- `CLAUDE_CREDENTIALS_PATH`: 이 서비스의 Claude OAuth credentials 파일. `CLAUDE_TOKEN_REFRESH_USE_CREDENTIALS=true`면 만료 전에 자동 갱신하고 새 토큰을 `.env`에도 기록합니다
- Claude가 사용 한도에 도달하면 다른 provider로 넘기지 않습니다. 방에 `Claude 사용 한도에 도달했습니다. 21:40에 재개할 수 있습니다.`처럼 재개 시각을 보내고(시각을 모르면 `잠시 후 다시 시도해 주세요`), 열린 paired task를 `claude_usage_limit`으로 닫습니다. 다음 메시지부터 새 작업으로 처리됩니다
- Claude가 사용 한도에 도달하면 다른 provider로 넘기지 않고 그 방의 작업을 일시정지합니다. 방에 `Claude 사용 한도에 도달해서 이 방의 작업을 일시정지했습니다. 21:40에 사용량이 초기화되면 자동으로 이어서 진행합니다.`처럼 재개 시각을 보내고, paired task와 처리하던 메시지는 그대로 둡니다. 한도가 남아 있는 동안 다른 방의 Claude turn도 실행하지 않고 일시정지합니다. 초기화 시각 1분 뒤 스케줄러가 방들을 다시 큐에 넣어 같은 turn을 이어서 실행합니다. 재개 시각을 모르면 10분 뒤에 다시 시도합니다. 일시정지 상태는 `router_state.claude_usage_pause`에 저장되어 재시작 후에도 유지되며, 일시정지 중 "중단"을 보내면 그 방은 재개하지 않습니다
Codex 쪽은 **OAuth 세션 파일** 기준으로 동작합니다. `~/.codex-accounts/0/auth.json`을 쓰고, 없으면 `~/.codex/auth.json`을 씁니다. Codex 실행은 계정 잠금으로 한 번에 하나만 돌고, 잠겨 있으면 최대 15분 기다립니다. `OPENAI_API_KEY`를 Codex child process에 넘겨서 빌링하는 구조는 사용하지 않습니다.