diff --git a/apps/server/execution/orchestrator.test.ts b/apps/server/execution/orchestrator.test.ts index 511a7cd..e3e0bf7 100644 --- a/apps/server/execution/orchestrator.test.ts +++ b/apps/server/execution/orchestrator.test.ts @@ -481,4 +481,21 @@ describe('handleAgentStopped — quality review integration', () => { expect(shouldRunQualityReview).not.toHaveBeenCalled(); expect(mocks.dispatchManager.completeTask).not.toHaveBeenCalled(); }); + + it('does not crash and still calls scheduleDispatch when shouldRunQualityReview throws', async () => { + vi.mocked(shouldRunQualityReview).mockRejectedValue(new Error('quality review check failed')); + + createOrchestrator(mocks); + + mocks.eventBus.emit({ + type: 'agent:stopped', + timestamp: new Date(), + payload: { taskId: 't1', reason: 'task_complete', agentId: 'a1' }, + }); + + // scheduleDispatch() must still run — verifiable via dispatchNext being called in the dispatch cycle + await vi.waitFor(() => expect(mocks.dispatchManager.dispatchNext).toHaveBeenCalled()); + // completeTask is not called from the catch block — error is swallowed after logging a warning + expect(mocks.dispatchManager.completeTask).not.toHaveBeenCalled(); + }); });