Skip to content

fix(ghidra): tell callers to reopen after the provider exits - #2945

Closed
RishTheFish21 wants to merge 1 commit into
morluto:mainfrom
RishTheFish21:fix/1719-reopen-after-ghidra-exit
Closed

RishTheFish21 wants to merge 1 commit into
morluto:mainfrom
RishTheFish21:fix/1719-reopen-after-ghidra-exit

Conversation

@RishTheFish21

Copy link
Copy Markdown
Contributor

Summary

Fixes #1719. The reopen and snapshot_path paths from the original report were already fixed by e59db2f and #2014; I verified them on real Ghidra (see Validation). The one remaining case: after the Ghidra process dies, a query without a reopen returned a generic execution_failure telling the caller to run rea doctor and that repeating would not help. Nothing is wrong with the installation, and a plain open_binary on the same target recovers.

Problem and expected behavior

Kill the Ghidra JVM after a successful query, then call list_documents without reopening:

  • Before: "Analysis could not complete. Run rea doctor and review the reported details; repeating the unchanged request is not expected to succeed."
  • After: "The Ghidra provider for this session exited before list_documents could complete. Call open_binary for the same target to start a new Ghidra session, then retry; session-only annotations from the previous provider are not retained."

Change and scope

  • projectSessionError in GhidraProviderClient.ts now receives the client's operationHealthSnapshot(). When a process/protocol failure coincides with health exited or unreachable (providerRetryAction = restart_provider), the ProviderAdapterError carries a user message pointing at open_binary. This follows the existing Hopper RESTART_OWNED_PROVIDER path.
  • The health is only consulted after this session's provider has started or answered at least once, so a Ghidra crash during startup keeps the installation guidance.
  • Bridge-reported (remote) failures and failures with unknown health are unchanged.

Not included: restarting Ghidra automatically on the next query. A silent restart would discard session annotations, so the caller reopens explicitly.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra provider client error projection.
  • CLI and MCP/tool-catalog contract: none. Same code (execution_failure), category, retryable: false and details; only the message and remediation text change in this case.
  • Provider, bridge, target-format, or platform compatibility: Ghidra only, all platforms.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: five cases in src/ghidra/GhidraProvider.behavior.test.ts: exited → reopen message; unreachable → reopen message; death before the first reply → keeps rea doctor; unknown health → unchanged; remote failure → unchanged.
  • Base reproduction or other evidence: the real-Ghidra run on main (ebaaa79ca) posted on [Bug] open_binary silently short-circuits without starting a real provider client #1719 shows the old message.
  • User-visible CLI/MCP output: see "Problem and expected behavior".
  • Remaining proof gaps: only tested on macOS arm64. The unreachable case (socket closed, process alive) is covered by the fake-client test, not reproduced with real Ghidra.

For evidence-bearing changes:

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

Validation performed

  • npm run test:focused -- src/ghidra/GhidraProvider.behavior.test.ts: passed
  • npm run check:fast: passed
  • npm run check: typecheck, compile and metadata passed; format:check fails on docs/readme/README_tr.md and scripts/lib/clean-linux-hopper-runtime.mjs, which this PR doesn't touch (pre-existing on main)
  • npm run lint and npm run knip: passed
  • Real Ghidra 12.1.4, JDK 21, macOS arm64, driving rea mcp over stdio and SIGKILLing the Ghidra JVM at set points:
    • open → query → query: ok (Ghidra starts on the first query)
    • kill → open_binary same target → query: ok
    • kill → query without reopen: fails with the new message (twice); a following open_binary + query: ok
    • close_binary with snapshot_path → open_binary with snapshot_path → query → second open → query: ok
    • kill → open_binary with snapshot_path → query: ok
    • no Ghidra JVMs left over at the end

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: real Ghidra on macOS arm64 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new process handling; the change reads health REA already records.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T18:44:14.910171Z e1e6a2c 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e960a64d82

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

? {}
: { progress: options.progress }),
});
if (called.ok) providerStarted = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat bridge replies as proof of startup

providerStarted is set only when callTool returns ok, but a remote error is also a validated response from an already-started bridge (GhidraClient.callTool completes startup before entering the request queue). If the first Ghidra query returns, for example, not_found or ambiguous and the JVM exits afterward, the next process failure still sees providerStarted === false, so lostProviderHealth() suppresses the observed exit and falls back to the misleading rea doctor guidance. Record completion of the startup handshake at the owning client boundary (and make ready-only dispatches use the same fact) instead of inferring it from a successful operation.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the earlier non-blocking gap in advice after a first bridge error still present.

