Skip to content

perf(renderer): keep worktree lineage map identity on no-op refresh - #14217

Merged
nwparker merged 5 commits into
mainfrom
nwparker/worktree-lineage-catalog-identity
Aug 13, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/worktree-lineage-catalog-identity

Conversation

@nwparker

@nwparker nwparker commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A no-op worktree lineage refresh still allocated new worktreeLineageById / workspaceLineageByChildKey maps because mergeLineageForHost, mergeWorkspaceLineageForHost, and mergeExactHostLineage always spread the incoming payload. Worktree rows were already gated; these maps were not. WorktreeList Object.is-subscribes to both maps, so every refresh missed.

This keeps the previous record when areValuesEqual says the incoming IPC clone is unchanged, returns the existing map when every key/value is still current, and skips set() from refreshWorktreeLineageForSettings / refreshRemoteWorktreeLineageBestEffort when both maps are === current — the same shape as the worktree-row early return.

Why a partial fix is inert

Identity has to survive every link from fetch to set(). Reusing worktree rows but still spreading lineage maps, or comparing with Object.is after structuredClone / hydrate rebuilds nested capture, still produces a new map and a new store write. The SSH host snapshot path had the same always-spread hole; fixing only the local list merge would leave mergeExactHostLineage churning the same subscribers.

Why reference compare fails

Lineage records are nested (capture, taskId, coordinatorHandle). IPC already clones; hydrate rebuilds nested objects. Object.is never hits after that, so the merge has to structurally compare with areValuesEqual / reuseEqualRecordMap rather than treating a new object as a new value. Main-process structuredClone is not the primary fix — the renderer merge still has to reuse.

Tests

  • Production-shaped fixtures: parentWorktreeId + nested capture + taskId + coordinatorHandle.
  • listLineage / host snapshot mocks return structuredClone(payload) so the incoming object is never the stored one.
  • fetchWorktreeLineage twice keeps both maps and entry refs; host-scoped merge keeps other-host rows by identity.
  • Hydration cloned no-op snapshot keeps map and foreign-host entry refs.
  • These go red if merge reuse is reverted. Existing toEqual tests against the same mock object are not sufficient.

Follow-up to #13744 / #13770 / #13803.

Made with Orca 🐋

A host-scoped lineage refresh always spread IPC clones into new maps, so
WorktreeList Object.is subscriptions missed every time even when capture,
taskId, and coordinatorHandle were unchanged. Reuse structurally equal
records, return the previous maps when nothing moved, and skip set() when
both maps are still current so a no-op refresh is actually a no-op.

Co-authored-by: Orca <[email protected]>
@coderabbitai

coderabbitai Bot commented Aug 13, 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 Plus

Run ID: 0dcac2d7-ea27-42f1-ba63-97bbc1d5ce8b

📥 Commits

Reviewing files that changed from the base of the PR and between 9a10561 and a013b5d.

📒 Files selected for processing (7)
  • src/renderer/src/hooks/direct-ssh-host-hydration.test.ts
  • src/renderer/src/hooks/direct-ssh-host-hydration.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/worktree-helpers.ts
  • src/renderer/src/store/slices/worktrees.test.ts
  • src/renderer/src/store/slices/worktrees.ts

📝 Walkthrough

Walkthrough

The change adds reuseEqualRecordMap to preserve equal record and map references. Host-scoped lineage refreshes now preserve entries for other hosts and return existing state for unchanged payloads. Lineage maps use readonly record types. New tests cover cloned no-op payloads, nested entry identity, no state publication, and multi-host preservation.

Mergeability Score: ⚪ Minimal · up to a013b

The change preserves lineage-map identity during unchanged refreshes and adds coverage for cloned and hydrated snapshots; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the implementation and tests, but it omits several required template sections and does not provide a Linked Issue in the required format. Add the required ELI5, What Changed, Linked Issue, Visual Proof, Testing, Review, Checklist, and Author sections; include the issue as Fixes #... and mark Visual Proof N/A if applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 clearly identifies the primary performance change: preserving worktree lineage map identity during no-op renderer refreshes.
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 💡 1
📝 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.

nwparker and others added 4 commits August 12, 2026 23:24
Widen reuseEqualRecordMap and the renderer lineage store fields to
Readonly<Record<...>> so a reused no-op refresh map cannot be mutated
in place.

Co-authored-by: Orca <[email protected]>
mergeExactHostLineage was writing into AppState map types after they
became Readonly. Use local mutable Records, then reuseEqualRecordMap.

Co-authored-by: Orca <[email protected]>
The lineage overlay rewrite pushed the file to 305 counted lines against the 300 cap, failing oxlint. Fold the duplicated per-map filter/overlay into one scoped helper so both maps share it.

Co-authored-by: Orca <[email protected]>
A key missing from next always shows up as either a key-count mismatch or a failed previous lookup in the first pass, so the second pass over the previous keys could never flip identical. Cover the identity contract with focused unit tests, including the same-count key swap that the removed loop appeared to guard.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker merged commit ac68eea into main Aug 13, 2026
44 checks passed
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