Repository navigation
fix(notebook): run cells only when the resolved owner is this computer - #30187
Conversation
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.
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to
|
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:
b4d062c6-defc-44f0-b725-4856837bef0d
📒 Files selected for processing: 6
src/renderer/src/components/editor/IpynbViewer.tsxsrc/renderer/src/components/editor/ipynb-execution-host.test.tssrc/renderer/src/components/editor/ipynb-execution-host.tssrc/renderer/src/components/editor/useIpynbCellExecution.test.tsxsrc/renderer/src/components/editor/useIpynbCellExecution.tssrc/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.
| const refusal = executionRefusal( | ||
| resolveNotebookExecutionHost(useAppStore.getState(), worktreeId), | ||
| notebook.language | ||
| ) | ||
| if (refusal) { | ||
| toast.error(refusal) | ||
| return | ||
| } |
There was a problem hiding this comment.
🔒 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 -100Repository: 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 -240Repository: 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 -320Repository: 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." |
There was a problem hiding this comment.
🎯 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}')
PYRepository: 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
doneRepository: 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}')
PYRepository: 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
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
.ipynbin 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:
Mechanism: a new
resolveNotebookExecutionHost(src/renderer/src/components/editor/ipynb-execution-host.ts) callsresolveOwner. It returnslocalonly for{ endpoint: self, at: local },remotefor any other resolved owner, andunresolvedformissingorambiguous.useIpynbCellExecution(the run gate) andIpynbViewer(the toolbar gate) both use it instead ofgetConnectionId.Why
resolveOwneris 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. PatchinggetConnectionIdto 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:76checks the runtime owner first and returns before theconnectionIdbranch.terminal-file-path-mapping.ts:46checks the runtime target and the ambiguous route first.WorktreeOpenInMenu.tsx:getLocalPathOpenOwnerForRoutealready 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:382andsettings-view-model.ts:109gate SSH-relay-specific behaviour or display, not local execution. Runtime-owned rows take their own paths, and several of these also checkexecutionHostId.getConnectionId(...) ?? undefinedcall 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.tsxnow runs against the realresolveOwner; 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.tscovers 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)