Skip to content

refactor(renderer): one owner adapter for the deprecated-resolver folds, pinned by an acceptance table - #30451

Merged
nwparker merged 2 commits into
mainfrom
nwparker/r3-owner-legacy-adapter
Oct 19, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/r3-owner-legacy-adapter

Conversation

@nwparker

@nwparker nwparker commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​122
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​161 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​157

ELI5

Orca has an old way and a new way of answering "which machine owns this workspace?". 57 files still use the old way. Before moving them, this PR adds the single helper they will all move to, plus a table test that pins its exact answer for every workspace shape we know about. Nothing calls the helper in production yet, so nothing changes for users.

What Changed

  • New resolveOwnerWithLegacyFallback in src/renderer/src/lib/worktree-runtime-owner.ts, next to the deprecated resolvers it replaces, so the deprecated-importer ratchet doesn't grow.

    • When a host is named (by the caller or by the active workspace selection), or when the rows carry a host stamp, it answers exactly as resolveOwner does. Twins and servers contesting one SSH host therefore stay ambiguous instead of reading as this computer.
    • When rows are missing or carry no host stamp, it gives the deprecated answer, including the "single saved and focused server" guess that terminal spawn already makes. Restored tabs, row-less setup terminals and pre-catalog folders keep working exactly as today.
  • New resolve-owner-acceptance.test.ts with a hand-reviewed fixture. It pins the full owner (endpoint and place) for all 76 matrix cases, plus probes:

    • a genuine twin;
    • a row-less worktree and a setup id under single focus;
    • a known repo with no worktree row;
    • a named host beating focus;
    • a repo twin with a detected local row.

    It also asserts that the adapter differs from the deprecated resolver only in the designed cases: folder and group twins, git twins, reconnect rivals or contested hosts, and the stale hub stamp.

  • conflict-repo::wt joins the matrix's ordinary ids, and the deprecated-resolver golden gains its 3 legacy values (unchanged behaviour).

  • The focus-read baseline for worktree-runtime-owner.ts goes 6 → 7 with an annotation. The adapter is the legacy focus path the folds move onto. fix(renderer): a created or lineage-refreshed worktree replaces only its own host's copy #30447 removes one reader elsewhere, and deleting the deprecated pair (round-3 F8) takes this file below 6.

Why

This is F0 of the SSH-hardening round 3 design (round3-design.md §2, §5, §6), which went through four adversarial Opus rounds and five Codex rounds.

The earlier attempts were rejected for these reasons:

  • Folding callers straight onto resolveOwner: it differs from the deprecated resolver in ways nobody had decided. Missing rows read as "refuse" or "local", which breaks setup terminals and teardown of row-less local terminals. Unstamped rows also lose the spawn-time server guess, so a close could land on a different machine than the one the shell was started on.
  • Putting a focus fallback inside resolveOwner: that would break its "never reads focus" contract and pull every caller into the focus-read ratchet.

One adapter with a pinned table makes each later fold a mechanical, reviewable swap.

Wire impact: none (renderer only).

Linked Issue

None (internal hardening; maintainer PR).

Visual Proof

N/A: no production caller yet, so no UI or behaviour change.

Testing

  • resolve-owner-acceptance.test.ts, the alias golden and resolve-owner.test.ts: 168 tests pass.

  • Unit tests, single worker: src/renderer/src/lib, src/renderer/src/store/terminals and src/renderer/src/store/slices. 1,113 files, 11,267 tests, all passed.

  • Full local pr.yml static job: 0 failures.

  • The managed-orcad Docker lane is dispatched on this head; the link is added when it finishes.

  • Codex review (gpt-6.1-sol, high): no findings.

  • I manually tested these changes locally

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

…ds, pinned by an acceptance table

resolveOwnerWithLegacyFallback answers as resolveOwner for a named host and for rows that carry a
host stamp, and keeps the deprecated answer (single focused runtime included) for missing and
unstamped rows. A full-owner acceptance table pins all matrix cases and asserts the only changes
from the deprecated resolver are the designed ones: twins and contested SSH hosts become ambiguous,
and a stale hub stamp routes through the server that names the target.
@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: f39dd53e-ee73-41f1-bfbd-1c5492300cd1
📥 Commits

Reviewing files that changed from the base of the PR and between 242f902 and fe8a319.

📒 Files selected for processing: 3
  • src/renderer/src/lib/resolve-owner-acceptance.test.ts
  • src/renderer/src/lib/resolve-owner.ts
  • 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; 7 remain after this review.

📝 Walkthrough

Adds resolveOwnerWithLegacyFallback, which uses canonical owner resolution when host evidence or specific routing conditions apply. Otherwise, it can use the legacy runtime environment or return local authority. Adds acceptance tests and fixtures for owner outcomes across focus states, active-owner selections, and repository and worktree cases.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to fe8a3

