Skip to content

Preserve same-id repos across hosts - #6030

Closed
prateek wants to merge 1 commit into
stablyai:mainfrom
prateek:codex/upstream-repo-reconcile-host-identity
Closed

prateek wants to merge 1 commit into
stablyai:mainfrom
prateek:codex/upstream-repo-reconcile-host-identity

Conversation

@prateek

@prateek prateek commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Context

Tracking issue: #6032

Remote Orca Servers can report repositories that share the same repo id across different hosts. The store had several paths that treated repo.id as globally unique. Refreshing or mutating one host could replace, remove, or reorder the row for another host with the same id. That breaks the SSH and remote-server case where two machines have independent checkouts of the same project.

Changed

  • Reconcile fetched repos by host-qualified identity.
  • Preserve same-id repos from other hosts when one host refreshes.
  • Route updateRepo, removeProject, and repo reorder operations to the matching host row.
  • Keep worktree ownership checks host-aware so same-id sibling repos keep their worktree and tab state.

Regression coverage

The tests model two hosts that expose the same repo id, then exercise refresh, update, removal, reorder, and runtime-owner lookup. These fail on main because the old store collapses rows by bare repo.id.

Tests

  • pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/store/slices/repo-identity-reconcile.test.ts src/renderer/src/store/slices/repo-host-refresh-merge.test.ts src/renderer/src/store/slices/repos-multi-host-refresh.test.ts src/renderer/src/store/slices/repos-same-id-host-mutations.test.ts src/renderer/src/store/slices/repo-reorder-host-split.test.ts src/renderer/src/lib/repo-runtime-owner.test.ts src/renderer/src/store/slices/repos-update-serialization.test.ts src/renderer/src/store/slices/project-host-setup-compatibility-merge.test.ts
  • pnpm exec oxlint src/renderer/src/lib/repo-runtime-owner.ts src/renderer/src/lib/repo-runtime-owner.test.ts src/renderer/src/store/slices/repo-host-refresh-merge.ts src/renderer/src/store/slices/repo-host-refresh-merge.test.ts src/renderer/src/store/slices/repo-identity-reconcile.ts src/renderer/src/store/slices/repo-identity-reconcile.test.ts src/renderer/src/store/slices/repo-reorder-host-split.ts src/renderer/src/store/slices/repo-reorder-host-split.test.ts src/renderer/src/store/slices/repos.ts src/renderer/src/store/slices/repos-multi-host-refresh.test.ts src/renderer/src/store/slices/repos-same-id-host-mutations.test.ts src/renderer/src/store/slices/project-host-setup-compatibility-merge.ts src/renderer/src/store/slices/project-host-setup-compatibility-merge.test.ts
  • pnpm run typecheck:web

Stack

  1. This PR: preserve same-id repos across hosts.
  2. Preserve shared project host setups on refresh #6031: preserve shared project host setup state across host refreshes.

Open in Stage

@ghost

ghost commented Jun 22, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR makes repo operations host-aware throughout the renderer store so that the same repo id can coexist on different execution hosts (local and runtime environments) without cross-host state collisions. The composite key (executionHostId, repo.id) replaces repo.id alone in reconciliation, refresh merging, reorder splitting, and mutation targeting. New helpers (mergeFetchedReposForHost, getRepoMutationOwnerHostId, isRepoMutationTarget, getActiveHostRepo) route removals, updates, and reorders to the correct host entry. The removeProject and updateRepo flows in the repo slice are updated to preserve sibling-host repos, and reorderRepos delegates to reorderReposByIdPermutation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers context, changes, regression coverage, and testing instructions. However, it lacks key sections from the template: Screenshots (not applicable but should state this), completion of the Testing checklist, AI Review Report with cross-platform compatibility confirmation, Security Audit summary, and Notes section. Add explicit statement that there is 'No visual change' for Screenshots section, complete the Testing checklist with check marks, and add AI Review Report and Security Audit sections as required by the template.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Preserve same-id repos across hosts' directly summarizes the main objective of the PR: enabling repositories with the same ID to coexist independently across different hosts without being collapsed or overwritten.
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 and usage tips.

@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

🧹 Nitpick comments (1)
src/renderer/src/store/slices/repo-reorder-host-split.ts (1)

28-41: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add a brief “why” comment for the per-id host queue logic.

This hostIdsByRepoId + .shift() strategy is non-obvious; a one-line rationale here would reduce regression risk during future refactors.

Proposed diff
   const hostIdsByRepoId = new Map<string, string[]>()
   for (const repo of repos) {
     const hasExplicitOwner = Boolean(repo.executionHostId?.trim() || repo.connectionId?.trim())
     const hostId = hasExplicitOwner ? getRepoExecutionHostId(repo) : focusedHostId
     const existing = hostIdsByRepoId.get(repo.id)
     if (existing) {
       existing.push(hostId)
     } else {
       hostIdsByRepoId.set(repo.id, [hostId])
     }
   }
   const groups = new Map<string, string[]>()
+  // Why: duplicate repo IDs can exist on different hosts; consume host IDs in
+  // order so each repeated ID is assigned to the correct host-specific group.
   for (const id of orderedIds) {
     const hostId = hostIdsByRepoId.get(id)?.shift()

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: afb261ca-6154-4ab3-9b75-a9733a6a4881

📥 Commits

Reviewing files that changed from the base of the PR and between d9b2d89 and f573e3f.

📒 Files selected for processing (11)
  • src/renderer/src/lib/repo-runtime-owner.test.ts
  • src/renderer/src/lib/repo-runtime-owner.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-same-id-host-mutations.test.ts
  • src/renderer/src/store/slices/repos.ts

Comment on lines +234 to +244
function reorderReposByIdPermutation(orderedIds: readonly string[], previous: readonly Repo[]) {
const reposById = queueReposById(previous)
const next: Repo[] = []
for (const id of orderedIds) {
const repo = reposById.get(id)?.shift()
if (repo) {
next.push(repo)
}
}
return next.length === previous.length ? next : null
}

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reject overlong reorder payloads before optimistic apply.

reorderReposByIdPermutation can return non-null when orderedIds contains extra IDs (e.g., extra duplicates), because it only compares next.length with previous.length. That violates the permutation contract and can let malformed input pass optimistic validation.

Suggested fix
 function reorderReposByIdPermutation(orderedIds: readonly string[], previous: readonly Repo[]) {
+  if (orderedIds.length !== previous.length) {
+    return null
+  }
   const reposById = queueReposById(previous)
   const next: Repo[] = []
   for (const id of orderedIds) {
     const repo = reposById.get(id)?.shift()
     if (repo) {
       next.push(repo)
     }
   }
   return next.length === previous.length ? next : null
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function reorderReposByIdPermutation(orderedIds: readonly string[], previous: readonly Repo[]) {
const reposById = queueReposById(previous)
const next: Repo[] = []
for (const id of orderedIds) {
const repo = reposById.get(id)?.shift()
if (repo) {
next.push(repo)
}
}
return next.length === previous.length ? next : null
}
function reorderReposByIdPermutation(orderedIds: readonly string[], previous: readonly Repo[]) {
if (orderedIds.length !== previous.length) {
return null
}
const reposById = queueReposById(previous)
const next: Repo[] = []
for (const id of orderedIds) {
const repo = reposById.get(id)?.shift()
if (repo) {
next.push(repo)
}
}
return next.length === previous.length ? next : null
}

@prateek

prateek commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Suggested reviewers: @Jinwoo-H for the Remote Orca Servers host model, and @nwparker for the renderer store/worktree cleanup paths. I tried to request reviews directly, but this fork account cannot call RequestReviewsByLogin on the upstream repo.

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this stack and the sharp analysis in #6032 — the failure class was real. Closing as superseded: #6136 (merged June 23) landed host-scoped repo identity for the refresh/update/remove/reorder/runtime-owner paths this PR covers, with regression coverage in repos-host-identity-routing.test.ts, and it fails closed on ambiguous duplicate hosts. Main has since moved ~1,500 commits and this branch now conflicts with the same files #6136 rewrote. A few narrow host-blind lookups that remain on main are tracked in #9783, with this stack credited for identifying the class.

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