fix: do not treat an approved reviewer STEP_DONE with progress as a deadlock

The reviewer prompt defines STEP_DONE as 'this step is acceptable, send the
task back to the owner without escalating to the arbiter', but once
round_trip_count reached ARBITER_DEADLOCK_THRESHOLD (2) every STEP_DONE
requested the arbiter, and with ARBITER_MAX_INTERVENTIONS=1 the next one
closed the task as escalated. Long multi-step requests (wargame room) were
stopping every 2-3 approved steps and needed a human 'continue'.

A reviewer STEP_DONE now counts as a deadlock only when the owner made no
committed change since the start of its latest turn (task.source_ref).
When it did, the task goes back to the owner and round_trip_count resets
so the deadlock counter measures rounds since the last approved step.
No-progress STEP_DONE loops and DONE_WITH_CONCERNS loops still go to the
arbiter as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-29 15:14:45 +09:00
parent 720223eb10
commit 0ce79c8d0c
4 changed files with 121 additions and 4 deletions

View File

@@ -101,6 +101,22 @@ describe('paired completion signals', () => {
deadlockThreshold: 3,
}),
).toEqual({ kind: 'request_arbiter' });
expect(
resolveReviewerCompletionSignal({
visibleVerdict: 'step_done',
roundTripCount: 3,
deadlockThreshold: 3,
ownerMadeProgress: true,
}),
).toEqual({ kind: 'request_owner_changes' });
expect(
resolveReviewerCompletionSignal({
visibleVerdict: 'done_with_concerns',
roundTripCount: 3,
deadlockThreshold: 3,
ownerMadeProgress: true,
}),
).toEqual({ kind: 'request_arbiter' });
expect(
resolveReviewerCompletionSignal({
visibleVerdict: 'done',

View File

@@ -76,6 +76,11 @@ export function resolveReviewerCompletionSignal(args: {
visibleVerdict: VisibleVerdict;
roundTripCount: number;
deadlockThreshold: number;
/**
* The owner committed code changes during the round the reviewer just
* approved. A STEP_DONE approval of real progress is not a deadlock.
*/
ownerMadeProgress?: boolean | null;
}): CompletionSignal {
const { visibleVerdict, roundTripCount, deadlockThreshold } = args;
@@ -84,7 +89,10 @@ export function resolveReviewerCompletionSignal(args: {
case 'done':
return { kind: 'request_owner_finalize' };
case 'step_done':
if (roundTripCount >= deadlockThreshold) {
if (
args.ownerMadeProgress !== true &&
roundTripCount >= deadlockThreshold
) {
return { kind: 'request_arbiter' };
}
return { kind: 'request_owner_changes' };

View File

@@ -11,7 +11,10 @@ import {
resolveReviewerCompletionSignal,
resolveReviewerFailureSignal,
} from './paired-completion-signals.js';
import { resolveCanonicalSourceRef } from './paired-source-ref.js';
import {
hasCodeChangesSinceRef,
resolveCanonicalSourceRef,
} from './paired-source-ref.js';
import { parseReviewerVerdict } from './paired-verdict.js';
import type { PairedTask } from './types.js';
@@ -193,10 +196,20 @@ export function handleReviewerCompletion(args: {
const { task, taskId, summary } = args;
const now = new Date().toISOString();
const verdict = parseReviewerVerdict(summary);
// task.source_ref is the owner workspace tree at the start of the latest
// owner turn, so a diff against it means the approved round made progress.
const ownerWorkspaceDir =
verdict === 'step_done'
? getPairedWorkspace(taskId, 'owner')?.workspace_dir
: undefined;
const ownerMadeProgress = ownerWorkspaceDir
? hasCodeChangesSinceRef(ownerWorkspaceDir, task.source_ref) === true
: false;
const signal = resolveReviewerCompletionSignal({
visibleVerdict: verdict,
roundTripCount: task.round_trip_count,
deadlockThreshold: ARBITER_DEADLOCK_THRESHOLD,
ownerMadeProgress,
});
switch (signal.kind) {
@@ -266,10 +279,15 @@ export function handleReviewerCompletion(args: {
nextStatus: 'active',
expectedUpdatedAt: task.updated_at,
updatedAt: now,
patch: { reviewer_failure_count: 0 },
patch: {
reviewer_failure_count: 0,
// An approved step with real progress starts a new step, so the
// deadlock counter only measures rounds since the last such step.
...(ownerMadeProgress ? { round_trip_count: 0 } : {}),
},
});
logger.info(
{ taskId, verdict },
{ taskId, verdict, ownerMadeProgress },
'Reviewer has feedback, task set back to active for owner',
);
return;

View File

@@ -1472,6 +1472,81 @@ describe('paired execution context', () => {
);
});
it('hands a reviewer STEP_DONE back to the owner past the deadlock threshold when the owner committed progress', () => {
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
const repoDir = createCanonicalRepoWithCommit('step 1');
const stepStartRef = resolveTreeRef(repoDir);
fs.writeFileSync(path.join(repoDir, 'step2.txt'), 'step 2\n');
execFileSync('git', ['add', 'step2.txt'], {
cwd: repoDir,
stdio: 'ignore',
});
execFileSync('git', ['commit', '-m', 'step 2'], {
cwd: repoDir,
stdio: 'ignore',
});
vi.mocked(db.getPairedTaskById).mockReturnValue(
buildPairedTask({
status: 'in_review',
source_ref: stepStartRef,
round_trip_count: config.ARBITER_DEADLOCK_THRESHOLD,
arbiter_intervention_count: 1,
}),
);
vi.mocked(db.getPairedWorkspace).mockImplementation((_taskId, role) =>
role === 'owner' ? buildWorkspace('owner', repoDir) : undefined,
);
completePairedExecutionContext({
taskId: 'task-1',
role: 'reviewer',
status: 'succeeded',
summary: 'STEP_DONE\n2단계 승인합니다. owner, 3단계를 진행하세요.',
});
expect(db.updatePairedTask).toHaveBeenCalledWith(
'task-1',
expect.objectContaining({ status: 'active', round_trip_count: 0 }),
);
expect(db.updatePairedTask).not.toHaveBeenCalledWith(
'task-1',
expect.objectContaining({ status: 'completed' }),
);
expect(db.updatePairedTask).not.toHaveBeenCalledWith(
'task-1',
expect.objectContaining({ status: 'arbiter_requested' }),
);
});
it('still requests the arbiter for a reviewer STEP_DONE past the deadlock threshold when the owner made no progress', () => {
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
const repoDir = createCanonicalRepoWithCommit('no progress');
vi.mocked(db.getPairedTaskById).mockReturnValue(
buildPairedTask({
status: 'in_review',
source_ref: resolveTreeRef(repoDir),
round_trip_count: config.ARBITER_DEADLOCK_THRESHOLD,
}),
);
vi.mocked(db.getPairedWorkspace).mockImplementation((_taskId, role) =>
role === 'owner' ? buildWorkspace('owner', repoDir) : undefined,
);
completePairedExecutionContext({
taskId: 'task-1',
role: 'reviewer',
status: 'succeeded',
summary: 'STEP_DONE\n바뀐 것이 없습니다. 같은 단계를 다시 진행하세요.',
});
expect(db.updatePairedTask).toHaveBeenCalledWith(
'task-1',
expect.objectContaining({ status: 'arbiter_requested' }),
);
});
it('records source_ref when reviewer verdict DONE arrives via failed fallback', () => {
const repoDir = createCanonicalRepoWithCommit('reviewed');
const approvedSourceRef = resolveTreeRef(repoDir);