Skip to content

fix: preserve source closure during snapshot replay - #8870

Merged
morluto merged 4 commits into
mainfrom
codex/snapshot-source-closure
Nov 7, 2026
Merged

morluto merged 4 commits into
mainfrom
codex/snapshot-source-closure

Conversation

@morluto

@morluto morluto commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Problem and outcome

A Ghidra saved-project observation carrying historical source Evidence cannot currently replay from an analysis snapshot, even when the parent and its sources were retained. The cache excludes all source-bearing executions to avoid dropping provenance. Reuse the authenticated retained parent and its source records when the entire transitive closure is available; otherwise run the provider. When an exact parent was present but its sources were missing, recheck the closure on the next query after source import; ambiguous parent provenance remains non-replayable. Related: #8869.

The same closure check now protects the one-shot pre-provider replay path. No snapshot format or provider output is duplicated. This does not solve default one-shot delivery of linked source records (#8590), documentless decompile replay (#8085), or incompatible-profile historical recovery (#8655).

The shared closure traversal now handles wide link arrays without spreading them into a function call, and snapshot staging reuses closure decisions against its immutable record set. Missing sources are rechecked against the current session on later queries.

Validation

  • Merged current main and reconciled replay source closure with the original Evidence parent retained by feat(native): page retained feature traces #8585. check:fast passed; snapshot cache, one-shot and MCP replay suites passed (84 tests, 2 skipped).

  • A 500,000-link retained-source regression failed on the previous spread-based traversal and passes with the shared traversal. A controlled 800-entry, 300-node shared-chain staging fixture had a 60.90 ms baseline median and 23.63 ms prototype median across five warm runs each; this isolates staging and excludes snapshot validation, file I/O and provider work.

  • Four focused source, Ghidra, public MCP and one-shot suites passed (96 tests, 2 skipped); check:fast, docs:check and git diff --check passed. New public MCP and one-shot regressions failed on the baseline. A one-shot regression also failed when only the new pre-provider closure check was removed.

  • Controls cover missing direct and transitive sources, source metadata replacement, same-session and exported-snapshot replay, missing-source fallback to the provider, source import followed by lazy revalidation, ambiguous parents, and source-bearing snapshot finalization with injected cleanup failure or cancellation followed by cleanup retry. A real Ghidra injected zero-retention control returned resource errors and persisted no entry or record in either MCP profile.

  • Real Ghidra 12.1.4/JDK 21 on macOS arm64, both MCP profiles: a disposable saved project with a synthetic historical report replayed a document-selected decompile in-session and after reopening, preserving the same source ID. A copied snapshot with that source removed did not replay; Ghidra reran and re-established the source. The target and selected .gpr descriptor hashes were unchanged. The project contents were not independently hashed as a whole.

  • Real Ghidra source-restoration control, both MCP profiles: after opening a snapshot with its historical source removed, importing the exact source bundle made the next call replay with the original source ID. The same sequence reran the provider before this change. The copied snapshot and target were unchanged.

  • Real Ghidra project-freshness control, both MCP profiles: after saving a source-bearing snapshot, an intentionally added file in a disposable project copy changed its profile. Reopening the old snapshot was refused with the profile mismatch, and analysis without it succeeded. The target and snapshot were unchanged. This does not test concurrent project mutation.

  • Additional real Ghidra controls in both MCP profiles refused a source-bearing snapshot for a byte-modified copy of the target, and refused another copied snapshot whose source Evidence payload was tampered without updating its identity. The original target, snapshot and project descriptor were unchanged.

  • Three alternating completed tasks per variant (open, two reads, snapshot close, reopen and read) on that fixture had median first/second/reopened call times of 3,048/3/3,089 ms baseline and 2,879/1/1 ms prototype; median task elapsed was 8,342/4,743 ms. Sampled summed process-family peak RSS was 899,408/899,280 KiB and sampled CPU lower bounds were 12.67/6.90 s. Serialized compact MCP catalog, requests and SDK results were 132,423/132,499 o200k_base tokens. Baseline included the unrelated fix!: guide snapshot inputs to the restore workflow #8867 import-guidance change; the prototype was based on main. These are host-specific samples; shared RSS can be counted twice, short-lived processes can be missed, and protocol framing and agent conversation were not counted. Answer hashes and source IDs matched.

  • Other providers and hosts, real cleanup failure, actual low-memory behavior and end-to-end performance on large shared closures remain unverified. Injected limits are test controls, not public settings.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] No blocking issue remains when this PR is reviewed with dependent PR #8873.

Summary

Preserves source-backed snapshot answers only when every linked record is available.

  • Binary sessions replay saved results only when their source records are complete.
  • One-shot analysis checks saved source links before returning cached evidence.

The supplied stack shows #8873 as a follow-up, not a replacement. Live PR status could not be confirmed. Source review and git diff --check completed; no tests were run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Find matching snapshot parent] --> B{Parent is unambiguous?}
  B -->|No| P[Run provider]
  B -->|Yes| C{All linked sources exist?}
  C -->|Yes| R[Replay with retained sources]
  C -->|No| P
  C -->|Session import adds sources| Q[Check again on next query]
  Q --> C
Loading

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T07:55:00.299170Z 95dc5c0 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.

# Conflicts:
#	src/application/DirectAnalysis.ts
#	src/application/binary/AnalysisSnapshotCache.ts
#	src/application/binary/AnalysisSnapshotReplayBinding.ts
#	src/application/investigation/InvestigationEvidence.ts
#	tests/boundary/filesystem/directAnalysisSnapshotReplay.test.ts
#	tests/boundary/mcp/workflowSnapshotReplayMcp.test.ts
@morluto
morluto merged commit 441ba94 into main Nov 7, 2026
49 of 51 checks passed
@morluto
morluto deleted the codex/snapshot-source-closure branch November 7, 2026 08:22
@morluto morluto added area: evidence Evidence, artifacts, and reconstruction bug Something isn't working labels Nov 22, 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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant