feat(memory): capture user_id at enqueue time for async-safe thread isolation

Add user_id field to ConversationContext and MemoryUpdateQueue.add() so the
user identity is stored explicitly at request time, before threading.Timer
fires on a different thread where ContextVar values do not propagate.
MemoryMiddleware.after_agent() now calls get_effective_user_id() at enqueue
time and passes the value through to updater.update_memory().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rayhpeng
2026-04-12 14:59:51 +08:00
parent dfa9fc47b3
commit 9af2f3e73c
4 changed files with 53 additions and 0 deletions
+2
View File
@@ -48,6 +48,7 @@ def test_process_queue_forwards_correction_flag_to_updater() -> None:
agent_name="lead_agent",
correction_detected=True,
reinforcement_detected=False,
user_id=None,
)
@@ -88,4 +89,5 @@ def test_process_queue_forwards_reinforcement_flag_to_updater() -> None:
agent_name="lead_agent",
correction_detected=False,
reinforcement_detected=True,
user_id=None,
)