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:
@@ -34,6 +34,7 @@ import {
|
||||
isUsageAlignmentBypassed,
|
||||
} from './usage-alignment-hold.js';
|
||||
import { completePairedTaskWithReason } from './paired-task-status.js';
|
||||
import { parkRoomForClaudeAuthRecovery } from './claude-auth-recovery.js';
|
||||
import {
|
||||
forceRefreshToken,
|
||||
getClaudeAuthRecoveryIncident,
|
||||
@@ -64,8 +65,8 @@ export const CLAUDE_RELOGIN_REQUIRED_COMPLETION_REASON =
|
||||
'claude_relogin_required';
|
||||
|
||||
export const CLAUDE_AUTH_RECOVERING_NOTICE =
|
||||
'⚠️ 클로드 인증 서버 오류로 토큰 갱신이 잠시 실패해서 이번 작업을 멈췄습니다. ' +
|
||||
'봇이 5분마다 자동으로 다시 시도하고 있습니다. 잠시 후 이 방에 "계속"이라고 보내 주시면 이어서 진행합니다. ' +
|
||||
'⚠️ 클로드 인증 서버 오류로 토큰 갱신이 잠시 실패해서 이 방의 작업을 일시정지했습니다. ' +
|
||||
'봇이 5분마다 자동으로 다시 시도하고, 복구되면 멈춘 작업을 자동으로 이어서 진행합니다. ' +
|
||||
'30분 넘게 복구되지 않으면 재로그인 안내를 드리겠습니다.';
|
||||
|
||||
// chatJid -> auth recovery incident already announced in that room.
|
||||
@@ -296,12 +297,13 @@ async function reportClaudeUsageLimitToRoom(
|
||||
*/
|
||||
async function reportClaudeReloginRequired(args: {
|
||||
chatJid: string;
|
||||
runId: string;
|
||||
activeRole: PairedRoomRole;
|
||||
pairedTaskId?: string;
|
||||
errorText?: string | null;
|
||||
pairedExecutionLifecycle: Pick<
|
||||
PairedExecutionLifecycle,
|
||||
'updateSummary' | 'completeImmediately'
|
||||
'updateSummary' | 'completeImmediately' | 'releaseForClaudeUsagePause'
|
||||
>;
|
||||
onOutput?: (output: AgentOutput) => Promise<void>;
|
||||
log: { warn: (obj: Record<string, unknown>, msg: string) => void };
|
||||
@@ -334,35 +336,48 @@ async function reportClaudeReloginRequired(args: {
|
||||
|
||||
/**
|
||||
* The token was rejected but refreshing failed only transiently (429/5xx/
|
||||
* timeout): the login may still be fine, so keep the task and let the
|
||||
* automatic retries run. Tell the room once per incident why the work stopped;
|
||||
* later failures in the same incident take the normal retry path.
|
||||
* timeout): the login may still be fine. Park the room like the usage-limit
|
||||
* pause: release the turn without counting a failure (no owner_failure_count,
|
||||
* no arbiter hand-off), keep the messages unconsumed, and resume the room
|
||||
* once the token recovers (claude-auth-recovery.ts). The room is told once
|
||||
* per incident.
|
||||
*/
|
||||
async function reportClaudeAuthRecovering(args: {
|
||||
chatJid: string;
|
||||
runId: string;
|
||||
activeRole: PairedRoomRole;
|
||||
errorText?: string | null;
|
||||
pairedExecutionLifecycle: Pick<
|
||||
PairedExecutionLifecycle,
|
||||
'updateSummary' | 'completeImmediately'
|
||||
'updateSummary' | 'releaseForClaudeUsagePause'
|
||||
>;
|
||||
onOutput?: (output: AgentOutput) => Promise<void>;
|
||||
log: { warn: (obj: Record<string, unknown>, msg: string) => void };
|
||||
}): Promise<boolean> {
|
||||
const incident = getClaudeAuthRecoveryIncident();
|
||||
if (incident === null) return false;
|
||||
if (announcedAuthRecovery.get(args.chatJid) === incident) return false;
|
||||
announcedAuthRecovery.set(args.chatJid, incident);
|
||||
args.log.warn(
|
||||
{ role: args.activeRole, incident, errorText: args.errorText },
|
||||
'Claude token refresh failing transiently; told the room and kept the task',
|
||||
);
|
||||
await deliverNoticeAndFailExecution({
|
||||
notice: CLAUDE_AUTH_RECOVERING_NOTICE,
|
||||
summary: CLAUDE_AUTH_RECOVERING_NOTICE,
|
||||
pairedExecutionLifecycle: args.pairedExecutionLifecycle,
|
||||
onOutput: args.onOutput,
|
||||
parkRoomForClaudeAuthRecovery(args.chatJid);
|
||||
markRunPausedForClaudeUsage(args.runId);
|
||||
args.pairedExecutionLifecycle.updateSummary({
|
||||
outputText: CLAUDE_AUTH_RECOVERING_NOTICE,
|
||||
});
|
||||
args.pairedExecutionLifecycle.releaseForClaudeUsagePause(
|
||||
'Claude token refresh is failing transiently; room parked until auth recovers',
|
||||
);
|
||||
const firstNotice = announcedAuthRecovery.get(args.chatJid) !== incident;
|
||||
args.log.warn(
|
||||
{ role: args.activeRole, incident, firstNotice, errorText: args.errorText },
|
||||
'Claude token refresh failing transiently; parked the room without counting a failure',
|
||||
);
|
||||
if (firstNotice) {
|
||||
announcedAuthRecovery.set(args.chatJid, incident);
|
||||
await args.onOutput?.({
|
||||
status: 'success',
|
||||
result: null,
|
||||
output: { visibility: 'public', text: CLAUDE_AUTH_RECOVERING_NOTICE },
|
||||
phase: 'final',
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user