Skip to content

fix(ida): retain bounded stderr on upstream transport failures - #2449

Merged
morluto merged 3 commits into
morluto:mainfrom
Melon-tgj:fix/ida-startup-diagnostics-20261013
Oct 13, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
Melon-tgj:fix/ida-startup-diagnostics-20261013

Conversation

@Melon-tgj

Copy link
Copy Markdown
Contributor

Summary

Retain bounded upstream stderr when the IDA MCP transport fails.

Problem and expected behavior

If an upstream IDA launcher writes its actual initialization failure to stderr and exits before MCP initialization, REA currently drains and discards that output. The caller receives only CONNECTION_CLOSED, which hides the diagnostic needed to distinguish an IDA initialization failure from a transport problem. Expected behavior is a failed operation retaining the available producer diagnostic.

Change and scope

This retains a bounded 16 KiB diagnostic tail and attaches it to genuine transport failures as ProviderAdapterError.capturedOutput, with the original byte count and explicit truncation flag. Retained bytes are copied so the tail does not keep a larger backing buffer alive. Existing transport credential redaction and failure behavior remain in place; no ambient environment is persisted. Maintainer scope decision: not applicable to this routine diagnostic fix within the existing read-only IDA adapter.

Contract and boundary impact

  • Semantic owner and earliest changed stage: IdaMcpConnection's stdio diagnostic stream.
  • Contribution scope: existing IDA analysis transport; no new provider or target execution capability.
  • CLI/MCP contract: existing error evidence gains producer stderr, byte counts and truncation state; successful results and catalog are unchanged.
  • Provider/platform compatibility: real SDK/Node child-process boundary; no IDA installation required for the regression.
  • Evidence/provenance: failed connection remains a failure; observed producer bytes remain attributed to the configured upstream.
  • Target selection/authority/cleanup: existing connection selection and close lifecycle remain in place.
  • Generated metadata/package/installation: none required by this error-evidence change.

Expected effects: the existing stdio adapter launches the configured upstream process; the added tests launch controlled Node children. No new target mutation, injection or protection recovery is introduced.

Evidence and regression coverage

  • Two real SDK/child-process boundary regressions fail against original main and pass with the fix: initialization stderr is retained, and a 20,009-byte diagnostic retains only the 16,384-byte tail with truncated: true.
  • Existing MCP connection tests pass; typecheck, lint and build pass on Node 24.20.0.
  • HTTP diagnostics and failures with no stderr preserve their existing path.

Validation performed

  • npm run test:focused -- tests/boundary/idaStartupDiagnostics.test.ts — 2 pass; both fail against original main because capturedOutput is missing.
  • npm run test:local -- src/ida/IdaMcpConnection.test.ts src/ida/IdaOperationFailures.test.ts src/domain/functionComparison.test.ts — 67 pass in the combined local validation build.
  • npm run check:fast and npm run build:cached — pass.

Compatibility, safety, and release

No migration is required. HTTP diagnostics and failures with no stderr retain their existing path. This error-evidence change does not establish real Hopper/Ghidra or OS/provider coverage. Only configured transport authentication values are redacted; arbitrary upstream producer text is preserved under the existing evidence policy. The child-process regressions require no licensed IDA installation.

Before merge

  • Concrete problem, focused title and regression coverage.
  • Final diff checked for secrets, unrelated changes and private targets.
  • Observations, failed attempts and explicit truncation remain visible.
  • Maintainer review. No separate issue is linked because this PR includes the reproducible bug and regression.

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] This PR appears safe to merge; no blocking issue remains.

Summary

This PR retains up to 16 KiB of upstream stderr on IDA transport failures, with the original byte count and an explicit truncation flag.

  • IDA transport errors can show the upstream process’s stderr.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Upstream stderr] --> B[Copied 16 KiB byte tail]
  B --> C[Transport failure]
  C --> D[Decode tail and apply credential redaction]
  D --> E[ProviderAdapterError with capturedOutput]
  E --> F[Requested operation error]
  E --> G[Cleanup error]
  E --> H[Cancellation error]
  F --> I[Public error with captured_output]
  G --> I
  H --> I
Loading

Reviews (4) · Last reviewed commit: "fix(ida): preserve cancellation and sing..." · Reviewed by Greptile

