refactor(native): build debugger and native cancellations with a required reason (#10599)

* 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

* refactor(native): build debugger and native cancellations with a required reason

Migrate every AnalysisCancelledError construction under src/native,
src/gdb and src/rizin to cancelledBy and delete Rizin's local
rizinCancellation constructor; its reason choice becomes a
CancellationReason. GDB close aborts active startups with
OwnerCancellation.ownerClosed.

* test(ci): cover the counted-baseline comparison behind the architecture guard

* refactor(native): drop an unused cancellation import from native UI observation
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 18:07:27 +08:00
1 parent f6752bbe2c
commit 57f75bb723
16 files changed
+229 -252

No files matched your search

+29 -38
View File
@@ -76,6 +76,8 @@ import {
AnalysisOutputError,
AnalysisUnsupportedTargetError,
AnalysisResourceConstraintError,
cancelledBy,
carriedReason,
} from "../domain/analysisErrorCore.js";
import {
DEFAULT_NATIVE_COMMAND_TIMEOUT_MS,
@@ -287,9 +289,7 @@ class NativeMacOSClient implements AnalysisClient {
),
);
if (options?.signal?.aborted === true)
return err(
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
);
return err(cancelledBy(operation, options.signal));
if (operation === "health")
return ok(createAnalysisExecution(null, IDENTITY));
if (this.activeTarget === undefined && operation !== "inspect_plist")
@@ -1487,12 +1487,7 @@ class NativeMacOSClient implements AnalysisClient {
): Promise<Result<NativeObservation, AnalysisError>> {
try {
return await this.#machoOperandResources.run(async () => {
if (signal?.aborted)
return err(
new AnalysisCancelledError("inspect_macho", {
cause: signal.reason,
}),
);
if (signal?.aborted) return err(cancelledBy("inspect_macho", signal));
let root: Pick<PrivateRuntimeRoot, "path" | "close">;
try {
root = await (this.privateRuntimeRootFactory?.() ??
@@ -1524,11 +1519,7 @@ class NativeMacOSClient implements AnalysisClient {
const operand = join(root.path, "artifact.macho");
await symlink(this.target.path, operand);
result = signal?.aborted
? err(
new AnalysisCancelledError("inspect_macho", {
cause: signal.reason,
}),
)
? err(cancelledBy("inspect_macho", signal))
: await inspect(operand);
} catch (cause: unknown) {
result = err(
@@ -1558,8 +1549,7 @@ class NativeMacOSClient implements AnalysisClient {
new AnalysisCleanupLeaseGroup(cleanup, [released.lease]);
const primary = result.ok
? signal?.aborted
? new AnalysisCancelledError("inspect_macho", {
cause: signal.reason,
? cancelledBy("inspect_macho", signal, {
partialObservation: inspectMachoSchema.parse(
result.value.result,
),
@@ -1578,8 +1568,7 @@ class NativeMacOSClient implements AnalysisClient {
}
if (signal?.aborted && result.ok)
return err(
new AnalysisCancelledError("inspect_macho", {
cause: signal.reason,
cancelledBy("inspect_macho", signal, {
partialObservation: inspectMachoSchema.parse(result.value.result),
}),
);
@@ -1765,9 +1754,8 @@ const nativeMachoSourcePrimary = (
: undefined;
const completedFailure = nativeMachoCompletedFailure(completed);
const previous = failed ?? completedFailure;
const options = {
cause,
...(previous === undefined
const optionsWithoutCause =
previous === undefined
? {}
: {
diagnostics: {
@@ -1775,22 +1763,24 @@ const nativeMachoSourcePrimary = (
projectAnalysisError(previous),
),
},
}),
};
};
const options = { cause, ...optionsWithoutCause };
if (cause instanceof ArtifactReaderFailure && cause.reason === "cancelled") {
// A returned failure is already the producer's physical outcome. A later
// cancelled identity check must not replace its output or cleanup owner.
if (completedFailure !== undefined)
return analysisErrorWithCancellation(
completedFailure,
new AnalysisCancelledError(operation, {
cause: artifactFileCancellationCause(cause),
}),
cancelledBy(
operation,
carriedReason(artifactFileCancellationCause(cause)),
),
);
return new AnalysisCancelledError(operation, {
...options,
cause: artifactFileCancellationCause(cause),
});
return cancelledBy(
operation,
carriedReason(artifactFileCancellationCause(cause)),
optionsWithoutCause,
);
}
if (cause instanceof ArtifactReaderFailure && cause.reason === "format")
return new AnalysisOutputError(operation, cause.message, options);
@@ -1841,12 +1831,13 @@ const nativeMachoCompletion = (
const completionCancellation =
completion?.cancellation === undefined
? undefined
: new AnalysisCancelledError(operation, {
cause: completion.cancellation.reason,
...(completedFailure === undefined ||
completedFailure.cleanupIncomplete ||
(cause instanceof ArtifactReaderFailure &&
cause.cleanup !== undefined)
: cancelledBy(
operation,
carriedReason(completion.cancellation.reason),
completedFailure === undefined ||
completedFailure.cleanupIncomplete ||
(cause instanceof ArtifactReaderFailure &&
cause.cleanup !== undefined)
? {}
: {
diagnostics: {
@@ -1854,8 +1845,8 @@ const nativeMachoCompletion = (
projectAnalysisError(completedFailure),
),
},
}),
});
},
);
return { observation, completedFailure, completionCancellation };
};