-
Notifications
You must be signed in to change notification settings - Fork 0
fix(memory): pass user_id through prefetch + scope per-user — Codex PR#33 P1 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
15d932b
ffb95e7
07a2258
4de996e
825cc5a
6f46176
ebb9a28
b45971f
dc669f6
4611cbc
f5115b8
ba76529
8180a1f
599862b
fee0aab
f2c663d
16e73b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,6 +143,7 @@ def __init__(self): | |
| self._prefetch_method = 'recall' | ||
| self._user_id = '' | ||
| self._prefetch_result = '' | ||
| self._prefetch_result_user: str = '' | ||
| self._prefetch_lock = threading.Lock() | ||
| self._prefetch_thread: threading.Thread | None = None | ||
| # Monotonic generation: only the latest queued prefetch may store its | ||
|
|
@@ -284,12 +285,17 @@ def _format_recall(payload: dict) -> str: | |
| lines.append(f'- {snippet}') | ||
| return '\n'.join(lines) | ||
|
|
||
| def prefetch(self, query: str, *, session_id: str = '') -> str: | ||
| def prefetch(self, query: str, *, session_id: str = '', user_id: str = '') -> str: | ||
| if self._prefetch_thread and self._prefetch_thread.is_alive(): | ||
| self._prefetch_thread.join(timeout=3.0) | ||
| with self._prefetch_lock: | ||
| # Discard a result queued for a different user to prevent cross-user leak. | ||
| if user_id and self._prefetch_result_user and self._prefetch_result_user != user_id: | ||
| self._prefetch_result = '' | ||
| self._prefetch_result_user = '' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memgw prefetch discard skips emptyMedium Severity The new cross-user prefetch guard only clears cached results when both the current Reviewed by Cursor Bugbot for commit 16e73b0. Configure here.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in PR #44 (fix(mem0): scope prefetch search and result cache by user_id): the guard now also discards cached results when Reviewed and confirmed by Claude Code. Generated by Claude Code |
||
| result = self._prefetch_result | ||
| self._prefetch_result = '' | ||
| self._prefetch_result_user = '' | ||
| if not result: | ||
| return '' | ||
| return f'## Memory Gateway\n{result}' | ||
|
|
@@ -299,6 +305,7 @@ def on_session_switch(self, new_session_id: str, **kwargs) -> None: | |
| # its cached result, so the new session can't be fed stale context. | ||
| with self._prefetch_lock: | ||
| self._prefetch_result = '' | ||
| self._prefetch_result_user = '' | ||
| self._prefetch_gen += 1 | ||
|
|
||
| def queue_prefetch(self, query: str, *, session_id: str = '', user_id: str = '') -> None: | ||
|
|
@@ -329,6 +336,7 @@ def _run(): | |
| with self._prefetch_lock: | ||
| if my_gen == self._prefetch_gen: | ||
| self._prefetch_result = text | ||
| self._prefetch_result_user = user_id | ||
| self._record_success() | ||
| except Exception as e: | ||
| self._record_failure() | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mem0 sync prefetch scope split
High Severity
When a
memgwagent is reused,queue_prefetchmay perform memory recall using a staleself._user_id(from agent initialization) instead of the currentuser_idprovided. This can lead to a user receiving prefetched memory content belonging to a different user, as theprefetchguard checks the intended user for the result, not the user actually used for the recall.Additional Locations (1)
plugins/memory/memgw/__init__.py#L287-L301Reviewed by Cursor Bugbot for commit 16e73b0. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in subsequent merged PRs:
queue_prefetchnow receives and forwards the per-turnuser_id.queue_prefetchuse the kwarguser_idfor their search/recall, notself._user_id.This PR (#39) was superseded by #41 and closed without merging.
Reviewed and confirmed by Claude Code.
Generated by Claude Code