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

@@ -7,6 +7,7 @@ import {
AnalysisOutputError,
AnalysisResourceConstraintError,
AnalysisTimeoutError,
OwnerCancellation,
} from "../domain/analysisErrorCore.js";
import type {
AnalyzeWebBundleInput,
@@ -267,6 +268,26 @@ it("carries the exact caller cancellation reason and completed prefix facts", as
});
});
it("refuses work after close with REA's own cancellation reason, not an absent one", async () => {
const analyzer = new IsolatedWebBundleAnalyzer(() => ({
analyze: async (script) => ok(analyzeCapturedWebScript(script)),
close: async () => {},
}));
await analyzer.close();
const captured = inspection(["fetch('/one');"]);
const reserved = await analyzer.reserve();
const analyzed = await analyzer.analyze(captured, noSourceMaps, input);
for (const result of [reserved, analyzed]) {
if (result.ok) throw new Error("Closed analyzer accepted work");
expect(result.error._tag).toBe("AnalysisCancelledError");
expect(result.error.cause).toBe(OwnerCancellation.ownerClosed);
}
if (analyzed.ok) throw new Error("Closed analyzer accepted work");
expect(analyzed.error.partialObservation).toBe(captured);
});
it("retains all completed facts when cancellation arrives during worker close", async () => {
const captured = inspection(["fetch('/one');", "fetch('/two');"]);
const closeStarted = deferred<void>();
+9 -3
View File
@@ -17,6 +17,8 @@ import {
AnalysisTimeoutError,
AnalysisResourceConstraintError,
AnalysisOutputError,
cancelledBy,
OwnerCancellation,
} from "../domain/analysisErrorCore.js";
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
@@ -91,7 +93,9 @@ export class IsolatedWebBundleAnalyzer {
/** Reserve capacity before capture, so concurrent captures cannot retain source inventories. */
async reserve(): Promise<Result<void, AnalysisError>> {
if (this.#closed)
return err(new AnalysisCancelledError("analyze_web_bundle"));
return err(
cancelledBy("analyze_web_bundle", OwnerCancellation.ownerClosed),
);
if (this.#admission.active() !== undefined)
return err(
new AnalysisResourceConstraintError(
@@ -124,7 +128,9 @@ export class IsolatedWebBundleAnalyzer {
}
if (this.#closed) {
this.#admission.release(this);
return err(new AnalysisCancelledError("analyze_web_bundle"));
return err(
cancelledBy("analyze_web_bundle", OwnerCancellation.ownerClosed),
);
}
return ok(undefined);
}
@@ -142,7 +148,7 @@ export class IsolatedWebBundleAnalyzer {
if (this.#closed)
return Promise.resolve(
err(
new AnalysisCancelledError("analyze_web_bundle", {
cancelledBy("analyze_web_bundle", OwnerCancellation.ownerClosed, {
partialObservation: inspection,
}),
),