Comment thread src/ida/IdaMcpConnection.ts Resolved
Comment thread src/ida/IdaMcpConnection.ts Resolved
@morluto
morluto marked this pull request as ready for review October 13, 2026 11:47
@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-13T13:46:26.342193Z ab46104 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.

Comment thread src/ida/IdaMcpConnection.ts Resolved

@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: 179f9de299

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

Comment thread src/ida/IdaMcpConnection.ts Resolved
Address review findings at their producing boundaries and preserve directly affected consumers. Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request.

@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: 6acda019a5

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

Comment thread src/ida/IdaSessionClient.ts Resolved
Comment thread src/ida/IdaMcpConnection.ts Resolved
Comment thread src/ida/IdaMcpConnection.ts Resolved
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

IdaCleanupError discarded typed transport diagnostics. It now preserves capturedOutput, upstream diagnostic fields and the original transport reason while retaining cleanup ownership and retry resources. Added close regressions for idb_close, the final idb_list and connection.close failures.

Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request. Commit: 6acda01

  1. thread 1

The bounded byte tail could begin inside a UTF-8 code point. Projection now skips leading continuation bytes before decoding, retains the original observed byte count, and marks the dropped prefix as truncated. Added a non-ASCII 18,000-byte regression with an exact whole-character tail.

Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request. Commit: 6acda01

  1. thread 1

The transport wrapper became the public operation owner. IdaSessionClient now rebinds transport ProviderAdapterError to the requested operation while preserving captured output, partial facts and cleanup, and restores the existing recovery guidance. Added an operation-projection regression.

Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request. Commit: 6acda01

  1. thread 1

Cleanup wrapping now carries capturedOutput and upstream diagnostics into IdaCleanupError, retaining the original transport failure reason rather than the generic wrapper message. The session-close regressions cover both database cleanup calls and client.close failure without surrendering retained workspace ownership.

Source inspection and git diff --check completed. Tests and automated checks were not run at the user’s explicit request. Commit: 6acda01

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

Retained transport output caused failure classification to run before caller cancellation. Cancellation now wins first in IdaSessionClient while carrying the producing error's captured output, diagnostics, partial observation and cleanup uncertainty into AnalysisCancelledError. Added cancellation-with-stderr regression coverage. No directly related source cleanup remains.

Validation: inspected the producer and affected consumers; targeted formatting applied where applicable. Tests and automated checks were not run at the user’s explicit request. Real-provider/platform execution remains unverified. Commit: ab46104

  1. thread 1

Leading continuation bytes were trimmed even when no byte eviction occurred. The stderr tail owner now trims a partial UTF-8 prefix only after observed bytes exceed the retained tail; in-budget undecodable bytes remain represented by the decoder. Added a three-byte raw-stderr regression without truncation. No directly related source cleanup remains.

Validation: inspected the producer and affected consumers; targeted formatting applied where applicable. Tests and automated checks were not run at the user’s explicit request. Real-provider/platform execution remains unverified. Commit: ab46104

  1. thread 1

The same stderr tail was projected twice. Removed diagnostics.upstream_stderr so capturedOutput is the single owner of stderr; diagnostics retains the transport reason. Updated consumer expectations and added an assertion that the duplicate field is absent. No directly related source cleanup remains.

Validation: inspected the producer and affected consumers; targeted formatting applied where applicable. Tests and automated checks were not run at the user’s explicit request. Real-provider/platform execution remains unverified. Commit: ab46104

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: cli CLI adapter and one-shot commands area: mcp MCP server, transport, and tool registration P2: medium Medium priority issue labels Oct 13, 2026
@morluto
morluto merged commit 30e9b83 into morluto:main Oct 13, 2026
1 check passed
morluto added a commit that referenced this pull request Oct 13, 2026
The attached fixture negotiates the legacy protocol, so list_procedures
calls list_functions, never list_funcs. The list_funcs mocks added in
#2449 never fired and both tests failed on arrival. No product change.
@morluto morluto added the provider: ida Analysis provider / engine: ida label 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: mcp MCP server, transport, and tool registration area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior bug Something isn't working P2: medium Medium priority issue provider: ida Analysis provider / engine: ida

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants