Skip to content

perf(native): record pwntools diagnostics once in their Evidence - #1404

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
perf/binary-diagnostics-raw-result
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
perf/binary-diagnostics-raw-result

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

BinaryLayoutService and RecordedCrashService build Evidence with result: value, rawResult: value. The decoded pwntools report is their only representation, so every inspect_binary_layout and inspect_recorded_crash Evidence record carries the complete report twice (raw_result deep-equals normalized_result). An MCP response repeats Evidence in text and structured content, so it carries the report four times. The duplicate also counts twice against the 10 MiB transport budget, which verify-binary-layout's large-result lane exercises with a 65,281-section ELF.

This is the explicit-argument variant of the default copy that #1402 removes from createAnalysisExecution. The two changes are independent.

Change

  • Both services record rawResult: null. normalized_result, confidence, limitations and locations are unchanged.
  • tests/fixtures/analysisView.ts mirrors production with rawResult: null. inspect_analysis_view does not read raw_result.
  • The real-provider verifiers asserted the duplicate (deepEqual(normalized_result, raw_result) and deepEqual(raw_result, report)). They now assert raw_result === null and still check the full report through normalized_result.

Tests

  • New BinaryLayoutService case: the decoded layout is the complete normalized_result, and raw_result is null. The RecordedCrashService debugger-context case also asserts null.
  • npm run test:focused -- the two service tests, analysis-view service/domain tests, and binaryDiagnosticsMcp/analysisViewMcp/recordedCrashMcp (7 files, 41 passed)
  • npm run check:fast

Real pwntools/pwndbg verification needs Linux x64. I could not run it on this Mac. The PR touches src/application/binaryDiagnostics/** and both verifiers, so the Real offline binary layout and Real recorded crash evidence workflows run here and are the real-provider check for this change.

Refs #723, #1065.

🤖 Generated with Claude Code

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 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 7623e21 into main Oct 10, 2026
21 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the perf/binary-diagnostics-raw-result branch October 10, 2026 03:00
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The fix works. Both pwntools tools now keep one copy of the report. That cuts their output in half. The huge test ELF still does not fit the 10 MiB MCP budget. It fails cleanly and points to the saved evidence.

This is a check after the merge. I tested 7623e21f and its parent 499e2f54.

Tests

The PR changes two test files and one fixture. Four more test files use that fixture. I ran all six.

Node Files Tests
22.23.1 6 pass 42 pass
24.18.0 6 pass 42 pass
26.11.1 6 pass 42 pass

Then I put the new tests on the parent, on Node 24. Two tests fail there. Each gets a full report where it expects null. The other 40 pass. So the tests catch the old copy.

Real pwntools runs

verify-binary-layout.mjs exited 0 on the merge. It passed 150 cases, and the large MCP lane passed too. That lane sets a 256 MiB budget on purpose.

The new check also bites. I pointed this verifier at the parent's REA. It failed on the first file, at the new raw_result line.

The full crash verifier needs pwndbg. I did not install it. So I wrote a small driver. It calls connectRecordedCrash from public.mjs. It skips every debugger case. 34 cases passed on the merge. On the parent's REA it failed on the first case, at the new raw_result line.

rea doctor does not check pwntools. Its output was the same with and without the venv.

Before and after

These are bytes from the CLI with --format json.

Input Before After Change
ELF, layout 158,697 81,124 -48.9%
Core, crash 98,442 50,381 -48.8%
65,281 sections 82,828,661 41,416,116 -50.0%

Before, raw_result was a full copy of normalized_result. After, it is null. normalized_result is the same in both. No other field changed. The Evidence ID changes, as expected. A second run gave the same bytes.

The 10 MiB budget

I also called the tools over MCP. Sizes are in MiB.

Input Text before Text after Fits 10 MiB?
ELF, layout 0.09 0.05 yes
Core, crash 0.07 0.04 yes
65,281 sections 43.72 21.86 no, both

The big case still needs a bigger budget. At the default, both commits give resource_constraint. The error says nothing was cut. It points to the saved evidence. The reply also carries the data as structured content. With both, my client counted 96.66 MiB before and 48.33 MiB after for the big case.

Typecheck and lint

tsc --noEmit passed on Node 24. It took 3.8 s and peaked at 2.39 GiB.

oxlint exited 0. It gave the same 485 warnings as the parent.

npm run lint stopped at the boundary step. That step runs git ls-files. My copy is not a git checkout. So I passed it the commit's file list. It passed on 1314 files.

Not run

  • The full crash verifier. It needs pwndbg.
  • Every debugger-context case, and the trace step. They need pwndbg too.
  • GDB 13.1, the version in REA's docs. I made the test core with GDB 17.2.
  • npm run lint as one command, for the reason above.
  • Typecheck on the parent, or on Node 22 and 26.
  • Full test suite, knip, format check and jscpd.

Thanks to kaoru0822-kitauji for the fix and the tighter verifier checks.

Commands
# pwntools in a throwaway venv
uv venv --python /usr/bin/python3 venv
uv pip install --python venv/bin/python 'pwntools==4.15.0' 'pyelftools==0.33' 'unicorn==2.1.2'
export REA_PWNTOOLS_PYTHON=$PWD/venv/bin/python

# tests, on each Node
npx vitest run \
  src/application/binaryDiagnostics/BinaryLayoutService.test.ts \
  src/application/binaryDiagnostics/RecordedCrashService.test.ts \
  src/domain/analysisView/analysisView.test.ts \
  src/application/analysisView/AnalysisViewService.test.ts \
  tests/boundary/mcp/analysisViewMcp.test.ts \
  tests/boundary/cli/analysisViewCli.test.ts

# layout verifier, with the large lane
REA_VERIFY_STRACE_COMMAND=/usr/bin/strace REA_VERIFY_LARGE_ELF_MCP=1 \
  node scripts/verify-binary-layout.mjs
# same verifier, aimed at the parent's REA
REA_VERIFY_STRACE_COMMAND=/usr/bin/strace \
  node scripts/verify-binary-layout.mjs ../base/scripts/rea.mjs

# before and after, on copies
node scripts/rea.mjs inspect-binary-layout ./protected --format json
node scripts/rea.mjs inspect-binary-layout ./extended-large --format json
node scripts/rea.mjs inspect-recorded-crash ./recording.core --format json

# typecheck and lint
/usr/bin/time -f "%e %M" npm run typecheck
npx oxlint
git ls-tree -r --name-only 7623e21f -- src | grep '\.ts$' \
  | xargs node scripts/verify-module-boundaries.mjs

The ELFs come from the verifier's own gcc flags and sectionNameFixtures. The core comes from createRecordedCore. For MCP sizes I set REA_MCP_MAX_RESPONSE_BYTES to 256 MiB. Then I ran once more at the default.

Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…luto#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.
@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the provider: pwntools Analysis provider / engine: pwntools label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work provider: pwntools Analysis provider / engine: pwntools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants