Repository navigation
fix(mcp): cancel evidence imports before session mutation - #1755
Conversation
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)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
N0zoM1z0
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
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
RegularFileCleanupFailureand its live handle owner when closing fails.Contract and boundary impact
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
21650455a9c90a26e725c3505a3c17054cc4516cbecause 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.Compatibility, safety, and release
Review checklist
type(scope): outcome.