Fix reviewer-to-owner follow-up race

This commit is contained in:
ejclaw
2026-04-07 01:22:27 +09:00
parent 48592d97ed
commit 9d8c97a8e2
5 changed files with 265 additions and 17 deletions

View File

@@ -1315,6 +1315,107 @@ describe('runAgentForGroup room memory', () => {
expect(deps.queue.enqueueMessageCheck).toHaveBeenCalledWith('group@test');
});
it('stores reviewer turn output before transitioning the paired task back to active', async () => {
const group = { ...makeGroup(), folder: 'test-group' };
const deps = makeDeps();
vi.mocked(serviceRouting.getEffectiveChannelLease).mockReturnValue({
chat_jid: 'group@test',
owner_agent_type: 'codex',
reviewer_agent_type: 'claude-code',
arbiter_agent_type: null,
owner_service_id: 'codex-main',
reviewer_service_id: 'claude',
arbiter_service_id: null,
activated_at: null,
reason: null,
explicit: false,
});
vi.mocked(
pairedExecutionContext.preparePairedExecutionContext,
).mockReturnValue({
task: {
id: 'paired-task-reviewer-output-order',
chat_jid: 'group@test',
group_folder: 'test-group',
owner_service_id: 'codex-main',
reviewer_service_id: 'claude',
title: null,
source_ref: 'HEAD',
plan_notes: null,
round_trip_count: 1,
review_requested_at: '2026-03-31T00:00:00.000Z',
status: 'in_review',
arbiter_verdict: null,
arbiter_requested_at: null,
completion_reason: null,
created_at: '2026-03-31T00:00:00.000Z',
updated_at: '2026-03-31T00:00:00.000Z',
},
workspace: null,
envOverrides: {},
});
vi.mocked(db.getPairedTaskById).mockReturnValue({
id: 'paired-task-reviewer-output-order',
chat_jid: 'group@test',
group_folder: 'test-group',
owner_service_id: 'codex-main',
reviewer_service_id: 'claude',
title: null,
source_ref: 'HEAD',
plan_notes: null,
round_trip_count: 1,
review_requested_at: '2026-03-31T00:00:00.000Z',
status: 'active',
arbiter_verdict: null,
arbiter_requested_at: null,
completion_reason: null,
created_at: '2026-03-31T00:00:00.000Z',
updated_at: '2026-03-31T00:00:00.000Z',
});
vi.mocked(agentRunner.runAgentProcess).mockImplementation(
async (_group, _input, _onProcess, onOutput) => {
await onOutput?.({
status: 'success',
result: 'DONE_WITH_CONCERNS\nreviewer feedback',
output: {
visibility: 'public',
text: 'DONE_WITH_CONCERNS\nreviewer feedback',
},
phase: 'final',
});
return {
status: 'success',
result: 'DONE_WITH_CONCERNS\nreviewer feedback',
};
},
);
const result = await runAgentForGroup(deps, {
group,
prompt: 'please review',
chatJid: 'group@test',
runId: 'run-reviewer-output-order',
forcedRole: 'reviewer',
onOutput: async () => {},
});
expect(result).toBe('success');
expect(db.insertPairedTurnOutput).toHaveBeenCalledWith(
'paired-task-reviewer-output-order',
1,
'reviewer',
'DONE_WITH_CONCERNS\nreviewer feedback',
);
expect(
vi.mocked(db.insertPairedTurnOutput).mock.invocationCallOrder[0],
).toBeLessThan(
vi.mocked(
pairedExecutionContext.completePairedExecutionContext,
).mock.invocationCallOrder[0],
);
});
it('does not enqueue a generic follow-up when reviewer output already returned the task to active', async () => {
const group = { ...makeGroup(), folder: 'test-group' };
const deps = makeDeps();