fix(memory): pass per-turn user_id through model tool calls + compat fallback - #48
Merged
Merged
Conversation
…fallback In shared gateway threads (thread_sessions_per_user=False), the cached AIAgent is reused across users. Previous PRs (#41, #44) scoped prefetch/sync, but model-invoked memory tools (memgw_recall, mem0_search, mem0_conclude, etc.) still used the stale _user_id from initialize() — leaking one user's memories to another. This closes the remaining P1 gap from Codex's PR #33 review: - tool_executor: pass user_id=agent._user_id at the dispatch site (already refreshed per-turn by the gateway since PR #33 follow-up) - memgw: call_user_id from kwargs → _user_scope(call_user_id) + _retain - mem0: derive call_user_id per-call; use it for all three tool filters - memory_manager: TypeError compat fallback for old external providers that override prefetch/queue_prefetch/sync_turn without user_id kwarg (silently broke them; now retries without the kwarg) Addresses Codex PR#33 comments (last unmerged items from PR #45).
🔎 Lint report:
|
3 tasks
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.
Summary
Closes the last unmerged items from Codex PR #33 P1 review (previously attempted in PR #45, which was approved but not merged).
The fix was applied directly to
main(fast-forward fromfix/memory-tool-call-user-scoping@79114ea2) since the PR was created as a draft and the GraphQL endpoint needed to convert it is not accessible from this environment.Changes merged
agent/tool_executor.pyuser_id=agent._user_idintohandle_tool_callat memory dispatchplugins/memory/memgw/__init__.pycall_user_idfrom kwargs; use_user_scope(call_user_id)for all three tool branchesplugins/memory/mem0/__init__.pycall_user_id = kwargs.get("user_id", "") or self._user_id; use inline per-call filters for all three toolsagent/memory_manager.pyTypeErrorcompat fallback inprefetch_all,queue_prefetch_all,sync_allfor old external providersGenerated by Claude Code