Skip to content

Use host-qualified worktree identities - #6096

Closed
Jinwoo-H wants to merge 15 commits into
mainfrom
codex/host-qualified-worktree-identities
Closed

Jinwoo-H wants to merge 15 commits into
mainfrom
codex/host-qualified-worktree-identities

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • consolidate the fixes from Preserve same-id repos across hosts #6030 and Preserve shared project host setups on refresh #6031 for same-id repos/project host setups across hosts
  • add canonical host-qualified worktree IDs while keeping legacy repoId::path IDs accepted at compatibility and persistence boundaries
  • migrate renderer/main/runtime state aliases so metadata, lineage, terminals, cleanup, and reconnect state follow the canonical ID
  • harden the renderer migration contract so new *ByWorktree* maps cannot be silently missed

Tests

  • pnpm run typecheck
  • pnpm run lint
  • git diff --check
  • pnpm exec vitest run --config config/vitest.config.ts src/main/ipc/repos-remote.test.ts
  • pnpm exec vitest run --config config/vitest.config.ts src/shared/worktree-id.test.ts src/main/daemon/pty-session-id.test.ts src/main/persistence.test.ts src/main/ipc/worktrees.test.ts src/main/ipc/repos-remote.test.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/runtime-rpc.test.ts src/renderer/src/store/slices/repos-host-identity-routing.test.ts src/renderer/src/store/slices/repos-same-id-host-mutations.test.ts src/renderer/src/store/slices/repos-update-serialization.test.ts src/renderer/src/store/slices/repos.test.ts src/renderer/src/lib/project-host-workspace-target.test.ts src/renderer/src/store/slices/worktrees.test.ts src/main/ipc/worktree-push-target-cleanup.test.ts src/renderer/src/lib/worktree-creation-flow.test.ts (15 files, 1377 tests)
  • Electron validation on this exact PR worktree: window.api.app.getIdentity() reported branch codex/host-qualified-worktree-identities and root /Users/jinwoohong/orca/workspaces/orca/review-orca-server-prs.
  • Local disposable demo-project: added project, created a worktree from main, verified the visible sidebar row, verified the worktree ID was orca-worktree://v1?...hostId=local..., verified git worktree list --porcelain, then removed it through Orca and confirmed no test branch/path remained.
  • Non-git folder project: added a disposable kind: "folder" project, created a folder workspace, and verified the main and child folder workspace IDs were host-qualified with hostId=local.
  • SSH live validation using a throwaway Debian Docker target, not localhost SSH: built relay with pnpm build:relay, connected target ssh-1782331073601-etpfjo, registered remote /work/demo-project, created/listed/removed /work/ssh-id-e2e-1782331210923, verified visible SSH project/worktree rows, and confirmed remote git worktree list --porcelain, branch list, and /work had no test artifacts after cleanup.
  • Mock paired-runtime validation: started a temporary OrcaRuntimeRpcServer with real E2EE WebSocket pairing, added it through window.api.runtimeEnvironments.addFromPairingCode, verified runtimeEnvironments.getStatus, then exercised repo.list, worktree.list, worktree.create, and worktree.rm through window.api.runtimeEnvironments.call. The created runtime worktree ID was orca-worktree://v1?...hostId=runtime%3Amock-paired&repoId=mock-repo-1..., and list count returned to 1 after removal.
  • Cleanup: removed disposable repos from the isolated Orca profile, removed local temp repos/folders, removed the SSH Docker container/temp key/profile, closed Playwright, and stopped only the Electron process launched for validation.

Notes:

  • Local commands ran on Node v26.0.0 while the repo engine warning asks for Node 24.

Made with Orca 🐋


Open in Stage

@coderabbitai

coderabbitai Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request migrates worktree identifiers from legacy repoId::path strings to canonical orca-worktree://v1?hostId=...&repoId=...&path=... keys throughout the stack. The shared worktree-id.ts module gains builders (makeWorktreeKey, makeRepoWorktreeKey), parsers (parseWorktreeKey, parseAnyWorktreeId, isLegacyWorktreeId), and alias-generation helpers. Legacy IDs remain accepted at public boundaries while discovered/created worktrees are written with canonical keys. Per-host project setup mutations are extended with optional hostId in shared types, IPC/RPC Zod schemas, and the persistence layer. The main process IPC handlers canonicalize state on discovery, support host-aware cleanup and remote creation, and implement safe legacy-to-canonical meta migration with host-compatibility checks. The runtime applies alias-aware worktree resolution, normalizes lineage to canonical IDs, and handles folder workspace identity migration. The renderer repos and worktrees slices gain host-scoped refresh merging, host-aware mutation routing, and lineage rename propagation. Renderer hooks propagate ownerHostId through worktree refresh queues and IPC bridges. A rollout validation document is added.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.48% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers summary, tests, and notes, but it omits the required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections, including 'No visual change' for screenshots, a cross-platform AI review summary, and a basic security audit.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: introducing host-qualified worktree identities as canonical replacements/additions to legacy ID formats.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
src/renderer/src/store/slices/repos.ts (1)

