Skip to content

fix(session-search): keep the Project scope working past 64 worktrees - #21496

Closed
Jinwoo-H wants to merge 1 commit into
mainfrom
session-search-project-scope
Closed

Jinwoo-H wants to merge 1 commit into
mainfrom
session-search-project-scope

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​67 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​64

Bug

In the Agent Session History panel, choosing the Project scope and typing a query showed "Could not search this computer. Check its connection and try again." on any repo with more than 64 worktrees. The Project scope sends one scope path per worktree; the search request schema caps that list at 64 and refused the request, and the panel rendered the rejection as a connection failure. The session list had the same problem in a quieter form: it scanned the first 64 paths and warned.

Fix

  • deriveAiVaultScopeSessionPaths folds sibling worktree paths into their parent directory once the project is past the cap. Orca keeps a repo's worktrees under one directory of their own, and both the scanner and the index match a scope by prefix, so the parent covers exactly what the siblings did. Below the cap nothing changes; a path with no sibling, or whose parent is a filesystem, drive, or share root, stays as it is.
  • The panel search request trims to the cap instead of throwing, matching the list.

Tests

  • Folding: under the cap untouched; siblings fold and lone paths survive; Windows drive and UNC roots never become a scope; top-level directories never fold into /.
  • End to end through deriveAiVaultScopeSessionPaths with a repo root plus more worktrees than the cap.
  • The existing at-scale timing guard now asserts the folded result.

The Project scope sent one path per worktree. A repo with more than 64 of
them had its list scanned partially and its search refused outright, which
the panel showed as "Could not search this computer". Sibling worktree
paths now fold into their parent directory once the project is past the
cap; Orca keeps a repo's worktrees under one directory of their own and
both the scanner and the index match by prefix, so the parent covers what
the siblings did. The search request also trims to the cap instead of
throwing, matching what the list already did.
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change adds foldSiblingScopePathsUnderCap, which replaces oversized sibling path groups with parent directories while preserving lone paths and filesystem, drive, and share roots. Session and workspace scope derivation use the folding behavior. AI vault search requests now limit scopePaths to AI_VAULT_SCOPE_PATHS_MAX_COUNT. Tests cover POSIX and Windows paths, root handling, scale, and session derivation.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to 619fe

At scale, unusual POSIX filenames or UNC share-root worktrees can produce incorrect AI vault scopes, causing searches and session listings to include or omit paths unexpectedly. The cases are narrow but should be corrected.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the bug, fix, scope, and tests, but it omits required template sections, including the linked issue, visual proof or an explicit N/A explanation, testing checklist, AI… Add the required template sections. Include the linked issue after “Fixes #”. Add visual proof or write N/A with a reason. Complete the testing checklist and document platform testing. Complete the AI Disclosure, Review, Agent skill upstr…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 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 fix for Project-scoped session search when repositories contain more than 64 worktrees.
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.
Full details: Description check

Explanation

The description clearly explains the bug, fix, scope, and tests, but it omits required template sections, including the linked issue, visual proof or an explicit N/A explanation, testing checklist, AI disclosure, review, boundary confirmation, notes, and final checklist.

Resolution

Add the required template sections. Include the linked issue after “Fixes #”. Add visual proof or write N/A with a reason. Complete the testing checklist and document platform testing. Complete the AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist sections.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e5402e62-3cc1-4fec-a139-115b173b34bd

📥 Commits

Reviewing files that changed from the base of the PR and between 0b57ce0 and 619fed3.

📒 Files selected for processing (3)
  • src/renderer/src/components/right-sidebar/ai-vault-scope-paths.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-scope-paths.ts
  • src/renderer/src/components/right-sidebar/use-ai-vault-search.ts

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

