Bug Report: ctx_search returns no results due to overly strict project filtering
Environment
- context-mode version: 1.0.162
- Platform: Windows 11 Pro 10.0.26200
- Claude Code version: Latest
- Node.js version: (via Claude Code)
Description
ctx_search returns "No results found" for all queries, even when the database contains matching content and direct SQLite queries return results successfully.
Root Cause
The bug is in src/search/ctx-search-schema.ts line 133:
export function resolveProjectScope(
raw: string | undefined,
isSharedMode: boolean,
getProjectDirFn: () => string,
): string | null | undefined {
if (!isSharedMode) return undefined;
if (raw === undefined) return getProjectDirFn(); // ← BUG HERE
if (raw === "global") return null;
return raw;
}
When project parameter is not provided, the function returns the current project directory, which enables sessionIdAllowSet filtering in searchWithFallback(). This filter is overly strict and excludes all valid results.
Steps to Reproduce
- Index content using
ctx_index:
ctx_index({
content: "Test content with keywords: mempalace, Docker, context-mode",
source: "test-document"
})
- Verify content is in database:
-- Direct SQLite query works
SELECT content FROM chunks WHERE chunks MATCH 'mempalace' LIMIT 3;
-- Returns results successfully
- Search using
ctx_search:
ctx_search({
queries: ["mempalace"],
limit: 3
})
// Returns: "No results found"
Expected Behavior
ctx_search should return matching results from the indexed content.
Actual Behavior
ctx_search returns "No results found" even though:
- Content exists in the database
- Direct SQLite FTS5 queries return results
- The chunks have valid
session_id values
Workaround
Adding project: "global" parameter disables filtering and returns results:
ctx_search({
queries: ["mempalace"],
limit: 3,
project: "global" // ← Workaround
})
// Returns: [matching results]
Proposed Fix
Change line 133 in src/search/ctx-search-schema.ts from:
if (raw === undefined) return getProjectDirFn();
to:
if (raw === undefined) return null;
This makes the default behavior "no filtering" instead of "filter by current project", which aligns with user expectations and prevents the overly strict filtering issue.
Impact of Fix
- Shared mode OFF: No change (returns
undefined in both cases)
- Shared mode ON, no param:
- Before: Filters by current project (causes bug)
- After: No filtering (returns all results)
- Explicit
project: "global": No change (returns null in both cases)
Additional Context
The sessionIdAllowSet filtering logic in store.searchWithFallback() appears to be working correctly when given the right session IDs. The issue is specifically in the default project scope resolution, which incorrectly enables filtering when it should be disabled.
Verification
After applying the fix:
- Rebuild the plugin:
npm run build
- Reload plugins:
/reload-plugins
- Test search without
project parameter:
ctx_search({ queries: ["test"], limit: 3 })
// Should now return results
Files involved:
src/search/ctx-search-schema.ts (source fix)
server.bundle.mjs (needs rebuild)
src/search/unified.ts (filtering logic - working correctly)
src/store.ts (searchWithFallback - working correctly)
Bug Report: ctx_search returns no results due to overly strict project filtering
Environment
Description
ctx_searchreturns "No results found" for all queries, even when the database contains matching content and direct SQLite queries return results successfully.Root Cause
The bug is in
src/search/ctx-search-schema.tsline 133:When
projectparameter is not provided, the function returns the current project directory, which enablessessionIdAllowSetfiltering insearchWithFallback(). This filter is overly strict and excludes all valid results.Steps to Reproduce
ctx_index:ctx_search:Expected Behavior
ctx_searchshould return matching results from the indexed content.Actual Behavior
ctx_searchreturns "No results found" even though:session_idvaluesWorkaround
Adding
project: "global"parameter disables filtering and returns results:Proposed Fix
Change line 133 in
src/search/ctx-search-schema.tsfrom:to:
This makes the default behavior "no filtering" instead of "filter by current project", which aligns with user expectations and prevents the overly strict filtering issue.
Impact of Fix
undefinedin both cases)project: "global": No change (returnsnullin both cases)Additional Context
The sessionIdAllowSet filtering logic in
store.searchWithFallback()appears to be working correctly when given the right session IDs. The issue is specifically in the default project scope resolution, which incorrectly enables filtering when it should be disabled.Verification
After applying the fix:
npm run build/reload-pluginsprojectparameter:Files involved:
src/search/ctx-search-schema.ts(source fix)server.bundle.mjs(needs rebuild)src/search/unified.ts(filtering logic - working correctly)src/store.ts(searchWithFallback - working correctly)