Skip to content

perf(evidence): stop copying normalized results into raw_result - #1402

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
perf/evidence-raw-result-no-copy
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
perf/evidence-raw-result-no-copy

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

createAnalysisExecution filled an omitted rawResult with a second complete copy of the result:

rawResult: options.rawResult === undefined ? jsonValueSchema.parse(result) : …

Every adapter call site that has no distinct provider representation therefore recorded the whole normalized_result twice in its Evidence (raw_result byte-identical to normalized_result). MCP results repeat Evidence in both text and structured content, so these responses carried four copies of the result. The duplicate also counted twice against the 10 MiB transport budget, and twice in the context of every agent that reads the result.

Affected call sites (all omitted rawResult):

Provider Operations
rea-artifact-graph decode_interface_builder, inspect_keyed_archive, inspect_asset_catalog, trace_dylib_resolution
native macOS inspect_native_dispatch_metadata, observe_native_calls, observe_native_ui / capture_native_ui_scenario (whose results include base64 screenshots)
Ghidra / IDA the open/started and health records (small)

Sibling operations of the same providers (inspect_artifact, extract_artifact, managed static analysis) already pass rawResult: null. Providers with a real upstream representation (Hopper, Ghidra calls, IDA, JADX, EVMole, Wakaru, inspect_plist provenance, …) pass it explicitly and are unchanged.

Change

An omitted rawResult now records null. The JSDoc and docs/mcp-contracts.md state the meaning: raw_result holds a provider representation distinct from the result, and is null when there is none. normalized_result, limitations, locations and subjects are unchanged. Evidence IDs of the affected operations change because the record changed.

Measurements (real MCP stdio client, pinned SDK, open_binary then the tool)

Tool Target main text / structured bytes This PR
trace_dylib_resolution Stash.app 3,217,119 1,612,524
trace_dylib_resolution Anki.app 1,093,111 550,918
decode_interface_builder KeepingYouAwake.app 3,831,653 1,917,473
decode_interface_builder Stash.app 2,814,104 1,414,774
inspect_asset_catalog Stash.app 1,120,144 560,945

Each figure is one representation. The MCP response carries it twice. normalized_result was compared byte for byte and is identical before and after on every target.

Tests

  • New src/application/AnalysisProvider.test.ts: an omitted raw result records null, and explicit raw results (including an explicit null) are preserved.
  • tests/boundary/cli/dylibResolutionCli.test.ts asserts raw_result: null on the real CLI path.
  • tests/composition/directAnalysisCleanup.test.ts pinned the old copy in its partial-observation expectations. It now expects null; the retained normalized_result assertion is unchanged.
  • Both new assertions fail with main's default and pass here.

Verification:

  • Full vitest run: 6200 passed. The remaining failures fail identically on unmodified main on this Mac: ibtool-compiled NIB tests (Command Line Tools only), hdiutil verify refusal, and three Node-discovery path tests. The MCP catalog tests needed the generated .cache catalog and pass once it is generated.
  • npm run check:fast, npm run docs:check

Not verified: real Ghidra and IDA (their only affected records are the small open/health ones), and real observe_native_ui capture (needs Accessibility permission). Refs #723, #1065 (T4: response repetition). This removes a duplicate inside Evidence; it does not change the text/structured repetition tracked there.

🤖 Generated with Claude Code

createAnalysisExecution defaulted an omitted rawResult to a second
complete copy of the result. Every caller that had no distinct provider
representation therefore doubled its Evidence: decode_interface_builder,
inspect_keyed_archive, inspect_asset_catalog, trace_dylib_resolution,
inspect_native_dispatch_metadata, observe_native_calls,
observe_native_ui/capture_native_ui_scenario (including screenshots), and
small Ghidra/IDA lifecycle records. Sibling operations of the same
providers already recorded null.

An omitted rawResult now records null. Normalized results are unchanged.
MCP responses repeat Evidence in text and structured content, so each
response and its share of the 10 MiB transport budget shrink by the same
half; e.g. trace_dylib_resolution on a real app bundle drops from
3,217,119 to 1,612,524 bytes per representation.

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 499e2f5 into main Oct 10, 2026
19 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the perf/evidence-raw-result-no-copy branch October 10, 2026 02:52
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The full typecheck passes on Linux. It peaks near 2.4 GiB, which is over a 2 GiB cap. The fix works. It cut two sample outputs by about 40%.

This is a check after the merge. I tested 499e2f54 and its first parent 6875d4a6.

Full typecheck

I ran tsc --noEmit on the merge commit. It passed with zero errors on every Node version.

Node Exit Time Peak RSS
22.23.1 0 3.8 s 2.41 GiB
24.18.0 0 4.8 s 2.39 GiB
26.11.1 0 3.1 s 2.41 GiB

The compiler is native, so the Node version matters little here. Peak RSS is the largest process, from /usr/bin/time. I also summed the whole process tree. That peak was 2.37 to 2.42 GiB. The tree is just the compiler.

So the default run goes past 2 GiB on this box. That would trip a 2 GiB cap.

I tried tsc --noEmit --singleThreaded once on Node 24. It passed. It took 6.5 s and peaked at 1.49 GiB. That may fit under the guard.

oxlint exited 0 with no errors. verify-module-boundaries exited 0 on 1314 files.

Tests

The PR changes three test files. All 17 tests pass on Node 22, 24 and 26.

I also put the new tests on the parent commit. Four tests fail there. Each one gets a full copy where it expects null. The other 13 still pass. So the tests catch the old behavior.

Before and after

The repo ships two keyed archives as XML. The CLI wants binary, so I converted them. Then I ran inspect-keyed-archive on both commits.

Fixture Before After Change
foundation 10,130 bytes 5,783 bytes -42.9%
archive 7,371 bytes 4,399 bytes -40.3%

These are the pretty JSON bytes from --format json. Compact JSON drops by 37% to 40%.

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 on each commit.

Not run

  • Full test suite, knip, format check and jscpd.
  • Typecheck on the parent commit.
  • Real nib, asset catalog and Mach-O inputs. The repo ships none.
  • Tools that need a Mac to run.
  • The decompiler check. It needs a binary import.
  • MCP response sizes. I only measured the CLI.

Thanks to kaoru0822-kitauji for the fix and the new tests.

Test setup
  • Box: Nobara Linux
  • CPU: AMD Ryzen 9 5900X (12 cores / 24 threads)
  • RAM: 32 GB DDR4-3600

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…uto#1402)

createAnalysisExecution defaulted an omitted rawResult to a second
complete copy of the result. Every caller that had no distinct provider
representation therefore doubled its Evidence: decode_interface_builder,
inspect_keyed_archive, inspect_asset_catalog, trace_dylib_resolution,
inspect_native_dispatch_metadata, observe_native_calls,
observe_native_ui/capture_native_ui_scenario (including screenshots), and
small Ghidra/IDA lifecycle records. Sibling operations of the same
providers already recorded null.

An omitted rawResult now records null. Normalized results are unchanged.
MCP responses repeat Evidence in text and structured content, so each
response and its share of the 10 MiB transport budget shrink by the same
half; e.g. trace_dylib_resolution on a real app bundle drops from
3,217,119 to 1,612,524 bytes per representation.
@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 area: evidence Evidence, artifacts, and reconstruction label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants