Skip to content

perf(evidence): reuse sealed bundle reads in compare and export - #2715

Merged
morluto merged 6 commits into
mainfrom
perf/evidence-bundle-compare-sealed
Oct 13, 2026
Merged

morluto merged 6 commits into
mainfrom
perf/evidence-bundle-compare-sealed

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

Comparing or exporting a large Evidence bundle re-authenticates every record several times. I exported an MCP session that ran inspect_artifact on Keynote.app (85 MB bundle, 2 records) and profiled rea compare bundle.json bundle2.json. About 5.4 s of its 8.7 s went to parseEvidenceBundle, and another 2.6 s to bundleDigest → serializeEvidenceBundle.

Each bundle is authenticated three times:

  1. readEvidenceBundle → parseEvidenceBundle (mutable, uncached)
  2. compareBundles → parseEvidenceBundle again
  3. bundleDigest → serializeEvidenceBundle → parseEvidenceBundle a third time

rea evidence-export does the same once more: writeEvidenceBundle re-parses the source it just read.

Fix

These consumers only read the bundle. They now load it through the existing sealed reader, readImmutableEvidenceBundle (added in #1721 for session import). The sealed bundle is registered in the immutable bundle cache, so steps 2 and 3, and the export writer's check, reuse the first authentication. Changed call sites:

  • compareEvidenceBundlesCommand (CLI rea compare)
  • the compare_bundles MCP tool
  • exportEvidenceBundleCommand (CLI rea evidence-export)

readEvidenceBundle deliberately stays mutable for ordinary file reads; #1721 tests that. Results, bundle digests and exported bytes are unchanged.

Measurements

Same 85 MB bundle, three warm runs each with /usr/bin/time -l, main and the branch built from the same base. Outputs are byte-identical (same SHA-256 for compare stdout and for the exported file).

Command main real / user branch real / user
rea compare a.json b.json 8.79 s / 10.0 s 4.95 s / 6.0 s
rea evidence-export a.json out.json 3.38 s / 4.08 s 2.48 s / 3.09 s

That is about 44% less wall time for compare and 27% less for export. Peak RSS is dominated by reading the file and is noisy across runs: compare 2.0–2.6 GB on both, export about 960 MB → 920 MB. Token cost is unchanged. The MCP compare_bundles path shares the change but wasn't timed separately.

Validation

  • npm run test:focused on the bundle comparison, import/export, cancellation and MCP compare_bundles suites (14 files): 102 passed.
  • npm run check:fast passes; npm run jscpd is at 2.99%.

🤖 Generated with Claude Code

`rea compare`, the compare_bundles MCP tool and `rea evidence-export`
read bundles through the mutable reader, so each consumer
re-authenticated every record again: compareBundles parsed both bundles
a second time and bundleDigest's serializeEvidenceBundle a third time;
export's writer parsed the source once more before serializing.

These consumers only read the bundle, so read it through the existing
sealed reader (readImmutableEvidenceBundle). Later parses hit the
immutable bundle cache. Ordinary mutable reads, kept deliberately by
#1721, are unchanged. Output is byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T13:09:39.442720Z 35cc473 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Comparison and export now use readImmutableEvidenceBundle so later checks can reuse an authenticated, frozen bundle. ProviderStartupDeadline.remainingMs() also returns zero after its timeout fires.

  • Bundle comparisons and exports reuse sealed reads to avoid repeat authentication.
  • A fired startup timeout leaves no reported time remaining.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI compare, MCP compare, or CLI export] --> B[Read current file bytes]
  B --> C[Authenticate bundle and records]
  C --> D[Deep-freeze bundle]
  D --> E[Cache by object identity]
  E --> F[Compare or export]
  F --> G[Reuse authenticated bundle for later checks]
Loading

Reviews (5) · Last reviewed commit: "fix(process): report no remaining time a..." · Reviewed by Greptile

kaoru0822-kitauji and others added 5 commits October 13, 2026 09:30
Node timers can fire while performance.now() is still a fraction of a
millisecond short of the monotonic deadline. ProviderStartupDeadline then
reported interruption "timeout" and an aborted signal while remainingMs()
returned ceil(0.x) = 1, so polling loops guarded by remainingMs() > 0
(Hopper and Ghidra startup) could run past an elapsed deadline, and the
real-timer test "aborts a bounded wait when its real monotonic deadline
expires" failed intermittently in CI (expected 1 to be 0).

Once the deadline's own timer has classified a timeout, report zero
remaining time. A deterministic regression test fires the timer with the
monotonic clock 0.4 ms short of the deadline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morluto
morluto merged commit 9680da7 into main Oct 13, 2026
5 checks passed
@morluto
morluto deleted the perf/evidence-bundle-compare-sealed branch October 13, 2026 13:50
@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.

2 participants