[PR #2715] [MERGED] perf(evidence): reuse sealed bundle reads in compare and export #5338

Closed
opened 2026-10-31 01:05:51 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/2715
Author: @kaoru0822-kitauji
Created: 10/13/2026
Status: ✅ Merged
Merged: 10/13/2026
Merged by: @morluto

Base: main ← Head: perf/evidence-bundle-compare-sealed


📝 Commits (6)

  • eefc667 perf(evidence): reuse sealed bundle reads in compare and export
  • f006966 Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed
  • e70544e Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed
  • 549f5f3 Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed
  • 1c92815 chore: sync captured upstream CI baseline
  • 35cc473 fix(process): report no remaining time after a provider deadline fires

📊 Changes

4 files changed (+30 additions, -6 deletions)

View changed files

📝 src/application/EvidenceBundleCommands.ts (+7 -3)
📝 src/process/ProviderDeadline.test.ts (+17 -0)
📝 src/process/ProviderDeadline.ts (+3 -0)
📝 src/server/registerBundleComparisonTool.ts (+3 -3)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/2715 **Author:** [@kaoru0822-kitauji](https://github.com/kaoru0822-kitauji) **Created:** 10/13/2026 **Status:** ✅ Merged **Merged:** 10/13/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `perf/evidence-bundle-compare-sealed` --- ### 📝 Commits (6) - [`eefc667`](https://github.com/morluto/rea/commit/eefc667b142c2685df1e62590a595268e2279efa) perf(evidence): reuse sealed bundle reads in compare and export - [`f006966`](https://github.com/morluto/rea/commit/f006966ade76c6619161728cf40a8d4655d9fb0e) Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed - [`e70544e`](https://github.com/morluto/rea/commit/e70544ec98bdb6464e22f57cc003583c47247fd9) Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed - [`549f5f3`](https://github.com/morluto/rea/commit/549f5f307cc4143bb315a5726f02d5bdb2fd6b8b) Merge remote-tracking branch 'origin/main' into perf/evidence-bundle-compare-sealed - [`1c92815`](https://github.com/morluto/rea/commit/1c928158dd713beb246dac3235cc3fec09431b34) chore: sync captured upstream CI baseline - [`35cc473`](https://github.com/morluto/rea/commit/35cc473fd229a8b7fb4a11224bf818768766e2f0) fix(process): report no remaining time after a provider deadline fires ### 📊 Changes **4 files changed** (+30 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/application/EvidenceBundleCommands.ts` (+7 -3) 📝 `src/process/ProviderDeadline.test.ts` (+17 -0) 📝 `src/process/ProviderDeadline.ts` (+3 -0) 📝 `src/server/registerBundleComparisonTool.ts` (+3 -3) </details> ### 📄 Description ## 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:05:51 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#5338
No description provided.