From 5438185ae2693eb44f6d60dfe83309f9bb1582cb Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Thu, 19 Nov 2026 08:19:27 -0500 Subject: [PATCH] fix(web): retain cancellation alongside capture read failures (#12347) --- src/application/WebScriptExportService.ts | 35 +++++++++++++------ .../filesystem/webScriptExport.test.ts | 10 ++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/application/WebScriptExportService.ts b/src/application/WebScriptExportService.ts index c3fe4b3ec8..e4d97c720a 100644 --- a/src/application/WebScriptExportService.ts +++ b/src/application/WebScriptExportService.ts @@ -19,6 +19,7 @@ import { carriedReason, } from "../domain/analysisErrorCore.js"; import { AnalysisError } from "../domain/analysisErrorBase.js"; +import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js"; import { ConfigurationError } from "../domain/configurationErrors.js"; import { createEvidence, type Evidence } from "../domain/evidence.js"; import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js"; @@ -262,11 +263,10 @@ const readCapture = async ( ? {} : { lease: retry.cleanupLease }), }; - if (retry.outcome.kind === "completed") { + if (cause.outcome.kind === "completed") { const cancellation = - signal?.aborted === true - ? { reason: signal.reason } - : regularFileCancellation(cause); + regularFileCancellation(cause) ?? + (signal?.aborted === true ? { reason: signal.reason } : undefined); if (cancellation !== undefined) { const primary = cancelledBy( OPERATION, @@ -278,12 +278,17 @@ const readCapture = async ( : incompleteCaptureCleanup(primary, path, cleanup), ); } - return ok({ bytes: retry.outcome.value as Buffer, cleanup }); + return ok({ bytes: cause.outcome.value as Buffer, cleanup }); } - const primary = captureReadFailure( - path, - cause, - retry.cleanup === undefined ? { cause: cause.cleanupCause } : undefined, + const primary = captureReadErrorWithCancellation( + captureReadFailure( + path, + cause, + retry.cleanup === undefined + ? { cause: cause.cleanupCause } + : undefined, + ), + signal, ); return err( retry.cleanup === undefined @@ -291,10 +296,20 @@ const readCapture = async ( : incompleteCaptureCleanup(primary, path, cleanup), ); } - return err(captureReadFailure(path, cause)); + return err( + captureReadErrorWithCancellation(captureReadFailure(path, cause), signal), + ); } }; +const captureReadErrorWithCancellation = ( + error: AnalysisError, + signal: AbortSignal | undefined, +): AnalysisError => + signal?.aborted === true + ? analysisErrorWithCancellation(error, cancelledBy(OPERATION, signal)) + : error; + const captureReadFailure = ( path: string, failure: unknown, diff --git a/tests/boundary/filesystem/webScriptExport.test.ts b/tests/boundary/filesystem/webScriptExport.test.ts index 1167f29149..61ba3aa17e 100644 --- a/tests/boundary/filesystem/webScriptExport.test.ts +++ b/tests/boundary/filesystem/webScriptExport.test.ts @@ -1034,6 +1034,7 @@ describe("capture read failure provenance", () => { new Error("physical capture read failed"), { code }, ); + const reason = sameReason ? physical : { request: "later cancellation" }; const closeFailure = new Error("capture close failed"); let handle: Awaited> | undefined; let closeCalls = 0; @@ -1042,9 +1043,7 @@ describe("capture read failure provenance", () => { if (String(args[0]) !== input.capture_path) return opened; handle = opened; vi.spyOn(opened, "read").mockImplementation(async () => { - controller.abort( - sameReason ? physical : { request: "later cancellation" }, - ); + controller.abort(reason); throw physical; }); const close = opened.close.bind(opened); @@ -1078,6 +1077,11 @@ describe("capture read failure provenance", () => { errors: [physical, closeFailure], }); else expect(primary.cause).toBe(physical); + expect(primary.secondaryFailures).toHaveLength(1); + expect(primary.secondaryFailures[0]?.cause).toBe(reason); + expect( + projectAnalysisError(result.error).details?.secondary_failures, + ).toEqual([expect.objectContaining({ code: "cancelled" })]); await expect(access(input.output_directory)).rejects.toMatchObject({ code: "ENOENT", });