diff --git a/scripts/verify/baselines/cleanup-dependency-binding.json b/scripts/verify/baselines/cleanup-dependency-binding.json index 9403311394..f263b223a5 100644 --- a/scripts/verify/baselines/cleanup-dependency-binding.json +++ b/scripts/verify/baselines/cleanup-dependency-binding.json @@ -33,7 +33,6 @@ "src/pcap/PcapProvider.ts": 5, "src/pcap/PcapSnapshot.ts": 1, "src/process/ArtifactAnalysisResources.ts": 1, - "src/process/OwnedDebuggerSessionRegistry.ts": 1, "src/process/capture/ProcessCaptureError.ts": 3, "src/providers/AnalysisClientFailure.ts": 1, "src/sqlite/SqliteDatabaseProvider.ts": 8 diff --git a/src/process/OwnedDebuggerSessionRegistry.test.ts b/src/process/OwnedDebuggerSessionRegistry.test.ts new file mode 100644 index 0000000000..e8d3881a1f --- /dev/null +++ b/src/process/OwnedDebuggerSessionRegistry.test.ts @@ -0,0 +1,30 @@ +import { expect, it } from "vitest"; +import { AnalysisCancelledError } from "../domain/analysisErrorCore.js"; +import { cancelledWithCallerReason } from "./OwnedDebuggerSessionRegistry.js"; + +it("preserves the caller's reason while a retained cancellation waits for release", () => { + const reason = new Error("caller stopped waiting"); + const previous = new AnalysisCancelledError("start", { + cleanup: { + reason: "session still closing", + resources: ["session"], + }, + }); + const claim = { cleanupReleased: false }; + previous.bindCleanupReleaseClaim(claim); + const current = cancelledWithCallerReason( + "close", + AbortSignal.abort(reason), + previous, + ); + expect(current.cause).toBe(reason); + expect(current.cleanupPrimary).toBe(previous); + expect(current.cleanupIncomplete).toBe(true); + expect(current.cleanupResources).toEqual(["session"]); + claim.cleanupReleased = true; + expect(current.cleanupIncomplete).toBe(false); + expect( + cancelledWithCallerReason("close", AbortSignal.abort(reason)) + .cleanupIncomplete, + ).toBe(false); +}); diff --git a/src/process/OwnedDebuggerSessionRegistry.ts b/src/process/OwnedDebuggerSessionRegistry.ts index 1fcedf7834..83624a8114 100644 --- a/src/process/OwnedDebuggerSessionRegistry.ts +++ b/src/process/OwnedDebuggerSessionRegistry.ts @@ -1,3 +1,4 @@ +import { withInheritedCleanupOwnership } from "../domain/analysisErrorCleanup.js"; import type { AnalysisError, AnalysisErrorOptions, @@ -294,7 +295,7 @@ export const cancelledWithCallerReason = ( ? {} : { partialObservation: previous.partialObservation }), }); - if (previous?.cleanupIncomplete) - cancellation.bindCleanupDependencies([previous]); - return cancellation; + return previous === undefined + ? cancellation + : withInheritedCleanupOwnership(cancellation, previous); };