Skip to content

fix(renderer): destructive host callers refuse an ambiguous owner instead of reading it as local - #30035

Merged
nwparker merged 1 commit into
mainfrom
nwparker/destructive-callers-refuse-ambiguous
Oct 17, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/destructive-callers-refuse-ambiguous

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​577 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​531
Prod 11 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​183 $\color{#cf222e}{\Huge{\mathbf{−}}}$​44 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​139

ELI5

Sometimes the same project shows up from two machines at once, for example your laptop and a paired Orca server both publish repo::/path. Orca calls these "twins". A few actions that change things on a host (new terminal tab, pushing a pane layout, closing a mirrored tab, syncing a Linear status) asked "which machine owns this?" through an old helper. When the answer was "both", the helper said "nobody", and the caller read "nobody" as "this computer". So a twin could get a shell started on the wrong machine, or borrow this computer's Linear account. Now these actions say "I can't tell which machine" and do nothing.

What Changed

Before: for a workspace two hosts publish, these callers treated the owner as this computer:

  • the "New Terminal Tab" menu or shortcut opened a local shell for the twin,
  • Workspace-board status moves synced the linked Linear issue with this computer's Linear settings,
  • closing a pageless browser mirror tore it down locally (and the host put it back),
  • the legacy-terminal identity check merged a twin's legacy terminal id with the same id from an unrelated local workspace.

After: each one refuses on an ambiguous owner, touches nothing on either host, and logs one console.warn per site and workspace (deduplicated, because layout persists and resume sweeps repeat):

Site On an ambiguous owner
runtime/web-runtime-terminal-actions.ts (pane layout, tab props) no host RPC, returns false (the local edit already happened, as for any local tab)
runtime/close-mirrored-editor-tab.ts no host close and no close intent; the local close still runs
lib/workspace-browser-tab-close.ts a pageless mirror returns a no-op plan (no host close, no local teardown). Tabs with pages are unchanged because the pages name their own owner
hooks/ipc-events/tab-lifecycle-ipc-bridge.ts (new terminal tab) neither a host create nor a local tab
lib/host-mirrored-pane-liveness.ts parks the resume sweep ({kind:'mirror', environmentId:null}) without arming a wait on either host. It never launches or clears
store/slices/terminal-tab-retirement.ts (PTY identity) a twin's legacy remote:<handle> id gets the identity pty:<raw id>: it matches only its own exact id and never merges with another host's terminal. Teardown already skips that id, because the twin's route is unresolved
components/sidebar/use-workspace-board-task-status-sync.ts skips that worktree's Linear sync and reports it in the existing "Task status sync skipped" toast, using the existing "Could not sync Linear issue X" message. Only missing maps to this computer

Mechanism: one small adapter next to resolveOwner, runtimeEnvironmentIdForWorkspaceOwner(state, ref), returns {resolved, environmentId} or {ambiguous} through an exhaustive switch:

  • missing keeps today's local reading (null), except that a folder whose saved session names its server (restoredRuntimeHostIdByWorkspaceSessionKey) still reads that server before its folder catalog loads.
  • an environment endpoint gives its id.
  • self gives null.

warnAmbiguousOwnerRefusalOnce sits next to it. The Linear site reuses the existing getRuntimeTargetForWorktreeOwner. No new UI strings.

Behaviour deltas besides ambiguous (per site)

Sites 1–5 and 7 now use resolveOwner, so they also pick up its intended differences from the deprecated resolver:

  • Focus fallback dropped: a worktree row with no host stamp and no stamped repo row no longer routes to the focused "Active Server". Pane layout, tab props, the mirrored-editor close, the pageless browser close, the new-tab host create and the resume wait now read it as this computer. The Linear site was already focus-free.
  • Strict selection: when the active workspace's selected host is ssh:t and two HUBs proxy it, the result is ambiguous, so the site refuses. The deprecated resolver returned no transport and read that as local; the new-terminal case used to open a local shell.
  • HUB transport recovery for an ssh: selection is unchanged in effect (it is recovered as before).

Why these are safe for mixed-version servers: every repo row entering the client is stamped by the client itself (adoptEndpointRepo in shared/endpoint-catalog-adoption.ts; worktrees via withRepoHostOwnership), whatever the server's version. So the only rows that lose the focus fallback are rows with no repo row at all. Web clients keep routing through their only server (onPairedWebClientHost, which resolveOwner keeps).

Site 6 is the exception and stays on the deprecated resolveRuntimeOwnerForWorktree, with only the ambiguous branch changed. Its identity has to agree with teardown's fallback route (resolveTerminalWorktreeRoute), which still reads focus. A focus-free identity would let closing a legacy-alias tab kill a terminal that another tab still shows (Codex round 1, P1). The fully focus-free version is blocked: the focus-read ratchet forbids making the identity function a focus reader, and the teardown route is outside this PR. It stays in the deprecated-owner baseline.

Why

  • Why one adapter instead of inlining resolveOwner at each site: six sites need exactly "environment id or refusal", so the mapping lives in one place.
  • Why not keep the deprecated resolver and only add an ambiguous check: that keeps the focus reads the ratchet is removing, and it keeps the non-strict rival-HUB reading.
  • Why pty:<raw id> for a twin's legacy terminal: it can't be pinned to either host, and exact-id matching is the only identity that never merges two hosts' terminals.

Mixed versions: no wire change. SSH: direct SSH owners read self and route exactly as before. Folder workspaces: folder:<id> keys go through the same resolver, including folder twins, now ambiguous since #30009.

Ratchets:

  • config/focus-setting-read-baseline.txt: 1096 → 1088.
  • config/deprecated-runtime-owner-importers-baseline.txt: 62 → 57 entries.

Linked Issue

Tracker row 1a.3 (SSH hardening, Stage 1a). No GitHub issue.

Visual Proof

N/A: no visual change. The refusals are no-ops plus a console warning, and the Linear skip reuses an existing toast.

Testing

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

For each site there is a test where an ambiguous twin (local plus a paired server publishing the same id) refuses and touches nothing, and one where a runtime-owned row still routes to its server. All the refusal tests fail on origin/main (checked by restoring the old site files). Also added:

  • adapter golden over the resolveOwner characterization rows × Active Server,
  • restored-folder evidence,
  • warn-once dedupe,
  • a Linear sync skip.

Existing tests that mocked the deprecated resolver now seed real owner rows.

Local gates:

  • pnpm tc,
  • unit folders src/renderer/src/{lib,runtime,hooks,store} and components/{sidebar,terminal-pane,tab-group,floating-terminal,terminal,tab-bar},
  • the full static-analysis job mirror, including the focus-read and deprecated-owner ratchets.

Live verify: none.

AI Disclosure

Written with Claude Code. Reviewed with Codex (gpt-6.1-sol, high): round 1 had one P1 (fixed by keeping site 6 aligned with teardown) and one P2 (restored-folder evidence, fixed). Round 2 was clean.

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

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 4cef4da9-7560-4ed5-b45f-a8dc3b51575c
📥 Commits

Reviewing files that changed from the base of the PR and between f0efcb8 and ae7ded7.

📒 Files selected for processing: 2
  • src/renderer/src/runtime/web-runtime-terminal-actions.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.ts

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

📝 Walkthrough

The change adds shared workspace-owner resolution and uses it across terminal creation, pane checks, tab closing, runtime tab updates, and board task synchronization. These paths refuse or skip selected operations when ownership is ambiguous. PTY retirement uses resolved ownership when assigning identities to unscoped runtime IDs. Tests cover these outcomes, and the importer and focus-setting read baselines are updated.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to ae7de

The owner-routing changes introduce no actionable merge risk in the reviewed evidence. An ambiguous-worktree PTY retirement edge case predates this PR and is unchanged in impact.

Pre-merge checks: Passed 3 · Failed 1 · Inconclusive 1

Failed Failed checks: 1 warning · 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 31.03% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 29 functions across 20 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive The description is detailed and covers the required explanation, changes, rationale, testing, visual proof, AI disclosure, and checklist. The Linked Issue section identifies an internal tracker row bu… Provide a link to the actual issue referenced by the PR, or confirm that the author is a repository maintainer and the internal tracker row is permitted under the template exception.
Passed Passed checks: 3 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 is concise and accurately describes the main change: destructive renderer callers now refuse ambiguous workspace ownership instead of treating it as local.
Full details: Description check

Explanation

The description is detailed and covers the required explanation, changes, rationale, testing, visual proof, AI disclosure, and checklist. The Linked Issue section identifies an internal tracker row but provides no actual issue link, so compliance depends on whether the author is covered by the maintainer exception in the template.

Resolution

Provide a link to the actual issue referenced by the PR, or confirm that the author is a repository maintainer and the internal tracker row is permitted under the template exception.

  • 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da8d4b0c-1e9f-42fe-a863-4f6c73ea8982
📥 Commits

Reviewing files that changed from the base of the PR and between 7adcefb and f0efcb8.

📒 Files selected for processing: 22
  • config/deprecated-runtime-owner-importers-baseline.txt
  • config/focus-setting-read-baseline.txt
  • src/renderer/src/components/sidebar/use-workspace-board-task-status-sync.test.ts
  • src/renderer/src/components/sidebar/use-workspace-board-task-status-sync.ts
  • src/renderer/src/components/sidebar/workspace-board-task-status-sync.test.ts
  • src/renderer/src/components/sidebar/workspace-board-task-status-sync.ts
  • src/renderer/src/components/tab-group/useTabGroupTabCloseCommands.test.tsx
  • src/renderer/src/hooks/ipc-events/tab-lifecycle-ipc-bridge.test.ts
  • src/renderer/src/hooks/ipc-events/tab-lifecycle-ipc-bridge.ts
  • src/renderer/src/lib/host-mirrored-pane-liveness.test.ts
  • src/renderer/src/lib/host-mirrored-pane-liveness.ts
  • src/renderer/src/lib/resolve-owner.test.ts
  • src/renderer/src/lib/resolve-owner.ts
  • src/renderer/src/lib/workspace-browser-tab-close.test.ts
  • src/renderer/src/lib/workspace-browser-tab-close.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/web-runtime-pane-layout-intent.test.ts
  • src/renderer/src/runtime/web-runtime-session-tab-props.test.ts
  • src/renderer/src/runtime/web-runtime-terminal-actions.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.test.ts
  • src/renderer/src/store/slices/terminal-tab-retirement.ts
💤 Files with no reviewable changes: 1
  • config/deprecated-runtime-owner-importers-baseline.txt

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

const owner = resolveRuntimeOwnerForWorktree(state, worktreeId)
// Why: a twin's legacy id can't be pinned to either host, so it matches only its own exact id.
if (owner.kind === 'ambiguous') {
return `pty:${ptyId}`

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

Scope ambiguous PTY identity to the worktree.

If two ambiguous worktrees contain the same legacy ptyId, this branch gives both terminals the same identity. The retirement plan can then mark separate terminals as shared. Include worktreeId in the ambiguous identity. Tabs in the same worktree will still share an identity. Add a test with two ambiguous worktrees to cover this case.

@nwparker
nwparker force-pushed the nwparker/destructive-callers-refuse-ambiguous branch from a459995 to ae7ded7 Compare October 17, 2026 23:30
@nwparker
nwparker changed the base branch from nwparker/host-worktree-target-purge to main October 17, 2026 23:30
@nwparker
nwparker merged commit 532cad2 into main Oct 17, 2026
51 of 71 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