From 4eb59e32fab055571f5b115fafbbce8be62579c1 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Fri, 11 Sep 2026 03:28:07 -0400 Subject: [PATCH] fix(ai-vault-search): keep a scope nothing could key from widening the search --- .../ai-vault-search/session-search-row-filter.test.ts | 10 ++++++++++ src/main/ai-vault-search/session-search-row-filter.ts | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/ai-vault-search/session-search-row-filter.test.ts b/src/main/ai-vault-search/session-search-row-filter.test.ts index dd7ca0d1e5c..1cec0a528f9 100644 --- a/src/main/ai-vault-search/session-search-row-filter.test.ts +++ b/src/main/ai-vault-search/session-search-row-filter.test.ts @@ -79,6 +79,16 @@ describe('a cwd scope is the sidebar key, or anything below it', () => { expect(selected(db)).toEqual([1]) }) + it('narrows to nothing when no scope the caller gave could be keyed', async () => { + // `cwdKey` returns null for a scope it cannot key, and a scope that matches + // nothing must return nothing; dropping it would answer the whole index. + const db = await openIndex() + addSession(db, 1, '/work/app') + addSession(db, 2, '/elsewhere') + expect(selected(db, { scopePaths: [''] })).toEqual([]) + expect(selected(db, { scopePaths: ['', '/work/app'] })).toEqual([1]) + }) + it('keeps a WSL UNC workspace distinct from the bare Linux spelling', async () => { // PR 2 decided cwd_key does not qualify a Linux path with its distro: the // collision is real but every SSH host has it too, and the fix is a column diff --git a/src/main/ai-vault-search/session-search-row-filter.ts b/src/main/ai-vault-search/session-search-row-filter.ts index 5015fa460e6..4f5b6106e7d 100644 --- a/src/main/ai-vault-search/session-search-row-filter.ts +++ b/src/main/ai-vault-search/session-search-row-filter.ts @@ -53,9 +53,9 @@ export function sessionRowFilter( const present = filters.scopePaths .map((scope) => scopeCondition(filter, scope)) .filter((condition) => condition !== null) - if (present.length > 0) { - filter.conditions.push(`(${present.join(' OR ')})`) - } + // Every scope unkeyable still means a scope, so it narrows to nothing; + // pushing no condition would widen the search to every session instead. + filter.conditions.push(present.length > 0 ? `(${present.join(' OR ')})` : '0 = 1') } return filter }