Repository navigation
fix: don't mint worktreeMeta from a sidebar sort-order snapshot - #9342
Merged
nwparker merged 1 commit intoJul 24, 2026
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughSort-order persistence now checks for existing worktree metadata before updating sort order in both the IPC handler and runtime snapshot loop. Missing or stale worktree IDs are skipped instead of creating metadata. A unit test verifies that stale IDs do not trigger metadata writes. 🚥 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 |
`worktrees:persistSortOrder` (ipc/worktrees.ts) and `persistManagedWorktreeSortOrder`
(orca-runtime.ts) call `store.setWorktreeMeta(id, { sortOrder })` for every id the
renderer sends. `setWorktreeMeta` has no repo-existence check, so a stale id the
client still lists — e.g. a removed repo's `${repoId}::${path}` that lingers in the
renderer's order — gets a brand-new `worktreeMeta` entry minted on every sidebar
snapshot, resurrecting an orphan/duplicate workspace on the next launch.
A sort-order snapshot must only reorder worktrees that already exist, never create
one. Guard both call sites with `getWorktreeMeta` so absent ids are skipped.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
nwparker
force-pushed
the
fix/persist-sort-order-no-orphan-mint
branch
from
July 23, 2026 11:48
e7d50ce to
cd64c4c
Compare
Contributor
|
Thanks so much for this, @PannenetsF — don't mint worktreeMeta from a sidebar sort-order snapshot. Verified (fail-on-main/pass-on-branch), rebased on latest |
bbingz
added a commit
to bbingz/orca
that referenced
this pull request
Jul 24, 2026
persistWorktreeSortOrder skips unchanged ranks and never mints worktreeMeta for unknown ids (stablyai#9342).
3 of 5 tasks
bbingz
added a commit
to bbingz/orca
that referenced
this pull request
Aug 5, 2026
persistWorktreeSortOrder skips unchanged ranks and never mints worktreeMeta for unknown ids (stablyai#9342).
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…lyai#9342) `worktrees:persistSortOrder` (ipc/worktrees.ts) and `persistManagedWorktreeSortOrder` (orca-runtime.ts) call `store.setWorktreeMeta(id, { sortOrder })` for every id the renderer sends. `setWorktreeMeta` has no repo-existence check, so a stale id the client still lists — e.g. a removed repo's `${repoId}::${path}` that lingers in the renderer's order — gets a brand-new `worktreeMeta` entry minted on every sidebar snapshot, resurrecting an orphan/duplicate workspace on the next launch. A sort-order snapshot must only reorder worktrees that already exist, never create one. Guard both call sites with `getWorktreeMeta` so absent ids are skipped. Co-authored-by: fanyunqian.1 <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stops a deleted or orphaned workspace from silently reappearing as a duplicate/"unknown" project whenever the sidebar snapshots its sort order.
In plain terms: the app was accidentally re-creating projects you had already deleted, just because it was saving the order they appear in the sidebar. It now only reorders projects that still actually exist.
Root cause & fix: Both
worktrees:persistSortOrder(src/main/ipc/worktrees.ts) andpersistManagedWorktreeSortOrder(src/main/runtime/orca-runtime.ts) looped over the renderer'sorderedIdsand calledstore.setWorktreeMeta(...), which has no repo-existence check — it merges onto defaults and mints a freshinstanceIdfor any key. A stale id in the client's order (a repo removed elsewhere, or an already-orphaned id) therefore got re-created on every snapshot. The fix guards both call sites with an earlycontinueon ids that have no existingworktreeMeta, so a snapshot can only reorder existing worktrees, never fabricate one.Trade-offs / regression risk: None expected. Legitimate worktrees always have meta stamped before their order is snapshotted, so no real ordering is dropped. The guard only adds an early-
continueon ids that lack existing meta — exactly the ids that previously would have been fabricated. Existing worktrees follow the identicalsetWorktreeMetapath as before.Credit to @PannenetsF (Yunqian Fan) for the original fix. Validated and rebased onto latest main during a bug-bash triage on 2026-07-23; original fix design preserved.
Screenshots
No visual change. The fix is entirely in the main process (IPC handler and runtime service); no renderer UI is touched. The observable behavioral effect is indirect: deleted/orphaned projects no longer resurface as duplicate/"unknown" entries in the sidebar after a relaunch.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildAuthor-reported testing (I cannot run pnpm in this environment, so the unchecked boxes above reflect that the full gates were not confirmed as run):
persistSortOrder only reorders existing worktrees and never mints meta for a stale idinsrc/main/ipc/worktrees.test.ts.src/main/ipc/worktrees.test.tspasses on-branch (Test Files 1 passed, Tests 200 passed) and that reverting both fix files toorigin/mainfails the new guard assertion.oxlinton both source files and the test exits 0 (note:pnpm lintfull run not confirmed, so left unchecked).AI Review Report
I reviewed this diff directly. The change is small and well-scoped: an identical early-
continueguard added to two loops that callstore.setWorktreeMeta(...), plus one added unit test.if (!store.getWorktreeMeta(id)) continuecorrectly prevents minting new meta for ids without existing entries, which is the documented root cause. Both call sites (worktrees.tsandorca-runtime.ts) are guarded consistently.orca-runtime.ts, theupdatedcounter now only increments for ids that already had meta — this is the intended behavior (it should reflect actual reorders, not attempted ones). One minor consideration: the guard adds agetWorktreeMetaread per id inside the loop; for largeorderedIdsthis is O(n) extra store reads, but sidebar orderings are small and this is negligible. Sort-order semantics (descending timestamps,now - i * 1000) are unchanged.${repoId}::${path}strings compared by identity, not parsed as paths. No platform-specific behavior was touched.No correctness or portability issues found beyond the negligible per-loop read noted above.
Security Audit
Reviewed for security-relevant surface:
orderedIdsfrom the renderer are treated as opaque keys and only used to look up / write store meta; the guard actually tightens input trust by rejecting ids that don't already exist. No new parsing or deserialization.worktrees:persistSortOrderIPC handler signature is unchanged; the change only makes it more conservative about what it persists.No security concerns identified.
Notes
setWorktreeMetastill has no repo-existence check of its own — this PR guards the two known callers rather than hardening the store itself, so any future caller must apply the same guard.🤖 Generated with Claude Code