/** The directory holding `pathValue`, or null when that would be a filesystem root. */
function runtimeParentDirectory(pathValue: string): string | null {
const trimmed = pathValue.replace(/[\\/]+$/g, '')
const separator = Math.max(trimmed.lastIndexOf('/'), trimmed.lastIndexOf('\\'))

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

Do not parse backslashes as POSIX separators.

On POSIX, \ is valid in a filename. If more than 64 paths include /foo\one and /foo\two, Line 134 assigns both paths the parent /foo and folds them. These are top-level paths and must remain separate. Only treat \ as a separator when the path has Windows semantics. Add a POSIX regression test.

Based on learnings: a backslash is a valid literal filename character on POSIX.

Source: Learnings

Comment on lines +138 to +141
const parent = trimmed.slice(0, separator)
// `//server/share/x` and `C:\x` both sit directly under a root; `/x` was caught above.
if (/^[a-zA-Z]:$/.test(parent) || /^[\\/]{2}[^\\/]+[\\/][^\\/]+$/.test(parent)) {
return null

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

Detect UNC share roots before deriving their parent.

If an over-cap list contains \\server\share-a and \\server\share-b, Line 138 derives \\server. Line 140 checks that derived value, so it does not preserve either share root. The function then folds both roots into \\server, which violates the root-handling contract. Detect UNC share roots from trimmed before slicing the parent and add a regression test.

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

Important

The fold assumes every worktree's parent directory is repo-specific, which only holds for the nested layout. With nestWorkspaces: false or SSH worktrees that parent is shared across repos, so folding widens the Project scope — and, because search hits bypass the panel's client-side project filter, the search results — to unrelated projects. Detail inline.

Reviewed changes

  • Fold siblings past the cap — deriveAiVaultScopeSessionPaths now returns foldSiblingScopePathsUnderCap(accumulator.paths), grouping paths by immediate parent and replacing any group of two or more with the parent.
  • Trim the search request — the panel slices scopePaths to AI_VAULT_SCOPE_PATHS_MAX_COUNT rather than letting the schema reject the request.
  • Tests — fold unit tests (under-cap unchanged, siblings fold, Windows drive/UNC roots, top-level directories), an end-to-end over-cap case through deriveAiVaultScopeSessionPaths, and the at-scale timing guard now asserts the folded result.

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

* covers what the siblings did. Below the cap nothing changes; a path with no
* sibling, or whose parent is a filesystem root, stays as it is.
*/
export function foldSiblingScopePathsUnderCap(paths: readonly string[]): string[] {

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.

The coverage argument here ("Orca keeps a repo's worktrees under one directory of their own") only holds for the nested layout. With nestWorkspaces: false worktrees land at <workspaceDir>/<name>, and SSH worktrees at <repoParent>/<repoName>-<name> — both share a parent with other repos. Folding 65 worktrees to that parent widens the scope to sibling repos, and search hits are not re-filtered by project, so unrelated projects' sessions appear in Project-scope search results.

Technical details
# Folding to a shared parent widens the Project scope

## Affected sites
- `src/renderer/src/components/right-sidebar/ai-vault-scope-paths.ts:100` — `foldSiblingScopePathsUnderCap` folds any parent with >1 member without checking that the parent belongs to the active repo.
- `src/renderer/src/components/right-sidebar/use-ai-vault-search.ts:161` — the folded paths become the search `scopePaths`.
- `src/renderer/src/components/right-sidebar/ai-vault-session-filters.ts:45` — `useAiVaultPanelSessions` returns search hits unfiltered (`searching ? sessions : filterAiVaultSessions(...)`), so the list's project-attribution filter never runs for search.

## Evidence
- `computeWorktreePathFromWorkspaceRoot` (`src/main/ipc/worktree-logic.ts:126`): nested → `<workspaceDir>/<repo>/<name>`; flat → `<workspaceDir>/<name>`. Default is `nestWorkspaces: true` (`src/shared/default-global-settings.ts:35`), but the setting is user-settable.
- `computeRemoteWorktreePath` (`src/main/ipc/worktree-logic.ts:202`) places SSH worktrees at `<repoParent>/<repoName>-<name>` when `workspaceDir` is absolute (the desktop default).
- `sessionRowFilter` (`src/main/ai-vault-search/session-search-row-filter.ts:81`) matches by `cwdKey` prefix, so a parent scope matches every repo beneath it.

## Required outcome
Folding must not pull in sessions whose cwd belongs to a different project/repo. Either restrict the fold to parents that are provably repo-specific, or carry an explicit project/repo filter alongside the widened scope in the search request.

## Open questions for the human
- Are the flat (`nestWorkspaces: false`) and SSH layouts in scope for this fix, or is the over-inclusion considered an acceptable trade above the cap?

@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Superseded by #21509, which resolves Workspace and Project scope on the host instead of folding paths under the cap.

@Jinwoo-H Jinwoo-H closed this Sep 18, 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