fix: stop the usage-limit loop (new banner, RESET misread, arbiter cap)

During the 2026-10-15 02:17-03:20 Claude session limit one task cycled
owner -> arbiter -> owner ~300 times:

- The CLI banner changed to "You've hit your session limit · resets
  3:20am"; only "hit your limit" was recognised, so the banner was a
  successful answer instead of a usage-limit pause. Match "hit your
  <0-2 words> limit".
- classifyArbiterVerdict matched the keyword anywhere in a line,
  case-insensitively, so "resets 3:20am" read as RESET. Require the
  upper-case keyword to lead the line as a whole word (the arbiter
  prompt already asks for that).
- The "reviewer failed repeatedly -> request arbiter" path did not pass
  arbiter_intervention_count, so ARBITER_MAX_INTERVENTIONS never applied
  there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-15 05:08:08 +09:00
parent aed7371cfa
commit 9dc5d9ea70
7 changed files with 130 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import {
detectClaudeProviderFailureMessage,
isClaudeOrgAccessDeniedMessage,
isClaudeSafetyRefusalMessage,
isClaudeUsageExhaustedMessage,
} from './agent-error-detection.js';
describe('agent-error-detection', () => {
@@ -126,4 +127,34 @@ describe('agent-error-detection', () => {
retryAfterMs: undefined,
});
});
it('detects Claude usage-limit banners, including ones that name the limit', () => {
for (const banner of [
"You've hit your limit · resets 9:40pm (Asia/Seoul)",
"You've hit your session limit · resets 3:20am (Asia/Seoul)",
'You\u2019ve hit your weekly limit · resets Oct 20, 9am (Asia/Seoul)',
'You have hit your Opus limit · resets 5pm',
]) {
expect(isClaudeUsageExhaustedMessage(banner)).toBe(true);
expect(classifyAgentError(banner)).toMatchObject({ reason: '429' });
}
expect(
isClaudeUsageExhaustedMessage(
"You're out of extra usage · resets 5pm (Asia/Seoul)",
),
).toBe(true);
});
it('does not treat an answer that quotes the usage-limit banner as one', () => {
expect(
isClaudeUsageExhaustedMessage(
`TASK_DONE\n원인은 "You've hit your session limit · resets 3:20am" 입니다.`,
),
).toBe(false);
expect(
isClaudeUsageExhaustedMessage(
"You've hit your limit with this approach.",
),
).toBe(false);
});
});

View File

