refactor(errors): require a reason for every analysis cancellation (#10566)

* refactor(errors): require a reason for every analysis cancellation

Add cancelledBy, the one constructor for AnalysisCancelledError. Its
reason argument is required: an aborted signal, an earlier cancellation,
a reason carried from an inner failure, or an OwnerCancellation when REA
closed the work's owner itself.

Closed adb, apktool, firmware, sqlite, gdb, web-bundle analyzer and
binary-session record owners now report OwnerCancellation.ownerClosed
instead of an absent reason. Firmware's predecessor wait returns its
cancellation as a Result, removing an unreachable reason-less fallback.

An architecture guard rejects new direct constructions, with a counted
per-file baseline that can only shrink.

* refactor(errors): share one aborted-signal predicate with cancelledBy

* refactor(process): return a departing caller's reason from a shared startup wait

* refactor(providers): build decompiler-provider cancellations with a required reason (#10587)

Migrate every AnalysisCancelledError construction under src/ghidra,
src/ida, src/cutter, src/jeb and src/kuna to cancelledBy and lower the
guard baseline from 671 to 572. Closed Kuna target commands report
OwnerCancellation.ownerClosed instead of an absent reason, and Kuna and
JEB close abort their lifetimes with that typed reason.

* fix(errors): read the reason of any signal-shaped cancellation source

* test(ci): cover the counted-baseline comparison behind the architecture guard
This commit is contained in:
morluto authored and GitHub committed 2026-11-14 15:20:03 -05:00
1 parent 2f4c588584
commit 85da0bd4ee
51 files changed
+900 -488

No files matched your search

+14 -5
View File
@@ -6,14 +6,19 @@ import {
STARTUP_OWNER_CLOSED,
} from "./SharedStartupAttempt.js";
it("keeps shared startup running for an interested peer", async () => {
it("keeps shared startup running for an interested peer and returns the departing caller's reason", async () => {
const completed = createDeferred<string>();
const attempt = new SharedStartupAttempt(() => completed.promise);
const controller = new AbortController();
const departing = attempt.wait(controller.signal);
const staying = attempt.wait();
controller.abort();
await expect(departing).resolves.toEqual({ status: "cancelled" });
const reason = { caller: "departing" };
controller.abort(reason);
const departed = await departing;
expect(departed).toEqual({ status: "cancelled", reason });
expect(departed.status === "cancelled" ? departed.reason : undefined).toBe(
reason,
);
expect(attempt.signal.aborted).toBe(false);
completed.resolve("ready");
await expect(staying).resolves.toEqual({
@@ -28,9 +33,13 @@ it("retains the final cleanup result when all callers cancel together", async ()
const first = new AbortController();
const last = new AbortController();
const waits = [attempt.wait(first.signal), attempt.wait(last.signal)];
first.abort();
const firstReason = new Error("first caller left");
first.abort(firstReason);
last.abort();
await expect(waits[0]).resolves.toEqual({ status: "cancelled" });
await expect(waits[0]).resolves.toEqual({
status: "cancelled",
reason: firstReason,
});
expect(attempt.signal.aborted).toBe(true);
expect(attempt.settled).toBe(false);
const failure = { cleanupIncomplete: true };
+3 -2
View File
@@ -6,7 +6,7 @@ export const STARTUP_OWNER_CLOSED = Symbol("provider startup owner closed");
/** The final departing caller retains the producer's complete cleanup result. */
export type SharedStartupWait<Value> =
| { readonly status: "completed"; readonly value: Value }
| { readonly status: "cancelled" }
| { readonly status: "cancelled"; readonly reason: unknown }
| { readonly status: "stopped"; readonly value: Value };
type StartupSettlement<Value> =
@@ -68,7 +68,8 @@ export class SharedStartupAttempt<Value> {
try {
const waited = await waitForAbortable(this.promise, signal);
if (waited !== ABORTED) return { status: "completed", value: waited };
if (this.#waiters > 1) return { status: "cancelled" };
if (this.#waiters > 1)
return { status: "cancelled", reason: signal?.reason };
if (!this.settled) this.#controller.abort(signal?.reason);
return { status: "stopped", value: await this.promise };
} finally {