diff --git a/src/paired-execution-context-owner.ts b/src/paired-execution-context-owner.ts index 441ec73..363ac4a 100644 --- a/src/paired-execution-context-owner.ts +++ b/src/paired-execution-context-owner.ts @@ -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: { diff --git a/src/paired-execution-context-reviewer.ts b/src/paired-execution-context-reviewer.ts index 4a72889..7548184 100644 --- a/src/paired-execution-context-reviewer.ts +++ b/src/paired-execution-context-reviewer.ts @@ -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; diff --git a/src/paired-execution-context.test.ts b/src/paired-execution-context.test.ts index 22ac9ea..b2c396a 100644 --- a/src/paired-execution-context.test.ts +++ b/src/paired-execution-context.test.ts @@ -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);