@@ -7,6 +7,15 @@
// ── Banner / text detection ─────────────────────────────────────
/**
* "hit your limit" and the newer variants that name the limit, e.g.
* "You've hit your session limit" / "You've hit your weekly limit".
*/
const CLAUDE_HIT_LIMIT_PATTERN = /hit your (?:[a-z0-9-]+ ){0,2}limit\b/;
const CLAUDE_HIT_LIMIT_BANNER = new RegExp(
`^you(?:'ve| have) ${CLAUDE_HIT_LIMIT_PATTERN.source}`,
);
export function isClaudeAuthError(text: string): boolean {
const lower = text.toLowerCase();
return (
@@ -25,8 +34,7 @@ export function isClaudeUsageExhaustedMessage(text: string): boolean {
const looksLikeBanner =
normalized.startsWith("you're out of extra usage") ||
normalized.startsWith('you are out of extra usage') ||
normalized.startsWith("you've hit your limit") ||
normalized.startsWith('you have hit your limit');
CLAUDE_HIT_LIMIT_BANNER.test(normalized);
const hasResetHint =
normalized.includes('resets ') ||
normalized.includes('reset at ') ||
@@ -297,7 +305,7 @@ export function classifyAgentError(
lower.includes('usage limit') ||
lower.includes('out of credits') ||
lower.includes('workspace out of credits') ||
lower.includes('hit your limit') ||
CLAUDE_HIT_LIMIT_PATTERN.test(lower) ||
lower.includes('too many requests') ||
lower.includes('rate_limit')
) {

View File

@@ -3510,6 +3510,45 @@ describe('runAgentForGroup Claude failure recovery', () => {
]);
});
it('pauses on the newer "session limit" banner instead of delivering it as an answer', async () => {
const outputs: string[] = [];
vi.mocked(agentRunner.runAgentProcess).mockImplementationOnce(
async (_group, _input, _onProcess, onOutput) => {
await onOutput?.({
status: 'success',
phase: 'final',
result: "You've hit your session limit · resets 3:20am (Asia/Seoul)",
});
return {
status: 'success',
result: null,
};
},
);
const result = await runAgentForGroup(makeDeps(), {
group: makeGroup(),
prompt: 'hello',
chatJid: 'group@test',
runId: 'run-session-limit-banner',
onOutput: async (output) => {
const text =
output.output && 'text' in output.output
? output.output.text
: output.result;
if (typeof text === 'string') outputs.push(text);
},
});
expect(result).toBe('success');
expect(outputs).toEqual([
expect.stringMatching(
/^Claude 사용 한도에 도달해서 이 방의 작업을 일시정지했습니다\. .*03:20에/,
),
]);
});
it('does not retry when Claude org access is denied', async () => {
const outputs: string[] = [];

View File

@@ -133,6 +133,7 @@ export function handleFailedReviewerExecution(args: {
'Reviewer failed repeatedly without a visible verdict — requesting arbiter',
escalateLogMessage:
'Reviewer failed repeatedly without a visible verdict — escalating to user',
arbiterInterventionCount: task.arbiter_intervention_count ?? 0,
logContext: {
taskId,
role: 'reviewer',

View File

@@ -1556,6 +1556,38 @@ describe('paired execution context', () => {
);
});
it('escalates instead of re-requesting the arbiter after repeated reviewer failures once the arbiter budget is spent', () => {
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
vi.mocked(db.getPairedTaskById).mockReturnValue(
buildPairedTask({
status: 'review_ready',
reviewer_failure_count: 1,
arbiter_intervention_count: config.ARBITER_MAX_INTERVENTIONS,
}),
);
completePairedExecutionContext({
taskId: 'task-1',
role: 'reviewer',
status: 'failed',
summary: 'runtime exploded before verdict',
});
expect(db.updatePairedTask).toHaveBeenCalledWith(
'task-1',
expect.objectContaining({
status: 'completed',
reviewer_failure_count: 2,
arbiter_verdict: 'escalate',
completion_reason: 'escalated',
}),
);
expect(db.updatePairedTask).not.toHaveBeenCalledWith(
'task-1',
expect.objectContaining({ status: 'arbiter_requested' }),
);
});
it('keeps arbiter tasks arbiter_requested when arbiter execution fails without a terminal verdict', () => {
vi.mocked(db.getPairedTaskById).mockReturnValue(
buildPairedTask({

View File

@@ -146,4 +146,16 @@ describe('paired verdict parser', () => {
expect(classifyArbiterVerdict('CONTINUE\nsame as proceed')).toBe('proceed');
expect(classifyArbiterVerdict('no verdict here')).toBe('unknown');
});
it('only reads a verdict keyword that leads its line', () => {
expect(
classifyArbiterVerdict(
"You've hit your session limit · resets 3:20am (Asia/Seoul)",
),
).toBe('unknown');
expect(classifyArbiterVerdict('The owner should proceed.')).toBe('unknown');
expect(classifyArbiterVerdict('RESETS are pending')).toBe('unknown');
expect(classifyArbiterVerdict('**PROCEED**\n근거')).toBe('proceed');
expect(classifyArbiterVerdict('VERDICT: ESCALATE')).toBe('escalate');
});
});

View File

@@ -137,8 +137,11 @@ export function classifyArbiterVerdict(
cleaned,
ARBITER_VERDICT_SCAN_LINE_LIMIT,
)) {
// The keyword must lead the line as a whole word: an unanchored,
// case-insensitive match read "resets 3:20am" in a Claude usage-limit
// banner as RESET.
const verdictMatch = line.match(
/\*{0,2}(?:VERDICT\s*[:—-]\s*)?(PROCEED|REVISE|RESET|ESCALATE|CONTINUE)\*{0,2}/i,
/^\*{0,2}(?:VERDICT\s*[:—-]\s*)?(PROCEED|REVISE|RESET|ESCALATE|CONTINUE)\b/,
);
if (verdictMatch) {
const normalized = verdictMatch[1].toLowerCase();