Skip to content

bug: vault_search excludes shared docs (agent_id=NULL) when agent searches #917

@teexiii

Description

@teexiii

Summary

Docs uploaded via UI without selecting an agent are permanently invisible to agent vault_search. This affects all shared-scope documents.

Root Cause

When docs are uploaded without an agent selected, they are stored with agent_id = NULL, scope = 'shared'.

When an agent calls vault_search, the SQL filter adds a strict equality check:

AND agent_id = 'agent-uuid'   -- NULL != 'uuid' → shared docs excluded

SQL NULL = 'uuid' evaluates to NULL (not TRUE), so all shared docs are silently excluded.

Affected Files

File Line Issue
internal/store/pg/vault_documents.go 546, 585 AND agent_id = $N excludes NULL rows in ftsSearch and vectorSearch
internal/http/vault_handler_upload.go upload handler Upload without agent selection → scope=shared, agent_id=NULL

Steps to Reproduce

  1. Upload docs via Vault UI without selecting an agent
  2. Create an agent and call vault_search with any query
  3. Observe: docs are not returned despite being in the vault

Expected Behavior

Agent should be able to find shared docs (scope = 'shared', agent_id = NULL) in addition to their own personal docs.

Actual Behavior

Only docs explicitly assigned to the agent (agent_id = agent-uuid) are returned. Shared docs with agent_id = NULL are never returned.

Proposed Fix

Change the agent_id filter in ftsSearch and vectorSearch to include NULL (shared) docs:

// internal/store/pg/vault_documents.go (line 546, 585)
// Before:
if agentID != nil {
    q += fmt.Sprintf(" AND agent_id = $%d", p)
    args = append(args, *agentID)
    p++
}

// After:
if agentID != nil {
    q += fmt.Sprintf(" AND (agent_id = $%d OR agent_id IS NULL)", p)
    args = append(args, *agentID)
    p++
}

Impact

Any user who uploads docs to the vault without selecting a specific agent (the default behavior) cannot have those docs found by agent search. This silently breaks the expected knowledge base workflow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highData loss, core logic broken — fix in sprintarea:vaultKnowledge Vault, vault_search, wikilinksbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions