Repository navigation
feat(ipynb): run notebook cells in a persistent Jupyter kernel - #22581
Conversation
Replaces the fresh-process runner (which silently re-ran every earlier cell) with the user's own ipykernel, driven by a small bundled Python bridge over line-framed JSON. One kernel per open notebook: started on first Run, shut down when its tab closes or Orca exits (stdin EOF), and the kernel's own parent poller reaps it if the bridge dies. The header gains a kernel pill (workspace .venv/.conda recommended, PATH interpreters, Browse), Interrupt/Restart/Run all/Clear all, and a one-time missing-ipykernel dialog with Install. Outputs stream live per cell and are written into the document when the run finishes.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughNotebook cell execution now uses persistent Python kernels instead of one-shot Python processes. The change adds Python environment discovery, kernel startup and lifecycle IPC, kernel output conversion, and renderer session management. The editor adds kernel selection, interrupt and restart controls, run-all and clear-output actions, keyboard shortcuts, and per-cell execution status. Kernel execution is limited to local Python notebooks. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No concrete merge-blocking issue is established from the supplied evidence; proceed with normal checks. 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
Full details: Description checkExplanation The description explains the user impact, implementation, rationale, linked issue, testing, limitations, and security considerations. However, the required Visual Proof section is incomplete because it says “Not attached” instead of providing attachments or the exact required N/A statement with a reason. The Review and AI Disclosure sections are also omitted. Resolution Provide before-and-after screenshots or videos, or write exactly Full details: Linked Issues checkExplanation Issue [
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: ebf0ac25-6d06-4506-90c2-d2a123afbe46
📒 Files selected for processing (30)
resources/notebook/kernel-bridge.pysrc/main/crash-reporting/self-initiated-tree-kill-log.tssrc/main/ipc/notebook.test.tssrc/main/ipc/notebook.tssrc/main/notebook/notebook-kernel.test.tssrc/main/notebook/notebook-kernel.tssrc/main/notebook/python-environments.test.tssrc/main/notebook/python-environments.tssrc/main/refused-tree-kill-root-termination.test.tssrc/preload/api/filesystem-api.tssrc/preload/api/notebook-bridge.tssrc/renderer/src/components/editor/IpynbCellRun.tsxsrc/renderer/src/components/editor/IpynbCellToolbar.tsxsrc/renderer/src/components/editor/IpynbKernelToolbar.tsxsrc/renderer/src/components/editor/IpynbRendering.test.tsxsrc/renderer/src/components/editor/IpynbViewer.tsxsrc/renderer/src/components/editor/ipynb-cell-mutations.tssrc/renderer/src/components/editor/ipynb-kernel-outputs.test.tssrc/renderer/src/components/editor/ipynb-kernel-outputs.tssrc/renderer/src/components/editor/ipynb-kernel-session.test.tssrc/renderer/src/components/editor/ipynb-kernel-session.tssrc/renderer/src/components/editor/ipynb-kernel-store.tssrc/renderer/src/components/editor/ipynb-parse.test.tssrc/renderer/src/components/editor/ipynb-parse.tssrc/renderer/src/components/editor/useIpynbCellExecution.test.tsxsrc/renderer/src/components/editor/useIpynbCellExecution.tssrc/renderer/src/i18n/locales/en.jsonsrc/shared/child-process/__fixtures__/child-process-import-allowlist.txtsrc/shared/child-process/child-process-import-boundary.test.tssrc/shared/notebook-kernel-types.ts
💤 Files with no reviewable changes (2)
- src/shared/child-process/fixtures/child-process-import-allowlist.txt
- src/main/refused-tree-kill-root-termination.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
…the run flow - Main keys kernels per renderer, so a reload, renderer crash or closed window shuts them down, and two windows never share one notebook kernel. One close-driven cleanup replaces the separate exit and start-failure deletions. - The first run uses the nearest workspace env, else the first Python on PATH; the picker no longer opens itself, so its open state stays in the toolbar. Closing the picker brings the missing-ipykernel dialog back instead of dropping the queue, which also keeps a Browse pick's run. - Discovery marks the kernel starting, so a second run during it queues instead of starting a second kernel, and a tab closed mid-discovery no longer leaks one. - Running an nbformat 4.4 notebook gives its cells ids (upgrading to 4.5), so moving a cell mid-run cannot misroute its output. - The death notice drops stderr from before the kernel was ready (the unencrypted-TCP warning). - SSH and non-Python runs toast instead of writing a notice into the cell. - Windows conda envs are named after their folder.
There was a problem hiding this comment.
Important
Two robustness gaps worth fixing before merge: an unhandled stream error can take down the main process, and a jupyter_client version range silently breaks kernel-death reporting. Both are small, single-line fixes.
Reviewed changes
Replaces the old python3 -c "prepend every earlier cell" execution path with a persistent per-notebook Jupyter kernel driven by a Python bridge.
- Kernel bridge (
resources/notebook/kernel-bridge.py): runs under the chosen interpreter, launchessys.executable -m ipykernel_launcherthroughjupyter_client.KernelManager, diverts fd 1 to stderr so only JSON frames use real stdout, and exchanges one frame per line. Commands inexecute/interrupt; events outready/missing/output/done/exit. Closing stdin shuts the kernel down. - Main process (
src/main/ipc/notebook.ts,src/main/notebook/*): one kernel per notebook file in a moduleMapowned by the startingWebContents, stopped on restart, tab close, windowdestroyed, or bridge stdin EOF; spawned viaspawnProcessand force-killed through the shared tree-kill. Adds env discovery/probing,pip installfor ipykernel, and the kernel frame event channel. Dropsnotebook.tsfrom the directchild_processimport allowlist (pin 154→153). - Renderer: a per-notebook kernel store and session state machine (queue/pump, statuses, interrupt-stall restart offer, install flow, tab-close cleanup), a kernel pill/toolbar, a cell run gutter with live outputs committed into the document once per run, and output mapping for stream merge,
\rcollapse,clear_output(wait),update_display_data, and transient stripping. - Removed: the
runPythonCellIPC and preamble path,kernelName, and the notebook cell from the tree-kill guard/log.
Verified during review: KernelSpec/_kernel_spec/execute_interactive are compatible across jupyter_client 6.x–8.x, and execute_interactive drains IOPub to status: idle for the matching parent_header.msg_id before returning, so done cannot overtake output frames.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
uv-created venvs ship without pip, so Install failed with 'No module named pip' there. When pip is missing, bootstrap it with the stdlib's ensurepip and retry. The install moves beside the other interpreter probes, and the copyable install command comes from one helper.
…client and the Windows venv hint - Swallow stdout/stderr stream errors on the bridge child, as spawnProcess requires, so a broken pipe cannot crash main. - The bridge exits (reporting the death) even when cleanup_resources is missing (jupyter_client < 6.1.5) or raises. - The install-failure hint suggests `py -m venv .venv` on Windows.
It does what Esc does: drops the cells waiting on the kernel.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-reviewed the four commits since the prior pullfrog review (7a5e051..0fbf091); both earlier findings are now fixed, and the surrounding refactors read clean.
- Fixed kernel-death reporting on older
jupyter_client—cleanup_resources()is wrapped intry/finally, soos._exit(1)runs even when the method is absent before 6.1.5. - Guarded every child stream — no-op
errorhandlers now coverstdin/stdout/stderrinnotebook-kernel.ts, closing the unhandled-errorcrash vector. - Keyed kernels per renderer document —
kernelsOfscopes kernels to the owningWebContentsand registers one-timedid-navigate/render-process-gone/destroyedshutdowns, so two windows no longer share a kernel for the same file. - Simplified the run flow —
runCellsreservesstartingbefore environment discovery (so a concurrent run queues rather than starting a second kernel), falls back to Python on PATH, and upgrades id-less nbformat 4.4 notebooks to 4.5 cell ids before queueing. - Install and dialog polish —
installIpykernelbootstraps pip withensurepipfor envs that ship without it, the failure hint is platform-aware (pyon Windows), and the missing-ipykernel dialog gains a Cancel button.
Verified at 0fbf091: the notebook suites pass (notebook, notebook-kernel, python-environments, ipynb-kernel-session, IpynbKernelToolbar, useIpynbCellExecution, ipynb-parse), and a throwaway probe confirmed clicking "Choose Another" does not drop the queued run (Radix does not fire onOpenChange(false) on an external open change).
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 13612149-9d57-45e9-a5b4-a2979b3555cd
📒 Files selected for processing (18)
resources/notebook/kernel-bridge.pysrc/main/ipc/notebook.test.tssrc/main/ipc/notebook.tssrc/main/notebook/notebook-kernel.test.tssrc/main/notebook/notebook-kernel.tssrc/main/notebook/python-environments.test.tssrc/main/notebook/python-environments.tssrc/renderer/src/components/editor/IpynbKernelToolbar.test.tsxsrc/renderer/src/components/editor/IpynbKernelToolbar.tsxsrc/renderer/src/components/editor/IpynbViewer.tsxsrc/renderer/src/components/editor/ipynb-cell-mutations.tssrc/renderer/src/components/editor/ipynb-kernel-session.test.tssrc/renderer/src/components/editor/ipynb-kernel-session.tssrc/renderer/src/components/editor/ipynb-parse.test.tssrc/renderer/src/components/editor/useIpynbCellExecution.test.tsxsrc/renderer/src/components/editor/useIpynbCellExecution.tssrc/renderer/src/i18n/locales/en.jsonsrc/shared/notebook-kernel-types.ts
💤 Files with no reviewable changes (1)
- src/renderer/src/components/editor/IpynbViewer.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
- src/shared/notebook-kernel-types.ts
- src/renderer/src/components/editor/ipynb-kernel-session.test.ts
- src/renderer/src/i18n/locales/en.json
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
…ommand per shell - Discovery moves into start, so one catch turns a rejected listPythonEnvironments or startKernel into the usual failed start: the session returns to off with the error in the cell, instead of sticking at starting. - The copyable ipykernel command quotes the interpreter only when its path has whitespace, prefixing PowerShell's call operator on Windows. Install itself still spawns without a shell.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Re-reviewed the single commit since the prior pullfrog review (0fbf091..eea4fe4); both earlier findings remain fixed and this delta reads clean.
- Recovered from a rejected kernel start —
start()now owns environment discovery (discoverEnvironment) and wraps discovery plusstartKernelin atry/catch, turning a rejected IPC call into afailedresult that surfaces as a cell notice rather than an unhandled rejection. - Scoped the copyable install command per shell —
ipykernelInstallCommandnow takes the interpreter path and quotes it only when it contains whitespace, using PowerShell's&call operator on Windows, with callers (toolbar, install-failure message) updated.
The new ipynb-kernel-session tests cover recovery for both a rejected listPythonEnvironments and a rejected startKernel, plus the quoting cases; all 11 tests in that suite pass at eea4fe4.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: d180f106-0043-4ec8-b8c8-4d7102597c9b
📒 Files selected for processing (3)
src/renderer/src/components/editor/IpynbKernelToolbar.tsxsrc/renderer/src/components/editor/ipynb-kernel-session.test.tssrc/renderer/src/components/editor/ipynb-kernel-session.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/components/editor/ipynb-kernel-session.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
Quote the interpreter path for every path, not only ones with whitespace, so paths with shell metacharacters like & copy as a working command. Single quotes are literal in POSIX shells and PowerShell; embedded quotes are escaped per shell, and PowerShell keeps its & call operator.
There was a problem hiding this comment.
ℹ️ No critical issues — one behavioral note inline, plus a nit below.
Reviewed changes
Re-reviewed the single commit since the prior pullfrog review (eea4fe4..33a2621); it reworks the copyable ipykernel install command to always shell-quote the interpreter path.
- Always shell-quote the install command —
ipykernelInstallCommandnow single-quotes the interpreter path on every platform, escaping an embedded'as'\''for POSIX shells and''for PowerShell, and always prefixes the path with PowerShell's&call operator on Windows instead of quoting only when the path contained whitespace.
ℹ️ Nitpicks
- The
ipynb-kernel-sessiontest name "quotes the copyable install command only when the path needs it" is now stale: the implementation quotes unconditionally. Rename it (e.g. "always quotes the copyable install command") so it matches the behavior.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| // Why single quotes: literal in POSIX shells and PowerShell; PowerShell runs a quoted path via `&`. | ||
| const program = windows | ||
| ? `& '${python.replaceAll("'", "''")}'` | ||
| : `'${python.replaceAll("'", "'\\''")}'` | ||
| return `${program} -m pip install -U ipykernel` |
There was a problem hiding this comment.
On Windows this always emits PowerShell syntax (& '…'). Orca lets the user set terminalWindowsShell to cmd.exe or git-bash/wsl.exe, where & '…' is not a command invocation — the copied command fails there, whereas the previous whitespace-only quoting at least worked for a space-free path in cmd.
Technical details
# Windows install command assumes PowerShell
## Affected sites
- `src/renderer/src/components/editor/ipynb-kernel-session.ts:28-30` — the `windows` branch always emits `& '…'`, which is PowerShell-only.
- `src/renderer/src/components/editor/ipynb-kernel-session.ts:239` — the install-failure cell notice embeds the same command.
- `src/renderer/src/components/editor/IpynbKernelToolbar.tsx:249` — the missing-ipykernel dialog's "Copy command" copies the same string.
## Evidence
- `src/shared/windows-terminal-shell.ts` classifies `terminalWindowsShell` into `posix` / `cmd` / `powershell`; the default is PowerShell, but `cmd.exe` and `git-bash`/`wsl.exe` are supported settings.
- `src/renderer/src/components/settings/CliSkillRuntimeSetup.tsx:245` already reads `resolveWindowsShellStartupFamily(...)` from the renderer, so the configured family is reachable here.
- In cmd.exe `&` separates commands and `'…'` is not quoting; in bash a leading `&` is a syntax error. Only PowerShell treats `& '…'` as a call.
## Required outcome
- The copied command runs in the shell the user actually has configured, or the UI says it targets PowerShell.
## Suggested approach (optional)
- Branch on `resolveWindowsShellStartupFamily(useAppStore.getState().settings?.terminalWindowsShell)`: single-quote for posix, `& '…'` for PowerShell, `"…"` for cmd. If PowerShell-only is intentional, note it in the dialog copy.
ELI5
Running a notebook cell in Orca used to start a fresh Python every time and quietly re-run every earlier cell. Plots,
df.head()and saved variables never really worked. Now each notebook gets a real Jupyter kernel, like in Jupyter or VS Code. Variables stick around between cells, plots show inline, and you can interrupt or restart.What Changed
Before: Run spawned
python3 -cfrom PATH with every earlier code cell prepended as a silent preamble. That meant:display();After:
.venv/.condaabove the notebook), then Python on PATH, then "Browse for Python…".ipykernel: one dialog offers Install (runspip install -U ipykernelin the background), Choose Another, or Copy command..venvhint.\rprogress bars collapse;execute_result,display_data(plots) andupdate_display_data;clear_output(includingwait) and errors;input()raises the kernel's standard "frontend does not support input" error.How it works:
resources/notebook/kernel-bridge.pyruns under the chosen interpreter. It usesjupyter_clientto launchsys.executable -m ipykernel_launcherand exchanges one JSON frame per line with Orca on a private stdout. Stray prints go to stderr.execute,interrupt. Closing stdin shuts it down.ready,missing, output messages, anddone.doneis sent only after bothexecute_replyand kernel idle, so completion never races output.src/main/notebook/):spawnProcessand force-killed with the shared tree-kill.import ipykernel, jupyter_clientis checked fresh on every start and never cached. VS Code caches it and shows false "requires ipykernel" prompts.Why
We use the user's own Python and
ipykernelbecause VS Code does the same, and it adds nothing to the app's size.We talk to the kernel through
jupyter_clientin a small Python bridge rather than from Node, because the alternatives are worse:zeromqmodule for every platform and arch, plus a glibc floor. VS Code keeps a fallback build of it for exactly this reason.jupyter serverneeds a Jupyter install and a JS client.jupyter_clientalready handles connection files, message signing, Windows interrupt events and restart.The UX follows VS Code's kernel picker and ipykernel prompt, simplified to one header control and one dialog.
Linked Issue
Fixes #17075 (the execution half; the rendering half landed in #22519)
Visual Proof
Not attached. Checked interactively in a dev build against a real ipykernel on a 35-cell notebook: plots, DataFrames, state across cells, interrupt, restart, Run All, the install flow, the PEP 668 failure, and a kernel crash.
Testing
Unit tests:
\rcollapse;Real-kernel tests in
src/main/notebook/notebook-kernel.test.ts. They are skipped unlessORCA_TEST_IPYKERNEL_PYTHON/ORCA_TEST_PYTHON_WITHOUT_IPYKERNELpoint at interpreters. They passed with jupyter_client 8.10, and with 7.4.9 plus ipykernel 6.Live, in a macOS dev build:
Checks:
pnpm tc, relevant test suites,check:code-quality:changed, oxlint, oxfmt, andverify:localization-*.Not verified yet:
py -3,Scripts\python.exe, interrupt viaJPY_INTERRUPT_EVENT, taskkill, and the stdout redirect under the Windows CRT;I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Known limitations:
update_display_dataonly updates displays from the same run.Security: execution stays behind the existing per-file trust dialog, and only runs the interpreter the user picked or Orca discovered.
SSH: unchanged, local-only message.
Mobile: not affected.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)