fix: stop silent Claude 401 stalls and token-family revocations
- Refreshing the OAuth token revokes the old access token, and agents hold it in CLAUDE_CODE_OAUTH_TOKEN (Claude Code keeps env tokens on 401). Refresh early only while no run is active; keep the 1h hard deadline. - forceRefreshToken (after a 401) now probes /api/oauth/profile: a revoked token keeps its expiresAt, so it was handed back unchanged forever. A rejected token is refreshed; if that fails, re-login is flagged at once and held until a different token appears. - Classify "OAuth access token has been revoked" as auth-expired. When the login is gone, close the paired task and tell the room to re-login instead of looping owner/arbiter retries with suppressed output. - Only suppress the CLI's own short 401 banner, not an answer quoting it (a sketchup-app TASK_DONE report was swallowed this way). - Runner denies Bash commands that copy or write .credentials.json: a CLI test against a copied login refreshed the real token family on 2026-11-02 and logged out every room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,11 @@ import {
|
||||
isUsageAlignmentBypassed,
|
||||
} from './usage-alignment-hold.js';
|
||||
import { completePairedTaskWithReason } from './paired-task-status.js';
|
||||
import {
|
||||
forceRefreshToken,
|
||||
isReloginRequired,
|
||||
RELOGIN_REQUIRED_MESSAGE,
|
||||
} from './token-refresh.js';
|
||||
import { prepareMessageAgentExecutionTarget } from './message-agent-executor-target.js';
|
||||
import { shouldRetryFreshSessionOnAgentFailure } from './session-recovery.js';
|
||||
import { bindPairedSessionToTask } from './paired-session-binding.js';
|
||||
@@ -53,6 +58,10 @@ import {
|
||||
/** completion_reason of a paired task closed because Claude's safeguards refused it. */
|
||||
export const CLAUDE_SAFETY_REFUSAL_COMPLETION_REASON = 'claude_safety_refusal';
|
||||
|
||||
/** completion_reason of a paired task closed because the Claude login is gone. */
|
||||
export const CLAUDE_RELOGIN_REQUIRED_COMPLETION_REASON =
|
||||
'claude_relogin_required';
|
||||
|
||||
export const CLAUDE_SAFETY_REFUSAL_NOTICE =
|
||||
'Claude 안전 필터가 이 요청을 차단해서 처리하지 못했습니다. 이 방의 Claude 세션은 초기화했습니다. 요청을 조금 바꿔서 다시 보내 주세요. 에러 원문은 붙이지 말아 주세요.';
|
||||
|
||||
@@ -246,6 +255,9 @@ async function reportClaudeUsageLimitToRoom(
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (args.reason === 'auth-expired') {
|
||||
return reportClaudeReloginRequired(args);
|
||||
}
|
||||
if (args.reason !== 'safety-refusal') return false;
|
||||
const task = args.pairedTaskId
|
||||
? getPairedTaskById(args.pairedTaskId)
|
||||
@@ -266,6 +278,48 @@ async function reportClaudeUsageLimitToRoom(
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Claude run failed with a 401. The retry path has usually force-checked the
|
||||
* token already; a failure after visible output has not, so check here. When
|
||||
* the token is valid again, return false and let the normal retry continue.
|
||||
* When the login is gone, close the task and tell the room, instead of letting
|
||||
* owner/arbiter retries fail silently until someone asks why the bot stopped.
|
||||
*/
|
||||
async function reportClaudeReloginRequired(args: {
|
||||
activeRole: PairedRoomRole;
|
||||
pairedTaskId?: string;
|
||||
errorText?: string | null;
|
||||
pairedExecutionLifecycle: Pick<
|
||||
PairedExecutionLifecycle,
|
||||
'updateSummary' | 'completeImmediately'
|
||||
>;
|
||||
onOutput?: (output: AgentOutput) => Promise<void>;
|
||||
log: { warn: (obj: Record<string, unknown>, msg: string) => void };
|
||||
}): Promise<boolean> {
|
||||
if (!isReloginRequired()) await forceRefreshToken();
|
||||
if (!isReloginRequired()) return false;
|
||||
const task = args.pairedTaskId
|
||||
? getPairedTaskById(args.pairedTaskId)
|
||||
: undefined;
|
||||
if (task) {
|
||||
completePairedTaskWithReason(
|
||||
task,
|
||||
CLAUDE_RELOGIN_REQUIRED_COMPLETION_REASON,
|
||||
);
|
||||
}
|
||||
args.log.warn(
|
||||
{ role: args.activeRole, errorText: args.errorText },
|
||||
'Claude login is gone; closed the task and asked the room to re-login',
|
||||
);
|
||||
await deliverNoticeAndFailExecution({
|
||||
notice: RELOGIN_REQUIRED_MESSAGE,
|
||||
summary: RELOGIN_REQUIRED_MESSAGE,
|
||||
pairedExecutionLifecycle: args.pairedExecutionLifecycle,
|
||||
onOutput: args.onOutput,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner finalize without an agent run (see paired-finalize.ts): close the task
|
||||
* and deliver the already-reviewed answer as the final message. Returns false
|
||||
|
||||
Reference in New Issue
Block a user