fix(engine): a failed parallel capture names the worker that failed, not the peers it stopped (#7803)

When one capture worker fails, the pool aborts its peers and each of them
reports "Parallel worker cancelled". The pool message listed every worker in
id order, so the one real cause sat between cancellations:

  Worker 0: Parallel worker cancelled; Worker 1: Parallel worker cancelled;
  Worker 2: Disk capture may need ~2712.6 MB ...; Worker 3: Parallel worker cancelled

The message now carries the failures that are not cancellations and counts
the peers that were stopped because of them. A pool where every worker was
cancelled keeps the full list.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
wonjang
2026-11-15 05:37:37 +00:00
committed by GitHub
co-authored by Claude Fable 5.2
parent 04ee926d97
commit db6b7478a7
3 changed files with 48 additions and 5 deletions
@@ -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 {
@@ -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({
@@ -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 ?? []);