fix(cancellation): preserve caller abort reason in cancellation errors (#6144)
* fix(cancellation): preserve caller abort reason in cancellation errors Several application, provider, and MCP boundaries constructed AnalysisCancelledError, ArtifactReaderFailure, or DetachedPgpSignatureError for an already-observed or newly-observed abort without passing the caller's signal.reason as the error cause. The typed result then reported cancellation with an undefined reason even though the exact object supplied to AbortController.abort(reason) was still available. Pass signal.reason as the cause at each producing cancellation site: JavaScript artifact reconstruction and file abort checks, derived MCP operation checkpoints, detached PGP verification, ASAR listing admission, Dart AOT inspection and its provider guard, evidence-file analysis views, binary layout and recorded crash admission, WASM inspection admission, and the Kuna shared assembly-index wait. Cancellation classification and cleanup behavior are unchanged. Fixes morluto/rea#5935 Fixes morluto/rea#5944 Fixes morluto/rea#6100 Fixes morluto/rea#6101 Fixes morluto/rea#6110 Fixes morluto/rea#6113 Fixes morluto/rea#6121 Fixes morluto/rea#6131 Fixes morluto/rea#6132 * test(cancellation): assert the exact caller reason identity Copied reasons satisfied toMatchObject, so the tests would pass even if the caller's abort reason were replaced by a structurally equal copy. Capture the rejection and assert the cause is the same object. Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5 --------- Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5
This commit is contained in:
1 parent
7ffae5a791
commit
4e28166626
22 files changed
+253
-52
No files matched your search
@@ -9,12 +9,16 @@ import { EvidenceIntegrityError } from "../domain/evidenceErrors.js";
|
||||
const context = (
|
||||
controller: AbortController,
|
||||
notifications: unknown[] = [],
|
||||
onMessage: (message: string) => void = () => undefined,
|
||||
) => ({
|
||||
mcpReq: {
|
||||
signal: controller.signal,
|
||||
_meta: { progressToken: "derived-test" },
|
||||
notify: (notification: unknown) => {
|
||||
notifications.push(notification);
|
||||
const message = (notification as { params?: { message?: unknown } })
|
||||
.params?.message;
|
||||
if (typeof message === "string") onMessage(message);
|
||||
return Promise.resolve();
|
||||
},
|
||||
},
|
||||
@@ -23,7 +27,8 @@ const context = (
|
||||
describe("derived MCP operation boundary", () => {
|
||||
it("cancels before computation and never evaluates the operation", async () => {
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
const reason = Object.freeze({ requested: "pre-compute-stop" });
|
||||
controller.abort(reason);
|
||||
let computed = false;
|
||||
const result = await runDerivedOperation(
|
||||
context(controller),
|
||||
@@ -38,9 +43,47 @@ describe("derived MCP operation boundary", () => {
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
expect(result.ok ? undefined : result.error.cause).toBe(reason);
|
||||
expect(computed).toBe(false);
|
||||
});
|
||||
|
||||
it("preserves the request's abort reason when cancellation wins after computation", async () => {
|
||||
const controller = new AbortController();
|
||||
const reason = Object.freeze({ requested: "post-compute-stop" });
|
||||
const result = await runDerivedOperation(
|
||||
context(controller),
|
||||
"compare",
|
||||
() => {
|
||||
controller.abort(reason);
|
||||
return "must-not-publish";
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
expect(result.ok ? undefined : result.error.cause).toBe(reason);
|
||||
});
|
||||
|
||||
it("preserves the request's abort reason when cancellation wins at terminal delivery", async () => {
|
||||
const controller = new AbortController();
|
||||
const reason = Object.freeze({ requested: "terminal-stop" });
|
||||
const result = await runDerivedOperation(
|
||||
context(controller, [], (message) => {
|
||||
if (message.startsWith("complete:")) controller.abort(reason);
|
||||
}),
|
||||
"compare",
|
||||
() => "must-not-publish",
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
expect(result.ok ? undefined : result.error.cause).toBe(reason);
|
||||
});
|
||||
|
||||
it("lets cancellation win immediately before result publication", async () => {
|
||||
const controller = new AbortController();
|
||||
const result = await runDerivedOperation(
|
||||
|
||||
@@ -31,7 +31,11 @@ export const runDerivedOperation = async <Value>(
|
||||
});
|
||||
await setImmediate();
|
||||
if (context.mcpReq.signal.aborted)
|
||||
return err(new AnalysisCancelledError(operation));
|
||||
return err(
|
||||
new AnalysisCancelledError(operation, {
|
||||
cause: context.mcpReq.signal.reason,
|
||||
}),
|
||||
);
|
||||
let value: Value;
|
||||
try {
|
||||
value = compute();
|
||||
@@ -62,7 +66,11 @@ export const runDerivedOperation = async <Value>(
|
||||
});
|
||||
await setImmediate();
|
||||
if (context.mcpReq.signal.aborted)
|
||||
return err(new AnalysisCancelledError(operation));
|
||||
return err(
|
||||
new AnalysisCancelledError(operation, {
|
||||
cause: context.mcpReq.signal.reason,
|
||||
}),
|
||||
);
|
||||
await progress.report({
|
||||
phase: "complete",
|
||||
completed: 2,
|
||||
@@ -71,6 +79,10 @@ export const runDerivedOperation = async <Value>(
|
||||
terminal: true,
|
||||
});
|
||||
if (context.mcpReq.signal.aborted)
|
||||
return err(new AnalysisCancelledError(operation));
|
||||
return err(
|
||||
new AnalysisCancelledError(operation, {
|
||||
cause: context.mcpReq.signal.reason,
|
||||
}),
|
||||
);
|
||||
return ok(value);
|
||||
};
|
||||
Reference in new issue
Block a user