Skip to content

fix(notebook): run cells only when the resolved owner is this computer - #30187

Merged
nwparker merged 1 commit into
mainfrom
nwparker/ipynb-exec-owner
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/ipynb-exec-owner

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​121 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57 $\color{#cf222e}{\Huge{\mathbf{−}}}$​16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41

ELI5

Orca can run Jupyter notebook cells, but only on this computer. It decided whether a notebook was on this computer by checking whether the workspace had an SSH connection id. Workspaces served by a managed SSH server (or any paired Orca server) have no SSH connection id, so Orca took them for local and offered to run their cells here. Now Orca asks the shared ownership resolver which host owns the workspace, and runs cells only when the answer is "this computer".

What Changed

Before: opening a .ipynb in a managed-SSH or paired-server workspace showed the kernel toolbar (Run all, kernel picker), and the per-cell run buttons started a kernel in the desktop's own Python. Usually that failed because the remote path doesn't exist locally. But if a file with the same path existed on this computer, the remote notebook's cells ran in local Python against it. The same thing happened while the workspace rows were still loading, or when two hosts published the same workspace: both cases also read as "no connection id".

After: the kernel toolbar shows only when the owner resolves to this computer. Clicking a cell's run button anywhere else shows a toast and starts nothing:

  • Owned by an SSH target or a paired/managed server: "Notebook cells can only run for files on this computer." (the existing message; there is no remote kernel path yet)
  • Owner missing (rows not loaded) or ambiguous (two hosts publish it): "Orca can't tell which computer this notebook is on yet, so its cells can't run."

Mechanism: a new resolveNotebookExecutionHost (src/renderer/src/components/editor/ipynb-execution-host.ts) calls resolveOwner. It returns local only for { endpoint: self, at: local }, remote for any other resolved owner, and unresolved for missing or ambiguous. useIpynbCellExecution (the run gate) and IpynbViewer (the toolbar gate) both use it instead of getConnectionId.

Why

resolveOwner is the canonical, focus-free resolver. It already models paired servers, SSH targets behind servers, folder workspaces and twins, so reusing it keeps the notebook in step with every other host decision. Patching getConnectionId to return something for runtime owners would change dozens of unrelated callers that forward the id to host-routed IPC. Remote kernel execution would be a separate feature, so remote owners get a clear refusal instead of being routed.

Other "no connection id means local" sites I audited (none needed a change; kept out of this PR to keep it tight):

  • terminal-native-file-drop.ts:76 checks the runtime owner first and returns before the connectionId branch.
  • terminal-file-path-mapping.ts:46 checks the runtime target and the ambiguous route first.
  • WorktreeOpenInMenu.tsx: getLocalPathOpenOwnerForRoute already takes the runtime environment and an unresolved flag.
  • editor-external-watch-targets.ts:214, parent-pr-checks-github-pr-cache.ts:78, repo-scan-failure.ts:32, use-linked-reviews.ts:93, workspace-session.ts:271, RepositoryPane.tsx:382 and settings-view-model.ts:109 gate SSH-relay-specific behaviour or display, not local execution. Runtime-owned rows take their own paths, and several of these also check executionHostId.
  • The getConnectionId(...) ?? undefined call sites in source control, checks and agent launch pass the id on to IPC that is routed separately by the runtime owner. They are not local-ownership gates.

Linked Issue

A reviewer finding (P2) on the host-ownership hardening work. No issue was filed.

Visual Proof

N/A: the only visible change is that the kernel toolbar is hidden for non-local notebooks (as it already was for direct SSH), and a toast appears instead of a kernel starting. Tests cover both.

Testing

  • useIpynbCellExecution.test.tsx now runs against the real resolveOwner; the store mock only supplies rows. On main, the managed-SSH, unloaded-rows and twin cases fail (a kernel would start). With this change they all pass, along with direct SSH, SSH behind a server, and the existing local cases.

  • ipynb-execution-host.test.ts covers local, legacy unstamped local, direct SSH, managed SSH (no connection id), unloaded rows, and local and server-owned folder workspaces.

  • pnpm test src/renderer/src/components/editor --maxWorkers=1: all 340 test files pass.

  • I ran the full static-analysis job steps locally: oxlint, anti-slop, native and type-aware code quality, changed-code quality, React Doctor, pnpm tc, Zustand fan-out, reliability gates, dead classes, the max-lines / ts-nocheck / runtime-electron / focus-read / layout-writer / deprecated-runtime-owner ratchets, the Node pin, and localization extraction and catalogs.

  • Verified live: nothing. This is a renderer gating change, tested only through unit tests that use the real resolver. I did not run a live managed-SSH notebook session.

  • I manually tested these changes locally

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

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Security: this closes a path where a remote notebook's code could run in the desktop's local Python. SSH: direct SSH is unchanged (still refused); managed SSH and paired servers are now refused instead of running locally. Folder workspaces go through the same resolver. There is no wire or persisted-state change.

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)

