fix(memory): pass user_id through prefetch + scope per-user (Codex PR#33 P1) - #41
Conversation
…#33 P1) - MemoryProvider.prefetch() base class: add user_id kwarg - All 9 plugins (mem0, honcho, hindsight, memgw, holographic, retaindb, supermemory, openviking, byterover): add user_id kwarg - memgw: scope prefetch results by user_id to prevent cross-user leakage - mem0: use per-turn user_id in sync_turn - memory_manager.prefetch_all(): thread user_id through to providers - conversation_loop: pass agent._user_id to prefetch_all - gateway/run.py: refresh agent identity on cached-agent reuse - tests: update mock prefetch() signatures to match base class Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
🔎 Lint report:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9207fd1. Configure here.
| if self._is_breaker_open(): | ||
| return | ||
|
|
||
| effective_user_id = user_id or self._user_id |
There was a problem hiding this comment.
Mem0 prefetch ignores per-turn user
High Severity
The prefetch mechanism has inconsistent user_id handling. queue_prefetch may search using an outdated user ID, and the prefetch method's cross-user guard can fail if the incoming user_id is empty. This can result in incorrect or leaked memories when agents are reused across different users.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 9207fd1. Configure here.
There was a problem hiding this comment.
Addressed in two merged follow-up PRs:
- PR fix(mem0): scope prefetch search and result cache by user_id #44 (fix(mem0): scope prefetch search and result cache by user_id) —
queue_prefetchnow passes the kwarguser_idto Mem0 search; the cross-user guard also handles emptyuser_idviaor not cached[1]. - PR fix(memory): pass per-turn user_id through model tool calls + compat fallback #48 (fix(memory): pass per-turn user_id through model tool calls + compat fallback) — all Mem0 tool call branches use per-call filters derived from the
user_idkwarg, eliminating the staleself._user_idread.
Reviewed and confirmed by Claude Code.
Generated by Claude Code


Summary
MemoryProvider.prefetch()base class: adduser_idkwarg (all providers now have a consistent signature)memgw: scope prefetch results byuser_id— prevents cross-user memory leakage in gateway sessionsmem0: use per-turnuser_idinsync_turnmemory_manager.prefetch_all(): threadsuser_idthrough to all providersconversation_loop: passesagent._user_idtoprefetch_allgateway/run.py: refreshes agent identity on cached-agent reuse (prevents stale identity after session swap)prefetch(user_id=)signatureSupersedes #36 and #39 (original commits were unsigned cursor-agent work; squashed into one signed commit).
Fixes Codex PR#33 P1 finding — cross-user identity + prefetch scoping.
🤖 Generated with Claude Code
Note
Medium Risk
Changes memory recall/write scoping and gateway cached-agent identity—important for multi-user sessions; most providers only extend signatures, with memgw/mem0 carrying the behavioral fixes.
Overview
Fixes cross-user memory identity in gateway sessions by plumbing
user_idthrough the memory prefetch path and tightening two provider-specific behaviors.MemoryProvider.prefetch()andMemoryManager.prefetch_all()now acceptuser_id; the conversation loop passesagent._user_idintoprefetch_allso per-turn recall can be scoped to the current caller. All memory plugins adopt the sameprefetch(..., user_id=)signature for consistency.memgw tags background prefetch results with the requesting
user_idand drops cached prefetch whenprefetchis called for a different user, avoiding stale cross-user injection in shared sessions. mem0sync_turnwrites withuser_idfrom the turn (falling back to config) instead of only static write filters.When the gateway reuses a cached agent, it now refreshes
_user_id, chat/thread metadata, and related identity fields from the currentsource, so shared-thread sessions do not keep the previous turn’s caller after a swap.Reviewed by Cursor Bugbot for commit 9207fd1. Configure here.