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
- Upload docs via Vault UI without selecting an agent
- Create an agent and call
vault_search with any query
- 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.
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:SQL
NULL = 'uuid'evaluates toNULL(notTRUE), so all shared docs are silently excluded.Affected Files
internal/store/pg/vault_documents.goAND agent_id = $Nexcludes NULL rows inftsSearchandvectorSearchinternal/http/vault_handler_upload.goscope=shared, agent_id=NULLSteps to Reproduce
vault_searchwith any queryExpected 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 withagent_id = NULLare never returned.Proposed Fix
Change the agent_id filter in
ftsSearchandvectorSearchto include NULL (shared) docs: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.