Skip to content

Worker API: /api/search/observations and /api/search/sessions ignore project parameter #1539

@Sheldenshi

Description

@Sheldenshi

Problem

The worker HTTP endpoints /api/search/observations and /api/search/sessions accept a project query parameter but ignore it completely. Queries always return results from all projects regardless of the project filter.

# Returns results from all projects even though project=project-a
curl "http://127.0.0.1:37777/api/search/observations?query=test&project=project-a"

Root Cause

In src/services/worker/SearchManager.ts, the searchObservations() method (line ~889) destructures the project from params but never uses it:

async searchObservations(args: any): Promise<any> {
    const normalized = this.normalizeParams(args);
    const { query, ...options } = normalized;
    // options.project exists but is never passed to queryChroma or hydration

    const chromaResults = await this.queryChroma(query, 100);  // no project filter
    // ...
    results = this.sessionStore.getObservationsByIds(recentIds, { orderBy: 'date_desc', limit });  // no project filter
}

Same issue in searchSessions() (line ~946).

Note: The main search() method (line ~126), used by the MCP tool, correctly handles project filtering — it builds a Chroma where clause with the project and passes it through. Only searchObservations() and searchSessions() are affected.

Expected Behavior

When project is passed as a query parameter, results should be scoped to that project only — both in the Chroma vector query and in the SQLite hydration.

Proposed Fix

  1. Pass options.project as a Chroma where filter in queryChroma() calls
  2. Pass options.project to getObservationsByIds() / getSessionSummariesByIds() during hydration

This mirrors the pattern already used in the main search() method.

Impact

This bug breaks project-scoped search for:

  • OpenClaw plugin search commands which call these endpoints with a project filter
  • Any direct HTTP API consumers filtering by project
  • The MCP search tool is not affected (it uses the main search() method which handles project 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