fix(native): bound retained observations and preserve failure evidence
This commit is contained in:
@@ -49,6 +49,7 @@ export interface AnalysisCleanupObservation {
|
||||
export interface AnalysisErrorOptions extends ErrorOptions {
|
||||
readonly capturedOutput?: AnalysisCapturedOutput;
|
||||
readonly cleanup?: AnalysisCleanupObservation;
|
||||
readonly partialObservation?: AnalysisPartialObservation;
|
||||
}
|
||||
|
||||
/** Base class for expected analysis, provider, and session failures. */
|
||||
@@ -66,16 +67,22 @@ export abstract class AnalysisError extends Error {
|
||||
this.cleanup = options?.cleanup;
|
||||
this.cleanupIncomplete = options?.cleanup !== undefined;
|
||||
this.cleanupResources = options?.cleanup?.resources ?? [];
|
||||
this.partialObservation = options?.partialObservation;
|
||||
}
|
||||
abstract readonly _tag: AnalysisErrorTag;
|
||||
readonly userMessage: string | undefined = undefined;
|
||||
readonly userCategory: "cancelled" | undefined = undefined;
|
||||
readonly executionFailure: string | undefined = undefined;
|
||||
readonly partialObservation: PartialProcessCaptureObservation | undefined =
|
||||
undefined;
|
||||
readonly partialObservation: AnalysisPartialObservation | undefined;
|
||||
readonly cleanupReport: ProcessCaptureCleanupReport | undefined = undefined;
|
||||
}
|
||||
import type {
|
||||
PartialProcessCaptureObservation,
|
||||
ProcessCaptureCleanupReport,
|
||||
} from "./process/processCapture.js";
|
||||
import type { NativeCallPartialObservation } from "./native/nativeCallPartialObservation.js";
|
||||
|
||||
/** Provider-neutral evidence collected before a typed analysis failure. */
|
||||
export type AnalysisPartialObservation =
|
||||
| PartialProcessCaptureObservation
|
||||
| NativeCallPartialObservation;
|
||||
|
||||
@@ -23,6 +23,34 @@ import { UnknownRegistryError } from "./unknownRegistryError.js";
|
||||
import { projectAnalysisError } from "./analysisErrorProjection.js";
|
||||
import { ProviderSelectionError } from "./providerSelectionError.js";
|
||||
import { analysisErrorProjectionSchema } from "../contracts/errorSchemas.js";
|
||||
import { nativeCallPartialObservationSchema } from "./native/nativeCallPartialObservation.js";
|
||||
|
||||
const nativeCallPartialObservation = nativeCallPartialObservationSchema.parse({
|
||||
kind: "native-call-observation",
|
||||
target: {
|
||||
path: "/tmp/selected-app",
|
||||
sha256: "a".repeat(64),
|
||||
architecture: "arm64",
|
||||
arguments: [],
|
||||
environment: {},
|
||||
working_directory: null,
|
||||
},
|
||||
process: {
|
||||
pid: 4242,
|
||||
stdout: {
|
||||
text: "partial stdout",
|
||||
bytes: 13,
|
||||
truncated: false,
|
||||
complete: false,
|
||||
},
|
||||
stderr: null,
|
||||
other_stops: [],
|
||||
},
|
||||
debugger: { version: null },
|
||||
events: [],
|
||||
coverage: { status: "partial", reason: "cancelled" },
|
||||
limitations: ["Observation ended before the requested window completed."],
|
||||
});
|
||||
|
||||
const retainedOutput = {
|
||||
stdout: "selected output\u0000",
|
||||
@@ -179,6 +207,50 @@ it("retains the original failure tag and code when cleanup is incomplete", () =>
|
||||
});
|
||||
});
|
||||
|
||||
it("projects native partial observations through healthy cancellation failures", () => {
|
||||
const projected = projectAnalysisError(
|
||||
new AnalysisCancelledError("observe_native_calls", {
|
||||
partialObservation: nativeCallPartialObservation,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(projected).toMatchObject({
|
||||
code: "cancelled",
|
||||
details: {
|
||||
operation: "observe_native_calls",
|
||||
cleanup: "complete",
|
||||
partial_observation: nativeCallPartialObservation,
|
||||
},
|
||||
});
|
||||
expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe(true);
|
||||
});
|
||||
|
||||
it("retains native partial observations and cleanup uncertainty on provider failures", () => {
|
||||
const projected = projectAnalysisError(
|
||||
new ProviderAdapterError("native-lldb", "observe_native_calls", {
|
||||
partialObservation: nativeCallPartialObservation,
|
||||
cleanup: {
|
||||
reason: "target process termination could not be verified",
|
||||
resources: ["native-target:4242"],
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
expect(projected).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
details: {
|
||||
provider_id: "native-lldb",
|
||||
operation: "observe_native_calls",
|
||||
cleanup: "incomplete",
|
||||
cleanup_reason: "target process termination could not be verified",
|
||||
resources: ["native-target:4242"],
|
||||
execution_failure: "execution_failure",
|
||||
partial_observation: nativeCallPartialObservation,
|
||||
},
|
||||
});
|
||||
expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe(true);
|
||||
});
|
||||
|
||||
describe("analysis error projection: provider failures", () => {
|
||||
it("projects the primary browser failure alongside incomplete cleanup", () => {
|
||||
const projected = projectAnalysisError(
|
||||
|
||||
@@ -61,6 +61,11 @@ export const projectAnalysisError = (
|
||||
...(error.capturedOutput === undefined
|
||||
? {}
|
||||
: { captured_output: { ...error.capturedOutput } }),
|
||||
...(error.partialObservation === undefined
|
||||
? {}
|
||||
: {
|
||||
partial_observation: jsonValueSchema.parse(error.partialObservation),
|
||||
}),
|
||||
};
|
||||
return {
|
||||
code,
|
||||
@@ -445,13 +450,6 @@ const lifecycleErrorDetails = (
|
||||
...(error.executionFailure === undefined
|
||||
? {}
|
||||
: { execution_failure: error.executionFailure }),
|
||||
...(error.partialObservation === undefined
|
||||
? {}
|
||||
: {
|
||||
partial_observation: jsonValueSchema.parse(
|
||||
error.partialObservation,
|
||||
),
|
||||
}),
|
||||
};
|
||||
if (error._tag === "ProcessCaptureError") {
|
||||
const details = {
|
||||
@@ -464,13 +462,6 @@ const lifecycleErrorDetails = (
|
||||
...(error.executionFailure === undefined
|
||||
? {}
|
||||
: { execution_failure: error.executionFailure }),
|
||||
...(error.partialObservation === undefined
|
||||
? {}
|
||||
: {
|
||||
partial_observation: jsonValueSchema.parse(
|
||||
error.partialObservation,
|
||||
),
|
||||
}),
|
||||
};
|
||||
return Object.keys(details).length === 0 ? undefined : details;
|
||||
}
|
||||
|
||||
@@ -205,6 +205,8 @@ export const nativeCallObservationResultSchema = z.strictObject({
|
||||
status: z.enum(["complete", "partial"]),
|
||||
event_limit_reached: z.boolean(),
|
||||
resource_limit_reached: z.boolean(),
|
||||
/** Aggregate breakpoint-location metadata exhausted its retained-byte budget. */
|
||||
breakpoint_locations_truncated: z.boolean().optional(),
|
||||
/** Requests that matched no code in any image loaded while observing. */
|
||||
unresolved_breakpoints: z.array(z.number().int().nonnegative()),
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { z } from "zod";
|
||||
import { nativeCallEventSchema } from "./nativeCallObservation.js";
|
||||
|
||||
const capturedOutputSchema = z.strictObject({
|
||||
text: z.string(),
|
||||
/** Bytes observed so far; the final stream size may be unknown. */
|
||||
bytes: z.number().int().nonnegative(),
|
||||
truncated: z.boolean(),
|
||||
complete: z.boolean(),
|
||||
});
|
||||
|
||||
/** Native call evidence retained when observation fails before a full result. */
|
||||
export const nativeCallPartialObservationSchema = z.strictObject({
|
||||
kind: z.literal("native-call-observation"),
|
||||
target: z.strictObject({
|
||||
path: z.string(),
|
||||
sha256: z.string().regex(/^[0-9a-f]{64}$/u),
|
||||
architecture: z.string(),
|
||||
arguments: z.array(z.string()),
|
||||
environment: z.record(z.string(), z.string()),
|
||||
working_directory: z.string().nullable(),
|
||||
}),
|
||||
process: z.strictObject({
|
||||
pid: z.number().int().positive().nullable(),
|
||||
stdout: capturedOutputSchema.nullable(),
|
||||
stderr: capturedOutputSchema.nullable(),
|
||||
other_stops: z.array(z.string()),
|
||||
}),
|
||||
debugger: z.strictObject({ version: z.string().nullable() }),
|
||||
events: z.array(nativeCallEventSchema),
|
||||
coverage: z.strictObject({
|
||||
status: z.literal("partial"),
|
||||
reason: z.enum([
|
||||
"cancelled",
|
||||
"timeout",
|
||||
"tracer-failure",
|
||||
"capture-failure",
|
||||
"cleanup-failure",
|
||||
]),
|
||||
}),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
export type NativeCallPartialObservation = z.infer<
|
||||
typeof nativeCallPartialObservationSchema
|
||||
>;
|
||||
Reference in New Issue
Block a user