Skip to content

perf(renderer): purge sparse-preset maps when a repo is removed - #7564

Merged
nwparker merged 1 commit into
mainfrom
nwparker/leak-sparse-presets-repo-purge
Jul 6, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/leak-sparse-presets-repo-purge

Conversation

@nwparker

@nwparker nwparker commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of a full-codebase memory-leak audit — one never-purged per-entity structure per PR.

Description

The sparse-preset feature keeps four per-repo maps in the store — sparsePresetsByRepo, sparsePresetsLoadingByRepo, sparsePresetsLoadStatusByRepo, sparsePresetsErrorByRepo — populated lazily by fetchSparsePresets(repoId). None of the repo-removal reducers pruned them, so an entry for every touched-then-removed repo lingered for the renderer's whole session.

Fix: add omitSparsePresetsForRepos(state, removedRepoIds) and call it from both repo-removal reducers (removeProject and deleteProjectHostSetup).

Evidence

  • store/slices/sparse-presets.ts: the four maps are only ever written per repoId; the slice has no removal reducer.
  • store/slices/repos.ts: removeProject (nextRepos = s.repos.filter(...)) and deleteProjectHostSetup shrink s.repos but left the sparse-preset maps untouched, unlike the ~30 worktree-scoped maps they already purge.
  • repoIds are random UUIDs (never reused), so re-adding the same repo cannot reclaim the orphaned keys.

Proof of fix

New test sparse-presets-repo-removal-purge-leak.test.ts seeds all four maps for two repos, drives the real removeProject reducer, and asserts every map key is gone for the removed repo and intact for the surviving one.

Test Files  3 passed (3)   ← incl. existing sparse-presets + repo-purge suites
      Tests  12 passed (12)

Typecheck (web) + oxlint clean.

ELI5

Each project could remember a few "sparse checkout presets." When you deleted a project, the app forgot the project but kept its preset notes forever. Now deleting a project also throws away its preset notes — and only that project's, leaving other projects' notes alone.

Trade-offs

  • User-facing behavior: none. The entries belong to a repo that's been removed; there's no UI that reads presets for a non-existent repo.
  • Host-duplicate safety: eviction is scoped to repo ids with no surviving entry (survivingRepoIds), so removing a repo id on one host while a duplicate id remains on another host keeps the presets. Mirrors the existing repoIdFullyRemoved logic in the same reducer.
  • Selector churn: the helper returns only the maps that actually changed, so unrelated selectors don't re-run. Target: 0 regression.

Made with Orca 🐋

The four per-repo maps (sparsePresetsByRepo, sparsePresetsLoadingByRepo,
sparsePresetsLoadStatusByRepo, sparsePresetsErrorByRepo) are populated lazily
by fetchSparsePresets but were never pruned on repo removal, so orphaned
entries accumulated for the renderer's whole session (repoIds are random
UUIDs, never reused, so re-adding a repo can't reclaim old keys).

Add omitSparsePresetsForRepos and call it from both repo-removal reducers
(removeProject + deleteProjectHostSetup), scoped to repo ids with no surviving
entry so a duplicate id on another host stays.

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

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds a helper function, omitSparsePresetsForRepos, that removes entries for specified repo IDs from the four per-repo sparse-preset state maps. This helper is wired into the deleteProjectHostSetup and removeProject operations in the repos store slice, so that sparse-preset state for removed repos is purged as part of those operations. A regression test validates that removing a project purges the removed repo's sparse-preset entries while leaving other repos' entries intact.

Changes

Cohort / File(s) Summary
Sparse preset cleanup on repo removal sparse-presets.ts, repos.ts, sparse-presets-repo-removal-purge-leak.test.ts Added omitSparsePresetsForRepos helper to prune sparse-preset maps for removed repos; wired it into deleteProjectHostSetup and removeProject; added regression test verifying purge behavior.

Related PRs: None identified.

Suggested labels: bug, renderer, store

Suggested reviewers: None identified.

Poem
A rabbit hops through repo state,
Pruning presets, sealing fate,
Four maps swept clean when repos go,
No stale sparse crumbs left to show,
Tests confirm the burrow's tight —
Only removed ones lose their light. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is informative but does not follow the required template; it omits Summary, Screenshots, Testing, AI Review Report, Security Audit, and Notes sections. Rewrite the description using the repository template and add the missing sections, including screenshots or 'No visual change', testing, review, security, and notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: purging sparse-preset maps when a repo is removed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

🧹 Nitpick comments (2)
src/renderer/src/store/slices/repos.ts (1)

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

Wiring is correct; only path lacking direct test coverage.

The removedRepoIds derivation here mirrors removeProject's (correctly preserves duplicate repo IDs on other hosts), but the new regression test only exercises removeProject. If this branch's repos/removedRepoIds computation regresses independently, nothing would catch it.

src/renderer/src/store/slices/sparse-presets-repo-removal-purge-leak.test.ts (1)

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

Solid regression test; consider also covering deleteProjectHostSetup.

This verifies the removeProject purge path well. Since deleteProjectHostSetup (repos.ts lines 2255-2262) independently computes removedRepoIds and calls the same helper, a similar test there would guard against a silent regression in that path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2f69115a-575e-43bb-a371-6878e4194594

📥 Commits

Reviewing files that changed from the base of the PR and between b41cab1 and 4e2dbb7.

📒 Files selected for processing (3)
  • src/renderer/src/store/slices/repos.ts
  • src/renderer/src/store/slices/sparse-presets-repo-removal-purge-leak.test.ts
  • src/renderer/src/store/slices/sparse-presets.ts

@nwparker
nwparker merged commit e82eb82 into main Jul 6, 2026
2 checks passed
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