Skip to content

Fix legacy worktree lineage projection after stable updates - #9913

Merged
OrcaWin merged 5 commits into
mainfrom
fix-lineage-after-stable-update
Jul 22, 2026
Merged

OrcaWin merged 5 commits into
mainfrom
fix-lineage-after-stable-update

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • restore desktop nesting when a resolved worktree carries valid exact-instance legacy lineage but the separately hydrated lineage side-map has no child entry
  • keep the side-map authoritative when it does contain the child, so stale same-path/replaced-instance records cannot fall back to inline data
  • use one validated projection contract for grouping, filtering, reveal/send targets, unlink/reparent actions, drag/drop, deletion, folder descendants and PR aggregation, desktop/runtime folder hydration, and mobile summaries

Deterministic reproduction and root cause

The motivating stable state is modeled with the production identities:

  • parent instance b0ffd635-91cd-424f-b804-80d4bb277a4c
  • child 9276 instance 1ceb9823-aa98-4f79-8eaa-af0b3a3d551b
  • child 9744 instance 87e2ef9a-99d3-48e3-9a53-3d1a979b5417

Both older children have mutually consistent persisted/runtime legacy lineage to assigned-issues, but workspaceLineage: null. A newly created child has both legacy and generalized workspace lineage. The narrow renderer fixture passes exact valid inline legacy lineage with an absent side-map entry; before this fix buildRows emits each child at depth 0, and after it emits the child beneath the exact parent.

The semantic mismatch was that desktop grouping trusted only the separately hydrated worktreeLineageById map even though resolved worktrees already carried authoritative instance-aware legacy lineage. Stable hydration could preserve and report lineage correctly while the renderer discarded it. The fix selects a side-map entry when the child key exists and otherwise falls back to resolved inline legacy lineage. Bare parentWorktreeId is never trusted.

The sidebar grouping/visibility files in v1.4.149 and v1.4.150 are byte-identical. The v1.4.149 -> v1.4.150 update exposed the mismatch for these workspaces, but the evidence does not support naming that update as the exact introducing commit.

Safety, security, and compatibility

Projected edges require matching child/parent record IDs, exact child and parent instance IDs, the same repository, and matching host/project identities when both sides know them. Missing parents, stale instances, disagreement with an existing side-map entry, self-links, and cycles stay flat/rejected. Runtime manual reparenting enforces the same boundary before persistence.

The repair does not migrate or rewrite lineage metadata and adds no new external-input or privilege boundary. It remains path-agnostic. Local, SSH, WSL, remote-runtime, multi-host/project, folder workspace, imported worktree, pinned row, filtering/sorting, hidden-child counts, large-list virtualization, mobile summaries, and intentionally flat Kanban behavior are covered or preserved. Graph validation is precomputed for bulk surfaces; drag checks validate only the proposed parent, and folder traversal uses adjacency plus BFS.

No production metadata was rewritten or manually reparented. The running production CLI still reports both affected children under the original parent with the exact instance IDs above.

Before / after evidence

  • before: latest stable rendered both affected children as independent roots immediately above assigned-issues
  • after: the fixed dev sidebar renders legacy inline-only lineage beneath the exact parent; screenshot evidence
  • attached screenshot SHA-256: 71474a32fa6954ae1d77bfbc2c31c30710b93e3212cb9c4863007bf052c58af4

Validation

  • 2,773 tests across 185 shared/runtime/store/sidebar files during the full investigation
  • 1,520 final relevant tests across shared projection, runtime, IPC/Windows, store, grouping/filtering, cards, folder hydration/PR aggregation, host boundaries, Kanban, and virtualization
  • full node, CLI, and web typecheck
  • touched-file oxlint, React Doctor, and formatting
  • reliability-gate manifest and max-lines ratchet
  • 5 Electron lineage E2Es at reviewed head 641799fa2, including legacy-only inline fallback and filtered-parent structural injection

Internal review

Iterative adversarial review found and fixed boundary/cycle, filtered-parent, unlink/reveal/delete/drag, folder PR aggregation, folder detected-hydration, and large-list performance gaps. The final independent round reported zero Critical, Important, or Minor findings and independently passed 1,191 targeted tests.

Limitation

Full pnpm lint reaches an unrelated pre-existing switch-exhaustiveness failure at src/renderer/src/components/skills/skill-freshness-group.tsx:101. All changed files pass lint.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 46dc9e47-ccfd-4a6e-b9cc-fbab7f72719a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ed1070 and 641799f.

📒 Files selected for processing (6)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/sidebar/folder-workspace-card-pr-display.test.ts
  • src/renderer/src/components/sidebar/folder-workspace-card-pr-display.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/ipc/worktrees.ts

📝 Walkthrough

Walkthrough

The change centralizes resolved worktree lineage validation and projection, including instance, repository, host, project, missing-parent, and cycle checks. Runtime and IPC worktree discovery now hydrate lineage through the shared projection. Renderer state updates preserve inline lineage, while sidebar rendering, visibility, deletion, parent selection, drag-and-drop, and context menus consume projected lineage utilities. Tests cover legacy hydration, boundary mismatches, stale records, cycles, and end-to-end inline lineage rendering.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR’s main change: fixing legacy worktree lineage projection after stable updates.
Description check ✅ Passed The description is detailed, but it does not follow the required template sections exactly and omits explicit testing checkboxes and a standalone AI review report.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

🧹 Nitpick comments (4)
src/renderer/src/components/sidebar/worktree-lineage-projection.ts (3)

