Skip to content

[hardening 3/N] refactor(renderer): fold getExplicitRuntimeEnvironmentIdForWorktree callers into resolveOwner - #30059

Merged
nwparker merged 1 commit into
mainfrom
nwparker/fold-explicit-runtime-owner
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/fold-explicit-runtime-owner

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 20 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​374 $\color{#cf222e}{\Huge{\mathbf{−}}}$​149 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​225
Prod 26 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​208 $\color{#cf222e}{\Huge{\mathbf{−}}}$​155 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​53

Stack (unmerged, review in order):

  1. fix(worktrees): a host-scoped purge leaves a surviving twin's tabs and edits alone #30030
  2. fix(renderer): destructive host callers refuse an ambiguous owner instead of reading it as local #30035
  3. this PR

ELI5

The same project can be open on two machines at once (for example this computer and a paired Orca server). Orca had a helper that answered "which paired server owns this workspace?" with either a server id or nothing, and "nothing" meant both "it's this computer" and "two machines claim it, I can't tell". A few actions that write or start things read that "nothing" as "this computer" and acted locally. This PR moves every caller of that helper onto the newer owner resolver, which says "ambiguous" out loud, so actions that change things stop instead of guessing.

What Changed

getExplicitRuntimeEnvironmentIdForWorktree (in worktree-runtime-owner.ts) had 20 production callers. Nineteen now use runtimeEnvironmentIdForWorkspaceOwner / resolveOwner (resolve-owner.ts). The last one, store/terminals/terminal-tab-create-through-layout-owner.ts, is owned by a parallel PR, so the old function stays, is marked @deprecated, and is now covered by the deprecated-owner importer ratchet.

What a user sees, per caller:

Caller Kind On a twin (no host picked) Before → after
Reopen closed terminal (Cmd/Ctrl+Shift+T), recently-closed-tabs.ts launches a shell refuses before: spawned a local shell for a tab that may have lived on the other machine. After: skipped, like a server-owned workspace
File explorer operations on a folder workspace, file-explorer-operation-owner.ts writes/deletes "owner unresolved" before: a folder twin fell through to SSH/local evidence. After: refused
Chat attachment upload host, native-chat-attachment-upload.ts writes files not ready before: refused only when connection evidence happened to be missing. After: refused on the owner verdict itself
File drag source, workspace-file-drag-source.ts a drop reads/uploads from the source no source written same as attachments: now refused on the owner verdict
Chat skill discovery, native-chat-skill-discovery-context.ts read not ready before: listed this computer's skills. After: waits for a host pick; its store selector now also passes the picked host and detected rows so a picked twin still scans
Agent detection for folders, useAgentDetectionTarget.ts read unresolved before: fell to connection checks. After: unresolved
Session-tab mirroring for the active workspace, use-web-session-tabs-sync.ts, active-session-subscription.ts (via new mirrored-workspace-owner.ts) read/mirror no mirror until a host is picked unchanged
Layout owner send, layout-apply-send.ts window layout only main's path unchanged; stays in step with the terminal-create path it shares main with
Terminal teardown for folder/floating surfaces, terminal-worktree-route.ts teardown local-or-SSH unchanged: runtime PTYs there carry remote: ids, so a raw id is local or SSH on either twin
Restored editor tab re-homing, sidebar SSH chip, host label, SSH connection phase, resume/Codex-restart platform lookup, terminal reveal, runtime file-route match, diff owner read no server unchanged

Also in resolve-owner.ts:

  • A route that names a host the resolver cannot reach (the runtime:unresolved-owner sentinel) is now ambiguous, not missing. Before, the adapter read missing as "this app", so a workspace selected on the sentinel could reopen a terminal locally or read its diff here.
  • resolveOwner now builds a small state object with only the fields the route resolvers read, instead of copying the whole store on every call. Per-row sidebar selectors call it on each store write.

Behaviour deltas (old helper vs resolveOwner)

The old helper used the active-workspace route, then detected-row explicit provenance, then the first matching worktree/repo row. resolveOwner uses the same rows, but:

  1. Sidebar SSH chip asks without a host qualifier, as before: the host-qualified lookup scans every row and runs per card on every store write.
  2. Strict SSH selection. When the active workspace is an ssh: host that two paired servers both proxy, the old helper returned "no server" (a direct SSH guess); now it is ambiguous. Read-only callers still see "no server"; mutating callers refuse.
  3. Repo twins. When the worktree row names no host and two repo rows with different stamped hosts exist, the old helper took the first repo row; now that is ambiguous. Read-only callers see "no server" instead of the first row's server.
  4. HUB recovery. An SSH worktree reached through a paired server is recovered only from the repo row whose SSH connection matches, not from whichever repo row came first. Single-HUB setups route as before.
  5. Paired web client. A row that names no server is routed through the web client's only server (fix(web): the paired server is the web client's only host #27266). The web client stamps every server row with its owner at ingest (withRuntimeRepoOwner / withRuntimeWorktreeOwner), so in practice both answers already agree there.
  6. Focus. Neither reads the Active Server setting; focus-read ratchet stays at 1088.

Session mirroring from every server, including a twin's server, comes from getRuntimeSessionMirrorEnvironmentIds, which is untouched. Only the active-workspace stream uses this owner check, and it still mirrors a twin once the user picks that copy (tested).

No wire change: nothing sent to or published by a host changes, so older paired servers, relays and web clients see the same traffic.

Why

Stage 1a of the SSH hardening work: "ambiguous" must be an outcome, and mutating callers must refuse it rather than read it as local. Folding this parallel resolver into resolveOwner removes one of the places where a twin silently became "this computer". I considered keeping a thin null-returning wrapper, but that would recreate the same collapse under a new name. Making each caller decide (refuse, or "no server" with a one-line reason) keeps the decision visible where it matters.

Linked Issue

SSH hardening tracker row 1a.4 (parallel owner resolvers). Third in the hardening stack; base branch is #30035.

Visual Proof

N/A: no layout or styling change. The only visible difference is that a few actions on a workspace two machines publish now wait or refuse instead of acting on this computer.

Testing

  • New src/renderer/src/store/host-twin-owner-refusals.test.ts (uses host-twin.test-fixture.ts): local+runtime and local+ssh twins refuse terminal reopen, chat attachment host and drag source; folder and project-group twins leave file operations unresolved; a single paired-server row still routes (attachment host, drag source, folder file op, mirroring); a local-only row still reopens locally; a twin's server is mirrored once picked; a workspace selected on the unresolved-owner sentinel neither reopens a terminal locally nor uploads; chat skill discovery waits on a twin and scans the picked copy (fails without the selector fix). The terminal-reopen and folder-file-operation cases fail on the old code. The attachment and drag-source twin cases already refused on these fixtures through missing connection evidence, so they pin the new explicit refusal.

  • Updated mocks in the session-tab-sync, layout-owner, reveal and drag-source tests to the new resolver.

  • Deprecated-owner ratchet self-test covers the new name.

  • pnpm tc, pnpm tc:web, the local static-analysis gate (PASS), and unit tests for lib, runtime, hooks, store and the touched components folders (all green). terminal-pane-recovery.test.ts and terminal-pane-recovery-unsettled-fallback.test.ts hang on this branch, but they hang the same way on fix(renderer): destructive host callers refuse an ambiguous owner instead of reading it as local #30035's head without this PR and pass on main, so the hang comes from lower in the stack.

  • Live verify: not run; the change is renderer owner routing covered by store-level twin fixtures, with no wire or main-process change.

  • I manually tested these changes locally

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

AI Disclosure

Review

Ratchets: deprecated runtime-owner importers 57 → 58 (scope widened to the third deprecated name; the only added file is store/terminals/terminal-tab-create-through-layout-owner.ts, owned by a parallel PR). Focus-read 1088 → 1088.

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

SSH and folder workspaces are covered by the twin fixtures. Cross-platform: no platform-specific code. Mobile: untouched.

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)

@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from e3625de to 7c3cf40 Compare October 17, 2026 11:39
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 56a3be6 to 871fab9 Compare October 17, 2026 11:39
@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from 7c3cf40 to c7c5f93 Compare October 17, 2026 11:56
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 871fab9 to 65689bf Compare October 17, 2026 11:56
@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from c7c5f93 to 8b7d1da Compare October 17, 2026 14:26
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 65689bf to 59fda1b Compare October 17, 2026 14:26
@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from 8b7d1da to a459995 Compare October 17, 2026 22:51
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 9732228 to 81fd4e5 Compare October 17, 2026 22:52
@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from a459995 to ae7ded7 Compare October 17, 2026 23:30
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 81fd4e5 to 0fe57b4 Compare October 17, 2026 23:43
@nwparker
nwparker changed the base branch from nwparker/destructive-callers-refuse-ambiguous to main October 17, 2026 23:43
@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 0fe57b4 to 858e871 Compare October 17, 2026 23:43
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f6e273dc-0763-4dc4-95b9-0aa6d44224db
📥 Commits

Reviewing files that changed from the base of the PR and between 858e871 and 98a5426.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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: 0dedde3d-b101-4cab-8306-3dfbf713fef3
📥 Commits

Reviewing files that changed from the base of the PR and between 532cad2 and 858e871.

📒 Files selected for processing: 46
  • src/renderer/src/components/editor/combined-diff/browse-files/combined-diff-file-tree-row-drag.test.tsx
  • src/renderer/src/components/editor/restored-editor-workspace-runtime-owner.ts
  • src/renderer/src/components/editor/useEditorPanelRemoteSiblingContentState.test.tsx
  • src/renderer/src/components/native-chat/native-chat-attachment-upload.ts
  • src/renderer/src/components/native-chat/native-chat-skill-discovery-context.ts
  • src/renderer/src/components/native-chat/use-native-chat-skills.test.ts
  • src/renderer/src/components/right-sidebar/file-explorer-operation-owner.ts
  • src/renderer/src/components/sidebar/use-worktree-card-foundation.ts
  • src/renderer/src/components/tab-bar/tab-bar-layout-owner-props.test.ts
  • src/renderer/src/components/terminal-pane/terminal-pane-layout-owner-commands.test.ts
  • src/renderer/src/hooks/ipc-events/terminal-pane-reveal-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/terminal-pane-reveal-ipc-bridge.ts
  • src/renderer/src/hooks/useAgentDetectionTarget.ts
  • src/renderer/src/lib/agent-account-restart-startup.ts
  • src/renderer/src/lib/agent-resume-launch-target.ts
  • src/renderer/src/lib/execution-host-display-label.ts
  • src/renderer/src/lib/resolve-owner.ts
  • src/renderer/src/lib/runtime-workspace-file-route.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts
  • src/renderer/src/lib/terminal-worktree-route.ts
  • src/renderer/src/lib/workspace-file-drag-source-runtime.test.ts
  • src/renderer/src/lib/workspace-file-drag-source.ts
  • src/renderer/src/lib/worktree-host-connection-phase.ts
  • src/renderer/src/lib/worktree-operation-catalog-route.ts
  • src/renderer/src/lib/worktree-operation-route.ts
  • src/renderer/src/lib/worktree-runtime-owner-index.detected-perf.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/layout-owner-command.test.ts
  • src/renderer/src/runtime/web-session-tabs-retired-epoch-census-repair.test.tsx
  • src/renderer/src/runtime/web-session-tabs-stream-end-resubscribe.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-initial-terminal-relaunch.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-reconnect-resubscribe.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-unverifiable-host.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-visibility-collision.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-window-visibility.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync-worktree-switch.test.tsx
  • src/renderer/src/runtime/web-session-tabs-sync/active-session-subscription.ts
  • src/renderer/src/runtime/web-session-tabs-sync/mirrored-workspace-owner.ts
  • src/renderer/src/runtime/web-session-tabs-sync/use-web-session-tabs-sync.ts
  • src/renderer/src/store/host-twin-owner-refusals.test.ts
  • src/renderer/src/store/slices/editor/git/diff-runtime-owner.ts
  • src/renderer/src/store/slices/recently-closed-tabs.ts
  • src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.test.ts
  • src/renderer/src/store/terminals/terminal-tab-create-through-layout-owner.ts
💤 Files with no reviewable changes: 1
  • src/renderer/src/lib/worktree-runtime-owner.ts

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

📝 Walkthrough

Renderer ownership lookups now use workspace-owner resolution instead of the removed explicit worktree runtime-environment lookup. The change updates runtime targeting, file and terminal operations, skill discovery, and session mirroring. Ambiguous ownership remains unresolved in affected paths. Tests update their ownership mocks and add coverage for twin, runtime-only, local-only, and unresolved-owner cases.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 858e8

This change moves renderer ownership lookups to the workspace-owner resolver so that ambiguous twin workspaces refuse or wait rather than being treated as local. No concrete merge-blocking risk was identified in the supplied changes. Runtime behavior was not executed, and the author reported that live verification was not run.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 52.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 42 functions across 45 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
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.
Title check Passed The title clearly identifies the main change: moving callers from getExplicitRuntimeEnvironmentIdForWorktree to resolveOwner.
Description check Passed The description is complete and relevant. It includes the required change summary, rationale, issue context, visual-proof explanation, testing details, AI disclosure section, scope notes, and checklis…
Full details: Description check

Explanation

The description is complete and relevant. It includes the required change summary, rationale, issue context, visual-proof explanation, testing details, AI disclosure section, scope notes, and checklist. It also transparently reports unrun live verification and known test hangs.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • 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.

@nwparker
nwparker force-pushed the nwparker/fold-explicit-runtime-owner branch from 858e871 to 98a5426 Compare October 18, 2026 03:24
@nwparker
nwparker merged commit 3d03c33 into main Oct 18, 2026
45 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