fix(native): preserve bridge failure types during cleanup

This commit is contained in:
morluto
2026-10-09 01:55:12 +08:00
parent 7c323870c2
commit 1d0baa352f
4 changed files with 165 additions and 21 deletions
+4 -3
View File
@@ -127,7 +127,8 @@ export const nativeCallEventSchema = z.strictObject({
backtrace: z.array(nativeCodeLocationSchema),
});
const capturedOutputSchema = z.strictObject({
/** Retained native output with explicit stream completeness and byte counts. */
export const nativeCapturedOutputSchema = z.strictObject({
text: z.string(),
/** Bytes observed by the bridge, not a total when complete is false. */
bytes: z.number().int().nonnegative(),
@@ -177,8 +178,8 @@ export const nativeCallObservationResultSchema = z.strictObject({
/** REA confirmed the process is gone when observation ended. */
terminated: z.boolean(),
elapsed_ms: z.number().nonnegative(),
stdout: capturedOutputSchema,
stderr: capturedOutputSchema,
stdout: nativeCapturedOutputSchema,
stderr: nativeCapturedOutputSchema,
/** Signal and exception stops LLDB reported; the process continued past each. */
other_stops: z.array(z.string()),
}),
@@ -1,13 +1,8 @@
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(),
});
import {
nativeCallEventSchema,
nativeCapturedOutputSchema,
} from "./nativeCallObservation.js";
/** Native call evidence retained when observation fails before a full result. */
export const nativeCallPartialObservationSchema = z.strictObject({
@@ -22,8 +17,8 @@ export const nativeCallPartialObservationSchema = z.strictObject({
}),
process: z.strictObject({
pid: z.number().int().positive().nullable(),
stdout: capturedOutputSchema.nullable(),
stderr: capturedOutputSchema.nullable(),
stdout: nativeCapturedOutputSchema.nullable(),
stderr: nativeCapturedOutputSchema.nullable(),
other_stops: z.array(z.string()),
}),
debugger: z.strictObject({ version: z.string().nullable() }),
+12 -7
View File
@@ -163,11 +163,16 @@ const ATTACH_REMEDIATION =
/** Production tracer: `lldb --batch` running the REA LLDB bridge. */
export class LldbCallTracer implements NativeCallTracer {
constructor(
private readonly launch: typeof runLldb = runLldb,
private readonly resolveTool: typeof resolveXcrunTool = resolveXcrunTool,
) {}
async trace(
request: Parameters<NativeCallTracer["trace"]>[0],
signal?: AbortSignal,
): Promise<Result<NativeCallTrace, AnalysisError>> {
const lldb = await resolveXcrunTool("lldb", signal);
const lldb = await this.resolveTool("lldb", signal);
if (!lldb.ok)
return err(
lldb.error.reason === "cancelled"
@@ -235,7 +240,7 @@ export class LldbCallTracer implements NativeCallTracer {
{ mode: 0o600 },
);
await prepareProcessOwnershipInspection(signal);
const exited = await runLldb(
const exited = await this.launch(
lldb.path,
[
"--batch",
@@ -333,6 +338,10 @@ export class LldbCallTracer implements NativeCallTracer {
},
),
);
if (output !== undefined && output.status !== "traced")
return err(
tracerFailure(output, lifecycleCleanup, await getPartialObservation()),
);
if (exited.cleanupFailure !== undefined)
return err(
new ProviderAdapterError(PROVIDER, OPERATION, {
@@ -367,11 +376,6 @@ export class LldbCallTracer implements NativeCallTracer {
: { cleanup: lifecycleCleanup }),
}),
);
if (output.status !== "traced") {
return err(
tracerFailure(output, lifecycleCleanup, await getPartialObservation()),
);
}
const stdout = await capturedOutput(
paths.stdoutCapture,
output.target_output.stdout_bytes,
@@ -417,6 +421,7 @@ export class LldbCallTracer implements NativeCallTracer {
const quote = (value: string): string =>
`"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
/** Preserve a decoded bridge failure's type independently of cleanup outcome. */
const tracerFailure = (
output: {
readonly status: