Skip to content

fix(sidebar): preserve existing filtered projects when adding new projects - #21031

Closed
denis-sj wants to merge 1 commit into
stablyai:mainfrom
denis-sj:feat/keep-filtered-projects-after-add-20796
Closed

denis-sj wants to merge 1 commit into
stablyai:mainfrom
denis-sj:feat/keep-filtered-projects-after-add-20796

Conversation

@denis-sj

Copy link
Copy Markdown
Contributor

Why

When a user has active project filters in the sidebar and adds a new project (git repo or folder workspace), Orca wiped all active filterRepoIds back to []. The user was forced to reconfigure their sidebar filters from scratch on every project add.

Two call sites were responsible:

  1. worktree-activation.ts: called state.setFilterRepoIds([]) when the newly activated worktree's repoId was absent from the current filter.
  2. add-repo-skip-finalization.ts: same reset when an imported project skipped worktree creation.

Summary

Both sites now append the newly added repoId instead of clearing the array:

// Before
state.setFilterRepoIds([])
// After
state.setFilterRepoIds([...state.filterRepoIds, repoId])

Resulting invariant:

  • Unfiltered sidebar (filterRepoIds.length === 0): stays unfiltered after add — no change.
  • Filtered sidebar: existing filtered projects remain visible; new project is immediately appended and revealed.

Tests

8 / 8 tests pass (worktree-activation-reveal.test.ts, add-repo-skip-finalization.test.ts). project-added-default-checkout.test.ts updated (15/15 pass). pnpm tc:web and pnpm run check:code-quality:changed — clean.

Issue Number

Fixes #20796

@pullfrog pullfrog 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.

ℹ️ No blocking issues — one doc/naming drift and one scope question.

Reviewed changes

  • Augment the repo filter instead of clearing it on reveal — activateAndRevealWorktree step 5 now appends wt.repoId to filterRepoIds when the target repo is filtered out, rather than resetting the array.
  • Same append in skip-finalization — finalizeImportedRepoAfterSkip appends the imported repo id under the same length > 0 && !includes guard, so both add-project branches (with and without a default checkout) preserve the existing selection.
  • Tests updated and extended — the three touched test files were updated to the append expectation, plus a new #20796 regression test in each of the two code paths.

ℹ️ This edit lives in the shared reveal helper, not just the add-project flow

The issue is scoped to adding projects, but activateAndRevealWorktree is the reveal path for every activation. With clearSidebarFilters defaulting to true, any activation whose target repo is filtered out now appends that repo to the user's persisted filterRepoIds, not only adds.

Technical details
# Reveal-helper scope

## Affected sites
- `src/renderer/src/lib/worktree-activation.ts:298` — `clearSidebarFilters` defaults to true, so callers that omit it append the target repo whenever the repo was filtered out.
- `src/renderer/src/hooks/ipc-events/worktree-event-runtime.ts:154` — host-runtime `activateWorktree` stream events.
- `src/renderer/src/components/sidebar/active-worktree-focus-after-delete.ts:90` — post-delete focus handoff (`revealInSidebar: false`, so the filter mutates without a reveal).
- `src/renderer/src/lib/sidebar-worktree-activation.ts:26` — sidebar row click (`revealInSidebar: false`).

`jumpToWorktreeFromSidebar` already passes `clearSidebarFilters: false` for targets it detected as filter-hidden, so the common Cmd+J / palette jump case does not grow the filter.

## Required outcome
- Confirm that appending the target repo on non-add activations is intended, or scope the append to the add-project call sites / an explicit option.

## Open questions for the human
- Should an automatic (host-runtime / post-delete) activation silently expand the user's persisted project filter?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

if (opts?.clearSidebarFilters !== false) {
if (state.filterRepoIds.length > 0 && !state.filterRepoIds.includes(wt.repoId)) {
state.setFilterRepoIds([])
state.setFilterRepoIds([...state.filterRepoIds, wt.repoId])

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.

Now that this augments the repo filter instead of clearing it, the step-5 comment above (// 5. Clear sidebar filters hiding the target) and the clearSidebarFilters option name/JSDoc no longer describe the behavior. Rewording them (e.g. "Extend the repo filter to include the target") would keep the next reader from expecting a full clear.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change preserves existing repository filters when imported repositories or worktrees are revealed. finalizeImportedRepoAfterSkip and activateAndRevealWorktree now append the target repository ID instead of clearing filters. Tests cover imported repositories, default-checkout fallback behavior, and worktree activation.

Priority: ⬇️ Low

Severity of issue fixed: Low

Merge Risk: 🔵 Low · up to 286ad

A repository added while a catalog refresh is already in flight can remain hidden behind the user's previous filters. The narrow race should be fixed before relying on this reveal behavior.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, affected call sites, solution, issue number, and test results. However, it omits several required template sections, including ELI5, What Changed, Visual Proof or… Complete the required template sections. Add ELI5, What Changed, Visual Proof or an explicit N/A with a reason, AI Disclosure if applicable, Review, Agent skill upstream boundary, Notes, and the required checklist items, including platform …
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. 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 change: preserving existing filtered projects when adding new projects.
Linked Issues check ✅ Passed Issue #20796 requires existing sidebar project filters to remain active after a new project folder is added. finalizeImportedRepoAfterSkip now appends importedRepoId to a non-empty filterRepoIds…
Out of Scope Changes check ✅ Passed The diff is limited to the two sidebar filtering call sites and their regression tests. The tests directly verify issue #20796 behavior. No unrelated production behavior or unrelated files are changed…
Full details: Description check

Explanation

The description explains the problem, affected call sites, solution, issue number, and test results. However, it omits several required template sections, including ELI5, What Changed, Visual Proof or N/A, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist details.

Resolution

Complete the required template sections. Add ELI5, What Changed, Visual Proof or an explicit N/A with a reason, AI Disclosure if applicable, Review, Agent skill upstream boundary, Notes, and the required checklist items, including platform testing and validation commands.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch feat/keep-filtered-projects-after-add-20796

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 332c447f-2ade-4468-b497-856160664893

📥 Commits

Reviewing files that changed from the base of the PR and between 291b4dd and 286ad3e.

📒 Files selected for processing (5)
  • src/renderer/src/components/sidebar/add-repo-skip-finalization.test.ts
  • src/renderer/src/components/sidebar/add-repo-skip-finalization.ts
  • src/renderer/src/components/sidebar/project-added-default-checkout.test.ts
  • src/renderer/src/lib/worktree-activation-reveal.test.ts
  • src/renderer/src/lib/worktree-activation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.

}
if (state.filterRepoIds.length > 0 && !state.filterRepoIds.includes(importedRepoId)) {
state.setFilterRepoIds([])
state.setFilterRepoIds([...state.filterRepoIds, importedRepoId])

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- target outline ---'
ast-grep outline src/renderer/src/components/sidebar/add-repo-skip-finalization.ts
printf '%s\n' '--- target source ---'
cat -n src/renderer/src/components/sidebar/add-repo-skip-finalization.ts
printf '%s\n' '--- worktree source ---'
sed -n '240,330p' src/renderer/src/lib/worktree-activation.ts
printf '%s\n' '--- relevant symbols ---'
rg -n --glob '!node_modules' 'retainValidFilterRepoIds|addRepoPath|filterRepoIds|catalog' src/renderer/src | head -240

Repository: stablyai/orca

Length of output: 37691


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- retain helper ---'
cat -n src/renderer/src/store/slices/repo-filter-selection.ts
printf '%s\n' '--- fencing ---'
cat -n src/renderer/src/store/repos/repo-catalog-fencing.ts
printf '%s\n' '--- repo state/add ---'
sed -n '120,205p' src/renderer/src/store/repos/repo-state.ts
sed -n '1,215p' src/renderer/src/store/repos/repo-add-actions.ts
printf '%s\n' '--- catalog action apply paths ---'
sed -n '1,190p' src/renderer/src/store/repos/repo-catalog-actions.ts
sed -n '1,210p' src/renderer/src/store/repos/runtime-repo-catalog-actions.ts
sed -n '1,215p' src/renderer/src/store/repos/all-host-repo-catalog-actions.ts
printf '%s\n' '--- relevant tests ---'
sed -n '330,410p' src/renderer/src/store/slices/repos-refresh-identity.test.ts
rg -n 'stale|generation|addRepoPath|fetchRepos|retainValidFilterRepoIds|filterRepoIds' src/renderer/src/store/repos src/renderer/src/components/sidebar src/renderer/src/lib/*test* | head

Repository: stablyai/orca

Length of output: 45676


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- fetched catalog merge ---'
sed -n '1,180p' src/renderer/src/store/repos/repo-catalog-merge.ts
printf '%s\n' '--- generation mutations and add/import callers ---'
rg -n 'reposFetchGeneration|claimRepoCatalogGeneration|latestRepoCatalogGeneration|addRepoPath\\(|finalizeImportedRepoAfterSkip|activateAndRevealWorktree' src/renderer/src | head -220
printf '%s\n' '--- add/import tests ---'
rg -l 'addRepoPath|finalizeImportedRepoAfterSkip|activateAndRevealWorktree' src/renderer/src --glob '*test*' | head -80

Repository: stablyai/orca

Length of output: 11498


🏁 Script executed:

#!/bin/bash
set -e
printf '%s\n' '--- host merge ---'
rg -n -A100 -B20 'function mergeFetchedReposForHost|mergeFetchedReposForHost' src/renderer/src/store/repos/repo-catalog-identity.ts
printf '%s\n' '--- add-race tests ---'
cat -n src/renderer/src/store/slices/repos-add-races.test.ts
printf '%s\n' '--- skip-finalization tests ---'
cat -n src/renderer/src/components/sidebar/add-repo-skip-finalization.test.ts
printf '%s\n' '--- exact generation usages ---'
rg -n 'reposFetchGeneration|claimRepoCatalogGeneration|latestRepoCatalogGenerationByHostByStore|latestAllHostRepoCatalogGenerationByStore' src/renderer/src

Repository: stablyai/orca

Length of output: 16016


Invalidate catalog generations when addRepoPath commits a repository. fetchRepos captures its generation before awaiting the catalog, but addRepoPath does not invalidate that generation. mergeFetchedReposForHost then removes current-host rows absent from the fetched identities. A fetch that started before the add can therefore remove the new repository, and retainValidFilterRepoIds removes its appended ID. The imported project remains hidden by the user's previous filters.

Use the existing catalog-generation fencing when addRepoPath commits the repository. This shared correction also protects the filter append in src/renderer/src/lib/worktree-activation.ts:300.

@nwparker

Copy link
Copy Markdown
Contributor

Thanks @denis-sj for the fix. #20796 is already fixed on main by #20987 (07b7687). Both the worktree-activation path and finalizeImportedRepoAfterSkip now go through revealRepoInProjectFilter, which appends the new repo id to the active Projects filter instead of clearing it, and leaves an unfiltered sidebar unfiltered. If you can still reproduce it on the latest build, please comment or reopen.

@nwparker nwparker closed this Oct 26, 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.

[Other]: Can we keep filtered projects after adding new project folders?

2 participants