1330-1341: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Match repo rows by host-qualified identity, not repo.id alone.

These paths still treat repo.id as globally unique. With same-id repos on different hosts, adding/setup/update/delete can reject a valid sibling, overwrite another host’s row, or remove it from state. Use (repo.id, getRepoExecutionHostId(repo)) consistently, and use isSameProjectHostSetup for setup rows in setupProjectExistingFolder.

🐛 Proposed direction
 function isSameProjectHostSetup(a: ProjectHostSetup, b: ProjectHostSetup): boolean {
   return a.id === b.id && a.hostId === b.hostId
 }
+
+function isSameRepoIdentity(
+  a: Pick<Repo, 'id' | 'connectionId' | 'executionHostId'>,
+  b: Pick<Repo, 'id' | 'connectionId' | 'executionHostId'>
+): boolean {
+  return a.id === b.id && getRepoExecutionHostId(a) === getRepoExecutionHostId(b)
+}
@@
-      const alreadyAdded = get().repos.some((r) => r.id === repo.id)
+      const alreadyAdded = get().repos.some((r) => isSameRepoIdentity(r, repo))
@@
-        if (s.repos.some((r) => r.id === repo.id)) {
+        if (s.repos.some((r) => isSameRepoIdentity(r, repo))) {
           return s
         }
@@
-        const nextRepos = s.repos.some((entry) => entry.id === repo.id)
-          ? s.repos.map((entry) => (entry.id === repo.id ? repo : entry))
+        const nextRepos = s.repos.some((entry) => isSameRepoIdentity(entry, repo))
+          ? s.repos.map((entry) => (isSameRepoIdentity(entry, repo) ? repo : entry))
           : [...s.repos, repo]
@@
-        const nextSetups = s.projectHostSetups.some((entry) => entry.id === setup.id)
-          ? s.projectHostSetups.map((entry) => (entry.id === setup.id ? setup : entry))
+        const nextSetups = s.projectHostSetups.some((entry) =>
+          isSameProjectHostSetup(entry, setup)
+        )
+          ? s.projectHostSetups.map((entry) =>
+              isSameProjectHostSetup(entry, setup) ? setup : entry
+            )
           : [...s.projectHostSetups, setup]
@@
-          ? s.repos.some((entry) => entry.id === repo.id)
-            ? s.repos.map((entry) => (entry.id === repo.id ? repo : entry))
+          ? s.repos.some((entry) => isSameRepoIdentity(entry, repo))
+            ? s.repos.map((entry) => (isSameRepoIdentity(entry, repo) ? repo : entry))
             : [...s.repos, repo]
@@
-        const repos = repo ? s.repos.filter((entry) => entry.id !== repo.id) : s.repos
+        const repos = repo
+          ? s.repos.filter((entry) => !isSameRepoIdentity(entry, repo))
+          : s.repos

Also applies to: 1390-1398, 1479-1482, 1528-1528

src/main/usage-worktree-metadata.ts (1)

25-33: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Host collisions still collapse usage state by repo.id.

Line 26/31 keys usage buckets by repo.id only. With same-id repos on different hosts, one host overwrites the other and later metadata can be attributed to the wrong repo host. This path needs host-qualified bucketing (e.g., (hostId, repoId)) end-to-end.

Also applies to: 38-39, 53-59

src/main/ipc/worktrees.ts (1)

579-586: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missing hostId in mergeWorktree call for disconnected SSH worktrees.

Other discovery paths (e.g., buildDetectedGitWorktrees at line 602-604, stampAndMergeVisibleDetectedWorktree at line 638-640) now pass { hostId: getRepoExecutionHostId(repo) } to mergeWorktree. This call is missing that option, which could result in inconsistent worktree identity for disconnected SSH repos.

Proposed fix
     const worktree = mergeWorktree(
       repo.id,
       synthesizeSshGitWorktree(repo, candidate.path, meta),
-      meta
+      meta,
+      repo.displayName,
+      { hostId: getRepoExecutionHostId(repo) }
     )
🧹 Nitpick comments (4)
src/renderer/src/store/slices/project-host-setup-compatibility-merge.test.ts (1)

13-13: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Use path utilities for fixture paths.

These fixture paths hard-code /; use node:path so the test stays cross-platform.

♻️ Proposed change
+import { join } from 'node:path'
 import { describe, expect, it } from 'vitest'
@@
-    path: `/${hostId}/${id}`,
+    path: join('/', hostId, id),
@@
-    path: `/${hostId}/${repoId}`,
+    path: join('/', hostId, repoId),

As per coding guidelines, “Use path.join or Electron/Node path utilities for file paths — never assume / or \ for cross-platform compatibility.”

Also applies to: 33-33

Source: Coding guidelines

src/renderer/src/components/settings/RepositoryHostSetupsSection.tsx (1)

27-29: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a one-line rationale for the composite setup key format.

Line 27 builds a hostId + '\0' + id key, which is a non-obvious constraint for same-id cross-host disambiguation. Please add a brief “why” comment to prevent accidental regressions.

As per coding guidelines, “When writing or modifying code driven by a design doc or non-obvious constraint, add a comment explaining why the code behaves the way it does.”

Source: Coding guidelines

src/main/ipc/remote-workspace.ts (1)

261-268: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Consider: the host-ID validation appears tautological.

makeRepoWorktreeKey(repo, worktreePath) already embeds getRepoExecutionHostId(repo) into the canonical key. The subsequent check that splitWorktreeId(candidate)?.hostId === getRepoExecutionHostId(repo) will therefore always be true for any candidate produced by that call.

This is harmless defensive coding, but if intentional as a guard against future refactors, a brief comment explaining the invariant would help future readers understand the purpose.

src/main/runtime/orca-runtime.test.ts (1)

1794-1803: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Extract a small canonical-ID test helper to reduce repeated setup drift.

Line 1794 and similar blocks duplicate makeWorktreeKey object literals across many tests. A helper keeps host/repo/path shape consistent and makes failures easier to read.

Proposed refactor
+const mkCanonicalWorktreeId = (hostId: string, repoId: string, path: string) =>
+  makeWorktreeKey({ hostId, repoId, path })

-const canonicalMainId = makeWorktreeKey({
-  hostId: 'ssh:ssh-missing',
-  repoId: remoteRepo.id,
-  path: '/home/user/repo'
-})
+const canonicalMainId = mkCanonicalWorktreeId('ssh:ssh-missing', remoteRepo.id, '/home/user/repo')

Also applies to: 2791-2797, 2836-2845, 14744-14748, 15561-15570, 15875-15884, 16331-16340, 21136-21140


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 73b5ae60-4c50-492c-8a89-161f484e3991

📥 Commits

Reviewing files that changed from the base of the PR and between 338540b and 18b6833.

📒 Files selected for processing (51)
  • docs/worktree-host-identity-rollout-validation.md
  • src/main/daemon/pty-session-id.test.ts
  • src/main/ipc/remote-workspace.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/workspace-cleanup.test.ts
  • src/main/ipc/workspace-cleanup.ts
  • src/main/ipc/worktree-metadata-merge.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/memory/hydrate-local-pty-registry.test.ts
  • src/main/memory/hydrate-local-pty-registry.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/project-runtime-rpc-methods.ts
  • src/main/runtime/worktree-teardown.ts
  • src/main/usage-worktree-metadata.ts
  • src/main/workspace-space-analysis.ts
  • src/renderer/src/components/settings/McpConfigSection.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.tsx
  • src/renderer/src/hooks/useIpcEvents.test.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/hooks/worktree-change-refresh-queue.ts
  • src/renderer/src/lib/project-host-workspace-target.test.ts
  • src/renderer/src/lib/project-host-workspace-target.ts
  • src/renderer/src/lib/repo-runtime-owner.test.ts
  • src/renderer/src/lib/repo-runtime-owner.ts
  • src/renderer/src/lib/worktree-runtime-owner.test.ts
  • src/renderer/src/lib/worktree-runtime-owner.ts
  • src/renderer/src/store/slices/project-host-setup-compatibility-merge.test.ts
  • src/renderer/src/store/slices/project-host-setup-compatibility-merge.ts
  • src/renderer/src/store/slices/repo-host-refresh-merge.test.ts
  • src/renderer/src/store/slices/repo-host-refresh-merge.ts
  • src/renderer/src/store/slices/repo-identity-reconcile.test.ts
  • src/renderer/src/store/slices/repo-identity-reconcile.ts
  • src/renderer/src/store/slices/repo-reorder-host-split.test.ts
  • src/renderer/src/store/slices/repo-reorder-host-split.ts
  • src/renderer/src/store/slices/repos-multi-host-refresh.test.ts
  • src/renderer/src/store/slices/repos-project-host-lifecycle.test.ts
  • src/renderer/src/store/slices/repos-same-id-host-mutations.test.ts
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/shared/pty-session-id-format.ts
  • src/shared/types.ts
  • src/shared/worktree-id.test.ts
  • src/shared/worktree-id.ts

@Jinwoo-H
Jinwoo-H force-pushed the codex/host-qualified-worktree-identities branch from d4c3fbb to d69c2ad Compare June 24, 2026 01:52

@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: Pro

Run ID: cbf61708-1b61-4919-b73b-7482f98a3d8c

📥 Commits

Reviewing files that changed from the base of the PR and between d4c3fbb and d69c2ad.

📒 Files selected for processing (31)
  • docs/worktree-host-identity-rollout-validation.md
  • src/main/claude-usage/scanner.ts
  • src/main/codex-usage/scanner.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/ipc/remote-workspace.ts
  • src/main/ipc/repos.ts
  • src/main/ipc/workspace-cleanup.test.ts
  • src/main/ipc/workspace-cleanup.ts
  • src/main/ipc/worktree-logic.test.ts
  • src/main/ipc/worktree-metadata-merge.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/memory/hydrate-local-pty-registry.test.ts
  • src/main/memory/hydrate-local-pty-registry.ts
  • src/main/opencode-usage/scanner.ts
  • src/main/persistence.test.ts
  • src/main/persistence.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/rpc/methods/project-runtime-rpc-methods.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/worktree-teardown.ts
  • src/main/usage-worktree-metadata.test.ts
  • src/main/usage-worktree-metadata.ts
  • src/main/workspace-space-analysis.test.ts
  • src/main/workspace-space-analysis.ts
  • src/renderer/src/components/settings/McpConfigSection.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.tsx
💤 Files with no reviewable changes (5)
  • src/renderer/src/components/settings/McpConfigSection.tsx
  • src/main/workspace-space-analysis.test.ts
  • src/main/workspace-space-analysis.ts
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.test.tsx
  • src/renderer/src/components/settings/RepositoryHostSetupsSection.tsx
✅ Files skipped from review due to trivial changes (1)
  • docs/worktree-host-identity-rollout-validation.md
🚧 Files skipped from review as they are similar to previous changes (17)
  • src/main/ipc/worktree-logic.test.ts
  • src/main/runtime/rpc/methods/project-runtime-rpc-methods.ts
  • src/main/daemon/pty-session-id.test.ts
  • src/main/ipc/worktree-metadata-merge.ts
  • src/main/memory/hydrate-local-pty-registry.ts
  • src/main/ipc/remote-workspace.ts
  • src/main/ipc/repos.ts
  • src/main/persistence.test.ts
  • src/main/ipc/worktrees-windows.test.ts
  • src/main/runtime/runtime-rpc.test.ts
  • src/main/runtime/worktree-teardown.ts
  • src/main/ipc/worktree-remote.ts
  • src/main/persistence.ts
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts

Comment thread src/main/ipc/workspace-cleanup.ts Resolved

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/store/slices/repos.ts (1)

2036-2039: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Route host-setup mutations using args.hostId when lookup misses.

If findProjectHostSetupByMutationArgs(...) returns no match, both methods default to local target. For runtime-scoped mutations, that can dispatch update/delete to the wrong host (or wrong setup when same IDs exist across hosts).

💡 Suggested fix
-      const target = currentSetup
-        ? getProjectSetupRuntimeTarget(currentSetup.hostId)
-        : { kind: 'local' as const }
+      const target = getProjectSetupRuntimeTarget(currentSetup?.hostId ?? args.hostId)
-      const target = currentSetup
-        ? getProjectSetupRuntimeTarget(currentSetup.hostId)
-        : { kind: 'local' as const }
+      const target = getProjectSetupRuntimeTarget(currentSetup?.hostId ?? args.hostId)

Also applies to: 2086-2089


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a8342a31-780a-4334-88cd-39addfca8332

📥 Commits

Reviewing files that changed from the base of the PR and between d69c2ad and cb53486.

📒 Files selected for processing (2)
  • src/main/runtime/orca-runtime.test.ts
  • src/renderer/src/store/slices/repos.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/runtime/orca-runtime.test.ts

@Jinwoo-H
Jinwoo-H force-pushed the codex/host-qualified-worktree-identities branch from fc743df to e814b3c Compare June 24, 2026 06:51
@AmethystLiang AmethystLiang added the orca-remote-server Remote Orca Server / orca serve / paired remote runtime label Jul 22, 2026
@OrcaWin
OrcaWin marked this pull request as draft October 27, 2026 09:53
@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Moving this PR to draft because it has been untouched for more than 80 days (latest recorded PR activity or commit timestamp: 2026-07-22T17:41:35Z; checked on 2026-10-27). This keeps the review queue focused on active work while preserving the proposal. Please mark it ready for review when work resumes.

@nwparker

nwparker commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Superseded by #16691, which shipped host-qualified worktree identities. Closing.

@nwparker nwparker closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orca-remote-server Remote Orca Server / orca serve / paired remote runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants