From 7623e21ff02cf4eb00ccb4fa357936e4ed01425e Mon Sep 17 00:00:00 2001 From: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Date: Fri, 9 Oct 2026 20:00:11 -0700 Subject: [PATCH] perf(native): record pwntools diagnostics once in their Evidence (#1404) inspect_binary_layout and inspect_recorded_crash passed the decoded report as both result and rawResult, so every Evidence record carried the whole report twice (and an MCP response four times, counting its text copy). The decoded report is the only representation, so raw_result is now null, as for other single-representation operations. The real pwntools verifiers asserted the duplicate; they now assert null. Co-authored-by: Claude Opus 5.5 --- scripts/verify-binary-layout.mjs | 2 +- scripts/verify/recorded-crash/public.mjs | 2 +- .../binaryDiagnostics/BinaryLayoutService.test.ts | 14 ++++++++++++++ .../binaryDiagnostics/BinaryLayoutService.ts | 3 ++- .../binaryDiagnostics/RecordedCrashService.test.ts | 1 + .../binaryDiagnostics/RecordedCrashService.ts | 3 ++- tests/fixtures/analysisView.ts | 2 +- 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/verify-binary-layout.mjs b/scripts/verify-binary-layout.mjs index 996eb3966..1f3b5e4bc 100644 --- a/scripts/verify-binary-layout.mjs +++ b/scripts/verify-binary-layout.mjs @@ -1283,7 +1283,7 @@ async function inspect( evidence.provider.version, "pwntools@4.15.0;pyelftools@0.33;unicorn@2.1.2", ); - assert.deepEqual(evidence.normalized_result, evidence.raw_result); + assert.equal(evidence.raw_result, null); assert.equal(evidence.normalized_result.diagnostics.truncated, false); return evidence.normalized_result; } diff --git a/scripts/verify/recorded-crash/public.mjs b/scripts/verify/recorded-crash/public.mjs index 76713bf9f..ecdfd14cd 100644 --- a/scripts/verify/recorded-crash/public.mjs +++ b/scripts/verify/recorded-crash/public.mjs @@ -80,7 +80,7 @@ export async function connectRecordedCrash({ entrypoint, environment }) { evidence.confidence, debuggerContext ? "derived" : "observed", ); - assert.deepEqual(evidence.raw_result, report); + assert.equal(evidence.raw_result, null); assert.equal(evidence.subject.local_path, path); assert.equal(report.artifact.path, path); assert.equal( diff --git a/src/application/binaryDiagnostics/BinaryLayoutService.test.ts b/src/application/binaryDiagnostics/BinaryLayoutService.test.ts index e8f3e2c6d..e65da65f6 100644 --- a/src/application/binaryDiagnostics/BinaryLayoutService.test.ts +++ b/src/application/binaryDiagnostics/BinaryLayoutService.test.ts @@ -5,6 +5,7 @@ import { BINARY_LAYOUT_TEST_PROVIDER, } from "../../../tests/fixtures/binaryDiagnostics/layout.js"; import { AnalysisCapabilityUnavailableError } from "../../domain/analysisErrorCore.js"; +import { parseEvidence } from "../../domain/evidence.js"; import { err, ok } from "../../domain/result.js"; it.each([ @@ -28,6 +29,19 @@ it.each([ }, ); +it("records the decoded layout once in its Evidence", async () => { + const layout = binaryLayoutFixture(); + const service = new BinaryLayoutService({ + identity: BINARY_LAYOUT_TEST_PROVIDER, + inspect: () => Promise.resolve(ok(layout)), + }); + const result = await service.inspect({ path: layout.artifact.path }); + if (!result.ok) throw result.error; + const evidence = parseEvidence(result.value); + expect(evidence.normalized_result).toEqual(layout); + expect(evidence.raw_result).toBeNull(); +}); + it("preserves a provider's actionable unsupported reason", async () => { const failure = new AnalysisCapabilityUnavailableError( "fixture-layout", diff --git a/src/application/binaryDiagnostics/BinaryLayoutService.ts b/src/application/binaryDiagnostics/BinaryLayoutService.ts index 11bfeb76e..bdb07da56 100644 --- a/src/application/binaryDiagnostics/BinaryLayoutService.ts +++ b/src/application/binaryDiagnostics/BinaryLayoutService.ts @@ -78,7 +78,8 @@ export class BinaryLayoutService { operation: OPERATION, parameters: input.data, result: value, - rawResult: value, + // The decoded report is the only representation; do not repeat it. + rawResult: null, confidence: "observed", limitations: value.limitations, locations: [{ kind: "artifact-path", path: value.artifact.path }], diff --git a/src/application/binaryDiagnostics/RecordedCrashService.test.ts b/src/application/binaryDiagnostics/RecordedCrashService.test.ts index 6060aef33..0ab49ee1b 100644 --- a/src/application/binaryDiagnostics/RecordedCrashService.test.ts +++ b/src/application/binaryDiagnostics/RecordedCrashService.test.ts @@ -24,6 +24,7 @@ it("labels an envelope containing debugger-derived maps as derived", async () => const evidence = parseEvidence(result.value); expect(evidence.confidence).toBe("derived"); expect(evidence.normalized_result).toEqual(fixture); + expect(evidence.raw_result).toBeNull(); }); it.each([ diff --git a/src/application/binaryDiagnostics/RecordedCrashService.ts b/src/application/binaryDiagnostics/RecordedCrashService.ts index cfc9278dc..5a4fff645 100644 --- a/src/application/binaryDiagnostics/RecordedCrashService.ts +++ b/src/application/binaryDiagnostics/RecordedCrashService.ts @@ -83,7 +83,8 @@ export class RecordedCrashService { operation: OPERATION, parameters: input.data, result: value, - rawResult: value, + // The decoded report is the only representation; do not repeat it. + rawResult: null, confidence: value.debugger.status === "available" ? "derived" : "observed", limitations: value.limitations, diff --git a/tests/fixtures/analysisView.ts b/tests/fixtures/analysisView.ts index 0f928a22a..d3be2b1e3 100644 --- a/tests/fixtures/analysisView.ts +++ b/tests/fixtures/analysisView.ts @@ -99,7 +99,7 @@ export const analysisViewLayoutEvidence = ( operation: "inspect_binary_layout", parameters: { path: layout.artifact.path }, result: layout, - rawResult: layout, + rawResult: null, confidence: "observed", limitations: layout.limitations, locations: [{ kind: "artifact-path", path: layout.artifact.path }],