From 4c02ceb282b79b2182c94ba92b44497986fb0799 Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:29:28 -0500 Subject: [PATCH] fix(source-maps): preserve launch admission failures during cancellation (#12565) * fix(source-maps): preserve launch admission failures during cancellation * fix(source-maps): distinguish launch rejection from observed cancellation --- .../sourceMaps/SourceMapCommand.test.ts | 45 +++++++++++++++++++ src/javascript/sourceMaps/SourceMapCommand.ts | 6 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/javascript/sourceMaps/SourceMapCommand.test.ts b/src/javascript/sourceMaps/SourceMapCommand.test.ts index be42fd5ea2..5ac2e07190 100644 --- a/src/javascript/sourceMaps/SourceMapCommand.test.ts +++ b/src/javascript/sourceMaps/SourceMapCommand.test.ts @@ -1,3 +1,4 @@ +import { assertProcessOwnershipInspectionActive } from "../../process/ProcessInspectionCancellation.js"; import { ProcessAdmissionError } from "../../process/ProcessAdmissionError.js"; import { access } from "node:fs/promises"; import { afterEach, expect, it, onTestFinished, vi } from "vitest"; @@ -368,3 +369,47 @@ it("retains a physical process admission error alongside cancellation", async () ); expect(result.error.secondaryFailures[0]?.cause).toBe(reason); }); + +it.each([ + "distinct reason", + "shared admission error", + "observed cancellation", +] as const)( + "keeps the launcher's reported outcome for %s", + async (scenario) => { + const controller = new AbortController(); + const physical = new ProcessAdmissionError("baseline_unavailable"); + const reason = + scenario === "distinct reason" + ? { caller: "during codec launch" } + : physical; + const result = await runSourceMapCommand( + "{}", + "/probe/source.map", + { signal: controller.signal }, + { + prepareOwnership: async () => {}, + launcher: async ({ signal }) => { + controller.abort(reason); + if (scenario === "observed cancellation") + assertProcessOwnershipInspectionActive(signal); + throw physical; + }, + }, + unexpectedCleanup, + ); + if (result.ok) throw new Error("expected failed launch"); + if (scenario === "observed cancellation") { + expect(result.error).toBeInstanceOf(AnalysisCancelledError); + expect(result.error.cause).toBe(reason); + expect(result.error.secondaryFailures).toHaveLength(0); + } else { + expect(result.error._tag).toBe("ProviderAdapterError"); + expect(result.error.cause).toBe(physical); + expect(result.error.secondaryFailures).toHaveLength(1); + const [cancelled] = result.error.secondaryFailures; + expect(cancelled).toBeInstanceOf(AnalysisCancelledError); + expect(cancelled?.cause).toBe(reason); + } + }, +); diff --git a/src/javascript/sourceMaps/SourceMapCommand.ts b/src/javascript/sourceMaps/SourceMapCommand.ts index 0fb29f3c3f..63a60686b8 100644 --- a/src/javascript/sourceMaps/SourceMapCommand.ts +++ b/src/javascript/sourceMaps/SourceMapCommand.ts @@ -412,7 +412,11 @@ class OwnedCodec implements SourceMapCleanupOwner { const outcome = this.#outcome; if (outcome?.kind === "physical") return this.#physicalFailure(outcome.observation); - if (outcome?.kind === "cancelled") + // The launcher reports cancellation separately from a physical admission failure. + if ( + outcome?.kind === "cancelled" && + !(cause instanceof ProcessAdmissionError) + ) return cancelledBy(OPERATION, carriedReason(outcome.callerReason)); if (outcome?.kind === "timeout") return new AnalysisTimeoutError(