Skip to content

refactor(ida): launch stdio registrations through the owned MCP transport - #10739

Merged
morluto merged 14 commits into
mainfrom
refactor/ida-owned-stdio
Nov 15, 2026
Merged

morluto merged 14 commits into
mainfrom
refactor/ida-owned-stdio

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

IDA stdio registrations ran through the MCP SDK's StdioClientTransport. REA did not own that child. It had no process-group or job ownership or cleanup verification, and detach() reached into the SDK's private _process. The connection now launches stdio servers through the shared OwnedMcpStdioTransport, as JADX and rea mcp doctor already do.

Workstream W4 (lifecycle), decision (2) of the queued plan; no linked issue.

Problem and expected behavior

  • A stdio IDA server, and any workers it started, was not stopped as one owned family. Incomplete cleanup could not be reported as a ProviderCleanupError.
  • detach() used Reflect.get(transport, "_process"), which depends on SDK internals.
  • The stdio reply limit was classified by matching the SDK's ReadBuffer exceeded maximum size of N bytes message text.
  • The SDK always merged its own inherited-environment defaults, which REA blanked with empty strings.

Expected: one owned process family per stdio connection. The limit failure is classified from a typed value. Only the selected environment snapshot plus the registration's env reaches the child.

Change and scope

  • src/ida/IdaMcpConnection.ts:
    • Stdio registrations use OwnedMcpStdioTransport. Its host environment is the selected snapshot; the overrides are IDA_MCP_MAX_WORKERS=1 plus the registration env.
    • expectedCommand: null, because registrations commonly launch interpreter-driven scripts.
    • A two-second graceful end-of-input close, matching the SDK's grace before signals.
    • Stderr feeds the existing redacted 16 KiB tail through onStderr.
  • Windows launch: a bare command resolves against the registration PATH/PATHEXT with findWindowsExecutable (allowBatch). .cmd/.bat launchers run through the shared windowsBatchCommand cmd.exe invocation with verbatim arguments. Owned Windows processes require an absolute executable, and Node refuses batch files without a shell. On Windows this now depends on REA's native-control artifact; the maintainer decision accepts that.
  • Close: owned stdio teardown notifies the SDK client itself and reports incomplete cleanup as its own ProviderCleanupError (ida_mcp_close). detach() calls the transport's new detach(), which unrefs the supervised process and streams.
  • src/process/OwnedMcpStdioTransport.ts:
    • maxOperationBytes is optional. IDA bounds frames only, as it did with the SDK.
    • Frame and operation overruns throw a typed OwnedMcpOutputLimitError (scope, limitBytes). Messages are unchanged, so JADX and doctor classification is unaffected.
    • New detach().
  • Review follow-up (7bba0b9):
    • findWindowsExecutable resolves a path-qualified command (C:\Python313\python, .venv\Scripts\python) at its own location with PATHEXT, because the owned launcher's CreateProcessW call never appends an extension. IDA routes every Windows registration through it.
    • A resolved non-drive (UNC) path is refused before launch with a drive-letter remedy; the native owned launcher accepts drive paths only.
    • StructuredContentMcpClient extends OwnedMcpClient, so an SDK-initiated close after a failed handshake cannot reject unhandled.
    • OwnedMcpStdioTransport attaches an owner-supplied capturedOutput to its cleanup failure; IDA passes its redacted stderr tail.
  • Not included: the HTTP transport (unchanged), real-IDA or Windows-host verification, and UNC application paths in the native owned launcher (maintainer scope decision; it would change every owned Windows launch).

