Skip to content

Start the kernel on demand when executing scratchpad code#615

Merged
manzt merged 2 commits into
mainfrom
push-xxyusnrpwsko
Jun 24, 2026
Merged

Start the kernel on demand when executing scratchpad code#615
manzt merged 2 commits into
mainfrom
push-xxyusnrpwsko

Conversation

@manzt

@manzt manzt commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Running scratchpad code—for example from the executeCode tool an agent uses
to drive a notebook—previously required a kernel session to already be running.
If the notebook was open but no cell had been run yet, the request quietly went
nowhere and the caller was left waiting on a result that never arrived.

Start the kernel on demand instead, the same way running a cell does: resolve
the interpreter for the notebook's selected kernel and bring up a session if one
isn't already running. An agent can now act on a notebook from the very first
step rather than depending on the user to run a cell first.

When no kernel is selected at all, that's reported back as an actionable signal
rather than failing silently, so the caller can ask the user to pick one.

Copilot AI review requested due to automatic review settings June 22, 2026 18:04
@manzt manzt added the enhancement New feature or request label Jun 22, 2026

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.

Pull request overview

This PR updates scratchpad execution so the server can create a kernel session on-demand (instead of requiring a pre-existing notebook run), and propagates the selected Python executable through the scratchpad API so the correct environment can be used consistently across extension + server.

Changes:

  • Make execute-scratchpad session-scoped by including an executable and creating/recreating the server session on demand when missing (or when the executable changes).
  • Refactor sandbox controller logic to expose a reusable “resolve interpreter for this notebook” effect, and route scratchpad runs through the active controller’s resolved executable.
  • Add coverage to ensure scratchpad execution does not hang when no session exists yet.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_server.py Adds executable to scratchpad requests and adds a regression test that scratchpad creates a session when missing.
src/marimo_lsp/api.py Changes scratchpad handler to accept SessionCommand and create (or recreate) a session when needed.
extension/src/types.ts Makes execute-scratchpad use SessionScoped<> (requires executable).
extension/src/kernel/SandboxController.ts Extracts PEP-723 env sync + interpreter resolution into resolveExecutable.
extension/src/kernel/NotebookControllerFactory.ts Documents the PythonController.executable field.
extension/src/kernel/KernelManager.ts Resolves an executable from the active controller and includes it in scratchpad commands; introduces NoActiveKernelError.
extension/src/kernel/ControllerRegistry.ts Adds resolveControllerExecutable(...) helper for Python vs Sandbox controllers.
extension/src/features/RegisterLanguageModelTools.ts Improves user-facing guidance and catches NoActiveKernelError for LM tool execution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread extension/src/kernel/KernelManager.ts
Comment thread extension/src/kernel/KernelManager.ts
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Area Lines Branches Functions
Python 50.15% (545 / 1030) 39.55% (106 / 268)
TypeScript 48.95% (2364 / 4829) 40.47% (937 / 2315) 45.91% (646 / 1407)

TypeScript statements: 48.77% (2470 / 5064)

@manzt manzt force-pushed the push-xxyusnrpwsko branch from 60ec41a to a2a5cbe Compare June 23, 2026 17:09
@manzt manzt changed the title Create a kernel session on demand for scratchpad runs Start the kernel on demand when executing scratchpad code Jun 23, 2026
@manzt manzt force-pushed the push-xxyusnrpwsko branch from a2a5cbe to f04fe0f Compare June 23, 2026 17:38
@manzt manzt force-pushed the push-xxyusnrpwsko branch from f04fe0f to caeec80 Compare June 23, 2026 17:40
@manzt manzt merged commit f9375f0 into main Jun 24, 2026
10 checks passed
@manzt manzt deleted the push-xxyusnrpwsko branch June 24, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants