Skip to content

feat(ipynb): run notebook cells in a persistent Jupyter kernel - #22581

Merged
Jinwoo-H merged 9 commits into
mainfrom
ipynb-kernel
Sep 24, 2026
Merged

Jinwoo-H merged 9 commits into
mainfrom
ipynb-kernel

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​729 $\color{#cf222e}{\Huge{\mathbf{−}}}$​182 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​547
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1674 $\color{#cf222e}{\Huge{\mathbf{−}}}$​388 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1286

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 -c from PATH with every earlier code cell prepended as a silent preamble. That meant:

  • no persistent state;
  • no last-expression value;
  • no plots or display();
  • the wrong Python (PATH, not the project venv);
  • a 60s cap on the whole chain.

After:

  • The kernel: each notebook runs a persistent kernel from the user's own Python environment. Orca ships no Python.
  • Kernel pill in the notebook header: it shows "Select Kernel", "Starting…" or ".venv (Python 3.12)" with a busy/idle dot, and "Kernel died" on a crash.
    • Clicking it lists the recommended env first (the nearest .venv/.conda above the notebook), then Python on PATH, then "Browse for Python…".
    • The choice is remembered per notebook.
  • First Run uses the recommended env automatically.
  • Missing ipykernel: one dialog offers Install (runs pip install -U ipykernel in the background), Choose Another, or Copy command.
    • Install failures show inline in the cell, including "externally managed" system Pythons (PEP 668), with the stderr tail, the command and a .venv hint.
    • "No Python" is an inline message too.
  • Header actions: Run All, Interrupt, Restart, and Clear All Outputs. If an interrupt gets no response, the pill offers a restart.
  • Keys: Shift+Enter runs and advances; Cmd/Ctrl+Enter runs in place. Runs queue instead of being dropped.
  • Outputs:
    • streams merge, and \r progress bars collapse;
    • execute_result, display_data (plots) and update_display_data;
    • clear_output (including wait) and errors;
    • real execution counts, plus a per-cell duration.
  • input() raises the kernel's standard "frontend does not support input" error.
  • Unchanged: the one-time "Run notebook code?" trust dialog. SSH worktrees still report execution as local-only.

How it works:

  • Bridge: resources/notebook/kernel-bridge.py runs under the chosen interpreter. It uses jupyter_client to launch sys.executable -m ipykernel_launcher and exchanges one JSON frame per line with Orca on a private stdout. Stray prints go to stderr.
    • Commands in: execute, interrupt. Closing stdin shuts it down.
    • Events out: ready, missing, output messages, and done. done is sent only after both execute_reply and kernel idle, so completion never races output.
  • Main process (src/main/notebook/):
    • One kernel per notebook, started on first Run.
    • Stopped when the tab closes, the window is destroyed, or Orca exits (the stdin pipe closes).
    • Spawned through spawnProcess and force-killed with the shared tree-kill.
    • ipykernel exits with its parent, so a killed bridge leaves no orphan kernel.
  • Environment probing: import ipykernel, jupyter_client is checked fresh on every start and never cached. VS Code caches it and shows false "requires ipykernel" prompts.
  • Renderer: a small per-notebook run store. Outputs stream into the running cell and are written into the document once, when the run finishes. Only the running cell re-renders.
  • Removed: the old re-run-every-cell execution path.

Why

We use the user's own Python and ipykernel because VS Code does the same, and it adds nothing to the app's size.

We talk to the kernel through jupyter_client in a small Python bridge rather than from Node, because the alternatives are worse:

  • Speaking ZeroMQ from Node needs the native zeromq module for every platform and arch, plus a glibc floor. VS Code keeps a fallback build of it for exactly this reason.
  • Spawning a full jupyter server needs a Jupyter install and a JS client.

jupyter_client already 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:

    • output mapping, stream merge and \r collapse;
    • frame parsing;
    • env discovery;
    • the run session store and cell execution hook.
  • Real-kernel tests in src/main/notebook/notebook-kernel.test.ts. They are skipped unless ORCA_TEST_IPYKERNEL_PYTHON / ORCA_TEST_PYTHON_WITHOUT_IPYKERNEL point at interpreters. They passed with jupyter_client 8.10, and with 7.4.9 plus ipykernel 6.

  • Live, in a macOS dev build:

    • inline plots, DataFrame display, persistent state, and the last-expression value;
    • progress-bar collapse, and interrupt of a running loop;
    • restart clears state, and Run All completes;
    • install on an env without ipykernel;
    • the Homebrew PEP 668 failure shown inline;
    • "Kernel died" after a crash;
    • no processes left after closing the tab, or after quitting mid-run;
    • SIGKILLing the bridge removes the kernel within 0.7s.
  • Checks: pnpm tc, relevant test suites, check:code-quality:changed, oxlint, oxfmt, and verify:localization-*.

  • Not verified yet:

    • a packaged build, where the bridge script must be unpacked from the asar;
    • Windows: py -3, Scripts\python.exe, interrupt via JPY_INTERRUPT_EVENT, taskkill, and the stdout redirect under the Windows CRT;
    • Linux: Debian/Ubuntu system Python without pip.
  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Known limitations:

  • Cells without ids (nbformat 4.4) are keyed by index, so moving cells mid-run can misroute output.
  • update_display_data only updates displays from the same run.
  • A renderer reload leaves kernels running until the next run or app quit.
  • "Browse for Python…" drops a queued run.
  • The chosen interpreter is persisted in localStorage.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

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.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 1a617a29-4d78-4da9-a9a2-9461620f5625

📥 Commits

Reviewing files that changed from the base of the PR and between eea4fe4 and 33a2621.

📒 Files selected for processing (2)
  • src/renderer/src/components/editor/ipynb-kernel-session.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/editor/ipynb-kernel-session.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Notebook 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 33a26

No concrete merge-blocking issue is established from the supplied evidence; proceed with normal checks.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the user impact, implementation, rationale, linked issue, testing, limitations, and security considerations. However, the required Visual Proof section is incomplete because i… Provide before-and-after screenshots or videos, or write exactly N/A with a brief reason if no visual or interaction change exists. Add the required Review and AI Disclosure sections, or explicitly document why they do not apply. Reconcil…
Linked Issues check ⚠️ Warning Issue [#17075] requests rendered Markdown and integrated, inspectable notebook outputs. The PR implements persistent kernel execution, streamed output handling, output persistence, run controls, and t… Add Markdown rendering for notebook Markdown cells with automated tests for the rendered content. Keep the existing kernel execution and output coverage.
Docstring Coverage ⚠️ Warning Docstring coverage is 29.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 81 functions across 28 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: running notebook cells in a persistent Jupyter kernel.
Out of Scope Changes check ✅ Passed The changes support the execution and output objectives in [#17075]. Kernel lifecycle, Python environment discovery, IPC, streaming output conversion, renderer controls, install-command quoting, and t…
Full details: Description check

Explanation

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 N/A with a brief reason if no visual or interaction change exists. Add the required Review and AI Disclosure sections, or explicitly document why they do not apply. Reconcile the unchecked checklist items with the reported validation results.

Full details: Linked Issues check

Explanation

Issue [#17075] requests rendered Markdown and integrated, inspectable notebook outputs. The PR implements persistent kernel execution, streamed output handling, output persistence, run controls, and tests. IpynbViewer still renders cells through IpynbCellSource; the PR adds no Markdown rendering implementation or test. The linked issue coding scope remains incomplete.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ebf0ac25-6d06-4506-90c2-d2a123afbe46

📥 Commits

Reviewing files that changed from the base of the PR and between 8352752 and 7a5e051.

📒 Files selected for processing (30)
  • resources/notebook/kernel-bridge.py
  • src/main/crash-reporting/self-initiated-tree-kill-log.ts
  • src/main/ipc/notebook.test.ts
  • src/main/ipc/notebook.ts
  • src/main/notebook/notebook-kernel.test.ts
  • src/main/notebook/notebook-kernel.ts
  • src/main/notebook/python-environments.test.ts
  • src/main/notebook/python-environments.ts
  • src/main/refused-tree-kill-root-termination.test.ts
  • src/preload/api/filesystem-api.ts
  • src/preload/api/notebook-bridge.ts
  • src/renderer/src/components/editor/IpynbCellRun.tsx
  • src/renderer/src/components/editor/IpynbCellToolbar.tsx
  • src/renderer/src/components/editor/IpynbKernelToolbar.tsx
  • src/renderer/src/components/editor/IpynbRendering.test.tsx
  • src/renderer/src/components/editor/IpynbViewer.tsx
  • src/renderer/src/components/editor/ipynb-cell-mutations.ts
  • src/renderer/src/components/editor/ipynb-kernel-outputs.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-outputs.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.ts
  • src/renderer/src/components/editor/ipynb-kernel-store.ts
  • src/renderer/src/components/editor/ipynb-parse.test.ts
  • src/renderer/src/components/editor/ipynb-parse.ts
  • src/renderer/src/components/editor/useIpynbCellExecution.test.tsx
  • src/renderer/src/components/editor/useIpynbCellExecution.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/child-process/__fixtures__/child-process-import-allowlist.txt
  • src/shared/child-process/child-process-import-boundary.test.ts
  • src/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.

Comment thread src/main/ipc/notebook.ts Resolved
Comment thread src/renderer/src/i18n/locales/en.json Resolved
…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, launches sys.executable -m ipykernel_launcher through jupyter_client.KernelManager, diverts fd 1 to stderr so only JSON frames use real stdout, and exchanges one frame per line. Commands in execute/interrupt; events out ready/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 module Map owned by the starting WebContents, stopped on restart, tab close, window destroyed, or bridge stdin EOF; spawned via spawnProcess and force-killed through the shared tree-kill. Adds env discovery/probing, pip install for ipykernel, and the kernel frame event channel. Drops notebook.ts from the direct child_process import 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, \r collapse, clear_output(wait), update_display_data, and transient stripping.
  • Removed: the runPythonCell IPC 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread src/main/notebook/notebook-kernel.ts Resolved
Comment thread resources/notebook/kernel-bridge.py Resolved
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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 in try/finally, so os._exit(1) runs even when the method is absent before 6.1.5.
  • Guarded every child stream — no-op error handlers now cover stdin/stdout/stderr in notebook-kernel.ts, closing the unhandled-error crash vector.
  • Keyed kernels per renderer document — kernelsOf scopes kernels to the owning WebContents and registers one-time did-navigate / render-process-gone / destroyed shutdowns, so two windows no longer share a kernel for the same file.
  • Simplified the run flow — runCells reserves starting before 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 — installIpykernel bootstraps pip with ensurepip for envs that ship without it, the failure hint is platform-aware (py on 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).

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 13612149-9d57-45e9-a5b4-a2979b3555cd

📥 Commits

Reviewing files that changed from the base of the PR and between 7a5e051 and 0fbf091.

📒 Files selected for processing (18)
  • resources/notebook/kernel-bridge.py
  • src/main/ipc/notebook.test.ts
  • src/main/ipc/notebook.ts
  • src/main/notebook/notebook-kernel.test.ts
  • src/main/notebook/notebook-kernel.ts
  • src/main/notebook/python-environments.test.ts
  • src/main/notebook/python-environments.ts
  • src/renderer/src/components/editor/IpynbKernelToolbar.test.tsx
  • src/renderer/src/components/editor/IpynbKernelToolbar.tsx
  • src/renderer/src/components/editor/IpynbViewer.tsx
  • src/renderer/src/components/editor/ipynb-cell-mutations.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-session.ts
  • src/renderer/src/components/editor/ipynb-parse.test.ts
  • src/renderer/src/components/editor/useIpynbCellExecution.test.tsx
  • src/renderer/src/components/editor/useIpynbCellExecution.ts
  • src/renderer/src/i18n/locales/en.json
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 plus startKernel in a try/catch, turning a rejected IPC call into a failed result that surfaces as a cell notice rather than an unhandled rejection.
  • Scoped the copyable install command per shell — ipykernelInstallCommand now 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d180f106-0043-4ec8-b8c8-4d7102597c9b

📥 Commits

Reviewing files that changed from the base of the PR and between 0fbf091 and eea4fe4.

📒 Files selected for processing (3)
  • src/renderer/src/components/editor/IpynbKernelToolbar.tsx
  • src/renderer/src/components/editor/ipynb-kernel-session.test.ts
  • src/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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 — ipykernelInstallCommand now 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-session test 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +27 to +31
// 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`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Jinwoo-H
Jinwoo-H merged commit 8ba7f82 into main Sep 24, 2026
30 checks 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.

[Feature] Better jupyter notebook support

1 participant