Contribution scope: existing provider, no new authority; not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: OwnedMcpStdioTransport owns the IDA stdio process and its frame limit. IdaMcpConnection consumes its typed failure. The superseded regex classification, the SDK env-default suppression and the _process reach-in are removed.
  • Contribution scope fit and linked maintainer decision: W4 decision (2), IDA stdio onto the owned transport.
  • CLI and MCP/tool-catalog contract: none. The limit failure is still AnalysisResourceConstraintError (transport, max_response_bytes).
  • Provider, bridge, target-format, or platform compatibility:
    • Windows stdio registrations now need the native-control artifact. Bare commands resolve via the registration PATH/PATHEXT rather than cross-spawn.
    • Variables in the SDK default-inheritance list that the selected snapshot omits are now absent rather than set to an empty string.
    • Replies must be valid UTF-8 (the owned transport decodes frames strictly).
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details: the IDA server and its descendants are stopped as one owned group or job after the end-of-input grace. A cleanup that cannot be confirmed is retained and retried through the existing IdaSessionClient path.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Launch or attach to a process.

Evidence and regression coverage

  • Tests added or updated (src/ida/IdaMcpEnvironment.test.ts):
    • The environment test now expects omitted variables to be absent (null), not the SDK's empty-string defaults. It stubs REA's own PATH to an ambient value again: since fix(process): run ps from fixed system locations, not REA's PATH #10755, owned cleanup runs ps from fixed system locations, so the earlier workaround that kept REA's PATH real is reverted. The child must see only the selected PATH.
    • New: a reply over a 4 KiB injected frame limit becomes the fixed transport allowance with max_response_bytes: 4096.
    • New: a C:\Tools\ida-mcp.cmd registration on win32 launches through cmd.exe /d /e:on /v:off /s /c with verbatim arguments and protocol stdin.
  • Base reproduction: with the production changes stashed, all 3 tests in src/ida/IdaMcpEnvironment.test.ts fail.
  • Remaining proof gaps: no real IDA run and no Windows host run. The Windows test checks the launch plan with an injected launcher, not WindowsOwnedProcess.

Validation performed

  • 2026-11-15, after merging current origin/main: main made protocol required on IDA registrations, so the owned-stdio fixtures now pass protocol: "legacy" (the local gate refused on this typecheck). npm run check:fast — passed; npm run test:local -- src/ida/IdaMcpEnvironment.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/ida/IdaMcpConnection.test.ts — 49 passed; architecture guards — passed.

  • npm run test:focused -- src/ida/IdaMcpEnvironment.test.ts src/ida/IdaMcpConnection.test.ts src/ida/IdaSessionClient.test.ts tests/boundary/idaStartupDiagnostics.test.ts tests/boundary/mcp/idaTransport.test.ts tests/boundary/providers/ida/retainedConnectionRetry.test.ts tests/boundary/providers/mcpHttpUtf8.test.ts src/ida/IdaProvider.test.ts src/ida/IdaStartupFailures.test.ts src/ida/IdaDoctor.test.ts: 10 files, 311 passed.

  • npm run test:focused -- src/mcpDoctor.cleanup.test.ts tests/boundary/android/jadxMcpTransport.test.ts tests/boundary/mcp/mcpStartupPolicy.test.ts (other owned-transport consumers): 23 passed.

  • Same IDA environment test file against the unfixed source: 3 failed.

  • tsc --noEmit -p tsconfig.json: passed. The pre-push check:fast hook passed.

  • After the review follow-up: npm run test:focused -- src/ida/IdaMcpConnection.test.ts tests/boundary/mcp/idaTransport.test.ts tests/boundary/android/jadxMcpTransport.test.ts src/desktop/AgentEnvComputer.test.ts src/providers/StructuredContentMcpClient.test.ts src/mcpDoctor.cleanup.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/ida/IdaMcpEnvironment.test.ts: 9 files, 202 passed. npm run test:local -- src/jeb/JebMcpConnection.test.ts src/process/WindowsExecutable.test.ts: passed. With the client and lookup fixes reverted, the new tests failed (4 failures plus an Unhandled Rejection). npm run check:fast: passed.

  • After the second review follow-up (transport-owned launch abort, temp-directory helper): npm run test:local -- src/ida/IdaMcpEnvironment.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/process/WindowsExecutable.test.ts: 17 passed; the stalled-lookup test timed out (30 s) with the abort removed. npm run test:focused -- tests/boundary/android/jadxMcpTransport.test.ts tests/boundary/process/artifactVerifierCleanupOwner.test.ts: 11 passed. npm run check:fast: passed.

  • After the third review follow-up (lookup bounded by the registration timeout): npm run test:focused -- src/ida/IdaMcpWindowsLaunch.test.ts src/ida/IdaMcpConnection.test.ts: 46 passed; the new timeout test timed out (30 s) on the previous commit. Architecture guards and the pre-push check:fast hook passed.

  • After rebasing onto main with fix(process): run ps from fixed system locations, not REA's PATH #10755 and reverting the PATH workaround: npm run test:focused -- src/ida/IdaMcpEnvironment.test.ts: 2 passed. npm run check:fast: passed.

  • After the fourth review follow-up (an uninspectable Windows candidate keeps its path and code): npm run test:local -- src/ida/IdaMcpWindowsLaunch.test.ts: 6 passed. The new case failed on the previous commit. The pre-push check:fast hook passed.

  • 2026-11-15, after merging main with the host-platform owner (refactor(platform): give the host platform one owner and ratchet ambient process.platform reads #10911): the local gate refused on the ambient-host-platform guard (process.platform default in IdaMcpConnection). Composition now passes HOST_PLATFORM.platform to the IDA connection factory, and the ambient read is gone. node scripts/verify/architecture-guards.mjs: passed. npm run check:fast: passed. npm run test:local -- src/ida/IdaMcpWindowsLaunch.test.ts src/ida/IdaMcpConnection.test.ts src/ida/IdaMcpEnvironment.test.ts: 49 passed. node scripts/verify-module-boundaries.mjs: passed.

  • macOS only.

  • After review (a failed launch's transferred ownership-preparation cleanup is owned by the transport's close and retried until released) and merging main (snapshotEnvironment now takes the host platform): npm run test:local -- src/process/OwnedMcpStdioTransport.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/ida/IdaMcpConnection.test.ts — 51 passed (the two new preparation cases failed on the previous revision); npm run test:focused -- tests/boundary/android/jadxMcpTransport.test.ts — 9 passed; npm run check:fast and architecture guards — passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none intended. On Windows, stdio registrations now need the native-control artifact, as other owned providers do.
  • Real Hopper/Ghidra, browser, or OS coverage: none; no real IDA.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: the ambient REA environment no longer reaches the child through SDK defaults. Batch arguments with cmd.exe metacharacters are refused by quoteWindowsBatchToken instead of being escaped.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • 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 Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T11:20:13.785129Z
We couldn’t complete this review. Comment @codex review to try again.
be70a99 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.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The reviewed changes appear safe to merge; failed-launch cleanup now remains owned and retryable.

Summary

Moves IDA stdio registrations to the shared owned transport. The latest change keeps cleanup from failed launches available until release succeeds.

  • IDA stdio connections keep their server process family under REA’s ownership.
  • IDA reply limits now come from typed frame errors.
  • Windows IDA registrations resolve commands before starting the server.
  • Structured-content MCP clients observe SDK-started close failures.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["IDA stdio registration"] --> B["OwnedMcpStdioTransport.start()"]
  B --> C{"Launch succeeds?"}
  C -->|Yes| D["Exchange bounded JSON-RPC messages"]
  C -->|No| E["Retain failed-launch cleanup"]
  D --> F["close()"]
  E --> F
  F --> G["Stop owned processes and release preparation resources"]
  G --> H{"Cleanup confirmed?"}
  H -->|Yes| I["Mark cleanup released"]
  H -->|No| J["Return ProviderCleanupError and retain owner"]
  J -->|Retry| F
Loading

Reviews (11) · Last reviewed commit: "fix(process): keep a failed launch's pre..." · Reviewed by Greptile

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

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Greptile's 2/5 summary reviewed 7c6da23, before the follow-up commit (now rebased onto main as the second commit on this branch). Status of each finding at the current head:

  1. Failed handshakes can stop REA — fixed. StructuredContentMcpClient now observes SDK-initiated closes the same way OwnedMcpClient does, so a rejected background close() after a failed handshake is handled while awaited cleanup still sees the rejection. Covered by src/ida/IdaMcpOwnedCleanup.test.ts.
  2. Extensionless Windows paths — fixed. findWindowsExecutable resolves path-qualified commands at their own location with PATHEXT (never on PATH), and IDA routes every Windows registration through it. Covered by src/process/WindowsExecutable.test.ts and src/ida/IdaMcpWindowsLaunch.test.ts ("appends PATHEXT to an extensionless path-qualified interpreter").
  3. Network-share executables — intentional, per maintainer decision: the owned Windows launcher creates processes from drive-letter paths only, so IDA refuses a UNC executable before launch with the remedy "map its network share to a drive letter or install the server locally" instead of reaching a guaranteed launch failure. Covered by IdaMcpWindowsLaunch.test.ts.
  4. Cleanup errors lose server output — fixed. OwnedMcpStdioTransport attaches an owner-redacted captured output to cleanup failures, and IDA passes its retained stderr tail, keeping the cleanup owner and retry behaviour. Covered by IdaMcpOwnedCleanup.test.ts.

Validation on the rebased head: npm run check:fast passed; npm run test:local -- src/ida/IdaMcpEnvironment.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/process/WindowsExecutable.test.ts — 16 passed (macOS arm64; Windows behaviour is simulated, not run on a Windows host).

@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review — the 2/5 summary predates the follow-up commit; see the status comment above for each finding.

Comment thread src/ida/IdaMcpConnection.ts Resolved
Comment thread src/ida/IdaMcpEnvironment.test.ts Resolved
@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Greptile's 4/5 findings on ed755ac, both fixed in 5cc117c:

  1. Windows lookup blocks shutdown — valid. Root cause: OwnedMcpStdioTransport gave the launcher no signal of its own, so IDA's PATH/PATHEXT lookup fell back to a signal nobody could abort, and #stop() then joined that launch. Fix at the transport (the acquisition owner): it passes the launcher a signal combined with any caller signal and aborts it with OwnerCancellation.ownerClosed before joining the start, so every owned stdio launcher, not only IDA's, stops resolving or spawning when the transport closes. IDA reports an interrupted lookup by the abort reason instead of "not found". Regression: src/ida/IdaMcpWindowsLaunch.test.ts "closes while a Windows command lookup is stalled on an unreachable PATH directory" stalls stat on a \\offline\tools PATH entry and requires close() to return; with the abort removed it times out at 30 s.
  2. Test cleanup bypasses required helper — valid. src/ida/IdaMcpEnvironment.test.ts now uses createTestTempDirectory for both of its roots (the frame-limit test and the pre-existing environment test), and the shared roots array and its rm loop are gone.

Validation: npm run check:fast passed; npm run test:local -- src/ida/IdaMcpEnvironment.test.ts src/ida/IdaMcpOwnedCleanup.test.ts src/ida/IdaMcpWindowsLaunch.test.ts src/process/WindowsExecutable.test.ts 17 passed; npm run test:focused -- tests/boundary/android/jadxMcpTransport.test.ts tests/boundary/process/artifactVerifierCleanupOwner.test.ts 11 passed (other owned stdio transport users). macOS arm64; Windows behaviour is simulated.

@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: 5cc117cc12

ℹ️ 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
…port

IDA stdio servers now run as an owned process group (POSIX) or job (Windows) through OwnedMcpStdioTransport instead of the SDK's unowned child. Windows bare commands resolve against the registration PATH/PATHEXT and .cmd/.bat launchers run through the shared WindowsBatchCommand cmd.exe invocation. The frame limit is classified from the transport's typed OwnedMcpOutputLimitError instead of parsing SDK error text, detach no longer reaches into the SDK's private _process, and the per-operation byte budget is optional.
…erpreter paths

- StructuredContentMcpClient observes SDK-initiated closes like OwnedMcpClient,
  so a failed handshake with incomplete owned cleanup cannot reject unhandled.
- OwnedMcpStdioTransport attaches an owner-redacted captured output to cleanup
  failures; IDA passes its retained stderr tail.
- findWindowsExecutable resolves path-qualified commands at their own location
  with PATHEXT; IDA routes every Windows registration through it and refuses
  non-drive paths with an actionable remedy before the owned launcher.
… closes

OwnedMcpStdioTransport passes the launcher a signal it aborts with OwnerCancellation.ownerClosed when it stops, so IDA's Windows PATH/PATHEXT lookup stalled on an unreachable directory no longer holds close() open; IDA reports the interrupted lookup by its abort reason. The IDA environment tests use createTestTempDirectory for owned temporary roots.
The PATH/PATHEXT search for a stdio registration now runs under a ProviderStartupDeadline of the registration's timeoutMs that also follows the transport's close signal. A lookup stalled on an unreachable PATH directory ends as an AnalysisTimeoutError (phase windows_path_lookup) instead of leaving connect() pending, matching Apktool's Windows lookup.
@morluto
morluto force-pushed the refactor/ida-owned-stdio branch from 7659657 to 4fc2ce2 Compare November 15, 2026 08:41
@morluto
morluto force-pushed the refactor/ida-owned-stdio branch from dbdfcd2 to 1e3400e Compare November 15, 2026 09:08
Comment thread src/ida/IdaMcpConnection.ts Resolved
@morluto

morluto commented Nov 15, 2026

Copy link
Copy Markdown
Owner Author

Greptile Issue 1 (uninspectable Windows command reported as missing): valid, fixed in ca2fe17.

  • Root cause: idaStdioLauncher folded every non-invalid_extension lookup failure from findWindowsExecutable into one "was not found" message, so the inspection failure's path and filesystem code were lost. ADB, Apktool and the update runner already keep them.
  • Fix: the inspection failure now gets its own message, with the candidate path and code (for example EACCES), and the original filesystem error is kept as cause. The "missing" wording is only used for missing. The message still goes through transportFailure, which keeps it after redaction.
  • Validation: new case in src/ida/IdaMcpWindowsLaunch.test.ts (a stat that throws EACCES). It fails on the previous code and passes now. npm run test:local -- src/ida/IdaMcpWindowsLaunch.test.ts: 6 passed. Pre-push check:fast passed.
  • Sibling sweep: the other three findWindowsExecutable callers (AdbConfiguration, ApktoolConfiguration, UpdateCommandRunner) already handle inspection separately. Nothing else to clean up.

Comment thread src/ida/IdaMcpConnection.ts Resolved
Main moved Windows PATH/PATHEXT search into src/process/executableSearch.
Path-qualified commands (resolved at their own location with PATHEXT, never on
PATH) now live in that owner's windowsPathCandidates, and findWindowsExecutable
probes its candidates.
Comment thread src/process/OwnedMcpStdioTransport.ts Resolved
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

… stdio transport's close

OwnedMcpStdioTransport discarded the launch rejection before a supervisor
existed, so an ownership-helper preparation that transferred a cleanup owner
(or reported a cleanup failure without one) was dropped and close() reported
success. The transport's close now closes each transferred owner from
processInspectionCleanupFailures, and reports a ProviderCleanupError naming the
preparation resource until it does; a later close retries it.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@morluto
morluto merged commit 998faa4 into main Nov 15, 2026
7 of 9 checks passed
@morluto
morluto deleted the refactor/ida-owned-stdio branch November 15, 2026 11:38
@morluto morluto added area: mcp MCP server, transport, and tool registration provider: ida Analysis provider / engine: ida labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration provider: ida Analysis provider / engine: ida

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant