Start the kernel on demand when executing scratchpad code#615
Merged
Conversation
There was a problem hiding this comment.
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-scratchpadsession-scoped by including anexecutableand 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.
Contributor
Coverage Report
TypeScript statements: 48.77% (2470 / 5064) |
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.
Running scratchpad code—for example from the
executeCodetool an agent usesto 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.