Repository navigation
feat(ghidra): checkpoint owned Programs across sessions - #9236
Conversation
Add opt-in packed-program checkpoints for stock native imports on POSIX, with shared CLI/MCP restore, exclusive session leases and retryable normal-close saves. Preserve source files and refuse mismatched or malformed saved state. Real-provider verification is in progress.
Track staged data separately by publication validity. Remove acknowledged failed exports without publishing partial files, retain failed removal for the next close, and expose retained checkpoint lease resources. Cover failed removal and lease-release retries.
Separate initial analysis generation from serialized packed-file identity so first publication does not replace the live MCP run or invalidate its initial query snapshot. Bind later saved states to content digests and conservatively retain legacy checkpoints. Verify cold MCP repeated opens with unsaved metadata and first-save snapshot replay through real public workflows.
Codex Review Summary: ❌ FailedThis 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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
[Medium impact] The PR appears safe to merge based on the reviewed code. SummaryAdds opt-in persistence for REA-owned Ghidra Programs across CLI and MCP processes.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Resolve target and profile] --> B[Acquire checkpoint lease]
B --> C{Saved Program exists?}
C -->|Yes| D[Verify and restore without auto-analysis]
C -->|No| E[Analyze and publish first checkpoint]
D --> F[Serve queries and metadata edits]
E --> F
F --> G[Normal close saves changes]
G --> H[Release owned resources]
G --> I[Target switch refreshes profile]
Reviews (2) · Last reviewed commit: "fix(ghidra): preserve checkpoints across..." · Reviewed by Greptile |
Refresh provider-owned profiles after a previous client publishes on close, including failed-switch restoration. Preserve typed file cancellation and cleanup owners, admit only stock loaders, and use one session source for health and metadata persistence caveats. Fix the real verifier compiler and cover edited alias switches.
Summary
Opt-in
REA_GHIDRA_CHECKPOINT_DIRsaves an owned Ghidra Program after initial analysis and on normal close after metadata changes. Fresh CLI/MCP processes restore its analysis, names, comments and types without rerunning auto-analysis. Refs #8165; existing read-only project reuse from #7236 remains separate.Problem and expected behavior
Fresh imports previously discarded the editable Program when the process ended. A saved REA snapshot carries immutable observations, not the editable database. This adds a basic last-successful-checkpoint workflow. Reopening the same target within a live MCP session preserves that Program and unsaved edits, including immediately after its first automatic save.
Change and scope
The shared Ghidra provider owns selection, lease, packed export/import and recovery. Keys bind target SHA-256 and the existing analysis profile; every admission verifies the packed file. Initial-analysis generation stays stable through first publication; subsequent saved states bind their content digest. Old local manifests are conservatively read as content-bound retained states.
A provider-owned lifetime flag makes the shared session transition refresh checkpoint-dependent profiles after the previous client saves on close, including failed-switch restoration. It preserves the selected provider and original selection provenance. Immutable providers keep their current path.
Publication syncs a new immutable packed file before atomically replacing the manifest, then removes the previous file. Failed publication retains the last good checkpoint and retryable ownership. Incomplete exports are discarded before retry. Restore uses an owned temporary project with
-noanalysis; no public bridge operation is added.Contract and boundary impact
GhidraCheckpointowns persisted identity, lease and publication;GhidraClientowns JVM export/finalization and staging. Recovery now uses an explicit session-source union instead of an ambiguous Boolean.Expected effects:
Evidence and regression coverage
The committed real-provider verifier exercises 13 public CLI/stdio-MCP scenarios on a source-built C fixture: a genuinely cold repeated open with unsaved edits; first save; initial snapshot replay; fresh-process restore; identical bytes at another path; live-run reuse and concurrent-owner refusal; name/comment/structure-field preservation and further edits; stale snapshot refusal; an edited live alias switch; profile mismatch; malformed manifest; corrupt packed data and explicit recovery. Target hash and owned-process cleanup are checked.
Lifecycle fixtures additionally cover failed/partial export, publication and staging-removal failures, cleanup retry, initial-finalization cancellation and held-close ordering. Owner tests cover caller
symlink/..semantics, corrupt/missing data, generation admission, legacy manifests and lease release. Existing session/transport cancellation and snapshot cleanup regressions are included in the focused run.A real cold-MCP reproduction at
cc62fb699replaced the run after first publication. Atef6ee4ce3, the same workflow retains its run and unsaved comments; the new cold scenario prevents the previously warm-only verifier from missing this again.Review also exposed an edited-alias switch refusal, reproduced with real Ghidra at
ef6ee4ce3and fixed in2648e511d. New regressions preserve exact cancellation/cleanup ownership for both manifest and packed reads, refuse the resolved PSP custom-loader profile, cover switch failure/restoration, and check health plus sibling metadata caveats. The unused ambient compiler selector was removed from the verifier.Representative restored-result caveat:
Restored owned Program <packed-path> (SHA-256 <verified-digest>); auto-analysis was not rerun.Validation performed
2648e511d:npm run check— passed (typecheck, lint, formatting, Knip, metadata, architecture/reachability checks and typed lint; no errors).2648e511d: the expanded 19-filenpm run test:focused -- ...run passed 720 tests with 3 platform skips and rebuilt the runtime. Push-hook typecheck/lint passed.npm run docs:checkpassed, including 9 consistency tests.git diff --check origin/mainpassed.2648e511dsuccessfully; all five initial review threads have root-cause/fix/validation replies and are resolved. Codex review was unavailable because the repository review quota was exhausted.2648e511d, including all eight test shards, source/static checks, Ghidra bridge compilation, reverse-tools quality, SQLite compatibility and platform/package lanes. No CI bypass was needed.verify:ghidra:checkpoints— all 13 scenarios verified on final head2648e511d; 141.812 s elapsed, 213.344 CPU s, 1403.895 MiB sampled peak process-family RSS; zero owned descendants after cleanup. Four-core affinity, two JVM active processors, 1536 MiB headless heap. RSS sampled every 250 ms; shared pages can be counted twice and short-lived children missed. One earlier local rerun was interrupted by a concurrent docs build clearingdist; its failed report was retained, cleanup verified, and the final run above was serialized./usr/bin/bash, SHA-25655b89ab22bee4792a210f493a53fb066accd5d30b69837c28d98be5ff863efcf, never executed, atc450305fb: identical_DT_INITresult across four fresh CLI processes. Ephemeral first/repeat: 60.78/51.84 s (135.32/118.90 CPU s); checkpoint initial/restore: 58.72/13.93 s (134.07/26.22 CPU s). Whole sequence: 185.724 s, 414.773 CPU s, 1645.906 MiB sampled family peak; cleanup verified. Ordered runs share warm OS/Ghidra caches; first baseline includes bridge compilation. Later fixes affect failure handling/generation identity. No universal speedup or token-savings claim; model token usage was not measured.Compatibility, safety, and release
Author readiness
Human owner: @gensokyo-dev (author exempt under CONTRIBUTING.md). These human declarations are intentionally left unchecked.
Merge used the author's repository-approved
pull_requests_onlyruleset bypass for the CODEOWNERS requirement after CI and Greptile passed; no human-review declaration was attested by the agent.Before merge