A managed SSH or paired-server workspace has no SSH connection id, so the
notebook read it as local and ran its cells in the desktop's own Python
against a same-named local file. Derive the execution host from resolveOwner;
refuse remote, ambiguous and unloaded owners.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The renderer now resolves a notebook’s execution host from worktree route state. It allows cell execution only for Python notebooks with a local host. Remote and unresolved hosts receive distinct refusal messages. Tests cover host classification and execution refusal cases.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 0c790

A notebook that becomes remote while its trust dialog is open can still run code in local Python. Recheck ownership on confirmation before merging. Users of five other locales may also see the new refusal message in English.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: notebook cells now run only when the resolved owner is the local computer.
Description check Passed The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, security, remote execution, and checklist items. The Linked Issue section states that no issue…
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.
Full details: Description check

Explanation

The description is detailed and covers the user impact, implementation, rationale, testing, visual proof, security, remote execution, and checklist items. The Linked Issue section states that no issue was filed, but the rest of the required description is substantially complete.

Full details: Docstring Coverage

Explanation

Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: b4d062c6-defc-44f0-b725-4856837bef0d
📥 Commits

Reviewing files that changed from the base of the PR and between b9b1b85 and 0c79081.

📒 Files selected for processing: 6
  • src/renderer/src/components/editor/IpynbViewer.tsx
  • src/renderer/src/components/editor/ipynb-execution-host.test.ts
  • src/renderer/src/components/editor/ipynb-execution-host.ts
  • src/renderer/src/components/editor/useIpynbCellExecution.test.tsx
  • src/renderer/src/components/editor/useIpynbCellExecution.ts
  • src/renderer/src/i18n/locales/en.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +109 to 116
const refusal = executionRefusal(
resolveNotebookExecutionHost(useAppStore.getState(), worktreeId),
notebook.language
)
if (refusal) {
toast.error(refusal)
return
}

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '90,165p' src/renderer/src/components/editor/useIpynbCellExecution.ts
sed -n '40,80p' src/renderer/src/components/editor/IpynbViewer.tsx
rg -n 'confirmPendingRun|pendingRun|setWorktree|worktreeRoute|resolveNotebookExecutionHost' src/renderer/src/components/editor src/renderer/src/store | head -100

Repository: stablyai/orca

Length of output: 15540


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- hook ---'
nl -ba src/renderer/src/components/editor/useIpynbCellExecution.ts | sed -n '1,175p'
printf '%s\n' '--- viewer dialog/lifecycle ---'
nl -ba src/renderer/src/components/editor/IpynbViewer.tsx | sed -n '40,310p'
printf '%s\n' '--- resolver ---'
nl -ba src/renderer/src/components/editor/ipynb-execution-host.ts | sed -n '1,180p'
printf '%s\n' '--- relevant tests ---'
nl -ba src/renderer/src/components/editor/useIpynbCellExecution.test.tsx | sed -n '1,240p'
printf '%s\n' '--- route/worktree state references ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'worktreeRoute' -e 'routeState' -e 'setWorktree' -e 'setWorktrees' -e 'worktreesByRepo' src/renderer/src/store src/renderer/src/components/editor | head -240

Repository: stablyai/orca

Length of output: 42427


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- route contract and owner resolver ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'export type WorktreeOperationRouteState' -e 'interface WorktreeOperationRouteState' -e 'function resolveOwner' -e 'resolveOwner(' src/renderer/src/lib src/renderer/src/store src/renderer/src/components | head -160
printf '%s\n' '--- route-state symbols ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'operationRoute' -e 'operationRoutes' -e 'worktreeOperation' -e 'routeState' -e 'setWorktreeOperation' -e 'setOperationRoute' src/renderer/src | head -240
printf '%s\n' '--- viewer callers and tab lifecycle ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e '<IpynbViewer' -e 'IpynbViewer' src/renderer/src/components src/renderer/src | head -180
printf '%s\n' '--- complete execution tests after line 40 ---'
nl -ba src/renderer/src/components/editor/useIpynbCellExecution.test.tsx | sed -n '40,260p'

Repository: stablyai/orca

Length of output: 36966


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- route-state definitions and resolver ---'
nl -ba src/renderer/src/lib/worktree-operation-route.ts | sed -n '1,340p'
nl -ba src/renderer/src/lib/resolve-owner.ts | sed -n '1,235p'
printf '%s\n' '--- owner-field writers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'runtimeOwnerEnvironmentId:' -e 'executionHostId:' -e 'hostId:' -e 'worktreesByRepo:' -e 'repos:' src/renderer/src/store src/renderer/src/lib | head -320
printf '%s\n' '--- editor surface notebook mount ---'
nl -ba src/renderer/src/components/editor/EditorEditFileSurface.tsx | sed -n '240,320p'
rg -n -F --glob '*.ts' --glob '*.tsx' -e 'routeState' -e 'runtimeOwnerEnvironmentId' -e 'executionHostId' -e 'setState({' src/renderer/src/store | head -320

Repository: stablyai/orca