Findings

  1. P2 First errors hide reopen advice ▶
Fix with agent prompt
### Issue 1
src/ghidra/GhidraProviderClient.ts:undefined-837
On a plain ELF target, `callTool` can complete startup and return a bridge error, but `providerStarted` stays false. For example, call `procedure_pseudo_code` for a missing procedure, then kill Ghidra and call `list_documents`. The new gate hides the exited health, so the caller still gets `rea doctor` advice instead of being told to reopen.

Track successful startup independently of successful tool results, and add a test for a bridge error followed by provider loss.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR tells callers to reopen their target when an established Ghidra provider exits or its bridge becomes unreachable.

  • Ghidra callers are told to reopen the target after the provider is lost.

Reviews (4) · Last reviewed commit: "fix(ghidra): tell callers to reopen afte..." · Reviewed by Greptile

? {}
: { progress: options.progress }),
});
if (called.ok) providerStarted = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 First errors hide reopen advice

On a plain ELF target, callTool can complete startup and return a bridge error, but providerStarted stays false. For example, call procedure_pseudo_code for a missing procedure, then kill Ghidra and call list_documents. The new gate hides the exited health, so the caller still gets rea doctor advice instead of being told to reopen.

Track successful startup independently of successful tool results, and add a test for a bridge error followed by provider loss.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/ghidra/GhidraProviderClient.ts
Line: 837

Comment:
**First errors hide reopen advice**

On a plain ELF target, `callTool` can complete startup and return a bridge error, but `providerStarted` stays false. For example, call `procedure_pseudo_code` for a missing procedure, then kill Ghidra and call `list_documents`. The new gate hides the exited health, so the caller still gets `rea doctor` advice instead of being told to reopen.

Track successful startup independently of successful tool results, and add a test for a bridge error followed by provider loss.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@morluto
morluto force-pushed the fix/1719-reopen-after-ghidra-exit branch from e960a64 to 543b14d Compare October 13, 2026 18:06

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 543b14d52f

ℹ️ 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".

return undefined;
if (
health === undefined ||
providerRetryAction(health.state) !== "restart_provider"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor the health snapshot's retry action

ProviderOperationHealth already carries the recovery decision chosen by its owner. If an exited or unreachable snapshot reports retryAction: "retry" or "unknown"—for example when the owner applies the startup-sensitive mapping supported by providerRetryAction(state, true)—this recomputation silently changes it to restart_provider, so the error tells callers to open_binary while binary_session.provider_operation_health exposes a different action. Gate on health.retryAction rather than deriving it again.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@morluto
morluto force-pushed the fix/1719-reopen-after-ghidra-exit branch from 543b14d to a106581 Compare October 13, 2026 18:23
@morluto
morluto force-pushed the fix/1719-reopen-after-ghidra-exit branch from a106581 to e1e6a2c Compare October 13, 2026 18:36
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Share tagged readiness observations, retain partial provider facts, authenticate bridge identity, bound diagnostics, and preserve cancellation and lost-session reasons. Fail closed for unparsed MIPS ABI attributes and macOS saved Hopper databases without a script-capable bridge route.

Reviewed fixes: #2010, #2108, #2513, #2695, #2731, #2771, #2828, #2867, #2868, #2870, #2880, #2919, #2945, #2961, #2981, #2998, #3000, #3002.

Validation: 285 focused source/boundary tests passed. Real Ghidra, IDA, Linux Hopper, and Windows provider runs were not repeated.

BREAKING CHANGE: MIPS targets with unresolved GNU ABI attributes and saved Hopper databases on macOS are refused rather than advertised as supported.
@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main already has this change in d4bd65c. The code is in src/ghidra/GhidraProviderClient.ts, and tells the caller to reopen the target when Ghidra exited covers it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Superseded by the lost-Ghidra-session guidance delivered on main in d4bd65c53 and current session/projection regressions. The failure retains the provider-specific reason and tells callers to reopen after provider exit rather than implying the lost session can continue. Closing this earlier proposal; #1719 is already resolved.

@morluto morluto closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thank you @RishTheFish21 for highlighting the recovery path after a Ghidra session is lost. Main provides reopen guidance for that failure.

@morluto morluto added area: providers Provider and capability discovery, including provider proposal triage provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: providers Provider and capability discovery, including provider proposal triage bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] open_binary silently short-circuits without starting a real provider client

3 participants