Skip to content

feat(ghidra): checkpoint owned Programs across sessions - #9236

Merged
gensokyo-dev merged 5 commits into
mainfrom
feat/ghidra-owned-checkpoints
Nov 7, 2026
Merged

gensokyo-dev merged 5 commits into
mainfrom
feat/ghidra-owned-checkpoints

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Opt-in REA_GHIDRA_CHECKPOINT_DIR saves 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

  • Semantic owner: GhidraCheckpoint owns persisted identity, lease and publication; GhidraClient owns JVM export/finalization and staging. Recovery now uses an explicit session-source union instead of an ambiguous Boolean.
  • Scope decision: the maintainer-directed task explicitly authorized this basic opt-in persistence of REA-owned Programs. This PR records that scope; [Design] Preserve and reopen owned Ghidra analysis with a packed-program checkpoint #8165 supplies the design context, not an approval claim. No new target execution, injection, source-project editing or protection-recovery capability.
  • CLI/MCP: one provider implementation; additive environment setting retained by setup. Existing commands/tool schemas and default ephemeral behavior remain unchanged.
  • Compatibility: stock native ELF/PE/Mach-O on Linux/macOS only. Reject existing-project, Windows, pinned-loader, language/analyzer override, seed and extension combinations.
  • Evidence: profile retains checkpoint directory and semantic generation; restored results identify the actual packed path and verified SHA-256, with an explicit no-reanalysis caveat. Old immutable snapshots refuse later edited generations.
  • Authority/cleanup: executable bytes remain unchanged and are never executed. Only owned metadata/artifacts are written; competing writers are refused through the existing socket-lease primitive. JVM/file/lease cleanup failures retain ownership for retry.
  • Package/generated metadata: one real-provider verification script; no dependency, version or generated-catalog changes.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process (user-supplied headless Ghidra).
  • Run scripts/code (REA's existing Ghidra bridge; never the target).
  • Change files (owned Program/checkpoint artifacts).
  • Contact network services.
  • Recover protected code or work around protections.

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 cc62fb699 replaced the run after first publication. At ef6ee4ce3, 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 ef6ee4ce3 and fixed in 2648e511d. 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.

  • Observed, derived and inferred claims remain distinguishable.
  • Artifact identity, source provenance and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable and uncertain outcomes remain visible.

Validation performed

  • On final head 2648e511d: npm run check — passed (typecheck, lint, formatting, Knip, metadata, architecture/reachability checks and typed lint; no errors).
  • On final head 2648e511d: the expanded 19-file npm run test:focused -- ... run passed 720 tests with 3 platform skips and rebuilt the runtime. Push-hook typecheck/lint passed. npm run docs:check passed, including 9 consistency tests. git diff --check origin/main passed.
  • Greptile reviewed final head 2648e511d successfully; 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.
  • GitHub CI passed on 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.
  • Real Ghidra 12.1.4/JDK 21 on Linux x64, verify:ghidra:checkpoints — all 13 scenarios verified on final head 2648e511d; 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 clearing dist; its failed report was retained, cleanup verified, and the final run above was serialized.
  • Representative 1.2 MiB /usr/bin/bash, SHA-256 55b89ab22bee4792a210f493a53fb066accd5d30b69837c28d98be5ff863efcf, never executed, at c450305fb: identical _DT_INIT result 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

  • Additive opt-in; unset the variable for current behavior. Restore reaches the last successful save, not edits lost after cancellation/crash. Initial analysis cannot resume midway. This is not a whole REA investigation archive or a host-crash durability promise.
  • Real-provider proof covers Linux x64 native ELF, small C and Bash targets. No real macOS/Windows run, large-game workload or real-engine disk-failure injection; controlled fixtures cover failure/cancellation paths.
  • No release, tag, version bump or publication is part of this PR.

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_only ruleset bypass for the CODEOWNERS requirement after CI and Greptile passed; no human-review declaration was attested by the agent.

  • 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.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved for the scope recorded above.
  • The PR has one focused outcome and a Conventional Commit title.
  • Related design issue is linked.
  • Tests cover changed behavior and meaningful failure paths; proof gaps are recorded.
  • Owning docs/contracts are updated; no generated files are committed.
  • Representative restored-result output is included above.
  • Diff checked for credentials, unrelated cleanup and unsupported claims.

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.
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-07T05:53:32.510687Z
We couldn’t complete this review. Comment @codex review to try again.
ef6ee4c PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge based on the reviewed code.

Summary

Adds opt-in persistence for REA-owned Ghidra Programs across CLI and MCP processes.

  • Ghidra can reopen an owned Program without repeating analysis.
  • A session can use the checkpoint profile saved when it closes.

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]
Loading

Reviews (2) · Last reviewed commit: "fix(ghidra): preserve checkpoints across..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraProvider.ts Resolved
Comment thread src/ghidra/GhidraCheckpoint.ts Resolved
Comment thread src/ghidra/GhidraProvider.ts Resolved
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.
@gensokyo-dev
gensokyo-dev merged commit c07ab4b into main Nov 7, 2026
56 checks passed
@gensokyo-dev
gensokyo-dev deleted the feat/ghidra-owned-checkpoints branch November 7, 2026 06:52
@morluto morluto mentioned this pull request Nov 11, 2026
3 tasks done
@morluto morluto added enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants