fix: send NEEDS_CONTEXT straight to the user instead of the arbiter
A NEEDS_CONTEXT from the owner or reviewer is a question only the user can answer, and the arbiter's own rules say to ESCALATE it. Routing it through the arbiter added a full turn first (13 of 23 arbiter calls in 30 days). Escalate directly; BLOCKED and deadlocks still go to the arbiter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -240,6 +240,7 @@ function handleOwnerFinalizeCompletion(args: {
|
||||
expectedUpdatedAt: task.updated_at,
|
||||
now,
|
||||
arbiterInterventionCount: task.arbiter_intervention_count ?? 0,
|
||||
maxArbiterInterventions: ownerVerdict === 'needs_context' ? 0 : undefined,
|
||||
arbiterLogMessage,
|
||||
escalateLogMessage,
|
||||
logContext: {
|
||||
@@ -470,6 +471,9 @@ export function handleOwnerCompletion(args: {
|
||||
expectedUpdatedAt: task.updated_at,
|
||||
now,
|
||||
arbiterInterventionCount: task.arbiter_intervention_count ?? 0,
|
||||
// A question for the user can only be answered by the user; routing it
|
||||
// through the arbiter just added a turn that ESCALATEd anyway.
|
||||
maxArbiterInterventions: ownerVerdict === 'needs_context' ? 0 : undefined,
|
||||
arbiterLogMessage: 'Owner blocked/needs_context — requesting arbiter',
|
||||
escalateLogMessage: 'Owner blocked/needs_context — escalating to user',
|
||||
logContext: {
|
||||
|
||||
@@ -251,6 +251,8 @@ export function handleReviewerCompletion(args: {
|
||||
escalateLogMessage,
|
||||
logContext: { taskId, verdict, summary: summary?.slice(0, 100) },
|
||||
arbiterInterventionCount: task.arbiter_intervention_count ?? 0,
|
||||
// Questions for the user go straight to the user (see owner side).
|
||||
maxArbiterInterventions: verdict === 'needs_context' ? 0 : undefined,
|
||||
patch: { reviewer_failure_count: 0 },
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -1430,6 +1430,77 @@ describe('paired execution context', () => {
|
||||
},
|
||||
);
|
||||
|
||||
it('sends an owner NEEDS_CONTEXT straight to the user even when the arbiter is enabled', () => {
|
||||
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
|
||||
vi.mocked(db.getPairedTaskById).mockReturnValue(
|
||||
buildPairedTask({ status: 'active', round_trip_count: 0 }),
|
||||
);
|
||||
|
||||
completePairedExecutionContext({
|
||||
taskId: 'task-1',
|
||||
role: 'owner',
|
||||
status: 'succeeded',
|
||||
summary: 'NEEDS_CONTEXT\n어느 방을 말씀하시는지 알려 주세요.',
|
||||
});
|
||||
|
||||
expect(db.updatePairedTask).toHaveBeenCalledWith(
|
||||
'task-1',
|
||||
expect.objectContaining({
|
||||
status: 'completed',
|
||||
completion_reason: 'escalated',
|
||||
}),
|
||||
);
|
||||
expect(db.updatePairedTask).not.toHaveBeenCalledWith(
|
||||
'task-1',
|
||||
expect.objectContaining({ status: 'arbiter_requested' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('sends a reviewer NEEDS_CONTEXT straight to the user even when the arbiter is enabled', () => {
|
||||
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
|
||||
vi.mocked(db.getPairedTaskById).mockReturnValue(
|
||||
buildPairedTask({ status: 'in_review', round_trip_count: 1 }),
|
||||
);
|
||||
|
||||
completePairedExecutionContext({
|
||||
taskId: 'task-1',
|
||||
role: 'reviewer',
|
||||
status: 'succeeded',
|
||||
summary: 'NEEDS_CONTEXT\n사용자에게 배포 대상을 확인해야 합니다.',
|
||||
});
|
||||
|
||||
expect(db.updatePairedTask).toHaveBeenCalledWith(
|
||||
'task-1',
|
||||
expect.objectContaining({
|
||||
status: 'completed',
|
||||
completion_reason: 'escalated',
|
||||
}),
|
||||
);
|
||||
expect(db.updatePairedTask).not.toHaveBeenCalledWith(
|
||||
'task-1',
|
||||
expect.objectContaining({ status: 'arbiter_requested' }),
|
||||
);
|
||||
});
|
||||
|
||||
it('still asks the arbiter when the owner reports BLOCKED and the arbiter is enabled', () => {
|
||||
vi.spyOn(config, 'isArbiterEnabled').mockReturnValue(true);
|
||||
vi.mocked(db.getPairedTaskById).mockReturnValue(
|
||||
buildPairedTask({ status: 'active', round_trip_count: 0 }),
|
||||
);
|
||||
|
||||
completePairedExecutionContext({
|
||||
taskId: 'task-1',
|
||||
role: 'owner',
|
||||
status: 'succeeded',
|
||||
summary: 'BLOCKED\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);
|
||||
|
||||
Reference in New Issue
Block a user