exec: send kernel interrupt on Ctrl+C#12
Merged
Merged
Conversation
When the CLI receives KeyboardInterrupt during execution, send an INTERRUPT request to the daemon before exiting. This ensures the remote kernel stops executing rather than continuing silently after the client disconnects. Partial results are still written to the output notebook. Exit code is 130 (standard SIGINT convention).
Race EXEC execution against reader.read(1) to detect client disconnect (EOF). When the CLI process is killed (SIGKILL from Claude Code cancel, or any other sudden death), the daemon now detects the closed socket and interrupts the remote kernel automatically. Also adds pytest-asyncio as a test dependency and configures asyncio_mode=auto in pyproject.toml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the CLI client is interrupted (Ctrl+C) during
nbexec exec, the CLI process dies but the daemon continues executing the cell on the remote kernel. The result is lost (socket closed) but the kernel keeps running indefinitely.Solution
Catch
KeyboardInterruptin_exec_oneand send anINTERRUPTrequest to the daemon before propagating. This makes Ctrl+C behave identically tonbexec interrupt --session <id>.Key details:
_send_interrupt()temporarily ignores SIGINT while sending the interrupt request (prevents a second Ctrl+C from breaking cleanup)Testing
4 new tests covering: single-cell interrupt, mid-notebook interrupt, partial output on interrupt, and interrupt-send failure resilience.