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
@@ -123,6 +123,7 @@ export const observeCdpSession = async (
|
||||
let endReason = await waitForWindow(
|
||||
context.input.observation_ms,
|
||||
capture,
|
||||
context.connection,
|
||||
context.signal,
|
||||
);
|
||||
if (endReason === "window_elapsed")
|
||||
@@ -593,18 +594,21 @@ const performanceTimestamp = (value: unknown): number => {
|
||||
const waitForWindow = async (
|
||||
durationMs: number,
|
||||
capture: TimelineCapture,
|
||||
connection: CdpConnection,
|
||||
signal?: AbortSignal,
|
||||
): Promise<EndReason> =>
|
||||
await new Promise<EndReason>((resolve, reject) => {
|
||||
const timerController = new AbortController();
|
||||
let settled = false;
|
||||
let removeEnd = (): void => {};
|
||||
let removeProtocolFailure = (): void => {};
|
||||
const settle = (complete: () => void): void => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
timerController.abort();
|
||||
signal?.removeEventListener("abort", onAbort);
|
||||
removeEnd();
|
||||
removeProtocolFailure();
|
||||
complete();
|
||||
};
|
||||
const finish = (reason: EndReason): void => settle(() => resolve(reason));
|
||||
@@ -619,6 +623,10 @@ const waitForWindow = async (
|
||||
signal?.addEventListener("abort", onAbort, { once: true });
|
||||
if (signal?.aborted === true) onAbort();
|
||||
if (!settled) removeEnd = capture.onEnd(finish);
|
||||
if (!settled)
|
||||
removeProtocolFailure = connection.onProtocolFailure((error) =>
|
||||
settle(() => reject(error)),
|
||||
);
|
||||
if (settled) return;
|
||||
void delayWithCancellation(
|
||||
durationMs,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DESTINATION_CASE_COLLISION_PREFIX } from "../../artifacts/ArtifactPaths
|
||||
import { SafeOutputTree } from "../../artifacts/SafeOutputTree.js";
|
||||
import { SafeOutputTreeCreationFailure } from "../../artifacts/SafeOutputTreeCreationFailure.js";
|
||||
import { PLAYWRIGHT_RESPONSE_BODY_PROVENANCE_LIMITATION } from "../../domain/browserNetworkEvidence.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
webScriptExportManifestSchema,
|
||||
webScriptExportResultSchema,
|
||||
@@ -30,6 +31,8 @@ const LIMITATIONS = [
|
||||
"Scenario response bytes preserve the output of Playwright's Response.body() API; any source-body provenance caveat from the capture is retained in this manifest. Debugger sources are the exposed text encoded as UTF-8. Redacted bytes are exported exactly as retained, and may no longer parse as JavaScript.",
|
||||
];
|
||||
|
||||
const OPERATION = "export_web_scripts";
|
||||
|
||||
interface PublishWebScriptsOptions {
|
||||
readonly resources: ArtifactResourceScope;
|
||||
readonly signal?: AbortSignal;
|
||||
@@ -128,19 +131,33 @@ export const publishWebScripts = async (
|
||||
const diagnostic = tree.published
|
||||
? `Publication completed, but descriptor cleanup failed (${message(cleanupCause)}). The published output remains available.`
|
||||
: `Publication failed (${message(cause)}); rollback failed (${message(cleanupCause)}). Remove the residual output directory before retrying.`;
|
||||
const partialObservation =
|
||||
tree.published && result !== undefined
|
||||
? ({ kind: "web-script-export", result } as const)
|
||||
: undefined;
|
||||
if (options.signal?.aborted === true) {
|
||||
const cancelled = new AnalysisCancelledError(OPERATION, {
|
||||
cause: options.signal.reason,
|
||||
cleanup: { reason: diagnostic, resources: [tree.outputRoot] },
|
||||
...(partialObservation === undefined
|
||||
? {}
|
||||
: { partialObservation }),
|
||||
});
|
||||
cleanup.lease.bindCleanupError(cancelled);
|
||||
throw cancelled;
|
||||
}
|
||||
const error = new WebScriptExportError(
|
||||
cause instanceof ArtifactReaderFailure ? cause.reason : "io",
|
||||
tree.outputRoot,
|
||||
diagnostic,
|
||||
{ residualPaths: [tree.outputRoot] },
|
||||
);
|
||||
if (tree.published && result !== undefined)
|
||||
error.retainPartialObservation({
|
||||
kind: "web-script-export",
|
||||
result,
|
||||
});
|
||||
if (partialObservation !== undefined)
|
||||
error.retainPartialObservation(partialObservation);
|
||||
cleanup.lease.bindCleanupError(error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (tree.published && result !== undefined) return result;
|
||||
}
|
||||
throw cause;
|
||||
|
||||
Reference in new issue
Block a user