Skip to content

Bug: ctx_search returns no results due to overly strict project filtering #827

@AlexDoratu

Description

@AlexDoratu

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

  1. Index content using ctx_index:
ctx_index({
  content: "Test content with keywords: mempalace, Docker, context-mode",
  source: "test-document"
})
  1. Verify content is in database:
-- Direct SQLite query works
SELECT content FROM chunks WHERE chunks MATCH 'mempalace' LIMIT 3;
-- Returns results successfully
  1. 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:

  1. Rebuild the plugin: npm run build
  2. Reload plugins: /reload-plugins
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions