Skip to content

Issue 301 - Option B - minimal implementation - #302

Merged
olaservo merged 2 commits into
mainfrom
fix/301-ctrl-c-minimal
Nov 15, 2026
Merged

olaservo merged 2 commits into
mainfrom
fix/301-ctrl-c-minimal

Conversation

@a-akimov

Copy link
Copy Markdown
Contributor

Motivation and Context

Option B from #301: quit and Ctrl+D are the clean exits, and Ctrl+C just stops the client. For comparison with #300 (option A).

  • Python: restore the default SIGINT handler, so Ctrl+C exits at once instead of hanging on the thread blocked in input()
  • TypeScript: Ctrl+C stops the client at once, also during a query (it used to wait for the pending reply). In a terminal readline takes Ctrl+C itself, so this is one rl.on("SIGINT", ...) line in place of the old process handler
  • Ruby: rescue Interrupt, so Ctrl+C exits without a backtrace
  • Go, Rust: unchanged, they already stop at once
  • READMEs: every client says quit or Ctrl+D exits cleanly and Ctrl+C stops the client at once
  • Tests: the tool-loop test presses Ctrl+C at the prompt with stdin left open and requires the client to exit within 15s

How Has This Been Tested?

Locally.

Breaking Changes

N/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Assisted by Claude Opus, reviewed by me

Copilot AI balanced review requested due to automatic review settings November 15, 2026 15:35

Copilot AI 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.

🟡 Changes recommended

The Ctrl-C regression test can pass without ever sending SIGINT and does not check stderr for the uncaught Interrupt backtrace it is intended to prevent.

2 open issues
What changed in this PR

Implements the minimal Ctrl-C behavior from issue #301 for the tutorial clients: quit and Ctrl-D remain clean exits, while Ctrl-C stops the client promptly.

Changes:

  • Adjusts interrupt handling in Python, TypeScript, and Ruby; Go and Rust code remain unchanged.
  • Documents exit behavior in all five client READMEs.
  • Adds a regression check that sends SIGINT at the prompt with stdin left open.
File Description
tests/​smoke-test.sh Updates a comment describing interrupt coverage.
tests/​README.md Documents the new Ctrl-C check.
tests/​helpers/​tool-loop-test.ts Adds a process-group interrupt check with a timeout.
mcp-client-typescript/​README.md Documents clean exits and Ctrl-C behavior.
mcp-client-typescript/​index.ts Makes readline Ctrl-C exit immediately.
mcp-client-rust/​README.md Documents clean exits and Ctrl-C behavior.
mcp-client-ruby/​README.md Documents clean exits and Ctrl-C behavior.
mcp-client-ruby/​client.rb Rescues Interrupt to suppress its backtrace.
mcp-client-python/​README.md Documents clean exits and Ctrl-C behavior.
mcp-client-python/​client.py Restores default SIGINT termination to avoid blocked-input shutdown hangs.
mcp-client-go/​README.md Documents clean exits and Ctrl-C behavior.

Review effort: Balanced

Comment thread mcp-client-ruby/client.rb Resolved
Comment thread tests/helpers/tool-loop-test.ts Resolved
Copilot AI balanced review requested due to automatic review settings November 15, 2026 16:40

Copilot AI 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.

🔵 Needs a closer look

The interrupt test only sends SIGINT at an idle prompt with piped stdio, leaving terminal Ctrl-C handling and timely exit during pending queries unverified.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Interrupt test misses Ctrl-C during pending queries

mcp-client-typescript/​index.ts:235

The new interrupt test sends an OS SIGINT only at an idle prompt with piped stdio, so it does not exercise readline's terminal SIGINT handler or interruption during a pending query. It would still pass if this handler were removed and terminal Ctrl-C reverted to waiting for the API reply. Add a held-response fake-API scenario that requires all five clients to exit within the deadline during a query, using terminal Ctrl-C input for TypeScript so this handler is covered.

1 resolved since last review

Review effort: Balanced

Copilot AI 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.

🟡 Changes recommended

The SIGINT test only covers an idle prompt with piped stdio, leaving pending-query cancellation and the terminal readline SIGINT handler untested.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread tests/helpers/tool-loop-test.ts Resolved

Copilot AI 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.

🟢 Approval recommended

The review reports no active issues with the Ctrl-C handling and exit-guidance changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@a-akimov
a-akimov requested a review from a team November 15, 2026 17:52

@olaservo olaservo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Going with Option B from #301. It fixes the two real defects (the Python hang on the blocked input() thread and the Ruby backtrace), gives TypeScript the same stop-at-once behavior in a terminal, and documents the rule in every README: quit or Ctrl-D is the clean exit, Ctrl-C just stops the client. That fits the AGENTS.md rule to leave out code that only makes an example more robust, and nothing leaks in practice since a stdio server exits when its stdin closes. The process-group SIGINT test with stdin left open covers the hang and the backtrace. CI is green. Merging.

One optional nit for a follow-up: Ruby now exits 0 after Ctrl-C while the other four exit 130. An exit 130 in the rescue Interrupt branch would make the five fully alike.


Generated by Claude Code

@olaservo
olaservo merged commit d0c5389 into main Nov 15, 2026
16 checks passed
@olaservo
olaservo deleted the fix/301-ctrl-c-minimal branch November 15, 2026 20:16
@a-akimov

Copy link
Copy Markdown
Contributor Author

Thank you, @olaservo !

@a-akimov a-akimov mentioned this pull request Nov 16, 2026
4 of 9 tasks
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.

3 participants