Skip to content

fix(mcp): propagate abort signal to stop test execution#38939

Closed
mxschmitt wants to merge 1 commit intomicrosoft:mainfrom
mxschmitt:fix/mcp-abort-signal
Closed

fix(mcp): propagate abort signal to stop test execution#38939
mxschmitt wants to merge 1 commit intomicrosoft:mainfrom
mxschmitt:fix/mcp-abort-signal

Conversation

@mxschmitt
Copy link
Contributor

When an MCP tool call is aborted (e.g., user cancels in Claude Code or another MCP client), the abort signal from the MCP SDK was not being propagated to the test runner, causing tests to continue running even after the call was cancelled.

This change:

  • Adds signal: AbortSignal parameter to ServerBackend.callTool
  • Passes extra.signal from MCP SDK request handler to backends
  • Listens for abort signal in runTestsWithGlobalSetupAndPossiblePause and calls testRunner.stopTests() when aborted
  • Updates all test tool handlers to accept and pass the signal

Fixes #38937

@yury-s yury-s requested a review from pavelfeldman January 26, 2026 05:38
const { testRunner, screen, claimStdio, releaseStdio } = testRunnerAndScreen;

// Stop tests when the signal is aborted
const abortHandler = () => testRunner.stopTests();
Copy link
Member

Choose a reason for hiding this comment

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

That is a synchronous callback, nothing good will happen if you just fire and forget and then start over. You'll need to serialize all the calls to the backend to support this.

Copy link
Contributor Author

@mxschmitt mxschmitt Jan 29, 2026

Choose a reason for hiding this comment

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

Fixed. Now using Promise.race with proper await testRunner.stopTests(), and added a _queue in
TestContext (same pattern as TestRunner._queue) to serialize test operations. Please re-review.

@mxschmitt mxschmitt force-pushed the fix/mcp-abort-signal branch from 83dd02e to 8b9c53b Compare January 29, 2026 19:30
- Pass AbortSignal from MCP SDK through to TestContext
- Use Promise.race to handle abort during test execution
- Add queue serialization in TestContext to ensure operations
  complete (including abort cleanup) before the next one starts
- Properly await testRunner.stopTests() when aborted

This addresses the concern about fire-and-forget abort handling.
The queue ensures that if a second call arrives while the first
is being aborted, it waits for the cleanup to complete.

Co-Authored-By: Claude <noreply@anthropic.com>

if (status === 'paused') {
if (result.type === 'aborted') {
await testRunner.stopTests();
Copy link
Member

Choose a reason for hiding this comment

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

Consider the following use case:

  • client runs tests
    • global setup runs
    • tests start to run
  • client aborts the run
  • client initiates new test run w/o waiting as per spec
    • global setup runs
  • testRunner.stop run in line 253
    • global teardown runs

@pavelfeldman
Copy link
Member

Closing as stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP test_run tool doesn't stop test execution when aborted

2 participants