[PR #3661] [MERGED] fix(mcp): keep a snapshot open ahead of later calls on the same connection #5869

Closed
opened 2026-10-31 01:10:04 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/3661
Author: @rudycelekli
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @baron

Base: main ← Head: fix/snapshot-open-order-20261014


📝 Commits (1)

  • 8d71dd9 fix(mcp): keep a snapshot open ahead of later calls on the same connection

📊 Changes

5 files changed (+92 additions, -20 deletions)

View changed files

📝 src/application/binary/BinarySession.ts (+28 -7)
📝 src/application/binary/BinarySessionOpen.ts (+10 -0)
📝 src/application/binary/BinarySessionPort.ts (+2 -0)
📝 src/server/registerSessionTools.ts (+13 -13)
📝 tests/boundary/mcp/sessionMcp.test.ts (+39 -0)

📄 Description

Summary

open_binary with snapshot_path read the snapshot file before the open entered the session's lifecycle order, so later calls on the same connection could overtake it. Fixes #3334.

Problem and expected behavior

Smallest trigger: one MCP connection issues, without awaiting, open_binary {path, snapshot_path}, then current_document, then close_binary. Expected: same order as the equivalent calls without a snapshot. Observed on main: current_document returns Evidence for the previous target (first.hop instead of second.hop) because it ran before the open was serialized, and the later close_binary runs against the old target, leaving the snapshot target open once everything settles.

Change and scope

The MCP handler awaited readAnalysisSnapshot before calling session.open; only session.open registers a lifecycle turn. The session now accepts a loadSnapshot loader and runs it as the first step inside the open's own serialized turn (BinarySession.#open), so ordering is owned by the session rather than by the adapter. The handler passes a loader instead of a pre-read snapshot. A failed or aborted load returns its error from the same turn. The eager snapshot option stays for direct callers that already hold a parsed snapshot.

Not included: other tools that read files before taking a session turn were not audited.

Not a new provider or capability; an ordinary fix within existing boundaries (scope decision not applicable). Opened as a draft.

Contract and boundary impact

  • Semantic owner and earliest changed stage: BinarySession lifecycle serialization; MCP open_binary handler.
  • Contribution scope fit and linked maintainer decision: bug fix within existing boundaries; not applicable.
  • CLI and MCP/tool-catalog contract: none; tool schema and results unchanged. Snapshot read errors now pass through the tool-execution logger like other open failures.
  • Provider, bridge, target-format, or platform compatibility: provider independent.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; snapshot validation against target/profile is unchanged and still happens before import.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

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 or updated: tests/boundary/mcp/sessionMcp.test.ts, MCP snapshot open ordering (concurrent open-with-snapshot, current_document, close_binary; asserts the read sees second.hop and the session ends closed).
  • Base reproduction or other evidence (executed): on upstream/main the new test fails: current_document returned Evidence whose subject name and normalized_result are first.hop, expected second.hop.
  • User-visible CLI/MCP output: the failing assertion above is the observable MCP output; no separate CLI capture.
  • Remaining proof gaps: only the in-memory MCP transport with a fixture provider was used; no real Ghidra/Hopper session and no stdio client.

For evidence-bearing changes:

  • 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 tests/boundary/mcp/sessionMcp.test.ts -t "snapshot open ordering" on main: 1 failed; with the fix: pass
  • npx vitest run tests/boundary/mcp/sessionMcp.test.ts: 9 pass; src/application/binary, src/server, workflowSnapshotReplayMcp, goBinaryMcp: 16 files / 118 tests pass
  • npx tsc --noEmit -p .: clean; npx oxfmt --check src tests/boundary/mcp: clean
  • npx oxlint on touched files: only pre-existing complexity/max-params warnings
  • Not run: full test suite, npm run check:pr, CI.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. BinarySessionPort.open gains an optional loadSnapshot.
  • Real Hopper/Ghidra, browser, or OS coverage: not exercised.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none expected; the same file is read through the same bounded reader and resource scope, only later.

Author readiness

Human owner: @rudycelekli

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

🤖 Generated with Claude Code


🔄 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/3661 **Author:** [@rudycelekli](https://github.com/rudycelekli) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@baron](https://github.com/baron) **Base:** `main` ← **Head:** `fix/snapshot-open-order-20261014` --- ### 📝 Commits (1) - [`8d71dd9`](https://github.com/morluto/rea/commit/8d71dd97d904e7aef81090ca3cc6e65bfc56531d) fix(mcp): keep a snapshot open ahead of later calls on the same connection ### 📊 Changes **5 files changed** (+92 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `src/application/binary/BinarySession.ts` (+28 -7) 📝 `src/application/binary/BinarySessionOpen.ts` (+10 -0) 📝 `src/application/binary/BinarySessionPort.ts` (+2 -0) 📝 `src/server/registerSessionTools.ts` (+13 -13) 📝 `tests/boundary/mcp/sessionMcp.test.ts` (+39 -0) </details> ### 📄 Description ## Summary `open_binary` with `snapshot_path` read the snapshot file before the open entered the session's lifecycle order, so later calls on the same connection could overtake it. Fixes #3334. ## Problem and expected behavior Smallest trigger: one MCP connection issues, without awaiting, `open_binary {path, snapshot_path}`, then `current_document`, then `close_binary`. Expected: same order as the equivalent calls without a snapshot. Observed on main: `current_document` returns Evidence for the previous target (`first.hop` instead of `second.hop`) because it ran before the open was serialized, and the later `close_binary` runs against the old target, leaving the snapshot target open once everything settles. ## Change and scope The MCP handler awaited `readAnalysisSnapshot` before calling `session.open`; only `session.open` registers a lifecycle turn. The session now accepts a `loadSnapshot` loader and runs it as the first step inside the open's own serialized turn (`BinarySession.#open`), so ordering is owned by the session rather than by the adapter. The handler passes a loader instead of a pre-read snapshot. A failed or aborted load returns its error from the same turn. The eager `snapshot` option stays for direct callers that already hold a parsed snapshot. Not included: other tools that read files before taking a session turn were not audited. Not a new provider or capability; an ordinary fix within existing boundaries (scope decision not applicable). Opened as a draft. ## Contract and boundary impact - Semantic owner and earliest changed stage: `BinarySession` lifecycle serialization; MCP `open_binary` handler. - Contribution scope fit and linked maintainer decision: bug fix within existing boundaries; not applicable. - CLI and MCP/tool-catalog contract: none; tool schema and results unchanged. Snapshot read errors now pass through the tool-execution logger like other open failures. - Provider, bridge, target-format, or platform compatibility: provider independent. - Evidence, artifact, provenance, or reconstruction contract: unchanged; snapshot validation against target/profile is unchanged and still happens before import. - Target selection, authority, upstream behavior, and cleanup details: not applicable. - Generated metadata, package, or installation impact: none. 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 or updated: `tests/boundary/mcp/sessionMcp.test.ts`, `MCP snapshot open ordering` (concurrent open-with-snapshot, `current_document`, `close_binary`; asserts the read sees `second.hop` and the session ends closed). - Base reproduction or other evidence (executed): on `upstream/main` the new test fails: `current_document` returned Evidence whose subject name and `normalized_result` are `first.hop`, expected `second.hop`. - User-visible CLI/MCP output: the failing assertion above is the observable MCP output; no separate CLI capture. - Remaining proof gaps: only the in-memory MCP transport with a fixture provider was used; no real Ghidra/Hopper session and no stdio client. For evidence-bearing changes: - [x] Observed, derived, and inferred claims remain distinguishable. - [x] Artifact identity, source provenance, and failed attempts remain preserved. - [x] Unsupported, incomplete, unavailable, or uncertain outcomes remain visible. ## Validation performed - `npx vitest run tests/boundary/mcp/sessionMcp.test.ts -t "snapshot open ordering"` on main: 1 failed; with the fix: pass - `npx vitest run tests/boundary/mcp/sessionMcp.test.ts`: 9 pass; `src/application/binary`, `src/server`, `workflowSnapshotReplayMcp`, `goBinaryMcp`: 16 files / 118 tests pass - `npx tsc --noEmit -p .`: clean; `npx oxfmt --check src tests/boundary/mcp`: clean - `npx oxlint` on touched files: only pre-existing complexity/max-params warnings - Not run: full test suite, `npm run check:pr`, CI. ## Compatibility, safety, and release - Breaking changes or migration steps: none. `BinarySessionPort.open` gains an optional `loadSnapshot`. - Real Hopper/Ghidra, browser, or OS coverage: not exercised. - Package or release metadata impact: none. - Security, privacy, process, or containment review: none expected; the same file is read through the same bounded reader and resource scope, only later. ## Author readiness <!-- The human owner completes these declarations before requesting review. The PR author is the owner by default. A different owner must explicitly accept ownership on this PR. AI agents must leave these declarations to a human to dictate to them or there could be catastrophic consequences for many users of REA. Draft PRs may leave them unchecked. These declarations record initial readiness when opening the PR for review; later pushes do not require a new human sign-off. Keep the description and validation evidence current as the work changes. See CONTRIBUTING.md#pull-request-ownership-and-readiness. --> Human owner: @rudycelekli - [x] 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. - [x] I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps. - [x] I declare this PR ready for initial maintainer review. ## Before merge <!-- Draft PRs may leave pending items unchecked. Resolve material scope and authority questions before integration. --> - [x] This PR addresses a concrete problem or an agreed enhancement. - [x] Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. - [x] 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. - [x] Owning docs, contracts, and generated metadata are updated where needed. - [x] User-visible CLI/MCP changes include representative output. - [x] I checked the final diff for secrets, unrelated cleanup, and unsupported claims. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 01:10:04 +00:00
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#5869
No description provided.