Skip to content

fix(execd): end a Jupyter run when its kernel shuts down (release-1.3.0) - #33

Merged
thomasfowler merged 2 commits into
feat/execd-kernel-stop-1.3.0from
fix/execd-kernel-stop-1.3.0
Dec 1, 2026
Merged

thomasfowler merged 2 commits into
feat/execd-kernel-stop-1.3.0from
fix/execd-kernel-stop-1.3.0

Conversation

@thomasfowler

@thomasfowler thomasfowler commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Re-cuts the execd kernel-stop patch onto the stable release-1.3.0 tag (8408f65f). Base branch feat/execd-kernel-stop-1.3.0 is the bare tag, so this PR shows only the patch.

Upstream now covers most of what the release-1.1.1 branch carried (#31, #32): since 1.2.0 a run ends when its kernel dies (restarting/dead, KernelDied) or its websocket drops (KernelConnectionLost), and since 1.3.0 a replied run is finalized when output goes quiet. Those commits are not carried forward, and the run-message matching and wake-up patch from #32 is dropped this cycle (its cause is fixed in ipykernel 7.4.0).

  • The remaining gap: shutting a kernel down while code runs in it, which is what deleting its context does. The kernel broadcasts shutdown_reply and an idle status, both parented to the shutdown request, and exits without the cell's execute_reply. Jupyter Server keeps the websocket open, so neither KernelDied nor KernelConnectionLost fires, release-1.3.0 has no handler for shutdown_reply, and the idle does not match the run's request. The /code stream stays open, sending only pings.
  • Why it matters: deleting the context is the only way a client can stop code that ignores interrupts, such as a long join in native code, without destroying the whole sandbox.

Change (components/execd/pkg/jupyter/execute): a MsgShutdownReply constant and a handler that fails the run in flight through the existing failExecution with ename KernelStopped. Like KernelDied, it keeps an outcome the kernel already sent (the cell's own error or its reply) and releases a finalizer already waiting for the reply. One sentence in docs/api/index.md; FORK.md describes the branch.

Not covered (in FORK.md): native code that holds the GIL blocks the kernel's shutdown reply, so its run is not ended by this patch.

Commits:

  • a92280e3 fix(execd): end a Jupyter run when its kernel shuts down
  • cf2efcb6 docs(fork): describe the execd kernel-shutdown patch branch

Testing

  • go test -race -count=1 -run 'KernelShutsDown|KernelShutdown' ./pkg/jupyter/execute/ with only the MsgShutdownReply constant (no handler): both new tests fail, every case with resultChan was not closed within 3s; got 0 results.
  • With the handler: both pass, and go test -race -count=3 ./pkg/jupyter/... passes.
  • TestExecuteCodeStreamFailsWhenKernelShutsDown replays the shutdown sequence over a websocket kept open; TestExecuteCodeStreamKernelShutdownKeepsReceivedOutcome covers no reply, a matching idle without a reply (finalizer polling), an IOPub error, and an error reply.
  • Not run against a live Jupyter Server with an execd built from this branch.

Breaking Changes

  • None. Where the stream used to hang, a client sees the events of an ordinary failing cell (error with ename KernelStopped) and the stream closes.

Merge with a merge commit (not squash or rebase): an image is built from the head commit, which must stay reachable from the base branch.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Shutting a kernel down while code runs in it (for example by deleting
its context) left the POST /code stream open. The kernel broadcasts
shutdown_reply and an idle status, both parented to the shutdown
request, then exits without the execution's execute_reply. The Jupyter
server keeps the websocket open, so neither KernelDied nor
KernelConnectionLost fires, and the idle does not match the request.

Handle shutdown_reply by failing the execution with KernelStopped
through failExecution, which keeps an outcome the kernel already sent
and releases a finalizer that is waiting for the reply.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T15:23:27.683379Z cf2efcb PR opened
🔒 Security Review ✅ Completed 2026-12-01T15:24:47.712824Z cf2efcb 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.

@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: cf2efcb6e9

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

Comment thread FORK.md
Comment on lines +3 to +4
Base: upstream tag `release-1.3.0` (commit `8408f65f`), the stable 1.3.0
umbrella release.

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 Keep Markdown paragraphs on single lines

The new FORK.md hard-wraps prose paragraphs and list items throughout the file, beginning with this paragraph. Repository conventions require every Markdown paragraph and list item to remain on one line so editors handle soft wrapping; please join the wrapped prose lines without changing their content.

AGENTS.md reference: AGENTS.md:L114-L116

Useful? React with 👍 / 👎.

@thomasfowler
thomasfowler merged commit cc574a7 into feat/execd-kernel-stop-1.3.0 Dec 1, 2026
1 check passed
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.

1 participant