fix(cancellation): preserve caller abort reasons through late finalization (#6143)
* fix(cancellation): preserve caller abort reasons through late finalization Caller aborts that arrived during final provider, cleanup, or protocol handling were dropped or replaced by I/O, cleanup, or success results. Each affected path now samples the caller signal after its owner has settled and returns AnalysisCancelledError carrying the exact signal.reason, keeping any completed partial Evidence or cleanup state. - Web script export: keep the exact reason for an interrupted output write, and honor a cancellation fact recorded before a retried capture close succeeds. - Native value tracing and Hopper regex search: check the signal after the final provider reply or regex worker settles. - Apple asset catalog: stop assetutil with SIGTERM so cancellation settles only after the helper exits. - CDP observation: end an armed window on a fatal protocol failure. - ADB bugreport: prefer cancellation over the staging-removal output error when the caller aborted. - JavaScript recovery: check the signal after provider success. - export-web-scripts CLI: run under command cancellation and forward the signal into the export workflow. - Objdump and Rizin CLI: report cancellation after cleanup completes. - Binary session: keep cancellation primary when previous-client retirement fails after abort. Fixes morluto/rea#6042 Fixes morluto/rea#6043 Fixes morluto/rea#6048 Fixes morluto/rea#6049 Fixes morluto/rea#6057 Fixes morluto/rea#6060 Fixes morluto/rea#6078 Fixes morluto/rea#6080 Fixes morluto/rea#6108 Fixes morluto/rea#6111 Fixes morluto/rea#6115 * fix(cancellation): keep caller reasons through export rollback and commit - Rollback failure after a caller abort now returns AnalysisCancelledError with the exact signal.reason, attaching the rollback failure as cleanup and retaining any published result as partial observation. - A capture close retry that succeeds after abort returns cancellation instead of the stale cleanup diagnostic. - An abort that lands during the final output commit returns cancellation carrying the completed manifest as partial observation. - Apple assetutil stop test: abort and await the run in finally so a timed-out wait does not leave the child running, and skip on Windows where the JavaScript SIGTERM handler cannot run. Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5 * fix(cancellation): bind export cancellations to cleanup and caller reasons - A rollback-failure cancellation is bound to the retained cleanup lease, so a later successful close clears cleanup_incomplete instead of reporting a residual directory that no longer exists. - mapExportFailure wraps the caller's own AnalysisCancelledError reason under export_web_scripts rather than returning it as the export's error. Co-authored-by: Copilot <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: morluto <[email protected]> Copilot-Session: 35b247e9-c793-4b8f-979a-807c27112cf5
This commit is contained in:
21 files changed
+611
-61
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { access, mkdir, symlink, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
import * as processOutput from "../../process/ExecFileOutput.js";
|
||||
import { encodeNibArchiveFixture } from "./NibArchive.fixture.js";
|
||||
import type { analyzeInterfaceBuilderBundle } from "./InterfaceBuilderAnalysis.js";
|
||||
import { ArtifactReaderFailure } from "../ArtifactReader.js";
|
||||
@@ -330,4 +331,50 @@ describe("Apple asset catalog and Interface Builder concurrency", () => {
|
||||
finishCatalog("[]");
|
||||
await expect(analysis).rejects.toThrow("interface builder failed");
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"settles a cancelled assetutil run only after its process exits",
|
||||
async () => {
|
||||
const bundle = await catalogBundle();
|
||||
const work = await createTestTempDirectory("rea-assetutil-stop-");
|
||||
const ready = join(work, "ready");
|
||||
const exited = join(work, "exited");
|
||||
const script = `const fs=require("node:fs");process.on("SIGTERM",()=>{setTimeout(()=>{fs.writeFileSync(process.argv[2],"exited");process.exit(0)},500)});fs.writeFileSync(process.argv[1],"ready");setInterval(()=>{},1000);`;
|
||||
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
||||
const realExecFileOutput = processOutput.execFileOutput;
|
||||
Object.defineProperty(process, "platform", {
|
||||
...platform,
|
||||
value: "darwin",
|
||||
});
|
||||
const spy = vi
|
||||
.spyOn(processOutput, "execFileOutput")
|
||||
.mockImplementation((_command, _args, options) =>
|
||||
realExecFileOutput(
|
||||
process.execPath,
|
||||
["-e", script, ready, exited],
|
||||
options,
|
||||
),
|
||||
);
|
||||
const controller = new AbortController();
|
||||
let settled: Promise<unknown> | undefined;
|
||||
try {
|
||||
settled = analyzeAppleAssetCatalogs({
|
||||
environment: {},
|
||||
bundlePath: bundle,
|
||||
targetSha256: "a".repeat(64),
|
||||
signal: controller.signal,
|
||||
analyzeInterfaceBuilder: async () => emptyGraph,
|
||||
}).catch((cause: unknown) => cause);
|
||||
await vi.waitFor(() => expect(access(ready)).resolves.toBeUndefined());
|
||||
controller.abort("stop asset inspection");
|
||||
expect(await settled).toMatchObject({ reason: "cancelled" });
|
||||
await expect(access(exited)).resolves.toBeUndefined();
|
||||
} finally {
|
||||
controller.abort("stop asset inspection");
|
||||
await settled;
|
||||
spy.mockRestore();
|
||||
Object.defineProperty(process, "platform", platform);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -274,6 +274,7 @@ const runAssetUtil = async (
|
||||
env: environment,
|
||||
timeout: 60_000,
|
||||
maxBuffer: MAX_CATALOG_BYTES,
|
||||
stopSignal: "SIGTERM",
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
})
|
||||
).stdout;
|
||||
|
||||
Reference in new issue
Block a user