Repository navigation
[P1] fix(routing): keep the paired-HUB owner for the active workspace selection - #11818
Conversation
… selection #11346 made `activeWorkspaceExecutionHostId` authoritative for the active workspace, but the short-circuits that read it never see the owner record, so a project reached through a paired runtime HUB (`hostId: ssh:<target>` plus `runtimeOwnerEnvironmentId: <hub>`) loses its transport and its repo: - `resolveWorktreeOperationRouteResult` returned `runtimeEnvironmentId: null` for any non-`runtime:` selection, bypassing the HUB recovery in `resolveExactWorktreeRoute` — every owner-routed terminal/git/filesystem operation on the active workspace lost the HUB that proxies the SSH target. - `selectRepoByIdForActiveWorkspace` filtered `state.repos` by the selected host with no fallback, but `withRepoHostOwnership` deliberately keeps the SSH host on the worktree while the repo row stays HUB-owned — so the active repo read as `null` and `useGitStatusPolling` stopped polling the whole workspace. Route resolution now recovers the HUB owner from the owner rows on the selected host, and drops it only when rival HUBs project the same host. The repo selector opens exactly one hole in #11346's fail-closed rule — an `ssh:` selection over a `runtime:` repo row — and every other host mismatch still returns `null`. `worktree-owner-route.ts` is a pure extraction of the existing owner-route helpers; no behavior moved with it.
Greptile SummaryFixes two regressions from #11346 that affect projects reached through a paired-HUB (SSH target proxied via a runtime HUB). The active-workspace short-circuit introduced by #11346 never had access to the
Confidence Score: 5/5Safe to merge — the changes are narrowly targeted to the paired-HUB topology and leave local and runtime-only paths untouched. Both routing fixes are tightly scoped: the active-workspace route now recovers the HUB environment ID from owner records rather than discarding it, and the repo selector opens exactly one new fallback path (ssh-selection over a runtime repo row) while keeping every other mismatch closed. New test coverage pins the two regressions, the rival-HUB ambiguity bail-out, and the non-regression cases from #11346. The full desktop suite passes with no IPC surface, no new dependencies, and no auth or path construction touched. Files Needing Attention: No files require special attention. The selector change in
|
| Filename | Overview |
|---|---|
| src/renderer/src/lib/worktree-operation-route.ts | Core fix: new resolveActiveWorkspaceRoute correctly handles local/runtime/ssh host kinds — ssh: scans owner records to recover the HUB environment ID, deduplicates with a Set, and fails closed when multiple HUBs project the same SSH host. |
| src/renderer/src/lib/worktree-owner-route.ts | New file; byte-identical extraction of routeForOwner, addRoute, resolveExactWorktreeRoute, and resolveRepoRouteForSshOwner from worktree-operation-route.ts. Type-only circular import is safe at runtime. |
| src/renderer/src/lib/worktree-runtime-owner.ts | Both getRuntimeEnvironmentIdForWorktree and getExplicitRuntimeEnvironmentIdForWorktree now call resolveActiveWorkspaceRoute instead of bare parseExecutionHostId; the three entry points can no longer drift apart. |
| src/renderer/src/store/selectors.ts | Host-exact match preserved as primary path; narrow paired-hub exemption (ssh: active host + exactly one runtime: repo candidate) correctly handles the topology without widening any other mismatch. |
| src/renderer/src/lib/worktree-operation-route.test.ts | Five new tests cover the active-workspace branch: HUB transport recovery, mixed-version repo recovery, selected-host authority, rival-HUB ambiguity bail-out, and unknown-worktree passthrough. |
| src/renderer/src/lib/worktree-runtime-owner.test.ts | Two new tests verify both runtime-environment-id functions return hub-a for the paired-hub topology, and that getExecutionHostIdForWorktree still returns the SSH host. |
| src/renderer/src/store/selectors.test.ts | Four new selector tests: paired-hub repo recovery, rival-HUB ambiguity closes the selector, host-exact match still wins when one ID spans hosts, and non-paired-hub mismatches all return null. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["resolveWorktreeOperationRouteResult(state, worktreeId)"] --> B["resolveActiveWorkspaceRoute(state, worktreeId)"]
B --> C{activeWorktreeId === worktreeId?}
C -- No --> D["return null (fall through to regular path)"]
C -- Yes --> E["parseExecutionHostId(activeWorkspaceExecutionHostId)"]
E --> F{host kind?}
F -- runtime --> G["return executionHostId + runtimeEnvironmentId"]
F -- local/other --> H["return executionHostId + null"]
F -- ssh --> I["ownerRecordsOnHost(state, worktreeId, activeHost.id)"]
I --> J["for each owner: resolveExactWorktreeRoute"]
J --> K{collect unique environmentIds}
K -- exactly 1 --> L["return ssh host + hubId"]
K -- 0 or more than 1 --> M["return ssh host + null (fail closed)"]
D --> N["folder workspace or resolveExplicitWorktreeOperationRouteResult"]
style G fill:#c8f7c5
style L fill:#c8f7c5
style H fill:#c8f7c5
style M fill:#f7e6c5
style D fill:#e8e8e8
Reviews (2): Last reviewed commit: "fix(routing): fail ambiguous paired-HUB ..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughWorktree routing now uses shared owner-route utilities for direct and SSH repository resolution. Active workspace routing preserves the selected execution host and recovers a unique HUB runtime environment when available. Runtime-owner lookups use the resolved active route. Repository selection prefers matching hosts, permits paired HUB SSH/runtime mismatches, and rejects unrelated mismatches. Tests cover these routing, ambiguity, fallback, runtime-owner, and repository-selection cases. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
… selection (stablyai#11818) * [P1] fix(routing): keep the paired-HUB owner for the active workspace selection stablyai#11346 made `activeWorkspaceExecutionHostId` authoritative for the active workspace, but the short-circuits that read it never see the owner record, so a project reached through a paired runtime HUB (`hostId: ssh:<target>` plus `runtimeOwnerEnvironmentId: <hub>`) loses its transport and its repo: - `resolveWorktreeOperationRouteResult` returned `runtimeEnvironmentId: null` for any non-`runtime:` selection, bypassing the HUB recovery in `resolveExactWorktreeRoute` — every owner-routed terminal/git/filesystem operation on the active workspace lost the HUB that proxies the SSH target. - `selectRepoByIdForActiveWorkspace` filtered `state.repos` by the selected host with no fallback, but `withRepoHostOwnership` deliberately keeps the SSH host on the worktree while the repo row stays HUB-owned — so the active repo read as `null` and `useGitStatusPolling` stopped polling the whole workspace. Route resolution now recovers the HUB owner from the owner rows on the selected host, and drops it only when rival HUBs project the same host. The repo selector opens exactly one hole in stablyai#11346's fail-closed rule — an `ssh:` selection over a `runtime:` repo row — and every other host mismatch still returns `null`. `worktree-owner-route.ts` is a pure extraction of the existing owner-route helpers; no behavior moved with it. * fix(routing): fail ambiguous paired-HUB repo selection closed
Summary
Both P1s from the
v1.4.163-rc.1..v1.4.163-rc.3production release scan. Both are regressions introduced by #11346 (60d2493bbb), both live in the same topology, and neither is survivable alone — so they ship together.The topology. A project reached through a paired runtime HUB has two owners at once.
withRepoHostOwnershipsays so in as many words (src/renderer/src/store/slices/worktrees.ts:423):So the worktree carries
hostId: ssh:<target>andruntimeOwnerEnvironmentId: <hub>, while its repo row staysruntime:<hub>. And activation stamps the worktree's host onto the store (src/renderer/src/components/sidebar/WorktreeCard.tsx:876):which lands in
activeWorkspaceExecutionHostIdatworktrees.ts:5412. So for this one topology,activeWorkspaceExecutionHostIdisssh:<target>while the repo isruntime:<hub>— by design. #11346 added two short-circuits that both assume they can't diverge.Local-only and runtime-only topologies are unaffected by either bug.
P1-1 — the active workspace loses its HUB transport
resolveWorktreeOperationRouteResultshort-circuits on the active host selection before any owner lookup happens (worktree-operation-route.ts:137-149onorigin/main):The branch has no access to the owner record at all — only the parsed host id — so
runtimeOwnerEnvironmentIdis structurally unreachable from it. Anssh:selection therefore always yieldsruntimeEnvironmentId: null, and the whole HUB-recovery path inresolveExactWorktreeRoute(which exists precisely to recover it) is skipped. Every owner-routed terminal, git, and filesystem operation on the active workspace loses the HUB that proxies the SSH target. The same short-circuit is duplicated ingetRuntimeEnvironmentIdForWorktreeandgetExplicitRuntimeEnvironmentIdForWorktree.P1-2 — the active repo reads as
null, and git status polling stopsselectRepoByIdForActiveWorkspacefiltersstate.reposby the selected host with no fallback (selectors.ts:181-193onorigin/main):For the paired-hub topology the selected host is
ssh:<target>and the repo row isruntime:<hub>, so thefindmisses and the active repo isnull. That this is a regression is not an inference —git show 60d2493bbb -- src/renderer/src/store/selectors.tsshows both selectors were unconditional lookups before:useRepoByIdis whatuseGitStatusPollinggates on (useGitStatusPolling.ts:61-82):A
nullrepo silently switches off git status polling for the entire workspace. Fourteen non-test modules readuseRepoById/useActiveRepo.Fix
worktree-operation-route.ts— the active-host branch becomesresolveActiveWorkspaceRoute. The host selection stays authoritative for identity; the HUB owner is recovered from the owner rows sitting on that host, via the existingresolveExactWorktreeRoute. Where rival HUBs project the same SSH host, the transport is dropped tonullrather than guessed — the host selection genuinely cannot disambiguate them.worktree-runtime-owner.ts— both duplicated short-circuits now callresolveActiveWorkspaceRoute, so the three entry points cannot drift apart again.selectors.ts— host-exact match still wins. On a miss, exactly one hole opens in fix: route server project adds to selected runtime #11346's fail-closed rule: anssh:selection over aruntime:repo row, which is the paired-hub shape and nothing else. Every other host mismatch still returnsnull.worktree-owner-route.ts— a pure extraction ofrouteForOwner/addRoute/resolveExactWorktreeRoute/resolveRepoRouteForSshOwner. No behavior moved with it; the functions are byte-identical to their previous bodies.ELI5
Some projects live on a machine you can't reach directly. Orca gets there by going through a second machine — a "hub" — the way you'd SSH through a bastion. So the project has two addresses at once: where it is (the target) and how you get there (the hub).
A recent change taught Orca to remember which host the workspace you're looking at is on, so that two projects with the same ID on two different machines don't get confused. Good idea. But it only remembered the first of those two addresses — where the project is — and threw away the second — how to get there.
Two things broke, both only for hub-routed projects:
This PR keeps the "remember the active host" idea intact and adds back the second address, by looking it up from the workspace's own record instead of trying to read it out of the host name — where it was never stored. When two different hubs both claim the same target and Orca genuinely can't tell which one you meant, it says so by returning nothing rather than picking one.
Screenshots
None. Neither defect renders. P1-1 is a routing argument on IPC calls; P1-2 is a selector returning
null, whose visible effect is the absence of a git-status refresh. Reproducing either on screen needs a live paired-HUB runtime plus an SSH target behind it, which is not something this workstation can stand up — and a screenshot of a sidebar that looks normal but has stopped polling would be evidence of nothing.The behavior is pinned by assertions on the literal resolved routes instead, reproduced below.
Proof of fix
With only the four production files reverted to
origin/mainand every test kept,npx vitest run --config config/vitest.config.tsover the five affected suites:Each defect reproduces as a distinct assertion: the two route resolutions and
expected null to be 'hub-a'are P1-1 across its three entry points;expected null to be { badgeColor … }is P1-2 — the selector returningnullwhere the repo object belongs.With the fix restored: 5 files / 79 tests passed.
New coverage:
keeps the HUB transport when the paired SSH worktree is the active workspaceruntimeOwnerEnvironmentIdrecovers the HUB transport from the repo for an active mixed-version SSH publicationkeeps the selected host authoritative when the same ID exists on two hostsdrops the HUB transport when two HUBs project the active SSH worktreekeeps an unknown active worktree on its selected hostkeeps the HUB transport for the active paired SSH worktreeworktree-runtime-owner's two entry pointskeeps the repo when a paired-hub worktree reports a different execution hostuseGitStatusPollinggate expressionstill prefers the host-matching row when one repo ID spans hostskeeps every non-paired-hub host mismatch failing closedProof of no regression
selected-host-active-workspace-identity.test.tsandrepos-selected-owner-routing.test.tsare untouched by this PR.null—does not fall back to a same-ID local repo when the active runtime row is absent(selectors.test.ts:266) — is unmodified and still passes. It is the reason the selector fix is a narrow exemption rather than a revert: alocalrow shadowing an absent runtime row must still fail closed.pnpm typecheck— clean (tsc: node + cli + web).oxfmt --checkandoxlintclean; nomax-linesdisable added, andworktree-operation-route.tsis net −7 lines after the extraction.Behavior changes beyond the two bugs — disclosed
{ executionHostId: 'local', runtimeEnvironmentId: null }), and this keeps the hot path O(1) — only anssh:selection can hide a paired HUB owner, so onlyssh:pays for the lookup.runtimeEnvironmentId: nullinstead of picking one. Previously the active-host branch also producednullhere, so this is not a change in outcome — but it is now a deliberate, tested decision rather than a side effect of never looking.WorktreeOperationOwnerRecordandWorktreeOperationRouteStateare now exported so the extracted module can type against them. Type-only; no runtime surface.Testing
pnpm lint— clean (oxlint, native + type-aware code-quality audits, reliability-gate manifest, max-lines ratchet, bundled skill guides, skill-bundle manifest, localization catalog/extraction/coverage);oxfmtclean via lint-stagedpnpm typecheck— clean (tsc: node + cli + web)pnpm test— five affected suites at tip (79 passed) plus the full desktop suitepnpm run ensure:electron-runtime && npx playwright test tests/e2e/pr11346-selected-runtime-add.spec.ts --config tests/playwright.config.ts --project <p> --workers=1 --reporter=line:electron-headless→routes … in hidden-window desktop parity— 1 passed (22.3s)electron-headful→routes every Add Project path to a selected non-default headed runtime @headful— 1 passed (21.1s)pnpm build— not run; no build-graph, packaging, or dependency changeAI Review Report
Reviewed by Claude Opus 5 as part of a 45-agent release scan with adversarial refutation, then re-verified against
origin/mainbefore any code was written. Risks checked:keeps the selected host authoritative when the same ID exists on two hosts,still prefers the host-matching row when one repo ID spans hosts). The selected host still decides identity; only the transport is recovered separately, and only for the one shape where identity provably cannot carry it.findKnownWorktreeById(worktrees.ts:826-873) also fails closed on host mismatch rather than falling back host-agnostically. So the repo selector was consistent with the worktree lookup, not an outlier; the fix is justified by the paired-hub topology being real, not by an inconsistency. Stating that plainly because the opposite would have been a stronger-sounding and wrong argument.config/reliability-gates.jsonc:2244-2449, headful + headless) over exactly this behavior, and it readsactiveWorkspaceExecutionHostIddirectly at three points.pnpm run check:reliability-gatesis only a manifest schema validator, sopnpm lintdoes not re-run it. Both gate projects were therefore run deliberately for this PR, and both pass — see the testing checklist.activeRepoId: nullon activation (worktrees.ts:5592), so the selector's active branch never applies to them.ssh:selections;localandruntime:return in constant time as before. The non-active path already did a full-catalog scan (worktree-operation-route.ts:133-139), so the scan shape is not new to this module.Security Audit
eval, no path construction, no auth, no secrets, no IPC surface added.executionHostIdis still taken verbatim from the active selection in every branch. OnlyruntimeEnvironmentId— the HUB transport — is added, and only from an owner row whose ownhostIdalready parses to the selected host. A row on a different host cannot contribute one.Repoobject from the store ornull; it constructs nothing and grants no capability the store did not already hold.Notes
Made with Orca 🐋