fix(native): supervise LLDB and preserve bounded capture uncertainty
This commit is contained in:
@@ -39,26 +39,37 @@ export interface AnalysisCapturedOutput {
|
||||
readonly truncated: boolean;
|
||||
}
|
||||
|
||||
/** Cleanup uncertainty attached to the original typed analysis failure. */
|
||||
export interface AnalysisCleanupObservation {
|
||||
readonly reason: string;
|
||||
readonly resources: readonly string[];
|
||||
}
|
||||
|
||||
/** Optional provider-neutral context that must survive typed error projection. */
|
||||
export interface AnalysisErrorOptions extends ErrorOptions {
|
||||
readonly capturedOutput?: AnalysisCapturedOutput;
|
||||
readonly cleanup?: AnalysisCleanupObservation;
|
||||
}
|
||||
|
||||
/** Base class for expected analysis, provider, and session failures. */
|
||||
export abstract class AnalysisError extends Error {
|
||||
readonly capturedOutput: AnalysisCapturedOutput | undefined;
|
||||
readonly cleanup: AnalysisCleanupObservation | undefined;
|
||||
readonly cleanupIncomplete: boolean;
|
||||
readonly cleanupResources: readonly string[];
|
||||
constructor(message: string, options?: AnalysisErrorOptions) {
|
||||
super(message, options);
|
||||
this.capturedOutput =
|
||||
options?.capturedOutput === undefined
|
||||
? undefined
|
||||
: { ...options.capturedOutput };
|
||||
this.cleanup = options?.cleanup;
|
||||
this.cleanupIncomplete = options?.cleanup !== undefined;
|
||||
this.cleanupResources = options?.cleanup?.resources ?? [];
|
||||
}
|
||||
abstract readonly _tag: AnalysisErrorTag;
|
||||
readonly userMessage: string | undefined = undefined;
|
||||
readonly userCategory: "cancelled" | undefined = undefined;
|
||||
readonly cleanupIncomplete: boolean = false;
|
||||
readonly cleanupResources: readonly string[] = [];
|
||||
readonly executionFailure: string | undefined = undefined;
|
||||
readonly partialObservation: PartialProcessCaptureObservation | undefined =
|
||||
undefined;
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { ArtifactOperationError } from "./artifactOperationError.js";
|
||||
import { BinaryTargetError } from "./configurationErrors.js";
|
||||
import { BrowserObservationError } from "./browserObservationError.js";
|
||||
import { EvidenceIntegrityError } from "./evidenceErrors.js";
|
||||
import {
|
||||
HopperProcessError,
|
||||
HopperRemoteError,
|
||||
@@ -131,6 +132,53 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
new AnalysisCancelledError("observe_native_calls", {
|
||||
cleanup: {
|
||||
reason: "target process termination could not be verified",
|
||||
resources: ["native-target:4242"],
|
||||
},
|
||||
}),
|
||||
new AnalysisTimeoutError("observe_native_calls", 65_000, {
|
||||
cleanup: {
|
||||
reason: "target process identity was unavailable",
|
||||
resources: ["native-target:4242"],
|
||||
},
|
||||
}),
|
||||
])("retains incomplete cleanup for lifecycle failures: $._tag", (failure) => {
|
||||
expect(projectAnalysisError(failure)).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
details: {
|
||||
cleanup: "incomplete",
|
||||
cleanup_reason: expect.any(String),
|
||||
resources: ["native-target:4242"],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("retains the original failure tag and code when cleanup is incomplete", () => {
|
||||
const error = new EvidenceIntegrityError(
|
||||
"The launched native target did not match its selected digest",
|
||||
{
|
||||
cleanup: {
|
||||
reason: "target survivor identity could not be verified",
|
||||
resources: ["native-target:4242"],
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(error._tag).toBe("EvidenceIntegrityError");
|
||||
expect(projectAnalysisError(error)).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
category: "integrity_mismatch",
|
||||
details: {
|
||||
cleanup: "incomplete",
|
||||
cleanup_reason: "target survivor identity could not be verified",
|
||||
resources: ["native-target:4242"],
|
||||
execution_failure: "evidence_integrity_mismatch",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe("analysis error projection: provider failures", () => {
|
||||
it("projects the primary browser failure alongside incomplete cleanup", () => {
|
||||
const projected = projectAnalysisError(
|
||||
|
||||
@@ -42,12 +42,26 @@ export const projectAnalysisError = (
|
||||
error: AnalysisError,
|
||||
): AnalysisErrorProjection => {
|
||||
assertKnownAnalysisErrorTag(error._tag);
|
||||
const code = errorCode(error);
|
||||
const underlyingCode = underlyingErrorCode(error);
|
||||
const code = error.cleanupIncomplete ? "cleanup_incomplete" : underlyingCode;
|
||||
const primaryDetails = errorDetails(error);
|
||||
const details =
|
||||
error.capturedOutput === undefined
|
||||
? primaryDetails
|
||||
: { ...primaryDetails, captured_output: { ...error.capturedOutput } };
|
||||
const details = {
|
||||
...primaryDetails,
|
||||
...(error.cleanupIncomplete
|
||||
? {
|
||||
cleanup: "incomplete",
|
||||
resources: [...error.cleanupResources],
|
||||
...(error.cleanup === undefined
|
||||
? {}
|
||||
: { cleanup_reason: error.cleanup.reason }),
|
||||
execution_failure:
|
||||
primaryDetails?.execution_failure ?? underlyingCode,
|
||||
}
|
||||
: {}),
|
||||
...(error.capturedOutput === undefined
|
||||
? {}
|
||||
: { captured_output: { ...error.capturedOutput } }),
|
||||
};
|
||||
return {
|
||||
code,
|
||||
category: analysisErrorCategory(error),
|
||||
@@ -56,12 +70,13 @@ export const projectAnalysisError = (
|
||||
remediation: {
|
||||
action: analysisErrorRemediationAction(error),
|
||||
},
|
||||
...(details === undefined ? {} : { details }),
|
||||
...(Object.keys(details).length === 0 ? {} : { details }),
|
||||
};
|
||||
};
|
||||
|
||||
const errorCode = (error: AnalysisError): AnalysisErrorProjection["code"] => {
|
||||
if (error.cleanupIncomplete) return "cleanup_incomplete";
|
||||
const underlyingErrorCode = (
|
||||
error: AnalysisError,
|
||||
): AnalysisErrorProjection["code"] => {
|
||||
if (error instanceof ProviderSelectionError)
|
||||
return error.reason === "provider_unavailable"
|
||||
? "provider_unavailable"
|
||||
@@ -380,11 +395,31 @@ const lifecycleErrorDetails = (
|
||||
error: AnalysisError,
|
||||
): Readonly<Record<string, JsonValue>> | undefined => {
|
||||
if (error instanceof AnalysisCancelledError)
|
||||
return { operation: error.operation, cleanup: "complete" };
|
||||
return {
|
||||
operation: error.operation,
|
||||
cleanup: error.cleanup === undefined ? "complete" : "incomplete",
|
||||
...(error.cleanup === undefined
|
||||
? {}
|
||||
: {
|
||||
cleanup_reason: error.cleanup.reason,
|
||||
resources: [...error.cleanup.resources],
|
||||
execution_failure: "cancelled",
|
||||
}),
|
||||
};
|
||||
if (error instanceof HopperCancelledError)
|
||||
return { operation: "hopper", cleanup: "complete" };
|
||||
if (error instanceof AnalysisTimeoutError)
|
||||
return { operation: error.operation, timeout_ms: error.timeoutMs };
|
||||
return {
|
||||
operation: error.operation,
|
||||
timeout_ms: error.timeoutMs,
|
||||
...(error.cleanup === undefined
|
||||
? {}
|
||||
: {
|
||||
cleanup: "incomplete",
|
||||
cleanup_reason: error.cleanup.reason,
|
||||
resources: [...error.cleanup.resources],
|
||||
}),
|
||||
};
|
||||
if (error instanceof HopperTimeoutError)
|
||||
return {
|
||||
stage: error.operation === undefined ? "startup" : error.stage,
|
||||
|
||||
@@ -129,8 +129,10 @@ export const nativeCallEventSchema = z.strictObject({
|
||||
|
||||
const capturedOutputSchema = z.strictObject({
|
||||
text: z.string(),
|
||||
/** Bytes observed by the bridge, not a total when complete is false. */
|
||||
bytes: z.number().int().nonnegative(),
|
||||
truncated: z.boolean(),
|
||||
complete: z.boolean(),
|
||||
});
|
||||
|
||||
/** Observed calls, the process lifecycle, and breakpoint resolution. */
|
||||
@@ -140,7 +142,21 @@ export const nativeCallObservationResultSchema = z.strictObject({
|
||||
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(),
|
||||
launch_identity: z.strictObject({
|
||||
/** A pathname hash does not verify the bytes mapped into the process. */
|
||||
loaded_image_sha256: z.null(),
|
||||
file_device: z.string().nullable(),
|
||||
file_inode: z.string().nullable(),
|
||||
selected_file_sha256: z
|
||||
.string()
|
||||
.regex(/^[0-9a-f]{64}$/u)
|
||||
.nullable(),
|
||||
module_path: z.string().nullable(),
|
||||
module_uuid: z.string().nullable(),
|
||||
stable: z.boolean(),
|
||||
}),
|
||||
}),
|
||||
debugger: z.strictObject({
|
||||
path: z.string(),
|
||||
@@ -154,6 +170,7 @@ export const nativeCallObservationResultSchema = z.strictObject({
|
||||
"duration-elapsed",
|
||||
"event-limit",
|
||||
"stop-limit",
|
||||
"resource-limit",
|
||||
]),
|
||||
exit_status: z.number().int().nullable(),
|
||||
exit_description: z.string().nullable(),
|
||||
@@ -187,6 +204,7 @@ export const nativeCallObservationResultSchema = z.strictObject({
|
||||
coverage: z.strictObject({
|
||||
status: z.enum(["complete", "partial"]),
|
||||
event_limit_reached: z.boolean(),
|
||||
resource_limit_reached: z.boolean(),
|
||||
/** Requests that matched no code in any image loaded while observing. */
|
||||
unresolved_breakpoints: z.array(z.number().int().nonnegative()),
|
||||
}),
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
import { AnalysisError } from "./analysisErrorBase.js";
|
||||
import {
|
||||
AnalysisError,
|
||||
type AnalysisErrorOptions,
|
||||
} from "./analysisErrorBase.js";
|
||||
|
||||
/** A provider adapter failed outside its more precise typed variants. */
|
||||
export interface ProviderAdapterErrorOptions extends ErrorOptions {
|
||||
export interface ProviderAdapterErrorOptions extends AnalysisErrorOptions {
|
||||
readonly diagnostics?: Readonly<Record<string, JsonValue>>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user