Length of output: 42185


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- non-test worktree catalog writers ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -g '!*.test.*' -g '!*.spec.*' -e 'worktreesByRepo:' -e 'worktreesByRepo =' -e 'setWorktrees' -e 'detectedWorktreesByRepo:' -e 'repos:' src/renderer/src/store | head -260
printf '%s\n' '--- catalog merge/action implementations ---'
nl -ba src/renderer/src/store/repos/repo-catalog-merge.ts | sed -n '1,180p'
nl -ba src/renderer/src/store/github/worktree-refresh.ts | sed -n '60,250p'
nl -ba src/renderer/src/store/repos/repo-add-actions.ts | sed -n '150,220p'
printf '%s\n' '--- notebook editor mount ---'
nl -ba src/renderer/src/components/editor/EditorEditFileSurface.tsx | sed -n '270,305p'

Repository: stablyai/orca

Length of output: 39210


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- repo catalog state commits ---'
nl -ba src/renderer/src/store/repos/repo-catalog-actions.ts | sed -n '70,145p'
nl -ba src/renderer/src/store/repos/runtime-repo-catalog-actions.ts | sed -n '35,90p'
nl -ba src/renderer/src/store/repos/all-host-repo-catalog-actions.ts | sed -n '45,105p'
printf '%s\n' '--- fetched worktree merge commits ---'
nl -ba src/renderer/src/store/slices/worktrees/listing/fetched-worktree-merge.ts | sed -n '180,280p'
nl -ba src/renderer/src/store/slices/worktrees/listing/known-ssh-worktree-fetch.ts | sed -n '135,175p'
printf '%s\n' '--- route-state removal commit ---'
nl -ba src/renderer/src/store/slices/worktrees/teardown/purge-stale-runtime-host-state.ts | sed -n '250,290p'

Repository: stablyai/orca

Length of output: 18270


Recheck the owner when confirming a queued run.

A catalog refresh can change the resolved owner while the viewer and trust dialog remain mounted. confirmPendingRun currently calls runCells without checking the current owner, so a notebook that is now remote or unresolved can execute in local Python.

Suggested fix
  const confirmPendingRun = (): void => {
+    const refusal = executionRefusal(
+      resolveNotebookExecutionHost(useAppStore.getState(), worktreeId),
+      'python'
+    )
+    if (refusal) {
+      toast.error(refusal)
+      setPendingRun(null)
+      return
+    }
    trustNotebook(filePath)
    setPendingRun(null)
    if (pendingRun) {
      void runCells(filePath, pendingRun, rootPath)
    }
  }

"localOnly": "Notebook cells can only run for files on this computer.",
"pythonOnly": "Only Python notebooks can run in Orca."
"pythonOnly": "Only Python notebooks can run in Orca.",
"ownerUnresolved": "Orca can't tell which computer this notebook is on yet, so its cells can't run."

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
python - <<'PY'
import json
from pathlib import Path

catalogs = Path('src/renderer/src/i18n/locales')
keys = ('auto', 'components', 'editor', 'IpynbViewer', 'ownerUnresolved')
for path in sorted(catalogs.glob('*.json')):
    value = json.loads(path.read_text())
    for key in keys:
        if not isinstance(value, dict) or key not in value:
            print(f'{path}: MISSING')
            break
        value = value[key]
    else:
        print(f'{path}: {value!r}')
PY

Repository: stablyai/orca

Length of output: 507


🏁 Script executed:

rg -n -F --glob '*.{ts,tsx,json}' -e 'fallbackLng' -e 'fallbackNS' -e 'i18n' -e 'ownerUnresolved' -e '"es"' -e '"fr"' -e '"ja"' -e '"ko"' -e '"zh"' src/renderer/src | head -240
printf '\n--- locale files ---\n'
find src/renderer/src/i18n/locales -maxdepth 1 -type f -name '*.json' -print | sort
printf '\n--- locale key neighborhoods ---\n'
for f in src/renderer/src/i18n/locales/{en,es,fr,ja,ko,zh}.json; do
  printf '\n%s\n' "$f"
  rg -n -F -- "$f" /dev/null >/dev/null 2>&1 || true
  rg -n -F -- 'ownerUnresolved' "$f" || true
  rg -n -F -- '"IpynbViewer"' "$f" | head -3
done

Repository: stablyai/orca

Length of output: 26141


🏁 Script executed:

printf '%s\n' '--- i18n configuration ---'
nl -ba src/renderer/src/i18n/i18n.ts | sed -n '48,75p'
printf '%s\n' '--- fallback test ---'
nl -ba src/renderer/src/i18n/lazy-locale.test.ts | sed -n '28,48p'
printf '%s\n' '--- IpynbViewer blocks ---'
python3 - <<'PY'
import json
from pathlib import Path
for path in sorted(Path('src/renderer/src/i18n/locales').glob('*.json')):
    data = json.loads(path.read_text())
    node = data['auto']['components']['editor']['IpynbViewer']
    print(f'{path}: keys={sorted(node)}')
    print(f'  ownerUnresolved={node.get("ownerUnresolved", "<missing>")!r}')
PY

Repository: stablyai/orca

Length of output: 8832


Add ownerUnresolved to each supported locale.

ownerUnresolved is missing from es.json, fr.json, ja.json, ko.json, and zh.json. i18n.ts uses English as the fallback locale, so users of these locales can see the English message.

Source: Learnings

@nwparker
nwparker merged commit fa738f3 into main Oct 18, 2026
31 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