Skip to content

[hardening 6/6] refactor: tighten the host-identity stack - #30124

Merged
nwparker merged 1 commit into
mainfrom
nwparker/host-identity-stack-cleanup
Oct 18, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/host-identity-stack-cleanup

Conversation

@nwparker

@nwparker nwparker commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​46 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3
Prod 37 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​239 $\color{#cf222e}{\Huge{\mathbf{−}}}$​380 $\color{#cf222e}{\Huge{\mathbf{−}}}$​141

Stack (host-identity hardening), bottom to top

  1. fix(worktrees): a host-scoped purge leaves a surviving twin's tabs and edits alone #30030 HostWorktreeTarget plus a host-scoped purge
  2. fix(renderer): destructive host callers refuse an ambiguous owner instead of reading it as local #30035 destructive callers refuse an ambiguous owner
  3. [hardening 3/N] refactor(renderer): fold getExplicitRuntimeEnvironmentIdForWorktree callers into resolveOwner #30059 owner lookups folded into resolveOwner
  4. [hardening 4/5] fix(sidebar): confirm before sleeping a workspace that another host's copy shares #30047 sleeping one copy of a twin sleeps the whole workspace, with a confirm
  5. [hardening 5/N] refactor(projects): shrink twin-removal teardown to the attributed close actions #30060 twin-removal attribution shrunk
  6. this PR: cleanup pass over 1–5

Net LoC (vs #30060): production 232 added / 380 removed (−148), tests 43 / 46 (−3). The stack's cumulative production diff against main drops from +1,638/−820 to +1,427/−757.

ELI5

The five PRs below this one taught Orca to tell apart two copies of the same workspace on two hosts (a "twin"). Along the way they added several small helpers that do the same thing under different names. This PR merges those duplicates and removes a few leftovers. Nothing the user sees should change.

What Changed

The user-facing behaviour stays the same. The code changes:

  • One read for "which paired server owns this workspace, if any". About a dozen callers each wrote owner.kind === 'resolved' ? owner.environmentId : null, and five of them wrapped it in a local helper (sshOwnerEnvironmentIdForPlatform, mirroredEnvironmentIdForWorkspace, sshOwnerEnvironmentId, isPairedServerLayout, hostEnvironmentIdForTabMirror, legacyMirroredFileEnvironmentId). They now share runtimeEnvironmentIdUnlessTwin in lib/resolve-owner.ts. It takes an optional action name that logs the twin refusal once.
  • One "ambiguous owner" warning. The stack added warnAmbiguousOwnerRefusalOnce, a second once-per-key console warning next to the existing warnAmbiguousOwnerOnce. Its set was never cleared, which is the same leak ambiguous-owner-warning-worktree-removal-leak.test.ts already guards against for the original. Both now go through lib/ambiguous-owner-warning.ts, which logs once per workspace and action and is cleared on worktree teardown. It is a leaf module so resolve-owner can import it without a cycle.
  • One shape for "one host's copy of a workspace". HostWorktreeTarget now carries id like the worktree row it brands, rather than worktreeId. That makes it a WorktreePurgeTarget already, so normalizeWorktreePurgeTarget is deleted and worktree-slice-lookups.ts is back to main's line.
  • Twin purge scopes are a plain map. collectHostTwinPurgeScopes returned { twinTargetKeys, byHost }, and twinTargetKeys could be derived from byHost. It now returns the map, and the purge works out which targets are full purges from the map's ids.
  • Leftover from the dropped per-copy sleep fence. store/repos/host-twin-terminal-evidence.ts was split out so the fence could share the attribution's terminal-evidence rules. The fence is gone and only the removal attribution used the module, so it is folded back. That restores main's ownsTerminal closure verbatim.
  • Single-caller modules inlined. sleep-failure-message.ts goes back into sleep-worktree-flow.ts, the only file that used it.
  • Reuse the existing host labeler. The twin-sleep confirm dialog's labelExecutionHosts built a new host registry. The dialog now uses selectExecutionHostDisplayLabel, which is already used to name a host to the user.
  • sleep-twin-confirmation.ts no longer converts each row to a HostWorktreeTarget and straight back again.
  • terminal-tab-create-through-layout-owner.ts: a helper had been placed between withMainTerminalFacts and its doc comment. The helper is gone, so the comment sits above its function again.

Why

These are only the duplicates the stack itself introduced or uncovered (AGENTS.md: reuse before reimplementing). I considered deleting mirrored-workspace-owner.ts too. I kept it because eight session-tabs tests mock that module by path, and it keeps a trim the other readers don't have.

Two changes affect only log output. I call them out because a reviewer could reasonably count them as behaviour:

  • The pre-existing warnAmbiguousOwnerOnce callers (activity-timestamp and unread persistence) now log once per workspace and action. Before, it was once per workspace across all actions. That's at most three lines per twin instead of one.
  • The stack's refusal warnings now use the existing message format ("Skipped …: workspace identity is ambiguous across hosts"), and worktree teardown clears them.

The confirm dialog's host names now come from selectExecutionHostDisplayLabel. It gives the same result for renamed hosts, paired servers, SSH targets and the local machine. It also falls back to a removed SSH target's last label, where the old code showed the raw id.

Left out on purpose: the owner.kind === 'ambiguous' early returns in native-chat-attachment-upload, native-chat-skill-discovery-context, file-explorer-operation-owner, useAgentDetectionTarget, workspace-file-drag-source and recently-closed-tabs. Each does something different on a twin (an early null, unresolved, or undefined), so folding them into the shared read would change behaviour. They stay explicit.

Linked Issue

Part of the host-identity hardening stack (design.md stage 1 / tracker 1.3, 1a.3, D77). No issue.

Visual Proof

N/A: no visual change. The confirm dialog's text and layout are unchanged. Only the code that looks up host names is shared now.

Testing

  • pnpm tc
  • pnpm test --maxWorkers=2 over src/renderer/src/{store,lib,runtime,hooks}, components/{sidebar,native-chat,right-sidebar} and the full components/terminal-pane folder
  • /tmp/hostid-track/static-gate.sh <merge-base>: GATE RESULT: PASS (full static-analysis job, including ratchets)
  • codex review --base nwparker/twin-removal-attribution-shrink: clean
  • Automated tests updated: resolve-owner.test.ts covers the shared read and the once-per-action refusal log in place of the deleted warning test. Mocks move to the shared read. The deleted labelExecutionHosts test goes with its function.

Ratchets: focus-read 1083, deprecated runtime owner 57, layout writers 211 main / 651 renderer, max-lines 4. None grew; this PR changes no baseline.

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

No wire, RPC or on-disk format changes. HostWorktreeTarget exists only in renderer memory. SSH, folder workspaces and cross-platform behaviour are 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/twin-removal-attribution-shrink branch from 4a4c4d4 to 6a952e0 Compare October 17, 2026 22:52
@nwparker
nwparker force-pushed the nwparker/host-identity-stack-cleanup branch from 2c5adf2 to 970abb8 Compare October 17, 2026 22:52
@nwparker
nwparker force-pushed the nwparker/twin-removal-attribution-shrink branch from 6a952e0 to 1ba9512 Compare October 18, 2026 04:00
@nwparker
nwparker force-pushed the nwparker/host-identity-stack-cleanup branch from 970abb8 to 0fea880 Compare October 18, 2026 04:12
@nwparker
nwparker changed the base branch from nwparker/twin-removal-attribution-shrink to main October 18, 2026 04:12
@coderabbitai

coderabbitai Bot commented Oct 18, 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: a0daa989-c61d-44eb-9b44-fe0adf6df4e3
📥 Commits

Reviewing files that changed from the base of the PR and between af056df and 0fea880.

📒 Files selected for processing: 47
  • src/renderer/src/components/editor/restored-editor-workspace-runtime-owner.ts
  • src/renderer/src/components/sidebar/SleepTwinWorkspaceDialog.tsx
  • src/renderer/src/components/sidebar/sleep-failure-message.ts
  • src/renderer/src/components/sidebar/sleep-twin-confirmation.test.ts
  • src/renderer/src/components/sidebar/sleep-twin-confirmation.ts
  • src/renderer/src/components/sidebar/sleep-worktree-flow.ts
  • src/renderer/src/components/sidebar/use-workspace-board-task-status-sync.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/tab-lifecycle-ipc-bridge.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/lib/agent-account-restart-startup.ts
  • src/renderer/src/lib/agent-resume-launch-target.ts
  • src/renderer/src/lib/ambiguous-owner-warning.ts
  • src/renderer/src/lib/execution-host-display-label.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/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-browser-tab-close.ts
  • src/renderer/src/lib/worktree-host-connection-phase.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.test.ts
  • src/renderer/src/runtime/close-mirrored-editor-tab.ts
  • src/renderer/src/runtime/layout-apply-send.ts
  • src/renderer/src/runtime/layout-owner-command.test.ts
  • src/renderer/src/runtime/web-runtime-terminal-actions.ts
  • src/renderer/src/runtime/web-session-tabs-sync/mirrored-workspace-owner.ts
  • src/renderer/src/store/repos/host-twin-terminal-evidence.ts
  • src/renderer/src/store/repos/repo-removal-host-twin-attribution.ts
  • src/renderer/src/store/repos/repo-removal-host-twin-teardown.ts
  • src/renderer/src/store/slices/ambiguous-owner-warning-worktree-removal-leak.test.ts
  • src/renderer/src/store/slices/editor/git/diff-runtime-owner.ts
  • src/renderer/src/store/slices/worktree-purge-target.ts
  • src/renderer/src/store/slices/worktrees/listing/worktree-owner-settings.ts
  • src/renderer/src/store/slices/worktrees/session/worktree-activity-bump.ts
  • src/renderer/src/store/slices/worktrees/session/worktree-slice-lookups.ts
  • src/renderer/src/store/slices/worktrees/teardown/host-twin-worktree-purge.ts
  • src/renderer/src/store/slices/worktrees/teardown/remove-worktree-store-cleanup.ts
  • src/renderer/src/store/slices/worktrees/teardown/worktree-purge-state.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
  • src/shared/worktree/host-qualified-identity.test.ts
  • src/shared/worktree/host-qualified-identity.ts
💤 Files with no reviewable changes: 4
  • src/renderer/src/components/sidebar/sleep-failure-message.ts
  • src/renderer/src/store/slices/worktree-purge-target.ts
  • src/renderer/src/lib/agent-resume-launch-target.ts
  • src/renderer/src/store/repos/host-twin-terminal-evidence.ts

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

📝 Walkthrough

The change adds runtimeEnvironmentIdUnlessTwin and shared per-worktree, per-action ambiguous-owner warning tracking. Renderer call sites and tests adopt these APIs. Host-twin purge scopes now use nested maps, and repository-removal attribution collects terminal PTY evidence locally. Host-qualified worktree targets use id instead of worktreeId. The sleep dialog uses the execution-host display-label selector, and sleep-failure message selection moves into the sleep-worktree flow module.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0fea8

No actionable issue was established that would prevent merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 56.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 51 functions across 43 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 this as the sixth host-identity hardening refactor and accurately summarizes the cleanup changes.
Description check Passed The description is detailed and covers the change, rationale, testing, visual proof, compatibility notes, and checklist. It does not provide an issue link and does not report separate lint and build c…
Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual proof, compatibility notes, and checklist. It does not provide an issue link and does not report separate lint and build commands, but the overall description is complete and relevant.

  • 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.

@nwparker
nwparker merged commit 6c45958 into main Oct 18, 2026
47 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