Repository navigation
fix(ghidra): recover stale clients on same-target reopen - #2014
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 007a34940f
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Codex Review SummaryThis 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. |
|
TL;DR: The fix works with real Ghidra. I killed the Ghidra process, then reopened the same file. On head the next query started a fresh Ghidra and worked. On base the queries after that reopen failed. ResultsBase is 42b0ed1 and head is ad717f5. Each row ran in one MCP session over stdio. Times are from my client. Row labels match the step names in my logs.
On base I copied in the PR's two test files and its fake Ghidra fixture. The original Not run
Thanks, lyly-bonbon, for the fix. Commandsgit -C ~/code/rea-mirror/rea.git fetch origin
git -C ~/code/rea-mirror/rea.git archive 42b0ed126 | tar -x -C $J/base
git -C ~/code/rea-mirror/rea.git archive ad717f566 | tar -x -C $J/head
# in each tree, Node 24.18.0
npm ci && npm run build && npm run test:prepare
npm run typecheck
npm run test:focused -- tests/boundary/mcp/ghidraReopen.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts
npm run test:focused -- tests/boundary/mcp/ghidraReopen.test.ts
# real Ghidra, one MCP server per session, driven over stdio
export GHIDRA_INSTALL_DIR=~/.local/opt/ghidra_12.1.4_PUBLIC JAVA_HOME=~/.local/opt/jdk-21.0.12.1+1
export REA_ANALYSIS_PROVIDER=ghidra REA_GHIDRA_STARTUP_TIMEOUT_MS=600000
node scripts/rea.mjs mcpEach real-Ghidra session sent these calls.
The client script finds the Java child by walking /proc from its own server PID. REA starts Java directly, so Java is the server's own child. Two helper processes sit under Java (the decompiler and a demangler). The script kills only that Java PID. After each session it checks that every PID it saw is gone. The PR branch forked from b8fab74, one commit before 42b0ed1. Both commits hold the same Ghidra source and fake fixture. The PR's own test file was copied into the base tree for the base unit-test runs. Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
Health and startup exit checks called the supervisor snapshot, which concatenates retained launcher output only to read the exit code.
|
TL;DR: This PR merged as 4573e8c. Before that, I retested its last code change. Every test and every real Ghidra case gave the same result as before. I retested head 2ecd9df. Results match my earlier comment on ad717f5, so nothing new broke. The final head, 2f325ae, only brought in main. The PR's own files there match what I tested.
All tests passed on Node 22, 24 and 26. Still not run
Thanks, lyly-bonbon, for the fix. Commandsgit -C ~/code/rea-mirror/rea.git archive 2ecd9df83 | tar -x -C $J/head
npm ci && npm run build && npm run test:prepare
npm run typecheck
npm run test:focused -- tests/boundary/mcp/ghidraReopen.test.ts
npm run test:focused -- tests/boundary/providers/ghidra/ghidraClient.test.ts
npm run test:focused -- src/process/ProviderProcessOutput.test.ts
# real Ghidra, same stdio script as my earlier comment
node scripts/rea.mjs mcpI ran each test file alone on each Node version. Each real-Ghidra case ran in its own MCP session, and case b ran 3 times. After each session, none of my processes were still running. The target was a 12 KB ELF built with gcc from a short C file. It is not the same file as in my first run. Queries ran about half a second slower, and the box was busier. I did not pin the cause. Test setup
🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
@lyly-bonbon, thank you for making same-target Ghidra reopen respond to observed process exits and disconnected sockets. The recovery path keeps lazy reuse for a live client, while holding onto ownership when cleanup is still uncertain—a useful lifecycle distinction. Welcome to REA! |
Summary
Recover a retained Ghidra session when its process has exited or its bridge connection has closed. Same-target
open_binarynow retires the stale client; the next query starts a replacement after cleanup succeeds.Refs #1719.
Problem and expected behavior
After a successful query, killing the Ghidra child or disconnecting its socket left the successful startup promise cached. Ghidra exposed no operational health snapshot, so the composite provider's health response let same-target reopen reuse that client. The next query still failed against the old bridge.
Reopen should release the stale session and permit a fresh lazy start. If cleanup cannot be confirmed, it must return
cleanup_incomplete, retain ownership, and retry cleanup on the next open without starting another child.Change and scope
GhidraClient.This addresses stale-client recovery. It does not change startup deadlines, snapshot semantics, or detection of a connected but unresponsive bridge.
Contract and boundary impact
Evidence and regression coverage
b8fab742and pass with this change: old resources survive reopen, a disconnected child remains alive, and unconfirmed cleanup is incorrectly bypassed on the base.open_binaryreturns success after stale resources are released;list_stringssucceeds through the replacement. Unconfirmed cleanup returns error codecleanup_incompleteand launches no replacement.Validation performed
On macOS arm64 with Node 24.18.0 and npm 11.16.0:
npm run test:focused -- tests/boundary/mcp/ghidraReopen.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts src/ghidra/GhidraProvider.behavior.test.ts src/application/binary/BinarySessionLiveness.test.ts tests/composition/analysis-sessions/binarySession.test.ts tests/composition/analysis-sessions/providerBinding.test.ts— 124 tests passed across six files.npm run check— passed; lint reported warnings and no errors.npm run checkafter making the shutdown diagnostic assertion compare against the child's observed exit code; both passed.npm run verify:test-discovery— all 895 test files discovered exactly once.npm run jscpd— passed.git diff --check— passed.npm run verify:ghidra— build passed; real-provider verification could not start becauseGHIDRA_INSTALL_DIRis unavailable. No real-engine result is claimed.Compatibility, safety, and release
Review checklist