Repository navigation
Preserve remote host repo state - #6136
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR introduces host-aware repo identity throughout the renderer store and library layers to correctly handle repos that share the same 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (5)
src/renderer/src/store/slices/repos.ts (4)
2221-2232: 🗄️ Data Integrity & Integration | 🔴 Critical | ⚡ Quick winPin queued repo updates to the captured owner host.
ownerHostIdis captured before chaining, butapplyRepoUpdaterecomputes the RPC target from the current focused settings when the queued update runs. If focus changes while a prior update is pending, the next update can be sent to the wrong host and then applied to the captured host row.🐛 Proposed fix
} const ownerHostId = getRepoExecutionHostId(ownerRepo) const updateChainKey = getRepoHostIdentityForParts(projectId, ownerHostId) + const parsedOwnerHost = parseExecutionHostId(ownerHostId) + const ownerTarget = + parsedOwnerHost?.kind === 'runtime' + ? ({ kind: 'environment', environmentId: parsedOwnerHost.environmentId } as const) + : ({ kind: 'local' } as const) const applyRepoUpdate = async () => { try { const sanitizedUpdates = sanitizeRepoUpdate(updates) - const target = getActiveRuntimeTarget(settingsForRepoOwner(get(), projectId)) + const target = ownerTarget const updatedRepo =Also applies to: 2281-2286
1752-1761: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winUse host identity in ProjectHostSetup repo mutations.
These setup flows still match repos by
entry.id === repo.id. With duplicate local/runtime repo IDs, setup/create/update can overwrite the sibling host row, and setup delete can remove all siblings.🐛 Proposed fix
const repo = repoWithFetchedOwner(result.repo, target) + const repoHostId = getRepoExecutionHostId(repo) const setup = setupWithFetchedOwner(result.setup, target) set((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) => + repoMatchesHostIdentity(entry, repo.id, repoHostId) + ) + ? s.repos.map((entry) => + repoMatchesHostIdentity(entry, repo.id, repoHostId) ? repo : entry + ) : [...s.repos, repo]const setup = setupWithFetchedOwner(result.setup, target) const repo = result.repo ? repoWithFetchedOwner(result.repo, target) : undefined + const repoHostId = repo ? getRepoExecutionHostId(repo) : null set((s) => ({ repos: repo - ? s.repos.some((entry) => entry.id === repo.id) - ? s.repos.map((entry) => (entry.id === repo.id ? repo : entry)) + ? s.repos.some((entry) => repoMatchesHostIdentity(entry, repo.id, repoHostId!)) + ? s.repos.map((entry) => + repoMatchesHostIdentity(entry, repo.id, repoHostId!) ? repo : entry + ) : [...s.repos, repo] : s.repos,const repo = result.repo ? repoWithFetchedOwner(result.repo, target) : undefined + const repoHostId = repo ? getRepoExecutionHostId(repo) : null set((s) => { const projectHostSetups = s.projectHostSetups.filter( (setup) => setup.id !== result.setup.id ) - const repos = repo ? s.repos.filter((entry) => entry.id !== repo.id) : s.repos + const repos = + repo && repoHostId + ? s.repos.filter((entry) => !repoMatchesHostIdentity(entry, repo.id, repoHostId)) + : s.reposAlso applies to: 1839-1850, 1882-1887
2117-2139: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winFilter last-visited cleanup by the host-owned worktree set.
The removal path now computes host-scoped
worktreeIds, but this loop still deletes every timestamp whose worktree ID parses to the bareprojectId. Removing one duplicate host can wipe the sibling host’s recency state.🐛 Proposed fix
let nextLastVisitedAtByWorktreeId = s.lastVisitedAtByWorktreeId for (const id of Object.keys(s.lastVisitedAtByWorktreeId)) { - if (getRepoIdFromWorktreeId(id) === projectId) { + if (worktreeIdSet.has(id)) { if (nextLastVisitedAtByWorktreeId === s.lastVisitedAtByWorktreeId) { nextLastVisitedAtByWorktreeId = { ...s.lastVisitedAtByWorktreeId } }
2349-2354: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winResync all hosts after a split reorder failure.
splitRepoReorderByHostcan persist order to non-active hosts, but the rejection/catch fallback callsfetchRepos(), which refreshes only the focused target. A remote-host rejection while local is focused leaves the optimistic remote order stale.🐛 Proposed fix
) if (results.some((result) => result.status === 'rejected')) { - await get().fetchRepos() + await get().fetchReposForAllHosts() } } catch (err) { console.error('Failed to reorder repos:', err) - await get().fetchRepos() + await get().fetchReposForAllHosts() }src/renderer/src/store/slices/worktrees.ts (1)
382-409: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winTreat hostless hydrated purge IDs as local-only.
Now that this helper is host-scoped, Line 405 still adds legacy hydrated session IDs for every host. A runtime/SSH authoritative scan can then purge local legacy tab state just because those hostless IDs are absent from that remote scan. Gate this fallback to
LOCAL_EXECUTION_HOST_ID.🐛 Proposed fix
- if (!state.hasHydratedWorktreePurge) { + if (!state.hasHydratedWorktreePurge && hostId === LOCAL_EXECUTION_HOST_ID) { // Why (`#1158`): hydration can preserve tab keys before worktree metadata exists; // the first authoritative scan still needs to reap deleted session-only keys. for (const id of getHydratedSessionWorktreeIdsForRepo(state, repoId)) { knownIds.add(id)
🧹 Nitpick comments (2)
src/renderer/src/store/slices/repos-host-identity-routing.test.ts (2)
74-100: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a regression for queued updates after focus changes.
This covers the immediate runtime update path, but not the chained
updateRepopath whereapplyRepoUpdatecan run aftersettings.activeRuntimeEnvironmentIdchanges. Add a pending first update, switch focus, then assert the queued update still targetsenv-1.
102-207: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert sibling-host recency metadata survives removal.
The removal tests cover worktrees, tabs, and PTYs, but not
lastVisitedAtByWorktreeId. Add local/remote timestamp assertions so host-scoped removal cannot regress to bare-repo-ID purging.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: decf33fc-b00c-4c7d-94b7-6c90144e3b16
📒 Files selected for processing (11)
src/renderer/src/lib/repo-runtime-owner.test.tssrc/renderer/src/lib/repo-runtime-owner.tssrc/renderer/src/store/slices/repo-host-identity.tssrc/renderer/src/store/slices/repo-identity-reconcile.test.tssrc/renderer/src/store/slices/repo-identity-reconcile.tssrc/renderer/src/store/slices/repo-reorder-host-split.test.tssrc/renderer/src/store/slices/repo-reorder-host-split.tssrc/renderer/src/store/slices/repos-host-identity-routing.test.tssrc/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/worktrees.test.tssrc/renderer/src/store/slices/worktrees.ts
There was a problem hiding this comment.
Actionable comments posted: 1
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/worktrees.ts (1)
450-469: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winApply host ownership to hydrated session-only purge IDs.
The purge baseline is host-scoped, but this hydration fallback still adds every session-only ID for the bare repo ID. A first authoritative scan for a runtime duplicate can therefore purge sibling local tab/terminal state before that sibling host refreshes.
🐛 Proposed guard
- if (!state.hasHydratedWorktreePurge) { + if (!state.hasHydratedWorktreePurge && matchOptions.unhostedWorktreesMatchHost === true) { // Why (`#1158`): hydration can preserve tab keys before worktree metadata exists; // the first authoritative scan still needs to reap deleted session-only keys. for (const id of getHydratedSessionWorktreeIdsForRepo(state, repoId)) { knownIds.add(id)
🧹 Nitpick comments (1)
src/renderer/src/store/slices/worktrees.ts (1)
424-427: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winKeep host merges stable in-place.
This removes the refreshed host rows and appends them after sibling-host rows. With duplicate repo IDs, alternating local/runtime refreshes can rewrite array order and bump
sortEpocheven when the refreshed payload is unchanged.♻️ Proposed stable merge
function mergeWorktreesForHost<T extends { hostId?: ExecutionHostId }>( current: readonly T[] | undefined, refreshed: readonly T[], hostId: ExecutionHostId, options?: WorktreeHostMatchOptions ): T[] { - return [ - ...(current ?? []).filter((worktree) => !worktreeMatchesHost(worktree, hostId, options)), - ...refreshed - ] + // Why: host-scoped refreshes must not move sibling-host rows and churn sortEpoch. + const existing = current ?? [] + const next: T[] = [] + let inserted = false + + for (const worktree of existing) { + if (worktreeMatchesHost(worktree, hostId, options)) { + if (!inserted) { + next.push(...refreshed) + inserted = true + } + continue + } + next.push(worktree) + } + + return inserted ? next : [...next, ...refreshed] }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 930a52bc-4a11-4292-8555-71b853129e59
📒 Files selected for processing (1)
src/renderer/src/store/slices/worktrees.ts
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0f640ffc-6912-4500-bcf1-c712b1875070
📒 Files selected for processing (6)
src/renderer/src/lib/repo-runtime-owner.tssrc/renderer/src/store/slices/repo-host-identity.tssrc/renderer/src/store/slices/repo-reorder-host-split.tssrc/renderer/src/store/slices/repos-host-identity-routing.test.tssrc/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/worktrees.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/renderer/src/store/slices/repo-reorder-host-split.ts
- src/renderer/src/store/slices/repo-host-identity.ts
- src/renderer/src/lib/repo-runtime-owner.ts
- src/renderer/src/store/slices/worktrees.ts
…32-remote-host-state # Conflicts: # src/renderer/src/store/slices/repos.ts
Co-authored-by: Orca <[email protected]>
* fix: address pr-bug-scan validated finding from #6136 removeProject now also drops lastVisitedAtByWorktreeId entries by repo-id mapping when the repo id is fully removed (no sibling host), catching unhydrated worktree timestamps. * test: cover unhydrated SSH timestamp cleanup * Test dropping visit timestamps for removed runtime repos Verify that removing an unhydrated runtime repository successfully drops its associated worktree entries from the persisted visit history. --------- Co-authored-by: orca-bug-scan-bot <[email protected]> Co-authored-by: Jinjing <[email protected]>
|
looking into it |
Co-authored-by: Orca <[email protected]>
* fix: address pr-bug-scan validated finding from stablyai#6136 removeProject now also drops lastVisitedAtByWorktreeId entries by repo-id mapping when the repo id is fully removed (no sibling host), catching unhydrated worktree timestamps. * test: cover unhydrated SSH timestamp cleanup * Test dropping visit timestamps for removed runtime repos Verify that removing an unhydrated runtime repository successfully drops its associated worktree entries from the persisted visit history. --------- Co-authored-by: orca-bug-scan-bot <[email protected]> Co-authored-by: Jinjing <[email protected]>
Summary
Preserves host-scoped repo, project, and worktree state when the same logical repo id exists on local and remote/runtime hosts. The renderer now routes repo refresh, update, remove, reorder, project compatibility, and worktree refresh paths through host-qualified repo identity instead of treating bare repo ids as globally unique.
Design Review
Brennan YOLO Lite design review completed cleanly after tightening the design around ambiguous duplicate-host fallback, host-scoped project compatibility merging, worktree bucket preservation, and map/set-style reconciliation cost.
Implementation Notes
projectHostSetups.fetchAllWorktreesmerge host-aware without changing the persistedworktreesByReposhape.No UI layout/copy changes were made.
Completeness Verification
Read-only completeness verification reported COMPLETE against the reviewed design. It noted non-blocking residual gaps around a few standalone helper edge tests and full remote-server e2e feasibility.
Code Review
Round 1 ran two independent reviewers. One reviewer found a real hostless legacy worktree purge bug in repo removal; fixed with a production predicate change and regression test. Round 2 ran two fresh independent reviewers; both returned
No issues found, with only non-blocking residual test-gap notes.Post-PR CodeRabbit review findings were fixed and rechecked. Latest CodeRabbit sweep reports no actionable comments on the current head.
Brennan Test Changes
Brennan test validation verdict: LAND. Deterministic store coverage exercises duplicate repo ids across local/runtime hosts for update, remove, reorder, reconciliation, and worktree refresh. Full remote-server e2e was not run; the remaining gap is explicit because the bug is store reconciliation/routing and is covered by deterministic mocked runtime transport tests.
Manual / Electron Validation
window.api.app.getIdentity()reporteddevRepoRootas this issue worktree.design-docs/evidence/issue-6032-electron.png(ignored scratch evidence, not committed).Tests
pnpm vitest run --config config/vitest.config.ts src/renderer/src/store/slices/repos-host-identity-routing.test.ts src/renderer/src/store/slices/settings.test.ts src/renderer/src/store/slices/worktrees.test.ts src/renderer/src/store/slices/repos-project-host-lifecycle.test.ts src/renderer/src/store/slices/repos.test.ts src/renderer/src/store/slices/repos-all-hosts.test.ts src/renderer/src/lib/repo-runtime-owner.test.ts src/renderer/src/store/slices/repo-reorder-host-split.test.ts— 209 passedpnpm vitest run --config config/vitest.config.ts src/renderer/src/store/slices/repos-host-identity-routing.test.ts src/renderer/src/store/slices/repos.test.ts src/renderer/src/store/slices/worktrees.test.ts— 179 passedpnpm run typecheck— passedpnpm run typecheck:web— passedpnpm exec oxlinton changed files — passedgit diff --check— passedpnpm test— one full local pass earlier in stabilization; later full local reruns hit unrelated transient timeouts/flakes (remote-runtime-shared-control-connectiontimeout once,WorktreeCard.quick-actionsimport timeout once), and both affected suites passed on immediate focused rerun.verifycheck — passed on current head.pnpm run lint— blocked locally by pre-existing localization catalog keys in untouchedTerminalInteractionSection.tsx; localization coverage itself passed.Post-PR Stabilization
Completed multiple required
sleep 480waits after pushes. CodeRabbit latest review reports no actionable comments on the current head, review threads are resolved/addressed, and GitHub PRverifyis SUCCESS.Risks / Gaps