Skip to content

fix(memory): pass user_id through prefetch + scope per-user (Codex PR#33 P1) - #41

Merged
dizhaky merged 1 commit into
mainfrom
dan/codex-p1-user-id-scoping
Jun 28, 2026
Merged

fix(memory): pass user_id through prefetch + scope per-user (Codex PR#33 P1)#41
dizhaky merged 1 commit into
mainfrom
dan/codex-p1-user-id-scoping

Conversation

@dizhaky

@dizhaky dizhaky commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • MemoryProvider.prefetch() base class: add user_id kwarg (all providers now have a consistent signature)
  • All 9 plugins updated: mem0, honcho, hindsight, memgw, holographic, retaindb, supermemory, openviking, byterover
  • memgw: scope prefetch results by user_id — prevents cross-user memory leakage in gateway sessions
  • mem0: use per-turn user_id in sync_turn
  • memory_manager.prefetch_all(): threads user_id through to all providers
  • conversation_loop: passes agent._user_id to prefetch_all
  • gateway/run.py: refreshes agent identity on cached-agent reuse (prevents stale identity after session swap)
  • Tests updated to match new prefetch(user_id=) signature

Supersedes #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_id through the memory prefetch path and tightening two provider-specific behaviors.

MemoryProvider.prefetch() and MemoryManager.prefetch_all() now accept user_id; the conversation loop passes agent._user_id into prefetch_all so per-turn recall can be scoped to the current caller. All memory plugins adopt the same prefetch(..., user_id=) signature for consistency.

memgw tags background prefetch results with the requesting user_id and drops cached prefetch when prefetch is called for a different user, avoiding stale cross-user injection in shared sessions. mem0 sync_turn writes with user_id from 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 current source, so shared-thread sessions do not keep the previous turn’s caller after a swap.

Reviewed by Cursor Bugbot for commit 9207fd1. Configure here.

…#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>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

🔎 Lint report: dan/codex-p1-user-id-scoping vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8649 on HEAD, 8649 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4570 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@dizhaky
dizhaky merged commit 71378e5 into main Jun 28, 2026
28 checks passed
@dizhaky
dizhaky deleted the dan/codex-p1-user-id-scoping branch June 28, 2026 02:48

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9207fd1. Configure here.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in two merged follow-up PRs:

Reviewed and confirmed by Claude Code.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant