Skip to content

fix(ghidra): retain launcher command outcome in launch failure diagnostics - #2011

Merged
morluto merged 2 commits into
morluto:mainfrom
sx4im:fix/ghidra-launch-failure-diagnostics
Oct 12, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
sx4im:fix/ghidra-launch-failure-diagnostics

Conversation

@sx4im

@sx4im sx4im commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1992. A failing Ghidra headless launch returned only the GhidraLaunchError name 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 session failure_cause projects it as launch_outcome, following the compiler_outcome pattern already in the codebase.

Problem and expected behavior

Smallest trigger: the POSIX LaunchSupport probe (<javaHome>/bin/java ... LaunchSupport <installRoot> -envvars / -vmargs in ghidraJavaLaunch) 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: describeCause kept only the GhidraLaunchError name, message, and code, and the nested exec error stdout/stderr never surfaced.

Change and scope

  • src/ghidra/GhidraLauncher.ts: GhidraLaunchError gains an optional capturedOutput in the shared AnalysisCapturedOutput envelope. The launch catch block extracts it from the cause with the existing execFileOutputFailure reader, 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: describeErrorCause now emits launch_outcome for GhidraLaunchError causes, with token-redacted stdout/stderr bounded to 8 KiB per stream via boundedUtf8Text, an explicit truncated flag with full byte counts when cut, plus exit_code/signal. This mirrors causeCompilerOutcome in the same file.
  • Not included: the primary failure message is unchanged, no spawn supervision changes, no doctor output changes.

Contract and boundary impact

  • Semantic owner and earliest changed stage: Ghidra provider adapter (launch) and Ghidra session failure projection. No domain contract changes.
  • CLI and MCP/tool-catalog contract: none. The failure_cause diagnostics record gains an optional launch_outcome object; existing fields are unchanged.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Process execution, authorization, cleanup, or containment impact: none; no new processes and no cleanup changes.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: src/ghidra/GhidraLaunchFailure.test.ts (4 tests).

  • Base reproduction: a stand-in bin/java script exiting 3 with known stderr makes GhidraHeadlessLauncher.launch() fail; on the base revision the error carried no capturedOutput (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 passed
  • npm run check:fast — typecheck and lint (including module boundaries) successful
  • npx oxfmt --check on the changed files — clean
  • npm run verify:test-discovery — 844 test files discovered exactly once

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: no real Ghidra on this host; the launch path was verified with a failing stand-in JVM binary on Linux (platform parameter "darwin" to mirror the issue macOS report).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: retained stderr is token-redacted and bounded to 8 KiB per stream at projection, with explicit truncation.

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.

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

chatgpt-codex-connector Bot commented Oct 12, 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-12T01:51:19.883714Z 9a0d672 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 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: 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 });

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 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.
@CassieFox23

Copy link
Copy Markdown
Contributor

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, launch_outcome. Output past 8 KiB is cut, so a reason on the last line can be lost. REA hides only its own session token, so another secret in the output stays visible.

Results

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

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
Typecheck, base not run pass not run
Typecheck, head not run pass not run
Five Ghidra test files, base not run 64 passed, 1 skipped not run
Same five files plus the PR's file, head not run 68 passed, 1 skipped not run
The PR's test file, head 4 passed 4 passed 4 passed
The PR's test file run on base code not run 3 of 4 failed not run
Real failure, launch.properties removed, base not run reason kept in the message (stack trace) not run
Same real failure, head not run same message, plus launch_outcome with exit code 1 and the same trace not run
Bad JAVA_HOME, base and head not run same JSON on both; REA says no before LaunchSupport starts not run
Stand-in jar, 3,092 bytes of stderr, base not run reason lost; message cut at 2 KiB not run
Same stand-in, head not run reason kept in launch_outcome.stderr, exit code 7, truncated: false not run
Same stand-in, failing in -vmargs, head not run reason kept, exit code 7 not run
Stand-in jar, 20,585 bytes of stderr, head not run truncated: true, 8,192 bytes kept, reason cut, byte counts shown not run
Session token echoed to stderr, head not run shown as [REDACTED] not run
Another secret echoed to stderr, head not run not redacted not run

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.

base: failure_cause.cause is the command error: code 7, message_truncated true,
      "REASON:" not in the JSON
head: failure_cause.launch_outcome:
        stdout "STUB-STDOUT-MARKER -envvars"
        stderr 3,092 bytes, ends "REASON: stub LaunchSupport failed in -envvars because the stub said so"
        truncated false, exit_code 7, signal null
      failure_cause.cause: unchanged from base (code 7, message_truncated true)

Two details about the new field:

  • Byte counts (stdout_bytes, stderr_bytes) appear only when truncated is true. In the 20,585-byte case they read 27 and 20585.
  • launch_outcome has one truncated flag. The flag text -envvars or -vmargs shows up in the command line and in the stand-in's own output.

Not run

  • The original macOS x64 failure, and native Windows or macOS.
  • A process killed by a signal, so signal was always null.
  • The rollback path where cleanup also fails. The diff keeps the output there too, but no case I ran reaches it.
  • The MCP route on real Ghidra. Only the CLI ran.
  • npm run check, which includes lint and formatting.
  • Real-world runs on Node 22 and 26.

Thanks, sx4im, for the PR.

What each case showed

Real failure, short output. I used the real LaunchSupport.jar with launch.properties removed. Base already kept the Java stack trace in the error message. Head adds the same text as separate stdout and stderr fields, plus the exit code.

Truncation. At 20,585 bytes, head kept the first 8,192 bytes of stderr. The reason on the last line was cut. stderr_bytes shows how much was lost. Real JVM errors are short, so this may never matter.

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 [REDACTED]. The stand-in also printed a made-up API_TOKEN=fake-api-token-value-9f3c1a, and head showed it in full. Base lost that line only because the message was cut. I did not check whether real LaunchSupport ever prints secrets. Only the stand-in did.

Unchanged parts. I hid the random runtime folder names. Then head's failure_cause without launch_outcome matched base's. That held in the five cases that reach LaunchSupport. REA exits 1 on every failure case, on base and on head.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: deab01f
  • Base: edf4624 (fix(targets): project invalid raw-binary loads as caller input #2004)
  • Ghidra: 12.1.4 (Apache-2.0)
  • JDK: Temurin 21.0.12.1+1 (GPL-2.0-only WITH Classpath-exception-2.0, from the JDK's own license file)
  • Ghidra ran from a scratch folder. The support folder was a copy and the other folders were links to the real install. The real install was not changed.
  • The stand-in jar is a small Java class named LaunchSupport. The real JDK 21 ran it through REA's real launch path. It replaced LaunchSupport.jar in the scratch copy only.
  • Target: a 12 KB C program built with gcc. Command: rea analyze <program> --provider ghidra --json.
  • Other agents may have shared the box. I did not check what else was running.
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 --json

Cases:

  • Remove launch.properties from the scratch copy.
  • Point JAVA_HOME at a folder that does not exist.
  • Swap in the stand-in jar. It fails in -envvars or -vmargs. It prints 3 KiB or 20 KiB of stderr. One run also echoes the session token and a made-up API_TOKEN.

#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) 🦊

@morluto
morluto merged commit d4e8ef7 into morluto:main Oct 12, 2026
31 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 12, 2026
3 tasks done
@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added area: cli CLI adapter and one-shot commands 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: cli CLI adapter and one-shot commands area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ghidra launch failures surface no actionable diagnostics (macOS)

3 participants