Skip to content

fix(mcp): cancel evidence imports before session mutation - #1755

Merged
N0zoM1z0 merged 1 commit into
mainfrom
fix/mcp-evidence-import-cancellation
Oct 11, 2026
Merged

N0zoM1z0 merged 1 commit into
mainfrom
fix/mcp-evidence-import-cancellation

Conversation

@N0zoM1z0

Copy link
Copy Markdown
Collaborator

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.

Propagate request cancellation through immutable JSON bundle reading and
check it before committing session state. Preserve failed-close ownership.

Fixes #1746

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T07:51:41.369494Z 6b02c9d PR opened
ℹ️ 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.

@N0zoM1z0 N0zoM1z0 added area: evidence Evidence, artifacts, and reconstruction area: mcp MCP server, transport, and tool registration bug Something isn't working P2: medium Medium priority issue labels Oct 11, 2026

@N0zoM1z0 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 6b02c9d1602c6bb008d82e56f79d5a7790c8e944; independent local Luna review found no material issue. The request signal reaches the existing file reader, failed-close ownership is retained, and the final check directly precedes synchronous session mutation. The SDK regression observes handler settlement and full session preservation, then verifies retry; Linux stdio cancellation/control and 47 focused tests passed. CI is running; this is a maintainer self-review comment, not an independent GitHub approval.

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

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

unknownRevisionKey(unknown),
),
);
if (signal.aborted)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Yield before checking queued import cancellation

When cancellation arrives while readImmutableEvidenceBundle is performing synchronous bundle or process-capture validation, the MCP cancellation notification remains queued because this continuation never yields before reading signal.aborted; the check therefore remains false and session.importEvidenceBundle mutates the session despite the canceled request. readAnalysisSnapshot explicitly uses await setImmediate() before its equivalent session handoff for this reason, so yield before this check as well.

AGENTS.md reference: AGENTS.md:L5-L5

Useful? React with 👍 / 👎.

@N0zoM1z0
N0zoM1z0 merged commit e5699d2 into main Oct 11, 2026
31 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/mcp-evidence-import-cancellation branch October 11, 2026 07:59
@morluto morluto mentioned this pull request Oct 13, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction area: mcp MCP server, transport, and tool registration bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cancelled MCP evidence import still commits into the live session

1 participant