fix(native): retain failed pwntools process and runtime cleanup (#1708)

* fix(native): retain failed pwntools process and runtime cleanup

Keep failed worker/debugger cleanup owners and their private files until
verified process shutdown and successful directory removal. Retry cleanup
before another inspection and expose shutdown through the shared services,
CLI and MCP server. Serialize acquisition without delaying cancellation of
queued callers, and preserve primary diagnostics when CLI cleanup fails.

The original decoder reproduction left a live owned Node child with its
runtime deleted and no retained cleanup owner; the regression now verifies
retention, admission blocking, retries and eventual process/file cleanup.

Validation: 10 lifecycle/public CLI/MCP tests, 20 service tests, test
discovery 814/814, build:cached and full check including architecture guards.
Actual POSIX process/filesystem boundaries used injected Node workers on
macOS; real Linux pwntools/GDB provider parsing was not exercised.

* test(native): verify retained recorded-crash cleanup lifecycle

* fix(native): finalize diagnostic cleanup before publishing results

* fix(native): retire decoder stages before reading runtime evidence

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Yijie Luandmorluto authored and GitHub committed 2026-10-13 01:37:47 +08:00
1 parent ad08510a11
commit 11fe5a13f8
26 files changed
+1716 -135

No files matched your search

@@ -21,10 +21,36 @@ const OPERATION = "inspect_binary_layout";
export class BinaryLayoutService {
constructor(readonly provider: BinaryLayoutPort) {}
close(): Promise<void> {
return this.provider.close?.() ?? Promise.resolve();
}
/** Bind complete observations to the caller-selected artifact before creating Evidence. */
async inspect(
rawInput: unknown,
options?: ExecutionOptions,
): Promise<Result<Evidence, AnalysisError>> {
return this.#inspect(rawInput, options, (input) =>
this.provider.inspect(input, options),
);
}
/** Complete the owned one-shot lifecycle before validating and publishing Evidence. */
inspectAndClose(
rawInput: unknown,
options?: ExecutionOptions,
): Promise<Result<Evidence, AnalysisError>> {
return this.#inspect(rawInput, options, (input) =>
this.provider.inspectAndClose(input, options),
);
}
async #inspect(
rawInput: unknown,
options: ExecutionOptions | undefined,
inspect: (
input: Parameters<BinaryLayoutPort["inspect"]>[0],
) => ReturnType<BinaryLayoutPort["inspect"]>,
): Promise<Result<Evidence, AnalysisError>> {
if (options?.signal?.aborted)
return err(new AnalysisCancelledError(OPERATION));
@@ -45,7 +71,7 @@ export class BinaryLayoutService {
},
]),
);
const inspected = await this.provider.inspect(input.data, options);
const inspected = await inspect(input.data);
if (!inspected.ok) return inspected;
const diagnostics = binaryLayoutSchema.shape.diagnostics.safeParse(
inspected.value.diagnostics,