Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(native): retain UI interruption source through final cleanup

morluto36d156ff05f4
diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.ts
index e2d961755..bc9db41b0 100644
--- a/src/native/NativeMacOSProvider.ts
+++ b/src/native/NativeMacOSProvider.ts
@@ -118,6 +118,7 @@ import {
createNativeUiHelperRuntime,
type NativeUiHelperRuntime,
} from "./NativeUiHelperRuntime.js";
+import { NativeUiInterruptionControl } from "./NativeUiInterruptionControl.js";
type SignatureRuntimeRootFactory = () => Promise<
Pick<PrivateRuntimeRoot, "path" | "close">
@@ -362,57 +363,57 @@ class NativeMacOSClient implements AnalysisClient {
this.#nativeUiCleanupFailure(earlierCleanupFailures, operation),
);
const runtime = createNativeUiHelperRuntime(this.environment);
- const observationSignal =
- signal === undefined
- ? runtime.signal
- : AbortSignal.any([signal, runtime.signal]);
- this.#pendingNativeUiRuntimes.add(runtime);
- let result: Awaited<ReturnType<typeof observeNativeUi>>;
- try {
- result = await observeNativeUi(this.target, operation, parameters, {
- environment: this.environment,
- signal: observationSignal,
- runtime,
- });
- } catch (cause: unknown) {
- result = err(
- cause instanceof AnalysisError
- ? cause
- : new ProviderAdapterError(IDENTITY.id, operation, { cause }),
- );
- }
+ const interruption = new NativeUiInterruptionControl(
+ signal,
+ runtime.signal,
+ );
try {
- await runtime.close();
- this.#pendingNativeUiRuntimes.delete(runtime);
- } catch (cause: unknown) {
- result = finishNativeUiObservation(
- result,
- operation,
- observationSignal,
- );
- const cleanup = this.#nativeUiCleanupFailure(
- [{ runtime, cause }],
- operation,
- result.ok ? result.value : undefined,
- );
- return err(
- result.ok
- ? cleanup
- : analysisErrorWithCleanupFailure(
- result.error,
- cleanup,
- operation,
- ).bindCleanupDependencies([result.error, cleanup]),
- );
+ this.#pendingNativeUiRuntimes.add(runtime);
+ let result: Awaited<ReturnType<typeof observeNativeUi>>;
+ try {
+ result = await observeNativeUi(this.target, operation, parameters, {
+ environment: this.environment,
+ runtime,
+ interruption,
+ });
+ } catch (cause: unknown) {
+ result = err(
+ cause instanceof AnalysisError
+ ? cause
+ : new ProviderAdapterError(IDENTITY.id, operation, { cause }),
+ );
+ }
+ try {
+ await runtime.close();
+ this.#pendingNativeUiRuntimes.delete(runtime);
+ } catch (cause: unknown) {
+ result = finishNativeUiObservation(result, operation, interruption);
+ const cleanup = this.#nativeUiCleanupFailure(
+ [{ runtime, cause }],
+ operation,
+ result.ok ? result.value : undefined,
+ );
+ return err(
+ result.ok
+ ? cleanup
+ : analysisErrorWithCleanupFailure(
+ result.error,
+ cleanup,
+ operation,
+ ).bindCleanupDependencies([result.error, cleanup]),
+ );
+ }
+ result = finishNativeUiObservation(result, operation, interruption);
+ return result.ok
+ ? ok(
+ createAnalysisExecution(result.value, IDENTITY, {
+ limitations: result.value.limitations,
+ }),
+ )
+ : result;
+ } finally {
+ interruption.dispose();
}
- result = finishNativeUiObservation(result, operation, observationSignal);
- return result.ok
- ? ok(
- createAnalysisExecution(result.value, IDENTITY, {
- limitations: result.value.limitations,
- }),
- )
- : result;
});
}
diff --git a/src/native/NativeUiHelperRuntime.ts b/src/native/NativeUiHelperRuntime.ts
index 4df72b8c5..5c80af77d 100644
--- a/src/native/NativeUiHelperRuntime.ts
+++ b/src/native/NativeUiHelperRuntime.ts
@@ -10,6 +10,7 @@ import { execFileOutput } from "../process/ExecFileOutput.js";
import { safeParseJson } from "../domain/safeJson.js";
import type { NativeUiHelper } from "./NativeUiObservation.js";
import { NATIVE_UI_HELPER_MAX_BUFFER } from "./NativeUiOutputBudget.js";
+import { NATIVE_UI_DEADLINE_MS } from "./NativeUiInterruptionControl.js";
export interface NativeUiHelperRuntime {
readonly invoke: NativeUiHelper;
@@ -24,7 +25,7 @@ export const createNativeUiHelperRuntime = (
environment: Readonly<NodeJS.ProcessEnv>,
): NativeUiHelperRuntime => {
const selectedEnvironment = snapshotEnvironment(environment);
- const deadlineSignal = AbortSignal.timeout(180_000);
+ const deadlineSignal = AbortSignal.timeout(NATIVE_UI_DEADLINE_MS);
const operations = new ArtifactResourceScope();
let root: string | undefined;
let preparation: Promise<string> | undefined;
diff --git a/src/native/NativeUiInterruptionControl.test.ts b/src/native/NativeUiInterruptionControl.test.ts
new file mode 100644
index 000000000..b6becef7c
--- /dev/null
+++ b/src/native/NativeUiInterruptionControl.test.ts
@@ -0,0 +1,57 @@
+import {
+ AnalysisCancelledError,
+ AnalysisTimeoutError,
+} from "../domain/analysisErrorCore.js";
+import { expect, it } from "vitest";
+import { NativeUiInterruptionControl } from "./NativeUiInterruptionControl.js";
+
+it("gives a pre-aborted caller priority over a pre-aborted deadline", () => {
+ const reason = { phase: "shared" };
+ const caller = new AbortController();
+ const deadline = new AbortController();
+ caller.abort(reason);
+ deadline.abort(reason);
+ const control = new NativeUiInterruptionControl(
+ caller.signal,
+ deadline.signal,
+ );
+ expect(control.error("observe_native_ui")).toBeInstanceOf(
+ AnalysisCancelledError,
+ );
+ expect(control.error("observe_native_ui")?.cause).toBe(reason);
+ control.dispose();
+});
+
+it("keeps the first observed source when caller and deadline share a reason", () => {
+ const reason = { phase: "shared" };
+ const caller = new AbortController();
+ const deadline = new AbortController();
+ const control = new NativeUiInterruptionControl(
+ caller.signal,
+ deadline.signal,
+ );
+ deadline.abort(reason);
+ caller.abort(reason);
+ expect(control.error("observe_native_ui")).toBeInstanceOf(
+ AnalysisTimeoutError,
+ );
+ expect(control.error("observe_native_ui")?.cause).toBe(reason);
+ control.dispose();
+});
+
+it("records a caller interruption before a later deadline", () => {
+ const reason = { phase: "shared" };
+ const caller = new AbortController();
+ const deadline = new AbortController();
+ const control = new NativeUiInterruptionControl(
+ caller.signal,
+ deadline.signal,
+ );
+ caller.abort(reason);
+ deadline.abort(reason);
+ expect(control.error("observe_native_ui")).toBeInstanceOf(
+ AnalysisCancelledError,
+ );
+ expect(control.error("observe_native_ui")?.cause).toBe(reason);
+ control.dispose();
+});
diff --git a/src/native/NativeUiInterruptionControl.ts b/src/native/NativeUiInterruptionControl.ts
new file mode 100644
index 000000000..6b6a512ea
--- /dev/null
+++ b/src/native/NativeUiInterruptionControl.ts
@@ -0,0 +1,70 @@
+import type { AnalysisPartialObservation } from "../domain/analysisErrorBase.js";
+import {
+ AnalysisCancelledError,
+ AnalysisTimeoutError,
+} from "../domain/analysisErrorCore.js";
+
+export const NATIVE_UI_DEADLINE_MS = 180_000;
+
+type Interruption =
+ | { readonly kind: "caller"; readonly reason: unknown }
+ | { readonly kind: "deadline"; readonly reason: unknown };
+
+/** Tracks whether the caller or the owned operation deadline stopped UI work. */
+export class NativeUiInterruptionControl {
+ readonly signal: AbortSignal;
+ #controller = new AbortController();
+ #interruption: Interruption | undefined;
+ #caller: AbortSignal | undefined;
+ #deadline: AbortSignal;
+ #onCallerAbort = (): void => {
+ this.#interrupt("caller", this.#caller?.reason);
+ };
+ #onDeadlineAbort = (): void => {
+ this.#interrupt("deadline", this.#deadline.reason);
+ };
+
+ constructor(caller: AbortSignal | undefined, deadline: AbortSignal) {
+ this.#caller = caller;
+ this.#deadline = deadline;
+ this.signal = this.#controller.signal;
+
+ // Match AbortSignal.any's iterable priority when both are already aborted.
+ if (caller?.aborted) this.#interrupt("caller", caller.reason);
+ else if (deadline.aborted) this.#interrupt("deadline", deadline.reason);
+ else {
+ caller?.addEventListener("abort", this.#onCallerAbort, { once: true });
+ deadline.addEventListener("abort", this.#onDeadlineAbort, {
+ once: true,
+ });
+ }
+ }
+
+ error(
+ operation: string,
+ partialObservation?: AnalysisPartialObservation,
+ ): AnalysisCancelledError | AnalysisTimeoutError | undefined {
+ const interruption = this.#interruption;
+ if (interruption === undefined) return undefined;
+ return interruption.kind === "deadline"
+ ? new AnalysisTimeoutError(operation, NATIVE_UI_DEADLINE_MS, {
+ cause: interruption.reason,
+ partialObservation,
+ })
+ : new AnalysisCancelledError(operation, {
+ cause: interruption.reason,
+ partialObservation,
+ });
+ }
+
+ dispose(): void {
+ this.#caller?.removeEventListener("abort", this.#onCallerAbort);
+ this.#deadline.removeEventListener("abort", this.#onDeadlineAbort);
+ }
+
+ #interrupt(kind: Interruption["kind"], reason: unknown): void {
+ if (this.#interruption !== undefined) return;
+ this.#interruption = { kind, reason };
+ this.#controller.abort(reason);
+ }
+}
diff --git a/src/native/NativeUiObservation.test.ts b/src/native/NativeUiObservation.test.ts
index 36a0a6974..9ecd09182 100644
--- a/src/native/NativeUiObservation.test.ts
+++ b/src/native/NativeUiObservation.test.ts
@@ -2,6 +2,12 @@ import { createHash } from "node:crypto";
import { describe, expect, it } from "vitest";
import { observeNativeUi } from "./NativeUiObservation.js";
+import {
+ AnalysisCancelledError,
+ AnalysisTimeoutError,
+} from "../domain/analysisErrorCore.js";
+import { ExecFileOutputCancelledError } from "../process/ExecFileOutput.js";
+import { AnalysisCleanupLease } from "../artifacts/AnalysisCleanupLease.js";
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
const target: BinaryTarget = {
@@ -268,6 +274,182 @@ describe("native UI capture selection and budgets", () => {
});
});
+describe("native UI deadline execution", () => {
+ it("reports the owned deadline as a timeout during helper execution", async () => {
+ const deadline = new AbortController();
+ const reason = new DOMException("deadline elapsed", "TimeoutError");
+ const result = await observeNativeUi(target, "observe_native_ui", scope, {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => {
+ deadline.abort(reason);
+ throw new ExecFileOutputCancelledError(reason);
+ },
+ });
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected deadline timeout");
+ expect(result.error).toBeInstanceOf(AnalysisTimeoutError);
+ expect(result.error.cause).toBe(reason);
+ });
+
+ it("preserves an independent producer cancellation when the deadline fires", async () => {
+ const deadline = new AbortController();
+ const producerReason = { phase: "producer" };
+ const result = await observeNativeUi(target, "observe_native_ui", scope, {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => {
+ deadline.abort({ phase: "late-deadline" });
+ throw new ExecFileOutputCancelledError(producerReason);
+ },
+ });
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected producer cancellation");
+ expect(result.error).toBeInstanceOf(AnalysisCancelledError);
+ expect(result.error.cause).toBe(producerReason);
+ });
+
+ it("keeps deadline failure in a scenario report as failed, not cancelled", async () => {
+ const deadline = new AbortController();
+ const reason = { phase: "scenario-deadline" };
+ let calls = 0;
+ const result = await observeNativeUi(
+ target,
+ "capture_native_ui_scenario",
+ { ...scope, steps: [{ kind: "click", path: [1] }] },
+ {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => {
+ if (++calls === 1) {
+ deadline.abort(reason);
+ return { ok: true, result: snapshot };
+ }
+ throw new Error("unexpected second capture");
+ },
+ },
+ );
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected deadline timeout");
+ expect(result.error).toBeInstanceOf(AnalysisTimeoutError);
+ expect(result.error.cause).toBe(reason);
+ expect(result.error.partialObservation).toMatchObject({
+ steps: [{ outcome: "failed", after: null }],
+ });
+ expect(calls).toBe(1);
+ });
+});
+
+describe("native UI interruption provenance", () => {
+ it("reports an owned deadline during a scenario wait as a failed step", async () => {
+ const deadline = new AbortController();
+ const reason = { phase: "wait-deadline" };
+ const timer = setTimeout(() => deadline.abort(reason), 0);
+ const result = await observeNativeUi(
+ target,
+ "capture_native_ui_scenario",
+ { ...scope, steps: [{ kind: "wait", milliseconds: 100 }] },
+ {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => ({ ok: true, result: snapshot }),
+ },
+ );
+ clearTimeout(timer);
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected deadline timeout");
+ expect(result.error).toBeInstanceOf(AnalysisTimeoutError);
+ expect(result.error.cause).toBe(reason);
+ expect(result.error.partialObservation).toMatchObject({
+ steps: [{ outcome: "failed", reason: expect.any(String) }],
+ });
+ });
+
+ it("treats a caller TimeoutError-shaped reason as caller cancellation", async () => {
+ const caller = new AbortController();
+ const reason = new DOMException("caller stopped", "TimeoutError");
+ caller.abort(reason);
+ const result = await observeNativeUi(target, "observe_native_ui", scope, {
+ environment: {},
+ signal: caller.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ });
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected caller cancellation");
+ expect(result.error._tag).toBe("AnalysisCancelledError");
+ expect(result.error.cause).toBe(reason);
+ });
+
+ it("preserves a physical helper failure even if the owned deadline fires", async () => {
+ const deadline = new AbortController();
+ const failure = new Error("physical helper failure");
+ const result = await observeNativeUi(target, "observe_native_ui", scope, {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => {
+ deadline.abort({ phase: "late-deadline" });
+ throw failure;
+ },
+ });
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected helper failure");
+ expect(result.error._tag).toBe("ProviderAdapterError");
+ expect(result.error.cause).toBe(failure);
+ });
+
+ it("preserves schema failure even if the owned deadline fires", async () => {
+ const deadline = new AbortController();
+ const result = await observeNativeUi(target, "observe_native_ui", scope, {
+ environment: {},
+ runtime: {
+ signal: deadline.signal,
+ invoke: async () => ({ ok: true, result: snapshot }),
+ cleanupLease: new AnalysisCleanupLease(async () => undefined),
+ close: async () => undefined,
+ resources: () => [],
+ },
+ invoke: async () => {
+ deadline.abort({ phase: "late-deadline" });
+ return { ok: true, result: { malformed: true } };
+ },
+ });
+ expect(result.ok).toBe(false);
+ if (result.ok) throw new Error("Expected schema failure");
+ expect(result.error._tag).toBe("ProviderAdapterError");
+ expect(result.error.cause).toMatchObject({ name: "ZodError" });
+ });
+});
+
describe("native UI target and cancellation failures", () => {
it.each([
"accessibility-denied",
diff --git a/src/native/NativeUiObservation.ts b/src/native/NativeUiObservation.ts
index ef5ad94b1..6116d2647 100644
--- a/src/native/NativeUiObservation.ts
+++ b/src/native/NativeUiObservation.ts
@@ -30,6 +30,7 @@ import {
NATIVE_UI_OUTPUT_BUDGET_BYTES,
NATIVE_UI_OUTPUT_WEIGHT,
} from "./NativeUiOutputBudget.js";
+import { NativeUiInterruptionControl } from "./NativeUiInterruptionControl.js";
const helper = fileURLToPath(
new URL("../../bridge/native/ReaNativeUI.swift", import.meta.url),
@@ -61,56 +62,64 @@ export const observeNativeUi = async (
signal?: AbortSignal | undefined;
invoke?: NativeUiHelper;
runtime?: NativeUiHelperRuntime;
+ interruption?: NativeUiInterruptionControl;
},
): Promise<Result<z.infer<typeof nativeUiResultSchema>, AnalysisError>> => {
const runtime =
options.runtime ?? createNativeUiHelperRuntime(options.environment);
- const signal =
- options.signal === undefined
- ? runtime.signal
- : AbortSignal.any([options.signal, runtime.signal]);
+ const interruption =
+ options.interruption ??
+ new NativeUiInterruptionControl(options.signal, runtime.signal);
+ const ownsInterruption = options.interruption === undefined;
let result: Result<z.infer<typeof nativeUiResultSchema>, AnalysisError>;
try {
- result = await observeWithHelper(target, operation, parameters, {
- signal,
- invoke: options.invoke ?? runtime.invoke,
- });
- } catch (cause: unknown) {
- result = err(
- cause instanceof AnalysisError
- ? cause
- : new ProviderAdapterError("native-macos", operation, { cause }),
- );
- }
- if (options.runtime === undefined) {
try {
- await runtime.close();
+ result = await observeWithHelper(target, operation, parameters, {
+ interruption,
+ invoke: options.invoke ?? runtime.invoke,
+ });
} catch (cause: unknown) {
- result = finishNativeUiObservation(result, operation, signal);
- const cleanup = new NativeUiCleanupError(
- [{ runtime, cause }],
- operation,
- result.ok ? result.value : undefined,
+ result = err(
+ cause instanceof AnalysisError
+ ? cause
+ : new ProviderAdapterError("native-macos", operation, { cause }),
);
- return result.ok
- ? err(cleanup)
- : err(
- analysisErrorWithCleanupFailure(
- result.error,
- cleanup,
- operation,
- ).bindCleanupDependencies([result.error, cleanup]),
- );
}
+ if (options.runtime === undefined) {
+ try {
+ await runtime.close();
+ } catch (cause: unknown) {
+ result = finishNativeUiObservation(result, operation, interruption);
+ const cleanup = new NativeUiCleanupError(
+ [{ runtime, cause }],
+ operation,
+ result.ok ? result.value : undefined,
+ );
+ return result.ok
+ ? err(cleanup)
+ : err(
+ analysisErrorWithCleanupFailure(
+ result.error,
+ cleanup,
+ operation,
+ ).bindCleanupDependencies([result.error, cleanup]),
+ );
+ }
+ }
+ return finishNativeUiObservation(result, operation, interruption);
+ } finally {
+ if (ownsInterruption) interruption.dispose();
}
- return finishNativeUiObservation(result, operation, signal);
};
const observeWithHelper = async (
target: BinaryTarget,
operation: "observe_native_ui" | "capture_native_ui_scenario",
parameters: unknown,
- options: { signal: AbortSignal; invoke: NativeUiHelper },
+ options: {
+ interruption: NativeUiInterruptionControl;
+ invoke: NativeUiHelper;
+ },
): Promise<Result<z.infer<typeof nativeUiResultSchema>, AnalysisError>> => {
const parsed = (
operation === "observe_native_ui"
@@ -135,17 +144,16 @@ const observeWithHelper = async (
}),
);
const steps = input.steps;
- const signal = options.signal;
+ const interruption = options.interruption;
+ const signal = interruption.signal;
const invoke = options.invoke;
let launchTime: number | undefined;
let outputBytes = 0;
const take = async (
action?: unknown,
): Promise<Result<z.infer<typeof nativeUiSnapshotSchema>, AnalysisError>> => {
- if (signal.aborted)
- return err(
- new AnalysisCancelledError(operation, { cause: signal.reason }),
- );
+ const interrupted = interruption.error(operation);
+ if (interrupted !== undefined) return err(interrupted);
try {
const response = responseSchema.parse(
await invoke(
@@ -202,7 +210,10 @@ const observeWithHelper = async (
if (cause instanceof AnalysisError) return err(cause);
return err(
cause instanceof ExecFileOutputCancelledError
- ? new AnalysisCancelledError(operation, { cause: cause.cause })
+ ? ((signal.aborted && cause.cause === signal.reason
+ ? interruption.error(operation)
+ : undefined) ??
+ new AnalysisCancelledError(operation, { cause: cause.cause }))
: new ProviderAdapterError("native-macos", operation, {
cause,
diagnostics: {
@@ -221,37 +232,8 @@ const observeWithHelper = async (
let before = initial.value;
let terminalFailure: AnalysisError | undefined;
for (const [index, step] of steps.entries()) {
- if (signal.aborted) {
- terminalFailure = new AnalysisCancelledError(operation, {
- cause: signal.reason,
- });
- results.push({
- index,
- kind: step.kind,
- before,
- after: null,
- outcome: "cancelled",
- reason: "Scenario cancelled before action",
- });
- break;
- }
- if (
- step.kind === "wait" &&
- (await waitForAbortableDelay(step.milliseconds, signal)) === "aborted"
- ) {
- terminalFailure = new AnalysisCancelledError(operation, {
- cause: signal.reason,
- });
- results.push({
- index,
- kind: step.kind,
- before,
- after: null,
- outcome: "cancelled",
- reason: "Scenario cancelled during wait",
- });
- break;
- }
+ if (step.kind === "wait")
+ await waitForAbortableDelay(step.milliseconds, signal);
const after = await take(step.kind === "wait" ? undefined : step);
if (!after.ok) {
terminalFailure = after.error;
@@ -288,11 +270,11 @@ const observeWithHelper = async (
"Click uses AXPress; scroll uses AXIncrement/AXDecrement; key-entry sets the selected element's AXValue. Unsupported elements fail without global event fallback.",
"Each completed action is followed immediately by capture; delayed UI changes require explicit wait steps. A failed after-capture can follow a completed action, so failure does not prove absence of application effects.",
"Scenarios can change app data, cause app network activity and persist changes. The caller explicitly chooses leave-as-is; automatic restoration is unsupported.",
- "Window matching uses exact PID and window ID for screenshots and unique accessibility geometry. Accessibility paths can change as the UI changes; stale or ambiguous paths fail. Screenshots are scaled to at most 2048 pixels; scenario output is budgeted at 64 MiB and execution is cancelled after 180 seconds.",
+ "Window matching uses exact PID and window ID for screenshots and unique accessibility geometry. Accessibility paths can change as the UI changes; stale or ambiguous paths fail. Screenshots are scaled to at most 2048 pixels; scenario output is budgeted at 64 MiB and execution has a 180-second deadline.",
],
});
return terminalFailure === undefined
- ? finishNativeUiObservation(ok(report), operation, signal)
+ ? finishNativeUiObservation(ok(report), operation, interruption)
: err(terminalFailure.retainPartialObservation(report));
};
@@ -300,13 +282,9 @@ const observeWithHelper = async (
export const finishNativeUiObservation = (
result: Result<z.infer<typeof nativeUiResultSchema>, AnalysisError>,
operation: string,
- signal?: AbortSignal,
-): Result<z.infer<typeof nativeUiResultSchema>, AnalysisError> =>
- result.ok && signal?.aborted
- ? err(
- new AnalysisCancelledError(operation, {
- cause: signal.reason,
- partialObservation: result.value,
- }),
- )
- : result;
+ interruption: NativeUiInterruptionControl,
+): Result<z.infer<typeof nativeUiResultSchema>, AnalysisError> => {
+ if (!result.ok) return result;
+ const error = interruption.error(operation, result.value);
+ return error === undefined ? result : err(error);
+};
diff --git a/tests/boundary/providers/native/nativeUiFinalization.test.ts b/tests/boundary/providers/native/nativeUiFinalization.test.ts
index 2117eb192..bdf2d0df0 100644
--- a/tests/boundary/providers/native/nativeUiFinalization.test.ts
+++ b/tests/boundary/providers/native/nativeUiFinalization.test.ts
@@ -266,11 +266,11 @@ it.each([false, true])(
});
const result = await client.execute("observe_native_ui", input);
expect(result.ok).toBe(false);
- if (result.ok) throw new Error("Expected owned deadline cancellation");
+ if (result.ok) throw new Error("Expected owned deadline timeout");
const primary = resolvedAnalysisError(
result.error.cleanupPrimary ?? result.error,
);
- expect(primary._tag).toBe("AnalysisCancelledError");
+ expect(primary._tag).toBe("AnalysisTimeoutError");
expect(primary.cause).toBe(reason);
expect(result.error.partialObservation).toMatchObject({
initial: snapshot,