fix(mcp): operator precedence in search_memory filter (#4470)#4474
Merged
whysosaket merged 1 commit intomem0ai:mainfrom Mar 21, 2026
Merged
Conversation
whysosaket
approved these changes
Mar 21, 2026
lukaj99
added a commit
to lukaj99/mem0
that referenced
this pull request
Mar 21, 2026
jamebobob
pushed a commit
to jamebobob/mem0-vigil-recall
that referenced
this pull request
Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
search_memoryfiltered vector hits with:if allowed and h.id is None or h.id not in allowed:Because
andbinds tighter thanor, Python evaluated(allowed and h.id is None) or (h.id not in allowed). WhenallowedisNone(no accessible memory IDs after ACL filtering), the second part still ran and evaluatedh.id not in None, causing:TypeError: argument of type 'NoneType' is not iterableThis broke MCP memory search whenever the allow-list was empty / unset in that code path.
Change: add parentheses so we only evaluate membership when filtering applies:
if allowed and (h.id is None or h.id not in allowed):Dependencies: None.
Fixes #4470
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
allowed = Noneand a hit with a non-Noneid, the old condition raises the sameTypeErroras the server; the new condition does not evaluateh.id not in allowedwhenallowedis falsy.openmemory/api/app/mcp_server.pymatches the intended boolean (filter only whenallowedis a non-empty set).No new automated test was added in this PR (small one-line fix); happy to add a unit test in a follow-up if needed
Checklist:
Maintainer Checklist