Repository navigation
fix: preserve source closure during snapshot replay - #8870
Conversation
[Medium impact] No blocking issue remains when this PR is reviewed with dependent PR #8873. SummaryPreserves source-backed snapshot answers only when every linked record is available.
The supplied stack shows #8873 as a follow-up, not a replacement. Live PR status could not be confirmed. Source review and 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
Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
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:fastpassed; 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:checkandgit diff --checkpassed. 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
.gprdescriptor 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_basetokens. 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: