Describe the bug
The resolveFilters function in opencode-mem0-selfhost produces filters in {AND: [{user_id: "..."}, {app_id: "..."}]} format, which is designed for the Mem0 Platform/cloud API. However, the self-host Mem0 server's /search endpoint expects flat filters like {user_id: "...", app_id: "..."} with user_id, agent_id, or run_id as direct keys at the top level.
This causes every search_memories call to fail with:
mem0 self-host POST /search failed (400): filters must contain at least one of: user_id, agent_id, run_id. Example: filters={'user_id': 'u1'}
To Reproduce
- Install opencode-mem0-selfhost v0.1.7
- Configure with a self-host Mem0 server
- Call the
search_memories tool with any query
- Observe the 400 error
Expected behavior
The search_memories tool should successfully search memories scoped to the current user/project.
Root Cause
The resolveFilters function (defined at around line 12932 in dist/index.js) always wraps filters in {AND: [...]} or {OR: [...]} structures:
https://github.com/imsudip/opencode-mem0-selfhost/blob/main/dist/index.js#L12932-L12984
The self-host server validates that filters (from the SearchRequest schema) contains at least one of user_id, agent_id, or run_id as a direct key. Since the plugin nests these inside AND, none of them appear at the top level and the server rejects the request.
Additionally, the search method in SelfHostMemoryClient sends filters directly to the server without any client-side post-processing. The self-host server stores app_id inside metadata.app_id and cannot filter on it server-side, so search results are not scoped to the current project.
Fix Applied Locally
I hotfixed dist/index.js with two changes:
-
resolveFilters: Now produces flat objects like {user_id: "peterkostadinov", app_id: "AI-Shorts"} instead of {AND: [{user_id: "..."}, {app_id: "..."}]}. Legacy AND/OR input is flattened.
-
search method: After getting the server response, applies memoryMatches client-side for non-first-class filter keys (like app_id which lives in metadata). This ensures app_id filtering works for search results.
Environment
- Plugin version: 0.1.7
- Self-host Mem0 server version: latest (REST API via docker)
- OpenCode version: latest
Additional context
Full source for resolveFilters is at dist/index.js ~L12932 and selfhost-client.ts in the SelfHostMemoryClient.search() method.
Describe the bug
The
resolveFiltersfunction inopencode-mem0-selfhostproduces filters in{AND: [{user_id: "..."}, {app_id: "..."}]}format, which is designed for the Mem0 Platform/cloud API. However, the self-host Mem0 server's/searchendpoint expects flat filters like{user_id: "...", app_id: "..."}withuser_id,agent_id, orrun_idas direct keys at the top level.This causes every
search_memoriescall to fail with:To Reproduce
search_memoriestool with any queryExpected behavior
The
search_memoriestool should successfully search memories scoped to the current user/project.Root Cause
The
resolveFiltersfunction (defined at around line 12932 indist/index.js) always wraps filters in{AND: [...]}or{OR: [...]}structures:https://github.com/imsudip/opencode-mem0-selfhost/blob/main/dist/index.js#L12932-L12984
The self-host server validates that
filters(from theSearchRequestschema) contains at least one ofuser_id,agent_id, orrun_idas a direct key. Since the plugin nests these insideAND, none of them appear at the top level and the server rejects the request.Additionally, the
searchmethod inSelfHostMemoryClientsends filters directly to the server without any client-side post-processing. The self-host server storesapp_idinsidemetadata.app_idand cannot filter on it server-side, so search results are not scoped to the current project.Fix Applied Locally
I hotfixed
dist/index.jswith two changes:resolveFilters: Now produces flat objects like{user_id: "peterkostadinov", app_id: "AI-Shorts"}instead of{AND: [{user_id: "..."}, {app_id: "..."}]}. LegacyAND/ORinput is flattened.searchmethod: After getting the server response, appliesmemoryMatchesclient-side for non-first-class filter keys (likeapp_idwhich lives inmetadata). This ensuresapp_idfiltering works for search results.Environment
Additional context
Full source for
resolveFiltersis atdist/index.js~L12932 andselfhost-client.tsin theSelfHostMemoryClient.search()method.