[PR #5283] feat(mcp): hold several analysis targets open concurrently #6855

Open
opened 2026-11-01 21:43:34 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/5283
Author: @goncalompontes
Created: 10/19/2026
Status: 🔄 Open

Base: main ← Head: feat/multi-target-sessions


📝 Commits (1)

  • 0aff2bd feat(mcp): hold several analysis targets open concurrently

📊 Changes

49 files changed (+1669 additions, -88 deletions)

View changed files

📝 docs/mcp-contracts.md (+22 -4)
➕ docs/specs/multi-target-sessions/spec.md (+155 -0)
➕ docs/specs/multi-target-sessions/tasks.md (+58 -0)
📝 docs/tool-design.md (+6 -0)
📝 docs/user-visible-errors.csv (+2 -1)
📝 src/application/AnalysisProvider.ts (+2 -0)
📝 src/application/DirectAnalysis.ts (+7 -6)
📝 src/application/DirectAnalysisCleanup.ts (+3 -2)
📝 src/application/DirectAnalysisDependencies.ts (+9 -9)
📝 src/application/binary/BinarySession.ts (+67 -10)
📝 src/application/binary/BinarySessionComposition.ts (+6 -4)
📝 src/application/binary/BinarySessionPort.ts (+68 -8)
➕ src/application/binary/BinaryTargetRegistry.test.ts (+164 -0)
➕ src/application/binary/BinaryTargetRegistry.ts (+709 -0)
📝 src/composition/binary.ts (+12 -7)
➕ src/config/binaryTargetLimits.ts (+14 -0)
📝 src/config/environment.ts (+11 -0)
📝 src/config/parseConfig.ts (+2 -0)
📝 src/config/types.ts (+2 -0)
📝 src/contracts/officialToolContracts.ts (+4 -1)

...and 29 more files

📄 Description

Summary

Tracks #5272. One MCP server can now hold several analysis targets at once. Each target keeps its own provider process, lifecycle lock, cancellation scope, and analysis snapshot, so work on different targets no longer replaces the current target or serializes behind it.

This is a draft because #5272 changes the target-bound tool contract and needs a maintainer scope decision before integration. keep_others_open is opt-in; the default remains today's single-target replacement.

Problem and expected behavior

BinarySession owns one active binding and one transition chain. Opening another target drains calls and retires the current provider, even though each Ghidra analysis already runs in its own JVM. A game with many DLLs therefore has to be analysed one module at a time.

After this change, open_binary returns an opaque target_id. keep_others_open: true adds a slot instead of replacing the current one. Official analysis tools accept an optional target_id; omitting it addresses the current target, so existing transcripts keep working. binary_session reports target_id and open_target_ids; close_binary accepts target_id. Unknown handles return target_not_open with the open ids and no paths.

Change and scope

  • BinaryTargetRegistry (src/application/binary/BinaryTargetRegistry.ts) owns independent BinarySession slots. Slots share one investigation-record store and provider registry; each keeps its own transition lock, calls, provider client, and snapshot cache.
  • REA_MAX_OPEN_TARGETS (default 4) bounds open slots with a capacity refusal. REA_MAX_CONCURRENT_ANALYSES (default 2) bounds overlapping starts with FIFO admission.
  • Routing happens once in withAdmittedAnalysis; the selector is stripped before provider parameters and Evidence parameters.
  • Server shutdown uses closeAll; the close_binary tool still closes only the selected/current slot.
  • Added the draft design and task status in docs/specs/multi-target-sessions/, plus updates to docs/mcp-contracts.md, docs/tool-design.md, and docs/user-visible-errors.csv.

Not included in this draft:

  • target_id on enhanced workflows, native, artifact, managed, and provider-specific tools. Official analysis and lifecycle tools are covered; the remaining families follow the same admission seam.
  • rea analyze <path>... --concurrency N.
  • A real-provider concurrent-versus-serial measurement. No number is claimed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application BinaryTargetRegistry; provider clients are created per slot as before.
  • Contribution scope fit and linked maintainer decision: pending. #5272 requires an explicit maintainer scope decision for the target-bound selector.
  • CLI and MCP/tool-catalog contract: additive optional target_id on official analysis tools and lifecycle inputs; keep_others_open defaults to false; new target_not_open error code.
  • Provider, bridge, target-format, or platform compatibility: no provider protocol change. Each slot uses the existing provider lifecycle.
  • Evidence, artifact, provenance, or reconstruction contract: Evidence stays bound to the target digest. The handle is routing metadata only and is not written into provider parameters.
  • Target selection, authority, upstream behavior, and cleanup details: read-only analysis; server shutdown closes every slot.
  • Generated metadata: docs/public/product-catalog.json and skills/ are generated outputs and are not committed.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added: src/application/binary/BinaryTargetRegistry.test.ts covers reopen identity, two-target routing, replacement, capacity refusal, unknown handles, FIFO start queueing, per-slot close, and close-all shutdown. tests/boundary/mcp/multiTargetSessionMcp.test.ts drives two targets over the MCP client/server boundary with an in-memory transport, checks status handles, routed Evidence identity, target_not_open, and closing one slot.
  • Base reproduction or other evidence: the existing BinarySession composition, liveness, status, contract, and error-projection tests still pass unchanged.
  • User-visible CLI/MCP output: in-memory MCP test asserts open_binary.result.target_id, binary_session.result.target_id/open_target_ids, and target_not_open.
  • Remaining proof gaps: real Ghidra concurrency measurements; built boundary runner (npm run test:focused) could not execute in this worktree because the packaged Windows native controls are missing. The boundary test was executed directly with npx vitest run. npm run docs:check is blocked for the same native-controls reason.

Validation performed

  • npm run check:fast — passed (typecheck and lint).
  • npm run test:local -- src/application/binary/BinaryTargetRegistry.test.ts tests/composition/analysis-sessions/binarySession.test.ts — 51 passed.
  • npm run test:local -- src/domain/analysisErrorProjection.test.ts src/domain/analysisErrorCleanup.test.ts src/contracts/sessionLifecycleInputs.test.ts — 72 passed.
  • npm run test:local -- src/contracts/... tests/composition/analysis-sessions/binarySession.test.ts — 150 passed (contracts and session).
  • npx vitest run tests/boundary/mcp/multiTargetSessionMcp.test.ts — 2 passed.
  • npx vitest run tests/boundary/mcp/ghidraEvidenceMcp.test.ts tests/boundary/mcp/ghidraInventoryMcp.test.ts — 14 passed, 1 failed on the pre-existing missing Windows native controls (PrivateRuntimeRootUnavailableError), not on this change.
  • npm run docs:check — not run to completion; blocked by missing native/windows/build/manifest.json.

Compatibility, safety, and release

  • Breaking changes or migration steps: none required. target_id and keep_others_open are additive; omission preserves single-target behavior.
  • Real Hopper/Ghidra, browser, or OS coverage: no real-provider run. The fixtures exercise the application and MCP boundaries only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: no new execution, injection, mutation, or network capability. target_not_open omits paths.

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/5283 **Author:** [@goncalompontes](https://github.com/goncalompontes) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/multi-target-sessions` --- ### 📝 Commits (1) - [`0aff2bd`](https://github.com/morluto/rea/commit/0aff2bd1d177afdb12444a162680dba555ae033c) feat(mcp): hold several analysis targets open concurrently ### 📊 Changes **49 files changed** (+1669 additions, -88 deletions) <details> <summary>View changed files</summary> 📝 `docs/mcp-contracts.md` (+22 -4) ➕ `docs/specs/multi-target-sessions/spec.md` (+155 -0) ➕ `docs/specs/multi-target-sessions/tasks.md` (+58 -0) 📝 `docs/tool-design.md` (+6 -0) 📝 `docs/user-visible-errors.csv` (+2 -1) 📝 `src/application/AnalysisProvider.ts` (+2 -0) 📝 `src/application/DirectAnalysis.ts` (+7 -6) 📝 `src/application/DirectAnalysisCleanup.ts` (+3 -2) 📝 `src/application/DirectAnalysisDependencies.ts` (+9 -9) 📝 `src/application/binary/BinarySession.ts` (+67 -10) 📝 `src/application/binary/BinarySessionComposition.ts` (+6 -4) 📝 `src/application/binary/BinarySessionPort.ts` (+68 -8) ➕ `src/application/binary/BinaryTargetRegistry.test.ts` (+164 -0) ➕ `src/application/binary/BinaryTargetRegistry.ts` (+709 -0) 📝 `src/composition/binary.ts` (+12 -7) ➕ `src/config/binaryTargetLimits.ts` (+14 -0) 📝 `src/config/environment.ts` (+11 -0) 📝 `src/config/parseConfig.ts` (+2 -0) 📝 `src/config/types.ts` (+2 -0) 📝 `src/contracts/officialToolContracts.ts` (+4 -1) _...and 29 more files_ </details> ### 📄 Description ## Summary Tracks #5272. One MCP server can now hold several analysis targets at once. Each target keeps its own provider process, lifecycle lock, cancellation scope, and analysis snapshot, so work on different targets no longer replaces the current target or serializes behind it. This is a draft because #5272 changes the target-bound tool contract and needs a maintainer scope decision before integration. `keep_others_open` is opt-in; the default remains today's single-target replacement. ## Problem and expected behavior `BinarySession` owns one active binding and one transition chain. Opening another target drains calls and retires the current provider, even though each Ghidra analysis already runs in its own JVM. A game with many DLLs therefore has to be analysed one module at a time. After this change, `open_binary` returns an opaque `target_id`. `keep_others_open: true` adds a slot instead of replacing the current one. Official analysis tools accept an optional `target_id`; omitting it addresses the current target, so existing transcripts keep working. `binary_session` reports `target_id` and `open_target_ids`; `close_binary` accepts `target_id`. Unknown handles return `target_not_open` with the open ids and no paths. ## Change and scope - `BinaryTargetRegistry` (`src/application/binary/BinaryTargetRegistry.ts`) owns independent `BinarySession` slots. Slots share one investigation-record store and provider registry; each keeps its own transition lock, calls, provider client, and snapshot cache. - `REA_MAX_OPEN_TARGETS` (default 4) bounds open slots with a `capacity` refusal. `REA_MAX_CONCURRENT_ANALYSES` (default 2) bounds overlapping starts with FIFO admission. - Routing happens once in `withAdmittedAnalysis`; the selector is stripped before provider parameters and Evidence parameters. - Server shutdown uses `closeAll`; the `close_binary` tool still closes only the selected/current slot. - Added the draft design and task status in `docs/specs/multi-target-sessions/`, plus updates to `docs/mcp-contracts.md`, `docs/tool-design.md`, and `docs/user-visible-errors.csv`. Not included in this draft: - `target_id` on enhanced workflows, native, artifact, managed, and provider-specific tools. Official analysis and lifecycle tools are covered; the remaining families follow the same admission seam. - `rea analyze <path>... --concurrency N`. - A real-provider concurrent-versus-serial measurement. No number is claimed. ## Contract and boundary impact - Semantic owner and earliest changed stage: application `BinaryTargetRegistry`; provider clients are created per slot as before. - Contribution scope fit and linked maintainer decision: pending. #5272 requires an explicit maintainer scope decision for the target-bound selector. - CLI and MCP/tool-catalog contract: additive optional `target_id` on official analysis tools and lifecycle inputs; `keep_others_open` defaults to false; new `target_not_open` error code. - Provider, bridge, target-format, or platform compatibility: no provider protocol change. Each slot uses the existing provider lifecycle. - Evidence, artifact, provenance, or reconstruction contract: Evidence stays bound to the target digest. The handle is routing metadata only and is not written into provider parameters. - Target selection, authority, upstream behavior, and cleanup details: read-only analysis; server shutdown closes every slot. - Generated metadata: `docs/public/product-catalog.json` and `skills/` are generated outputs and are not committed. Expected effects: - [x] Read existing files or captured data. - [ ] Launch or attach to a process. - [ ] Inject instrumentation or run scripts/code. - [ ] Change process memory, registers, files, or configuration. - [ ] Contact network services. - [ ] Recover protected code or work around protections. - [ ] Documentation or usability only; no target interaction. - [ ] Not sure yet; investigation or maintainer guidance needed. ## Evidence and regression coverage - Tests added: `src/application/binary/BinaryTargetRegistry.test.ts` covers reopen identity, two-target routing, replacement, capacity refusal, unknown handles, FIFO start queueing, per-slot close, and close-all shutdown. `tests/boundary/mcp/multiTargetSessionMcp.test.ts` drives two targets over the MCP client/server boundary with an in-memory transport, checks status handles, routed Evidence identity, `target_not_open`, and closing one slot. - Base reproduction or other evidence: the existing `BinarySession` composition, liveness, status, contract, and error-projection tests still pass unchanged. - User-visible CLI/MCP output: in-memory MCP test asserts `open_binary.result.target_id`, `binary_session.result.target_id`/`open_target_ids`, and `target_not_open`. - Remaining proof gaps: real Ghidra concurrency measurements; built boundary runner (`npm run test:focused`) could not execute in this worktree because the packaged Windows native controls are missing. The boundary test was executed directly with `npx vitest run`. `npm run docs:check` is blocked for the same native-controls reason. ## Validation performed - `npm run check:fast` — passed (typecheck and lint). - `npm run test:local -- src/application/binary/BinaryTargetRegistry.test.ts tests/composition/analysis-sessions/binarySession.test.ts` — 51 passed. - `npm run test:local -- src/domain/analysisErrorProjection.test.ts src/domain/analysisErrorCleanup.test.ts src/contracts/sessionLifecycleInputs.test.ts` — 72 passed. - `npm run test:local -- src/contracts/... tests/composition/analysis-sessions/binarySession.test.ts` — 150 passed (contracts and session). - `npx vitest run tests/boundary/mcp/multiTargetSessionMcp.test.ts` — 2 passed. - `npx vitest run tests/boundary/mcp/ghidraEvidenceMcp.test.ts tests/boundary/mcp/ghidraInventoryMcp.test.ts` — 14 passed, 1 failed on the pre-existing missing Windows native controls (`PrivateRuntimeRootUnavailableError`), not on this change. - `npm run docs:check` — not run to completion; blocked by missing `native/windows/build/manifest.json`. ## Compatibility, safety, and release - Breaking changes or migration steps: none required. `target_id` and `keep_others_open` are additive; omission preserves single-target behavior. - Real Hopper/Ghidra, browser, or OS coverage: no real-provider run. The fixtures exercise the application and MCP boundaries only. - Package or release metadata impact: none. - Security, privacy, process, or containment review: no new execution, injection, mutation, or network capability. `target_not_open` omits paths. ## Author readiness Human owner: <!-- @GitHub-handle --> - [ ] 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`. - [x] Related issue is linked, or the reason for not linking one is stated above. - [x] 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#6855
No description provided.