No additional merge-blocking issue is established for the current change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the renderer refactor: one legacy-resolver owner adapter backed by an acceptance table.
Description check Passed The description is complete and focused. It explains the user impact, implementation, rationale, linked-issue exception, visual proof, testing, and scope. Automated validation is detailed, and the unc…
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.
Full details: Description check

Explanation

The description is complete and focused. It explains the user impact, implementation, rationale, linked-issue exception, visual proof, testing, and scope. Automated validation is detailed, and the unchecked manual-testing item is non-critical because the PR introduces no production caller or UI change.

  • 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: 33579dca-e12f-407e-b8ea-c07b64cde6e8
📥 Commits

Reviewing files that changed from the base of the PR and between 30a66ac and 242f902.

📒 Files selected for processing: 6
  • config/focus-setting-read-baseline.txt
  • src/renderer/src/lib/resolve-owner-acceptance.test-fixture.ts
  • src/renderer/src/lib/resolve-owner-acceptance.test.ts
  • src/renderer/src/lib/runtime-owner-alias-golden.test-fixture.ts
  • src/renderer/src/lib/runtime-owner-alias-matrix.test-fixture.ts
  • 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; 4 remain after this review.

Comment on lines +240 to +260
function hasHostEvidence(state: WorktreeRuntimeOwnerState, workspaceId: string): boolean {
const scope = parseWorkspaceKey(workspaceId)
if (scope?.type === 'folder') {
const folder = findFolderWorkspaceOwner(state, scope.folderWorkspaceId)
return Boolean(
folder &&
(hasRowHost(folder) ||
state.projectGroups?.some(
(group) => group.id === folder.projectGroupId && hasRowHost(group)
))
)
}
const repoId = getRepoIdFromWorktreeId(workspaceId)
const isStampedCopy = (row: Parameters<typeof isStampedWorktreeRow>[0] & { id: string }) =>
row.id === workspaceId && isStampedWorktreeRow(row)
return Boolean(
state.worktreesByRepo?.[repoId]?.some(isStampedCopy) ||
state.detectedWorktreesByRepo?.[repoId]?.worktrees.some(isStampedCopy) ||
state.repos?.some((repo) => repo.id === repoId && hasRowHost(repo))
)
}

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

🔎 Supported by static analysis

🏁 Script executed:

sed -n '225,300p' src/renderer/src/lib/worktree-runtime-owner.ts
rg -n 'parseWorkspaceKey|getRepoIdFromWorktreeId|worktree:|resolveRoute' src/renderer/src/lib/resolve-owner.ts src/renderer/src/lib/worktree-operation-route.ts src/renderer/src/lib/worktree-runtime-owner.ts

Repository: stablyai/orca

Length of output: 4928


🏁 Script executed:

set -e
printf '%s\n' '--- workspace scope parser ---'
rg -n -C 12 -F -- 'export function parseWorkspaceKey' src/shared src
printf '%s\n' '--- worktree ID helper ---'
rg -n -C 12 -F -- 'function getRepoIdFromWorktreeId' src
printf '%s\n' '--- resolve-owner routing and resolver ---'
sed -n '1,220p' src/renderer/src/lib/resolve-owner.ts
printf '%s\n' '--- runtime owner relevant definitions ---'
sed -n '1,230p' src/renderer/src/lib/worktree-runtime-owner.ts
printf '%s\n' '--- operation route scoped handling ---'
sed -n '240,315p' src/renderer/src/lib/worktree-operation-route.ts
printf '%s\n' '--- adapter callers and scoped test cases ---'
rg -n -C 5 -F -e 'resolveOwnerWithLegacyFallback' -e 'worktree:' src/renderer/src/lib src/renderer/src -g '*.ts' -g '*.tsx' || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 45660


🏁 Script executed:

set -e
printf '%s\n' '--- parser and ID helpers ---'
sed -n '1,70p' src/shared/workspace-scope.ts
sed -n '1,75p' src/shared/worktree/id.ts
printf '%s\n' '--- route implementation symbols ---'
rg -n -F -e 'export function resolveWorktreeOperationRouteResult' -e 'function resolveWorktreeOperationRouteResult' -e 'export function resolveActiveWorkspaceRoute' -e 'function resolveActiveWorkspaceRoute' src/renderer/src/lib src/shared
printf '%s\n' '--- route implementation ---'
sed -n '250,330p' src/renderer/src/lib/worktree-operation-route.ts
printf '%s\n' '--- deprecated resolver and changed adapter ---'
rg -n -F -e 'export function resolveRuntimeOwnerForWorktree' -e 'export function resolveOwnerWithLegacyFallback' src/renderer/src/lib/worktree-runtime-owner.ts
sed -n '60,150p' src/renderer/src/lib/worktree-runtime-owner.ts
sed -n '235,300p' src/renderer/src/lib/worktree-runtime-owner.ts
printf '%s\n' '--- exact adapter references and focused tests ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -- 'resolveOwnerWithLegacyFallback' src || test "$?" -eq 1
rg --files src | rg 'resolve-owner|runtime-owner|worktree-operation-route' | head -80

