Skip to content

perf(artifacts): share sealed inventory and report in inspect_artifact - #2690

Merged
morluto merged 5 commits into
mainfrom
perf/artifact-inspection-sealed-inventory
Oct 13, 2026
Merged

morluto merged 5 commits into
mainfrom
perf/artifact-inspection-sealed-inventory

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

inspect_artifact on a large bundle spent much of its CPU re-validating and re-digesting the same payload. On Keynote.app the payload is a 42 MB inventory. A CPU profile of rea inspect-artifact /Applications/Keynote.app showed it being canonically digested into an Evidence ID about four times and zod-parsed about five times:

Boundary Repeated work
createArtifactInspection → parseEvidence re-authenticates the nested inventory Evidence (full parse + clone + ID digest)
createAnalysisExecution → jsonValueSchema.parse clones the inspection report
outer createEvidence parses the envelope with the mutable-result schema
recordEvidence → immutableEvidence → parseEvidence re-authenticates the outer Evidence (parse + ID digest)

Root cause

inspectArtifact owns two freshly parsed values: the inventory and the inspection report. It left both mutable. The Evidence layer already has a zero-copy path for sealed immutable JSON snapshots (freezeJsonSnapshot / immutableEvidenceSnapshots), but these values never qualified for it.

Fix

Seal both exclusively owned values with freezeJsonSnapshot at the point where they're produced. Each downstream boundary then uses the existing immutable path: nested createEvidence remembers the record, parseEvidence hits the snapshot cache, jsonValueSchema.parse returns the sealed report as-is, and the outer Evidence is shared and recorded without re-authentication. No contract or output changes.

Measurements

These are warm runs, three each, on an Apple Silicon Mac, measured with /usr/bin/time -l around rea inspect-artifact <app> --format json. Main and the branch were built from the same base.

Target main (real / user / peak RSS) branch (real / user / peak RSS)
Keynote.app (42 MB result) 7.60 s / 6.76 s / 725 MB 6.46 s / 5.58 s / 588 MB
Anki.app (7.7 MB result) 1.88 s / 2.30 s / 443 MB 1.74 s / 2.17 s / 437 MB

On Keynote that is about 15% less wall time, 17% less user CPU and 19% less peak RSS. Token cost is unchanged: stdout is byte-identical before and after on Keynote and Sublime Text (same SHA-256). Cold-cache runs and the MCP adapter were not measured separately; both share this provider path.

Validation

  • npm run test:focused on every test file that references inspect_artifact / createArtifactInspection (22 files: CLI, MCP, sessions, composition, acceptance, conformance): 138 passed. This shows no downstream consumer mutates the now-sealed report.
  • npm run check:fast passes.

Remaining

createArtifactInspection still re-parses the inventory with artifactInventoryResultSchema, and its final artifactInspectionResultSchema.parse traverses the nested Evidence once more (about 0.25 s on Keynote). Removing those would mean changing what the domain function's unknown input contract validates, so it's left out of this change.

🤖 Generated with Claude Code

inspect_artifact parsed a fresh inventory and inspection report but left
both mutable, so each later Evidence boundary cloned and re-digested the
complete payload: createArtifactInspection re-authenticated the nested
inventory Evidence, createAnalysisExecution re-parsed the report, and
recordEvidence re-authenticated the outer Evidence.

Seal both exclusively owned values with freezeJsonSnapshot so those
boundaries take the existing immutable-snapshot path. 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-13T11:55:17.171891Z ed80d29 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] This PR appears safe to merge; sealing the values preserves their checks and fits the existing recording path.

Summary

inspect_artifact now seals its inventory and report so later steps can share them instead of copying and hashing them again.

  • Artifact inspection reuses sealed inventory and report snapshots.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Parse inventory"] --> B["Seal inventory"]
  B --> C["Create and authenticate inventory Evidence"]
  C --> D["Create and parse inspection report"]
  D --> E["Seal report"]
  E --> F["Share report with execution and outer Evidence"]
  F --> G["Record sealed Evidence"]
Loading

Reviews (5) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

@morluto
morluto merged commit 11268fe into main Oct 13, 2026
31 checks passed
@morluto
morluto deleted the perf/artifact-inspection-sealed-inventory branch October 13, 2026 13:16
@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