You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[hardening 6/6] refactor: tighten the host-identity stack - #30124
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)
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)
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: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
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 checks: 4 passed
Check name
Status
Explanation
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Title check
The title clearly identifies this as the sixth host-identity hardening refactor and accurately summarizes the cleanup changes.
Description check
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack (host-identity hardening), bottom to top
resolveOwnerNet 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:
owner.kind === 'resolved' ? owner.environmentId : null, and five of them wrapped it in a local helper (sshOwnerEnvironmentIdForPlatform,mirroredEnvironmentIdForWorkspace,sshOwnerEnvironmentId,isPairedServerLayout,hostEnvironmentIdForTabMirror,legacyMirroredFileEnvironmentId). They now shareruntimeEnvironmentIdUnlessTwininlib/resolve-owner.ts. It takes an optional action name that logs the twin refusal once.warnAmbiguousOwnerRefusalOnce, a second once-per-key console warning next to the existingwarnAmbiguousOwnerOnce. Its set was never cleared, which is the same leakambiguous-owner-warning-worktree-removal-leak.test.tsalready guards against for the original. Both now go throughlib/ambiguous-owner-warning.ts, which logs once per workspace and action and is cleared on worktree teardown. It is a leaf module soresolve-ownercan import it without a cycle.HostWorktreeTargetnow carriesidlike the worktree row it brands, rather thanworktreeId. That makes it aWorktreePurgeTargetalready, sonormalizeWorktreePurgeTargetis deleted andworktree-slice-lookups.tsis back to main's line.collectHostTwinPurgeScopesreturned{ twinTargetKeys, byHost }, andtwinTargetKeyscould be derived frombyHost. It now returns the map, and the purge works out which targets are full purges from the map's ids.store/repos/host-twin-terminal-evidence.tswas 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'sownsTerminalclosure verbatim.sleep-failure-message.tsgoes back intosleep-worktree-flow.ts, the only file that used it.labelExecutionHostsbuilt a new host registry. The dialog now usesselectExecutionHostDisplayLabel, which is already used to name a host to the user.sleep-twin-confirmation.tsno longer converts each row to aHostWorktreeTargetand straight back again.terminal-tab-create-through-layout-owner.ts: a helper had been placed betweenwithMainTerminalFactsand 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.tstoo. I kept it because eight session-tabs tests mock that module by path, and it keeps atrimthe other readers don't have.Two changes affect only log output. I call them out because a reviewer could reasonably count them as behaviour:
warnAmbiguousOwnerOncecallers (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 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 innative-chat-attachment-upload,native-chat-skill-discovery-context,file-explorer-operation-owner,useAgentDetectionTarget,workspace-file-drag-sourceandrecently-closed-tabs. Each does something different on a twin (an earlynull,unresolved, orundefined), 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 tcpnpm test --maxWorkers=2oversrc/renderer/src/{store,lib,runtime,hooks},components/{sidebar,native-chat,right-sidebar}and the fullcomponents/terminal-panefolder/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: cleanresolve-owner.test.tscovers the shared read and the once-per-action refusal log in place of the deleted warning test. Mocks move to the shared read. The deletedlabelExecutionHoststest 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
Notes
No wire, RPC or on-disk format changes.
HostWorktreeTargetexists only in renderer memory. SSH, folder workspaces and cross-platform behaviour are untouched.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)