Repository navigation
Conversation
📝 WalkthroughWalkthroughAdds shared worktree sort-order persistence that validates existing ranks, avoids redundant writes, and assigns descending timestamp-based ranks when needed. The IPC and runtime reorder paths now use this helper and return early when no updates occur. Adds tests for ordering persistence scenarios and a renderer test covering remote repository results arriving before a pending local fetch. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
c9433f1 to
5eb1888
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
0990010 to
3a6c69b
Compare
|
Rebased onto current |
3a6c69b to
0cc96ef
Compare
|
Rebased onto current #9342 ( The reason this is still needed on top of #9342: without it every smart-sort recompute still calls Verified: |
0cc96ef to
65adf31
Compare
Greptile SummaryThis PR fixes a smart-sort refresh loop by extracting sort-order persistence into a shared
Confidence Score: 4/5Safe to merge; the change is a focused extraction of sort-order persistence logic into a shared helper with thorough unit coverage across all meaningful edge cases. The core persistence helper and both call sites (IPC and runtime) are well-reasoned and logically sound. The IPC handler test only exercises two paths (unchanged order and empty input) — the changed-order path is covered only indirectly through the helper's own suite, leaving a small gap in integration-level confidence for that call site. Files Needing Attention: src/main/ipc/worktrees-sort-order.test.ts — the IPC-level changed-order path has no direct test; all other files are thoroughly covered.
|
| Filename | Overview |
|---|---|
| src/main/worktree-sort-order-persistence.ts | New shared helper; correctly gates writes behind a strictly-descending rank check and skips unknown IDs in both the check and write phases. |
| src/main/ipc/worktrees.ts | IPC persistSortOrder handler now delegates to the shared helper; empty-array guard is kept as a fast path before the helper is called. |
| src/main/runtime/orca-runtime.ts | Runtime persistManagedWorktreeSortOrder now skips cache invalidation and reposChanged broadcast when updated count is 0, directly breaking the refresh loop. |
| src/main/worktree-sort-order-persistence.test.ts | Thorough unit tests for the helper: unchanged order, changed order, missing ranks, tied ranks, duplicates, unknown IDs, and exact write values. |
| src/main/ipc/worktrees-sort-order.test.ts | IPC handler tests cover unchanged order and empty input; changed-order path is only exercised via the shared helper's own test suite. |
| src/main/runtime/orca-runtime-sort-order.test.ts | Runtime tests verify the full event/cache-invalidation lifecycle for first change, no-op repeat, and subsequent real change. |
| src/renderer/src/store/slices/repos-cross-host-fetch-race.test.ts | New regression test locks the existing merge-inside-set behavior that prevents a slow local catalog from overwriting a faster runtime catalog. |
Sequence Diagram
sequenceDiagram
participant Renderer
participant IPC as IPC (worktrees.ts)
participant RT as Runtime (orca-runtime.ts)
participant Persist as persistWorktreeSortOrder
participant Store
Renderer->>IPC: "persistSortOrder({orderedIds})"
IPC->>Persist: persistWorktreeSortOrder(store, orderedIds)
Persist->>Store: getWorktreeMeta(id) × N
alt ranks already strictly descending
Persist-->>IPC: 0 (no-op)
IPC-->>Renderer: undefined (no events)
else order changed / ranks invalid
Persist->>Store: "setWorktreeMeta(id, {sortOrder}) × N"
Persist-->>IPC: updated count
IPC-->>Renderer: undefined
end
Renderer->>RT: persistManagedWorktreeSortOrder(orderedIds)
RT->>Persist: persistWorktreeSortOrder(store, orderedIds)
Persist->>Store: getWorktreeMeta(id) × N
alt ranks already strictly descending
Persist-->>RT: 0
RT-->>Renderer: "{updated: 0} (no cache invalidation, no reposChanged)"
else order changed / ranks invalid
Persist->>Store: "setWorktreeMeta(id, {sortOrder}) × N"
Persist-->>RT: updated count
RT->>RT: invalidateResolvedWorktreeCache()
RT->>Renderer: reposChanged event
RT-->>Renderer: "{updated: N}"
end
Reviews (1): Last reviewed commit: "fix(workspaces): combine smart-sort no-o..." | Re-trigger Greptile
persistWorktreeSortOrder skips unchanged ranks and never mints worktreeMeta for unknown ids (stablyai#9342).
65adf31 to
23439b8
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Closing as superseded by current The no-op smart-sort + no-mint meta guard now lives in
Rebase of this PR conflicts heavily and would only re-introduce a parallel helper. No further action needed from this branch. |
|
Superseded by planWorktreeSortOrderUpdates on main (see prior comment). |
Closes #8272.
Summary
reposChangedbroadcasts for unchanged orders.Composition with #9342 (merged 2026-07-24): that fix added the same no-mint guard separately at each call site. Its guard and this PR's skip-unchanged short-circuit are complementary — one decides which ids may be written, the other whether any write is needed — and both now live in a single
persistWorktreeSortOrderhelper (src/main/worktree-sort-order-persistence.ts) called fromsrc/main/ipc/worktrees.tsandsrc/main/runtime/orca-runtime.ts, instead of two overlapping call-site guards.Screenshots
No visual change.
Testing
pnpm lintpnpm typecheckpnpm test— not run in full; the five affected suites re-run post-rebase at 23439b8: 286/286 passed.pnpm build— not run; no build-system or packaging behavior changed.Targeted command:
AI Review Report
Reviewed both loops described in #8272. Current
mainalready merges fetched catalogs insideset(state), so the stale local-vs-runtime overwrite is structurally fixed; the new race test locks that behavior. The remaining loop came from every Smart-order effect call replacing all ranks with fresh timestamps and the runtime broadcastingreposChanged, even when relative order was unchanged.The persistence review checked first-time/missing ranks, changed order, tied or invalid ranks, duplicate IDs, single-host and split-host calls, local IPC, remote runtime notification behavior, and concurrent repeated calls. Only a complete strictly descending rank sequence is considered unchanged; ambiguous state is repaired rather than skipped.
Cross-platform behavior was checked explicitly. The helper is path- and platform-neutral, uses owner-host metadata only, and does not alter shortcuts, labels, filesystem paths, shells, SSH routing, or git-provider behavior. It applies equally to macOS/Linux local hosts and Windows/remote runtimes.
Security Audit
The change reads existing worktree metadata and writes the same bounded
sortOrderfields as before. It adds no command execution, IPC surface, authentication, secrets, filesystem access, or dependencies. Malformed duplicate IDs, missing metadata, non-finite ranks, and ties fail toward re-persistence rather than suppressing an update. No security follow-up is required.Notes
For a genuinely changed order, ranks are still rewritten and the remote runtime still invalidates its resolved cache and emits
reposChanged. For an unchanged order, the runtime returns{ updated: 0 }without a broad refresh, breaking thepersist -> reposChanged -> refresh -> sortEpoch -> persistcycle.ELI5
Smart-sort could keep rewriting worktree order and broadcasting changes even when the order had not really changed, causing refresh loops. Persistence is a no-op when ranks already match, including on remote runtimes, so the UI stops thrashing.