Skip to content

fix(memory): pass per-turn user_id through model tool calls + compat fallback - #48

Merged
dizhaky merged 1 commit into
mainfrom
fix/memory-tool-call-user-scoping
Jun 29, 2026
Merged

fix(memory): pass per-turn user_id through model tool calls + compat fallback#48
dizhaky merged 1 commit into
mainfrom
fix/memory-tool-call-user-scoping

Conversation

@dizhaky

@dizhaky dizhaky commented Jun 29, 2026

Copy link
Copy Markdown
Owner

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 from fix/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

File Change
agent/tool_executor.py Pass user_id=agent._user_id into handle_tool_call at memory dispatch
plugins/memory/memgw/__init__.py Extract call_user_id from kwargs; use _user_scope(call_user_id) for all three tool branches
plugins/memory/mem0/__init__.py Derive call_user_id = kwargs.get("user_id", "") or self._user_id; use inline per-call filters for all three tools
agent/memory_manager.py TypeError compat fallback in prefetch_all, queue_prefetch_all, sync_all for old external providers

Generated by Claude Code

…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).
@github-actions

Copy link
Copy Markdown

🔎 Lint report: fix/memory-tool-call-user-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 79114ea into main Jun 29, 2026
28 checks passed
@dizhaky
dizhaky deleted the fix/memory-tool-call-user-scoping branch June 29, 2026 00:23
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.

2 participants