diff --git a/packages/engine/src/services/parallelCoordinator-peerAbort.test.ts b/packages/engine/src/services/parallelCoordinator-peerAbort.test.ts index ad89b3b6a4..4dae2fa0b0 100644 --- a/packages/engine/src/services/parallelCoordinator-peerAbort.test.ts +++ b/packages/engine/src/services/parallelCoordinator-peerAbort.test.ts @@ -51,10 +51,15 @@ describe("executeParallelCapture peer abort", () => { () => null, ); - await expect(result).rejects.toMatchObject({ - name: "CaptureFailure", - kind: "authoring", - }); + const failure = await result.then( + () => undefined, + (error: unknown) => error, + ); + expect(failure).toMatchObject({ name: "CaptureFailure", kind: "authoring" }); + const message = (failure as Error).message; + expect(message).toContain("Worker 0: Composition has zero duration"); + expect(message).toContain("(1 other worker was stopped after this failure)"); + expect(message).not.toContain("Worker 1"); expect(captureFrame).not.toHaveBeenCalled(); expect(closeCaptureSession).toHaveBeenCalledTimes(2); } finally { diff --git a/packages/engine/src/services/parallelCoordinator.test.ts b/packages/engine/src/services/parallelCoordinator.test.ts index 8015015e8c..f381ea89a8 100644 --- a/packages/engine/src/services/parallelCoordinator.test.ts +++ b/packages/engine/src/services/parallelCoordinator.test.ts @@ -8,6 +8,7 @@ import { distributeFrames, expectedFramesForTask, flagSilentWorkerExits, + formatPoolFailure, formatWorkerFailure, isFfmpegInfrastructureFailure, isPoolFatalWorkerFailure, @@ -286,6 +287,35 @@ describe("worker failure diagnostics", () => { ]); }); + it("names the worker that failed and counts the peers it stopped", () => { + const worker = (workerId: number, failure: CaptureFailure): WorkerResult => ({ + workerId, + framesCaptured: 0, + startFrame: 0, + endFrame: 30, + durationMs: 10, + error: failure.message, + failure, + }); + const stopped = (workerId: number) => + worker( + workerId, + new CaptureFailure({ kind: "cancelled", message: "Parallel worker cancelled" }), + ); + const cause = worker(3, new CaptureFailure({ kind: "io", message: "disk is full" })); + + expect(formatPoolFailure([stopped(0), stopped(1), cause, stopped(4)])).toBe( + "Worker 3: disk is full (3 other workers were stopped after this failure)", + ); + expect(formatPoolFailure([cause, stopped(4)])).toBe( + "Worker 3: disk is full (1 other worker was stopped after this failure)", + ); + expect(formatPoolFailure([cause])).toBe("Worker 3: disk is full"); + expect(formatPoolFailure([stopped(0), stopped(1)])).toBe( + "Worker 0: Parallel worker cancelled; Worker 1: Parallel worker cancelled", + ); + }); + it("adds compact diagnostics to the worker failure message", () => { expect( formatWorkerFailure({ diff --git a/packages/engine/src/services/parallelCoordinator.ts b/packages/engine/src/services/parallelCoordinator.ts index ee07be145e..8b3c9f7d87 100644 --- a/packages/engine/src/services/parallelCoordinator.ts +++ b/packages/engine/src/services/parallelCoordinator.ts @@ -279,6 +279,14 @@ export function formatWorkerFailure(result: WorkerResult): string { return `${base}; diagnostics: ${diagnostics}`; } +export function formatPoolFailure(errors: WorkerResult[]): string { + const causes = errors.filter((result) => result.failure?.kind !== "cancelled"); + const stopped = errors.length - causes.length; + if (causes.length === 0 || stopped === 0) return errors.map(formatWorkerFailure).join("; "); + const peers = stopped === 1 ? "1 other worker was" : `${stopped} other workers were`; + return `${causes.map(formatWorkerFailure).join("; ")} (${peers} stopped after this failure)`; +} + /** Which constraint produced the final auto-sized worker count. */ export type WorkerSizingBound = | "explicit" @@ -1245,7 +1253,7 @@ export async function executeParallelCapture( const errors = results.filter((r) => r.failure || r.error); if (errors.length > 0) { - const errorMessages = errors.map(formatWorkerFailure).join("; "); + const errorMessages = formatPoolFailure(errors); const representative = failureHandler.firstFatalFailure() ?? errors.find((result) => result.failure)?.failure; const workerDiagnostics = errors.flatMap((result) => result.failure?.workerDiagnostics ?? []);