Repository navigation
fix(ghidra): retain launcher command outcome in launch failure diagnostics - #2011
Conversation
…stics Ghidra headless launch failures surfaced only the GhidraLaunchError name and a generic message, dropping the launcher command's exit code/signal and JVM stderr. Retain the failed command outcome on GhidraLaunchError in the shared captured-output envelope and project it as launch_outcome in the session failure_cause, mirroring the compiler_outcome diagnostics. Fixes morluto#1992
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a0d6723bf
ℹ️ 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".
| const failingJavaHome = async (script: string): Promise<string> => { | ||
| const javaHome = await mkdtemp(join(tmpdir(), "rea-fake-java-")); | ||
| await mkdir(join(javaHome, "bin"), { recursive: true }); | ||
| await writeFile(join(javaHome, "bin", "java"), script, { mode: 0o755 }); |
There was a problem hiding this comment.
Gate the POSIX JVM fixture on Windows
When this test file is run on a Windows host, failingJavaHome writes an extensionless /bin/sh script and ghidraJavaLaunch hands it directly to execFile, which Windows cannot execute; the outcome tests therefore see a spawn error (exit_code: null and no fixture stderr) instead of exits 3/1. I checked the curated Windows job in .github/workflows/ci.yml:481-512; it does not include this new file, so CI misses the failure, but a focused Windows run of this test breaks. Mark the suite as a named Windows skip (as the other Ghidra launcher script fixture does) or use a cross-platform executable fixture.
AGENTS.md reference: AGENTS.md:L46-L46
Useful? React with 👍 / 👎.
The bin/java fixture is an extensionless POSIX shell script handed to execFile, which Windows cannot execute. Follow the repo pattern (test.skipIf) so the suite is a named Windows skip.
|
TL;DR: On Linux with real Ghidra 12.1.4, a failed LaunchSupport now keeps its exit code and output in a new JSON field, ResultsBase is edf4624 (#2004). Head is deab01f, two commits on top of base. The PR's parent is base, so head is base plus the PR's three files. GitHub's merge ref targets a newer main, 538f8cc (#2037). That main does not touch the three files, so I tested head directly. Real-world runs used Node 24.18.0 only.
The three tests that failed on base are the first three in the new file. The fourth test passes on base. It checks that non-command failures keep no output. The key repro. A stand-in LaunchSupport prints 3 KiB to stderr and exits 7. The reason is on the last line. Two details about the new field:
Not run
Thanks, sx4im, for the PR. What each case showedReal failure, short output. I used the real Truncation. At 20,585 bytes, head kept the first 8,192 bytes of stderr. The reason on the last line was cut. Redaction. The redactor knows one thing: the random session token REA makes for each run. The stand-in jar read that token from the session file and printed it. Head showed Unchanged parts. I hid the random runtime folder names. Then head's Test setup
Commands# build and typecheck, each tree (Node 24, under a memory cap)
npm ci && npm run build && npm run test:prepare
npm run typecheck
npm run test:focused -- src/ghidra/GhidraSessionError.test.ts \
tests/boundary/mcp/ghidraFailureDiagnostics.test.ts \
src/ghidra/GhidraRequestQueue.test.ts \
tests/boundary/providers/ghidra/ghidraClient.test.ts \
tests/boundary/providers/ghidra/ghidraLauncher.test.ts
# the PR's test file on head (Node 22, 24, 26) and on base code
npm run test:focused -- src/ghidra/GhidraLaunchFailure.test.ts
# real-world run, per tree and per case
GHIDRA_INSTALL_DIR=<scratch copy> JAVA_HOME=<JDK 21> \
node scripts/rea.mjs analyze <program> --provider ghidra --jsonCases:
#2010 changes the same failure path; my results there are in this comment. 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
Summary
Fixes #1992. A failing Ghidra headless launch returned only the
GhidraLaunchErrorname and the generic "Ghidra headless launch failed" message. The launcher command exit code/signal and JVM stderr were dropped, so a fault in REA process spawning was indistinguishable from a broken Ghidra install. The launch error now retains the failed command outcome in the shared captured-output envelope, and the sessionfailure_causeprojects it aslaunch_outcome, following thecompiler_outcomepattern already in the codebase.Problem and expected behavior
Smallest trigger: the POSIX LaunchSupport probe (
<javaHome>/bin/java ... LaunchSupport <installRoot> -envvars/-vmargsinghidraJavaLaunch) exits non-zero, e.g. a broken JDK. Expected: failure diagnostics retain the command outcome detail (exit/signal plus bounded output), the way provider-selection failures and unexpected request failures already do. Actual:describeCausekept only theGhidraLaunchErrorname, message, and code, and the nested exec error stdout/stderr never surfaced.Change and scope
src/ghidra/GhidraLauncher.ts:GhidraLaunchErrorgains an optionalcapturedOutputin the sharedAnalysisCapturedOutputenvelope. The launch catch block extracts it from the cause with the existingexecFileOutputFailurereader, on both the primary failure and the cleanup-incomplete rollback path. Non-command failures (missing JDK home, aborts) are unchanged: no captured output.src/ghidra/GhidraSessionError.ts:describeErrorCausenow emitslaunch_outcomeforGhidraLaunchErrorcauses, with token-redacted stdout/stderr bounded to 8 KiB per stream viaboundedUtf8Text, an explicittruncatedflag with full byte counts when cut, plusexit_code/signal. This mirrorscauseCompilerOutcomein the same file.Contract and boundary impact
failure_causediagnostics record gains an optionallaunch_outcomeobject; existing fields are unchanged.Evidence and regression coverage
Tests added or updated:
src/ghidra/GhidraLaunchFailure.test.ts(4 tests).Base reproduction: a stand-in
bin/javascript exiting 3 with known stderr makesGhidraHeadlessLauncher.launch()fail; on the base revision the error carried nocapturedOutput(3 of the 4 tests failed), and all 4 pass with the fix.User-visible CLI/MCP output: session failure diagnostics now include e.g.
failure_cause: { name: "GhidraLaunchError", message: "Ghidra headless launch failed", launch_outcome: { exit_code: 3, signal: null, stdout: "", stderr: "jvm probe exploded", truncated: false } }.Remaining proof gaps: no real Ghidra install on this Linux host, so the probe path was exercised with a failing stand-in binary rather than a real JDK.
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
npx vitest run src/ghidra/GhidraLaunchFailure.test.ts— 4 passed (3 failed before the fix)npx vitest run src/ghidra/ src/domain/analysisErrorProjection.test.ts— 407 passednpm run check:fast— typecheck and lint (including module boundaries) successfulnpx oxfmt --checkon the changed files — cleannpm run verify:test-discovery— 844 test files discovered exactly onceCompatibility, safety, and release
Review checklist
type(scope): outcome.