Repository: stablyai/orca

Length of output: 18546


🏁 Script executed:

set -e
printf '%s\n' '--- active and explicit route handling ---'
sed -n '75,155p' src/renderer/src/lib/worktree-operation-route.ts
sed -n '210,290p' src/renderer/src/lib/worktree-operation-route.ts
rg -n -C 8 -F -e 'export function resolveExplicitWorktreeOperationRouteResult' -e 'function resolveExplicitWorktreeOperationRouteResult' src/renderer/src/lib
printf '%s\n' '--- indexed worktree lookup ---'
rg -n -C 12 -F -e 'export function resolveIndexedWorktreeOwner' -e 'function resolveIndexedWorktreeOwner' src/renderer/src/lib/worktree-runtime-owner-index.ts
printf '%s\n' '--- acceptance tests and fixture scoped IDs ---'
sed -n '1,120p' src/renderer/src/lib/resolve-owner-acceptance.test.ts
rg -n -C 5 -F -e 'worktree:' -e 'WorkspaceOwnerRef' src/renderer/src/lib/resolve-owner-acceptance.test-fixture.ts src/renderer/src/lib/resolve-owner-acceptance.test.ts src/renderer/src/lib/resolve-owner.test.ts src/renderer/src/lib/worktree-operation-route.test.ts

Repository: stablyai/orca

Length of output: 15991


🏁 Script executed:

set -e
printf '%s\n' '--- indexed lookup complete function ---'
sed -n '192,245p' src/renderer/src/lib/worktree-runtime-owner-index.ts
printf '%s\n' '--- explicit route complete function ---'
sed -n '31,115p' src/renderer/src/lib/worktree-operation-catalog-route.ts
printf '%s\n' '--- fixture ID construction and scoped references ---'
rg -n -C 4 -F -e 'worktreeId:' -e 'worktreeWorkspaceKey' -e 'worktree:' src/renderer/src/lib/runtime-owner-alias-matrix.test-fixture.ts src/renderer/src/lib/resolve-owner-acceptance.test-fixture.ts src/renderer/src/lib/resolve-owner-acceptance.test.ts
printf '%s\n' '--- all exact adapter references outside generated/vendor paths ---'
rg -n -F --glob '*.ts' --glob '*.tsx' -- 'resolveOwnerWithLegacyFallback' src/renderer/src | cut -d: -f1-3

Repository: stablyai/orca

Length of output: 7169


Normalize scoped worktree keys before owner resolution.

parseWorkspaceKey accepts worktree:<id>, but this adapter passes the scoped value unchanged. For worktree:repo::/path, the repo lookup derives worktree:repo, while the indexes contain repo::/path under repo repo. Both owner lookups can therefore miss the canonical remote row, and the adapter can return self@local.

Suggested fix
 export function resolveOwnerWithLegacyFallback(
   state: WorktreeRuntimeOwnerState,
   ref: WorkspaceOwnerRef
 ): ExecutionHostOwnerMatch<HostAuthority> {
-  const match = resolveOwner(state, ref)
+  const scope = parseWorkspaceKey(ref.workspaceId)
+  const normalizedRef =
+    scope?.type === 'worktree' ? { ...ref, workspaceId: scope.worktreeId } : ref
+  const match = resolveOwner(state, normalizedRef)
   const hostNamed =
     Boolean(ref.hostId) ||
-    (state.activeWorktreeId === ref.workspaceId && Boolean(state.activeWorkspaceExecutionHostId))
+    (state.activeWorktreeId === normalizedRef.workspaceId &&
+      Boolean(state.activeWorkspaceExecutionHostId))
   if (
     hostNamed ||
     match.kind === 'ambiguous' ||
-    getFloatingWorkspaceOperationRoute(ref.workspaceId) ||
-    (match.kind === 'resolved' && hasHostEvidence(state, ref.workspaceId))
+    getFloatingWorkspaceOperationRoute(normalizedRef.workspaceId) ||
+    (match.kind === 'resolved' && hasHostEvidence(state, normalizedRef.workspaceId))
   ) {
     return match
   }
-  const legacyEnvironmentId = getRuntimeEnvironmentIdForWorktree(state, ref.workspaceId)
+  const legacyEnvironmentId = getRuntimeEnvironmentIdForWorktree(
+    state,
+    normalizedRef.workspaceId
+  )

… rule

Clean-code pass: one namedHostForOwnerRef for both resolvers, floating counts as host evidence,
and the acceptance test drops non-null assertions.
@nwparker
nwparker merged commit a8e90dd into main Oct 19, 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