Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(evm): retain completed evidence through cleanup cancellation
morlutod694aef227e9
diff --git a/src/application/evm/EvmInterfaceEvidence.ts b/src/application/evm/EvmInterfaceEvidence.tsnew file mode 100644index 000000000..38fe9ea70--- /dev/null+++ b/src/application/evm/EvmInterfaceEvidence.ts@@ -0,0 +1,18 @@+import { createEvidence } from "../../domain/evidence.js";+import type { InspectEvmInterfaceInput } from "../../domain/evm/evmInterface.js";+import type { EvmInterfaceExecution } from "./EvmInterfacePort.js";++/** Preserve the same validated inference and provenance on success and failed finalization. */+export const evmInterfaceEvidence = (+ input: InspectEvmInterfaceInput,+ execution: EvmInterfaceExecution,+) =>+ createEvidence(execution.subject, execution.provider, {+ operation: "inspect_evm_interface",+ parameters: input,+ result: execution.result,+ ...(execution.rawResult === null ? {} : { rawResult: execution.rawResult }),+ confidence: "inferred",+ locations: execution.locations,+ limitations: execution.limitations,+ });diff --git a/src/application/evm/EvmInterfaceService.test.ts b/src/application/evm/EvmInterfaceService.test.tsindex 1f8925802..45133089b 100644--- a/src/application/evm/EvmInterfaceService.test.ts+++ b/src/application/evm/EvmInterfaceService.test.ts@@ -139,3 +139,22 @@ it("keeps malformed interface output ahead of a late cancellation", async () =>expect(result.ok).toBe(false);if (!result.ok) expect(result.error).toBeInstanceOf(AnalysisOutputError);});++it.each([null, "caller stopped", { requested: "stop" }])(+ "preserves the exact admission reason without invoking the provider: %j",+ async (reason) => {+ const controller = new AbortController();+ controller.abort(reason);+ const service = new EvmInterfaceService({+ inspect: () => {+ throw new Error("must not start");+ },+ });+ const result = await service.inspect(+ { path: "/selected.hex", encoding: "hex" },+ { signal: controller.signal },+ );+ if (result.ok) throw new Error("Expected cancellation");+ expect(result.error.cause).toBe(reason);+ },+);diff --git a/src/application/evm/EvmInterfaceService.ts b/src/application/evm/EvmInterfaceService.tsindex 01e001a9b..7e358ad6f 100644--- a/src/application/evm/EvmInterfaceService.ts+++ b/src/application/evm/EvmInterfaceService.ts@@ -8,7 +8,8 @@ import {AnalysisInputError,AnalysisOutputError,} from "../../domain/analysisErrorCore.js";-import { createEvidence, type Evidence } from "../../domain/evidence.js";+import type { Evidence } from "../../domain/evidence.js";+import { evmInterfaceEvidence } from "./EvmInterfaceEvidence.js";import {inspectEvmInterfaceInputSchema,evmInterfaceSchema,@@ -36,7 +37,9 @@ export class EvmInterfaceService {options?: ExecutionOptions,): Promise<Result<Evidence, AnalysisError>> {if (options?.signal?.aborted)- return err(new AnalysisCancelledError(OPERATION));+ return err(+ new AnalysisCancelledError(OPERATION, { cause: options.signal.reason }),+ );const input = inspectEvmInterfaceInputSchema.safeParse(rawInput);if (!input.success)return err(@@ -78,17 +81,7 @@ export class EvmInterfaceService {),);return completeProviderEvidence(- createEvidence(execution.subject, execution.provider, {- operation: OPERATION,- parameters: input.data,- result: report.data,- ...(execution.rawResult === null- ? {}- : { rawResult: execution.rawResult }),- confidence: "inferred",- locations: execution.locations,- limitations: execution.limitations,- }),+ evmInterfaceEvidence(input.data, execution),options?.signal,outputOptions?.capturedOutput,);diff --git a/src/evm/EvmoleInterfaceProvider.ts b/src/evm/EvmoleInterfaceProvider.tsindex a1eb2a7c6..aee44ed89 100644--- a/src/evm/EvmoleInterfaceProvider.ts+++ b/src/evm/EvmoleInterfaceProvider.ts@@ -31,7 +31,7 @@ import {AnalysisOutputError,} from "../domain/analysisErrorCore.js";import { projectAnalysisError } from "../domain/analysisErrorProjection.js";-import { createEvidence } from "../domain/evidence.js";+import { evmInterfaceEvidence } from "../application/evm/EvmInterfaceEvidence.js";import type { InspectEvmInterfaceInput } from "../domain/evm/evmInterface.js";import { evmInterfaceSchema } from "../domain/evm/evmInterface.js";import { solidityMetadataSchema } from "../domain/evm/solidityMetadata.js";@@ -95,20 +95,6 @@ const compactErrorProjection = (error: AnalysisError) => {return { ...projection, details };};-const evmExecutionEvidence = (- input: InspectEvmInterfaceInput,- execution: EvmInterfaceExecution,-) =>- createEvidence(execution.subject ?? undefined, execution.provider, {- operation: OPERATION,- parameters: input,- result: execution.result,- ...(execution.rawResult === null ? {} : { rawResult: execution.rawResult }),- confidence: "inferred",- locations: execution.locations,- limitations: execution.limitations,- });-const evmCleanupFailure = (input: InspectEvmInterfaceInput,result: EvmOutcome,@@ -118,7 +104,7 @@ const evmCleanupFailure = (cause?: unknown,): ProviderCleanupError => {const partialObservation = result.ok- ? evmExecutionEvidence(input, result.value)+ ? evmInterfaceEvidence(input, result.value): result.error.partialObservation;const capturedOutput = result.ok? output@@ -204,7 +190,10 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {this.environment.REA_EVM_PRLIMIT_COMMAND ?? "/usr/bin/prlimit";let result: Result<EvmInterfaceExecution, AnalysisError>;try {- if (options?.signal?.aborted) throw new AnalysisCancelledError(OPERATION);+ if (options?.signal?.aborted)+ throw new AnalysisCancelledError(OPERATION, {+ cause: options.signal.reason,+ });if (process.platform !== "linux" || process.arch !== "x64")throw new AnalysisCapabilityUnavailableError(EVMOLE_PROVIDER_IDENTITY.id,@@ -574,12 +563,13 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {}return result.ok && options?.signal?.aborted? err(- new AnalysisCancelledError(- OPERATION,- retainedOutput === undefined- ? undefined- : { capturedOutput: retainedOutput },- ),+ new AnalysisCancelledError(OPERATION, {+ cause: options.signal.reason,+ partialObservation: evmInterfaceEvidence(input, result.value),+ ...(retainedOutput === undefined+ ? {}+ : { capturedOutput: retainedOutput }),+ }),): result;}diff --git a/tests/boundary/evm/evmoleInterfaceProvider.test.ts b/tests/boundary/evm/evmoleInterfaceProvider.test.tsindex 51b5cb54a..5abd9fe3f 100644--- a/tests/boundary/evm/evmoleInterfaceProvider.test.ts+++ b/tests/boundary/evm/evmoleInterfaceProvider.test.ts@@ -10,6 +10,8 @@ import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.import { cleanupOwnedProcessGroup } from "../../../src/process/ProcessOwnership.js";import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";+import { parseEvidence } from "../../../src/domain/evidence.js";+import { EvmInterfaceService } from "../../../src/application/evm/EvmInterfaceService.js";import {createTestWorkspace,removeTestWorkspace,@@ -636,11 +638,22 @@ it.runIf(!unsupportedHost)(},);-it.runIf(!unsupportedHost).each(["late-cancellation", "cleanup-failure"])(+it+ .runIf(!unsupportedHost)+ .each([+ "success",+ "late-cancellation",+ "cleanup-failure",+ "cancelled-cleanup-failure",+ ])("retains captured warnings after a successful worker: %s",async (scenario) => {const { path } = await fixture();const controller = new AbortController();+ const reason = { requested: "stop during root removal" };+ let denyClose =+ scenario === "cleanup-failure" ||+ scenario === "cancelled-cleanup-failure";let ownedRoot = "";const provider = new EvmoleInterfaceProvider({},@@ -679,16 +692,29 @@ it.runIf(!unsupportedHost).each(["late-cancellation", "cleanup-failure"])(path: root.path,close: async () => {await root.close();- if (scenario === "late-cancellation") controller.abort();- else throw new Error("reported cleanup failure");+ if (+ scenario === "late-cancellation" ||+ scenario === "cancelled-cleanup-failure"+ )+ controller.abort(reason);+ if (denyClose) throw new Error("reported cleanup failure");},};},);+ onTestFinished(async () => {+ denyClose = false;+ await provider.close();+ });const result = await provider.inspect({ path, encoding: "hex" },{ signal: controller.signal },);+ if (scenario === "success") {+ expect(result.ok).toBe(true);+ await expect(access(ownedRoot)).rejects.toMatchObject({ code: "ENOENT" });+ return;+ }if (result.ok) throw new Error("Expected lifecycle failure");const output = { stdout: "", stderr: "upstream warning", truncated: false };expect(projectAnalysisError(result.error)).toMatchObject({@@ -699,6 +725,27 @@ it.runIf(!unsupportedHost).each(["late-cancellation", "cleanup-failure"])(? { captured_output: output }: { diagnostics: { captured_output: output } },});+ const evidence = parseEvidence(result.error.partialObservation);+ expect(evidence).toMatchObject({+ operation: "inspect_evm_interface",+ parameters: { path, encoding: "hex" },+ subject: { path, sha256: expect.any(String) },+ provider: { id: "evmole-interface" },+ raw_result: { functions: [] },+ normalized_result: {+ artifact: { path, encoding: "hex" },+ bytecode: { hex: "60006000f3", bytes: 5 },+ diagnostics: output,+ },+ });+ expect(evidence.limitations.length).toBeGreaterThan(0);+ if (scenario === "late-cancellation")+ expect(result.error.cause).toBe(reason);+ else expect(result.error.cleanupIncomplete).toBe(true);+ const forwarded = await new EvmInterfaceService({+ inspect: async () => result,+ }).inspect({ path, encoding: "hex" });+ expect(forwarded).toBe(result);await expect(access(ownedRoot)).rejects.toMatchObject({ code: "ENOENT" });},);