Skip to content

feat(ipynb): create a .venv when pip is locked out, and show ipykernel setup progress - #22710

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

Jinwoo-H merged 4 commits into
mainfrom
ipynb-kernel-setup

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​255 $\color{#cf222e}{\Huge{\mathbf{−}}}$​34 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​221
Prod 19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​554 $\color{#cf222e}{\Huge{\mathbf{−}}}$​197 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​357

ELI5

To run notebook cells, Python needs a package called ipykernel. When it was missing, Orca's popup offered an Install button that often couldn't work, and gave no sign of whether anything was happening. Now the popup shows the install as it runs and shows any error. When the Python won't accept installs at all (for example Homebrew's), Orca offers to create a private project environment with ipykernel and runs the notebook there.

What Changed

Before:

  • The "Install ipykernel?" dialog had four buttons in a row.
  • Clicking Install closed the dialog right away. The only sign of progress was a small "Installing ipykernel…" label in the notebook toolbar, and any failure was written into a cell's output.
  • On Homebrew and most Linux distribution Pythons, pip refuses to install into the system Python (Python's "externally managed" rule, PEP 668). Install could never succeed there, so the dialog came back every time a cell ran.

After:

  • Detects Pythons that block pip. When ipykernel is missing, the kernel bridge (kernel-bridge.py) also reports whether pip is blocked. It does this the way pip does: it looks for the EXTERNALLY-MANAGED marker file and skips the check inside a venv.
  • Blocked Python: the dialog asks "Create a virtual environment?". Create .venv runs python -m venv .venv in the workspace root, or next to the notebook if it's outside the workspace, installs ipykernel into it, switches the notebook to it, and runs the cells that were waiting.
  • Normal Python: it's still "Install ipykernel?", but the dialog stays open while the work runs, with a spinner and "Installing…" / "Creating…" on the button.
  • Failures stay in the dialog. Python's error output appears in the dialog, the button becomes "Try again", and the queued cells keep waiting. If pip reports success but Python still can't import ipykernel, the dialog says so instead of quietly reopening.
  • Copyable command: the command box shows the matching shell line (the pip install, or the venv steps), quoted for POSIX shells or PowerShell.
  • Environment picker: a new "Create virtual environment…" entry runs the same flow, using a Python found on PATH as the base.
  • Layout: the dialog is wider. The footer is "Use another Python…" on the left, and Cancel and the main action on the right.

Why

VS Code's Jupyter extension (from microsoft/vscode-jupyter) handles the same prompt:

  • Progress: it shows install progress in a notification with live pip output and a Cancel button. Orca had nothing comparable, so this PR keeps the progress inside the dialog.
  • Environments: it offers "Create Python Environment" from the kernel picker, which creates .venv and installs ipykernel. Orca now has the same entry.
  • Blocked Pythons: it does not detect them. Its Install adds --user and fails the same way Orca's did.

Checking for the marker file up front sends people straight to the step that works, instead of a failure and then a retry.

Alternatives I didn't take:

  • Passing --break-system-packages: it can break the user's system Python, and pip warns against it.
  • Streaming live pip output: it needs a streaming hook in the shared runProcess runner. I left that for a later change; progress here is the phase (spinner plus status text), not pip's live output.

Linked Issue

N/A. This is a follow-up to #22581.

Visual Proof

Before:

pr-before.png

After: Homebrew Python, where pip is blocked:

pr-after-locked.png

After: while the environment is being created:

pr-after-progress.png

After: done, running in the new .venv:

pr-after-done.png

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Manual, macOS, dev build:

  • Opened a notebook whose Python is Homebrew python3 (3.14, pip blocked), ran a cell, and got the "Create a virtual environment?" dialog.
  • Clicked Create .venv. The dialog showed "Creating…", then .venv was created, ipykernel was installed, the kernel started in .venv, and the cell printed hello.
  • Ran the bridge directly against three Pythons: Homebrew python3 reported blocked, while Apple's /usr/bin/python3 and a fresh venv reported not blocked.

Automated:

  • The frame reader parses the new "blocked" flag.
  • createNotebookVenv runs the venv step, then the install, then describes the new Python, and returns the error when venv fails.
  • The session keeps the dialog open with the error and cells queued, reports "installed but still can't load", and runs queued cells in a newly created venv.
  • The shell commands are built correctly for POSIX and PowerShell.
  • notebookVenvParent picks the right folder.

pnpm tc, the changed-code quality gate and oxlint pass.

Not tested manually: Linux and Windows. The Windows paths go through Scripts\python.exe and the PowerShell ; separator, and are unit-tested.

Review

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

  • Remote SSH: notebook kernels already run only for files on this computer, and that is unchanged. The new IPC checks that the notebook path and workspace root are ones this workspace is allowed to access (resolveAuthorizedPath) before it runs anything.
  • Existing .venv: python -m venv without --clear keeps an existing .venv and only fills in missing pieces. The picker entry uses a Python from PATH as the base, not the currently selected one, so it never rebuilds a venv from its own interpreter.
  • Mixed versions: the kernel bridge ships with the app, so the new externallyManaged field arrives together with the code that reads it. A missing field is read as "not blocked".
  • Translations: new English strings only. Other locales fall back to English.

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)

@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

pnpm run verify:localization-catalog — a step in the PR CI workflow (.github/workflows/pr.yml:213) — fails on this branch. Deleting auto.components.editor.IpynbViewer.installFailed from en.json leaves stale copies of that key in fr.json, ja.json, ko.json, and zh.json; the verifier rejects any locale key absent from en.json.

Reviewed changes

  • PEP 668 detection in the kernel bridge — kernel-bridge.py gains externally_managed(), which mirrors pip's own check (sys.prefix != base_prefix, EXTERNALLY-MANAGED under sysconfig.get_path("stdlib")), and reports it on the missing frame.
  • Venv creation path — new notebook:createVenv IPC handler and createNotebookVenv (create .venv, install ipykernel, describe it), plus notebookVenvParent / venvInterpreterPath in src/shared.
  • Renderer flow — new IpynbKernelSetupDialog replaces the inline dialog; installIpykernel / createVirtualEnvironment keep the dialog open with progress and surface failures through setupError; new creating-venv status plus externallyManaged / setupError session fields.
  • Command helpers — ipykernelInstallCommand and venvSetupCommand move to ipynb-kernel-setup-commands.ts with POSIX/PowerShell quoting.
  • Tests — frame parsing, createNotebookVenv, venv location, session install/venv flows, and the toolbar cancel path.

⚠️ verify:localization-catalog fails: stale installFailed entries in four locales

This PR removes auto.components.editor.IpynbViewer.installFailed from en.json (it is no longer referenced anywhere), but fr.json, ja.json, ko.json, and zh.json still carry the key. verify-localization-catalog.mjs treats any locale key missing from en.json as an error (extraInLocale) and aborts the whole check on the first offender:

Locale catalog validation failed for fr.json.
extra: auto.components.editor.IpynbViewer.installFailed
Fix or retire the existing target entry in a localization PR.

The CI step will stay red until those four entries are retired.

Technical details
# Retire the orphaned IpynbViewer.installFailed entries

## Affected sites
- src/renderer/src/i18n/locales/fr.json:15030 — `auto.components.editor.IpynbViewer.installFailed`
- src/renderer/src/i18n/locales/ja.json:14927 — same key
- src/renderer/src/i18n/locales/ko.json:14927 — same key
- src/renderer/src/i18n/locales/zh.json:14927 — same key

## Required outcome
- `pnpm run verify:localization-catalog` passes: no locale entry exists that `en.json` lacks.

## Suggested approach
- Delete the four `installFailed` entries. Keeping the `en.json` key would also satisfy the gate, but the string is now dead copy.

</details>

### ℹ️ Nitpicks

- No test covers the new `notebook:createVenv` handler in `src/main/ipc/notebook.test.ts`, which already exercises the other handlers (including their authorization calls).

<!--
Pullfrog review metadata. These findings were written against b898395;
if commits have landed on ipynb-kernel-setup since, treat every specific bug, file, or
line callout as POTENTIALLY STALE and re-diff before acting on it.

- Mode: Review (initial)
- Files reviewed: 19
- Commits reviewed: 1
- Base: main (c4e58fa)
- Head: ipynb-kernel-setup (b898395)
- Reviewed commits:
  - b898395 — feat(ipynb): set up ipykernel in a new .venv when pip is locked out, and show install progress in the dialog
- Prior pullfrog review: none
-->

<!-- PULLFROG_DIVIDER_DO_NOT_REMOVE_PLZ -->
<sup><a href="https://pullfrog.com"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pullfrog.com/logos/frog-white-full-18px.png"><img src="https://pullfrog.com/logos/frog-green-full-18px.png" width="9px" height="9px" style="vertical-align: middle; " alt="Pullfrog"></picture></a>&nbsp;&nbsp;| [Fix all ➔](https://pullfrog.com/trigger/stablyai/orca/22710?action=fix&review_id=5308946776) | [Fix 👍s ➔](https://pullfrog.com/trigger/stablyai/orca/22710?action=fix-approved&review_id=5308946776) | [View workflow run](https://github.com/stablyai/orca/actions/runs/36045197087/job/107786924931) | Using `DeepSeek Flash` (free via [Pullfrog for OSS](https://pullfrog.com/for-oss)) | [𝕏](https://x.com/pullfrogai)</sup>

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

📝 Walkthrough

Walkthrough

The kernel bridge now reports whether a missing ipykernel is associated with an externally managed Python environment. The main process and preload API add notebook virtual-environment creation, including ipykernel installation and import checks. Renderer session state tracks setup progress and errors. The toolbar and setup dialog expose installation and virtual-environment actions.

Merge Risk: 🔵 Low · up to bf852

Cells queued while creating a virtual environment can be silently skipped. This is a narrow, recoverable issue, but queued execution should be preserved before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.49% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 43 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: creating a .venv when pip is blocked and showing ipykernel setup progress.
Description check ✅ Passed The description is detailed and covers the required user impact, implementation, rationale, visual proof, testing, compatibility notes, and checklist. The Linked Issue section is incomplete because it…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • 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: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: d6ceac04-23db-498b-9de2-1ebeb8d20083

📥 Commits

Reviewing files that changed from the base of the PR and between c4e58fa and b898395.

📒 Files selected for processing (19)
  • resources/notebook/kernel-bridge.py
  • 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/preload/api/filesystem-api.ts
  • src/preload/api/notebook-bridge.ts
  • src/renderer/src/components/editor/IpynbKernelSetupDialog.tsx
  • src/renderer/src/components/editor/IpynbKernelToolbar.tsx
  • src/renderer/src/components/editor/ipynb-kernel-runs.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-setup-commands.ts
  • src/renderer/src/components/editor/ipynb-kernel-store.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/notebook-kernel-types.ts
  • src/shared/notebook-venv-location.test.ts
  • src/shared/notebook-venv-location.ts

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

Comment thread src/shared/notebook-venv-location.ts Resolved

@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. The localization-catalog retirements landed cleanly and the previously blocking finding is resolved; the two nitpicks from the prior review remain open.

Reviewed changes

  • Removed the orphaned auto.components.editor.IpynbViewer.installFailed entry from fr.json, ja.json, ko.json, and zh.json, clearing the verify:localization-catalog failure flagged in the prior review.

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

…iew findings

- Kernel status now only describes the kernel; a single `setup` object (base, offer, phase, error) drives the dialog, replacing the extra statuses and the externallyManaged/setupError fields.
- The picker's 'Create virtual environment…' opens the same dialog; success switches through selectEnvironment, so a running kernel is only replaced once the venv exists.
- Async setup results are dropped when the dialog they belong to is gone (tab closed/reopened).
- main verifies ipykernel imports after pip, reuses an existing .venv instead of re-running venv over it, and explains failures that printed nothing.
- Windows copy command guards the install with if ($?); notebooks at a filesystem root get a correct .venv parent; 'Try again' shows for both retry paths.

@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

Reviewed the setup-state refactor in db3cc70 — the commit that collapsed the ad-hoc kernel statuses into a single setup object and fixed the findings from the earlier reviews.

  • Collapsed setup states into one object — missing-ipykernel / installing / creating-venv plus the flat externallyManaged / setupError fields are now setup: KernelSetup | null (base, offer, phase, error); status stays off while a setup is pending and runCells waits on setup.
  • Fixed both prior nitpicks — the dialog button label is now error && !working ? 'Try again' : copy.action, so a failed venv shows "Try again" too, and the picker's venv item no longer falls back to the selected interpreter (venvBase = environments?.path[0]).
  • Verified installs in main — installIpykernel runs python -c 'import ipykernel, jupyter_client.manager' after pip, so "pip succeeded but it still won't load" surfaces as a dialog error; failureDetail explains empty output by timeout / signal / exit code.
  • Reused existing .venv — createNotebookVenv skips python -m venv when the interpreter already exists, and notebookVenvParent keeps the root separator for a notebook at a filesystem root.
  • Command/copy cleanup — getRendererAppPlatform() replaces the user-agent check, and the PowerShell venv command guards the install with if ($?).

Both prior Pullfrog threads are resolved. Tests (ipynb-kernel-session, IpynbKernelToolbar, ipynb-kernel-setup-commands, python-environments, notebook-venv-location — 27 passing), typecheck:web, typecheck:node, and verify:localization-catalog all pass.

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: bfc334a3-a144-4478-a6f8-627a18f447fb

📥 Commits

Reviewing files that changed from the base of the PR and between f7451af and db3cc70.

📒 Files selected for processing (18)
  • src/main/notebook/notebook-kernel.test.ts
  • src/main/notebook/python-environments.test.ts
  • src/main/notebook/python-environments.ts
  • src/renderer/src/components/editor/IpynbKernelSetupDialog.tsx
  • src/renderer/src/components/editor/IpynbKernelToolbar.test.tsx
  • 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
  • src/renderer/src/components/editor/ipynb-kernel-setup-commands.test.ts
  • src/renderer/src/components/editor/ipynb-kernel-setup-commands.ts
  • src/renderer/src/components/editor/ipynb-kernel-store.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/notebook-venv-location.test.ts
  • src/shared/notebook-venv-location.ts
💤 Files with no reviewable changes (4)
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/notebook/python-environments.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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Preserve queued cells when creating a virtual environment from a… · ipynb-kernel-session.ts:248-250

src/renderer/src/components/editor/ipynb-kernel-session.ts:248-250
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve queued cells when creating a virtual environment from a ready kernel.

If a cell is running when the setup dialog opens, runCells queues later cells. Successful creation calls selectEnvironment, which restarts the ready kernel. stopRuns clears the queue, so those cells are lost instead of running in the new environment.

Suggested fix
@@
-export function restartKernel(filePath: string): void {
-  updateSession(filePath, stopRuns)
+export function restartKernel(filePath: string, keepQueue = false): void {
+  updateSession(filePath, (session) => ({
+    ...stopRuns(session),
+    ...(keepQueue ? { queue: session.queue } : {})
+  }))
   void start(filePath)
 }
 
 export function selectEnvironment(filePath: string, environment: PythonEnvironment): void {
+  const keepQueue = getSession(filePath).setup !== null
   setEnvironment(filePath, environment)
@@
   if (getSession(filePath).status === 'off') {
     void start(filePath)
   } else {
-    restartKernel(filePath)
+    restartKernel(filePath, keepQueue)
   }
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 046a43c3-3123-4183-872f-6f975a4e770c

📥 Commits

Reviewing files that changed from the base of the PR and between db3cc70 and bf8528c.

📒 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; 8 remain after this review.

@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

Reviewed bf8528cc — the only commit since the prior pullfrog review — which fixes the setup prompt lingering after a different interpreter is picked.

  • Picking another Python closes the setup prompt — selectEnvironment now clears an idle setup right after setEnvironment, so the missing-ipykernel / Create a virtual environment? dialog closes when the user chooses a different interpreter and the waiting cells run there; if the newly picked interpreter also lacks ipykernel, start reopens the prompt.
  • In-flight setup is preserved — the phase === 'idle' guard keeps the setup visible through installing / creating-venv, including createVirtualEnvironment's success path (which calls selectEnvironment while creating-venv and lets start clear the setup on ready).
  • Regression test added — the new session test asserts setup === null after the pick, checks the new interpreter's startKernel call, and confirms the queued cell executes. The toBeNull() assertion fails against the pre-bf8528cc code, so it is a real regression test.

Both prior pullfrog threads on this PR are already resolved.

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

@Jinwoo-H
Jinwoo-H merged commit 5610b11 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.

1 participant