[PR #1755] [MERGED] fix(mcp): cancel evidence imports before session mutation #4797

Closed
opened 2026-10-31 00:55:09 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/1755
Author: @N0zoM1z0
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @N0zoM1z0

Base: main ← Head: fix/mcp-evidence-import-cancellation


📝 Commits (1)

  • 6b02c9d fix(mcp): cancel evidence imports before session mutation

📊 Changes

5 files changed (+235 additions, -12 deletions)

View changed files

📝 src/application/EvidenceBundleFiles.ts (+28 -6)
📝 src/application/JsonFiles.ts (+5 -2)
📝 src/server/registerSessionRecordTools.ts (+10 -3)
📝 tests/boundary/filesystem/evidenceBundleFiles.test.ts (+53 -1)
➕ tests/boundary/mcp/evidenceImportCancellation.test.ts (+139 -0)

📄 Description

Summary

Fixes #1746. Cancelling an MCP Evidence import during file reading now stops the reader and leaves the session unchanged; a subsequent import still succeeds.

Problem and expected behavior

Previously, the SDK rejected the cancelled client request while the server continued reading and committed the entire bundle. Cancellation observed before the synchronous import must preserve the existing session and release the owned file handle.

Change and scope

Propagate the request signal through the immutable bundle and JSON readers, return typed import cancellation, and check it immediately before session mutation. Preserve RegularFileCleanupFailure and its live handle owner when closing fails.

Contract and boundary impact

  • Semantic owner and earliest changed stage: application file reading and MCP import lifecycle.
  • CLI and MCP/tool-catalog contract: unchanged inputs and output schemas; MCP import now honors request cancellation.
  • Provider, bridge, target-format, or platform compatibility: provider-neutral regular JSON files; no bridge changes.
  • Evidence, artifact, provenance, or reconstruction contract: immutable authentication unchanged; cancelled imports retain the complete prior session.
  • Process execution, authorization, cleanup, or containment impact: cancel the existing reader; retain ownership on failed cleanup.
  • Generated metadata, package, or installation impact: none.

Evidence and regression coverage

  • Tests added or updated: real SDK cancellation with handler-settlement observation, complete session comparison, ping and retry; pre-aborted input and simultaneous abort/close-failure ownership.

  • Base reproduction: the new SDK regression failed on 21650455a9c90a26e725c3505a3c17054cc4516c because the cancelled import added a record.

  • User-visible MCP output: client cancellation; session remains unchanged. Uncancelled import returns the usual result.

  • Remaining proof gaps: cancellation cannot interrupt synchronous validation or mutation mid-turn; no such claim is made.

  • 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

  • npm run test:focused -- tests/boundary/mcp/evidenceImportCancellation.test.ts tests/boundary/mcp/evidenceExportCancellation.test.ts tests/boundary/filesystem/evidenceBundleFiles.test.ts tests/boundary/filesystem/cliJsonInput.test.ts tests/boundary/cli/evidenceBundleCommands.test.ts — 47 tests passed.
  • npm run test:focused -- tests/boundary/mcp/evidenceImportCancellation.test.ts — final test revision passed.
  • npm run check — passed typecheck, lint, format, knip, metadata and architecture checks.
  • npm run verify:test-discovery — all 814 files discovered exactly once.
  • Real Linux stdio MCP probe with 128 MiB valid whitespace-prefixed bundle — matched cancellation notification; 0 records/0 Unknowns afterward, closed descriptor, successful ping and owned server exit. Uncancelled control retained the full 1-record/1-Unknown bundle.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux stdio exercised; providers not invoked. Other OS coverage is CI.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: selected file and authenticated Evidence preserved; no ambient-environment persistence or target execution.

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.

🔄 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/1755 **Author:** [@N0zoM1z0](https://github.com/N0zoM1z0) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/11/2026 **Merged by:** [@N0zoM1z0](https://github.com/N0zoM1z0) **Base:** `main` ← **Head:** `fix/mcp-evidence-import-cancellation` --- ### 📝 Commits (1) - [`6b02c9d`](https://github.com/morluto/rea/commit/6b02c9d1602c6bb008d82e56f79d5a7790c8e944) fix(mcp): cancel evidence imports before session mutation ### 📊 Changes **5 files changed** (+235 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src/application/EvidenceBundleFiles.ts` (+28 -6) 📝 `src/application/JsonFiles.ts` (+5 -2) 📝 `src/server/registerSessionRecordTools.ts` (+10 -3) 📝 `tests/boundary/filesystem/evidenceBundleFiles.test.ts` (+53 -1) ➕ `tests/boundary/mcp/evidenceImportCancellation.test.ts` (+139 -0) </details> ### 📄 Description ## Summary Fixes #1746. Cancelling an MCP Evidence import during file reading now stops the reader and leaves the session unchanged; a subsequent import still succeeds. ## Problem and expected behavior Previously, the SDK rejected the cancelled client request while the server continued reading and committed the entire bundle. Cancellation observed before the synchronous import must preserve the existing session and release the owned file handle. ## Change and scope Propagate the request signal through the immutable bundle and JSON readers, return typed import cancellation, and check it immediately before session mutation. Preserve `RegularFileCleanupFailure` and its live handle owner when closing fails. ## Contract and boundary impact - Semantic owner and earliest changed stage: application file reading and MCP import lifecycle. - CLI and MCP/tool-catalog contract: unchanged inputs and output schemas; MCP import now honors request cancellation. - Provider, bridge, target-format, or platform compatibility: provider-neutral regular JSON files; no bridge changes. - Evidence, artifact, provenance, or reconstruction contract: immutable authentication unchanged; cancelled imports retain the complete prior session. - Process execution, authorization, cleanup, or containment impact: cancel the existing reader; retain ownership on failed cleanup. - Generated metadata, package, or installation impact: none. ## Evidence and regression coverage - Tests added or updated: real SDK cancellation with handler-settlement observation, complete session comparison, ping and retry; pre-aborted input and simultaneous abort/close-failure ownership. - Base reproduction: the new SDK regression failed on `21650455a9c90a26e725c3505a3c17054cc4516c` because the cancelled import added a record. - User-visible MCP output: client cancellation; session remains unchanged. Uncancelled import returns the usual result. - Remaining proof gaps: cancellation cannot interrupt synchronous validation or mutation mid-turn; no such claim is made. - [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 - `npm run test:focused -- tests/boundary/mcp/evidenceImportCancellation.test.ts tests/boundary/mcp/evidenceExportCancellation.test.ts tests/boundary/filesystem/evidenceBundleFiles.test.ts tests/boundary/filesystem/cliJsonInput.test.ts tests/boundary/cli/evidenceBundleCommands.test.ts` — 47 tests passed. - `npm run test:focused -- tests/boundary/mcp/evidenceImportCancellation.test.ts` — final test revision passed. - `npm run check` — passed typecheck, lint, format, knip, metadata and architecture checks. - `npm run verify:test-discovery` — all 814 files discovered exactly once. - Real Linux stdio MCP probe with 128 MiB valid whitespace-prefixed bundle — matched cancellation notification; 0 records/0 Unknowns afterward, closed descriptor, successful ping and owned server exit. Uncancelled control retained the full 1-record/1-Unknown bundle. ## Compatibility, safety, and release - Breaking changes or migration steps: none. - Real Hopper/Ghidra, browser, or OS coverage: Linux stdio exercised; providers not invoked. Other OS coverage is CI. - Package or release metadata impact: none. - Security, privacy, process, or containment review: selected file and authenticated Evidence preserved; no ambient-environment persistence or target execution. ## Review checklist - [x] This PR addresses a concrete problem or an agreed enhancement. - [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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 00:55:09 +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#4797
No description provided.