12-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Local WorktreeWithResolvedLineage shadows the shared type with a different shape.

This file defines its own unexported WorktreeWithResolvedLineage (only an optional lineage field), while src/shared/resolved-worktree-lineage.ts exports a same-named generic type with required parentWorktreeId/childWorktreeIds/lineage. Same name, different structure across two closely-related files invites confusion for future maintainers reasoning about lineage shapes.

Consider renaming this local type (e.g. WorktreeWithInlineLineage) or deriving it from the shared type via Pick/Partial.


14-22: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing "why" comment on the side-map precedence rule.

This function implements the PR's central design decision — the hydrated side-map is authoritative when present, inline worktree.lineage is only a fallback — but there's no comment explaining that rationale, unlike the codebase's extensive use of // Why: comments elsewhere for similarly non-obvious logic.
As per coding guidelines: "Add concise, preferably one-line comments only for non-obvious code, explaining why rather than how."

Source: Coding guidelines


81-100: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

getWorktreeLineageAncestors breaks the "precompute cycles once" pattern.

getLineageRenderInfo accepts a precomputed cyclicLineageIds so callers can compute it once and reuse it across many worktrees, but getWorktreeLineageAncestors doesn't take that parameter and instead recomputes getCyclicProjectedWorktreeLineageIds (an O(n) full-map scan) internally on every call. If this is invoked per-row (e.g. for ancestor breadcrumbs across many worktrees), that's O(n²) total instead of O(n).

Consider accepting an optional precomputed cyclicLineageIds (falling back to computing it if omitted) to match the established pattern.

src/renderer/src/components/sidebar/worktree-list-groups.ts (1)

1293-1311: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Redundant if/else — both branches are now identical. items and hostContextLabelByRepoId are already computed conditionally on groupBy === 'repo' above (Lines 1288-1292), so both appendWorktreeRows calls pass the same option object. The branch can be collapsed into a single call.

♻️ Collapse the identical branches
-        if (groupBy === 'repo') {
-          appendWorktreeRows(result, items, repoMap, lineageById, worktreeMap, {
-            nestLineage,
-            collapsedGroups,
-            groupDepth: projectGroupDepth,
-            sectionKey: key,
-            hostContextLabelByRepoId,
-            cyclicLineageIds
-          })
-        } else {
-          appendWorktreeRows(result, items, repoMap, lineageById, worktreeMap, {
-            nestLineage,
-            collapsedGroups,
-            groupDepth: projectGroupDepth,
-            sectionKey: key,
-            hostContextLabelByRepoId,
-            cyclicLineageIds
-          })
-        }
+        appendWorktreeRows(result, items, repoMap, lineageById, worktreeMap, {
+          nestLineage,
+          collapsedGroups,
+          groupDepth: projectGroupDepth,
+          sectionKey: key,
+          hostContextLabelByRepoId,
+          cyclicLineageIds
+        })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 94d99f76-bd93-4749-8b8d-4888a406c4f7

📥 Commits

Reviewing files that changed from the base of the PR and between 7304776 and 0ed1070.

📒 Files selected for processing (28)
  • src/main/ipc/worktrees.test.ts
  • src/main/ipc/worktrees.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/right-sidebar/folder-workspace-attached-worktrees.test.ts
  • src/renderer/src/components/right-sidebar/folder-workspace-attached-worktrees.ts
  • src/renderer/src/components/sidebar/WorktreeContextMenu.test.ts
  • src/renderer/src/components/sidebar/WorktreeContextMenu.tsx
  • src/renderer/src/components/sidebar/WorktreeList.tsx
  • src/renderer/src/components/sidebar/use-visible-workspace-kanban-worktree-ids.ts
  • src/renderer/src/components/sidebar/visible-worktrees.test.ts
  • src/renderer/src/components/sidebar/visible-worktrees.ts
  • src/renderer/src/components/sidebar/workspace-delete-lineage.test.ts
  • src/renderer/src/components/sidebar/workspace-delete-lineage.ts
  • src/renderer/src/components/sidebar/worktree-lineage-drag-drop.test.ts
  • src/renderer/src/components/sidebar/worktree-lineage-drag-drop.ts
  • src/renderer/src/components/sidebar/worktree-lineage-projection.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.test.ts
  • src/renderer/src/components/sidebar/worktree-list-groups.ts
  • src/renderer/src/components/sidebar/worktree-parent-candidates.ts
  • src/renderer/src/components/sidebar/worktree-parent-eligibility.test.ts
  • src/renderer/src/components/sidebar/worktree-parent-eligibility.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts
  • src/shared/resolved-worktree-lineage.test.ts
  • src/shared/resolved-worktree-lineage.ts
  • tests/e2e/worktree-lineage-state.ts
  • tests/e2e/worktree-lineage.spec.ts

Comment thread src/main/ipc/worktrees.test.ts Resolved
@OrcaWin

OrcaWin commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

Fresh internal-review-until-clean pass completed at 641799fa2. One new adversarial round reviewed the full diff, including elegance and performance interrogations, and found no remaining in-scope issues. Fresh verification: 12 targeted lineage/runtime/sidebar suites, 1,444 tests; full typecheck; changed-file oxlint/format; React Doctor; reliability gates; and max-lines ratchet all pass. No code changes were required.

@OrcaWin
OrcaWin merged commit 0d82cc3 into main Jul 22, 2026
1 check passed
@OrcaWin
OrcaWin deleted the fix-lineage-after-stable-update branch July 22, 2026 22:52
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant