fix(web): pass user_id to remove_chat_session from the stale-session …#115
Merged
Conversation
…reaper The reaper thread spawned by web/server.py:_reap_stale_sessions called remove_chat_session(sid) without user_id, but remove_chat_session requires user_id (ownership check parity with the per-user DELETE endpoint). Every reaper tick raised: TypeError: remove_chat_session() missing 1 required positional argument: 'user_id' The daemon thread died on first invocation, so stale ChatSession objects accumulated in the in-memory cache instead of being evicted when their last_active aged past _IDLE_TIMEOUT — a slow memory leak in long-running web deployments. Fix: the ChatSession object already carries .user_id from its constructor; capture (sid, user_id) pairs under _chat_lock and apply remove_chat_session(sid, user_id) outside the lock (matches the existing collect-then-act pattern; avoids reentrant locking since remove_chat_session re-acquires the same lock to pop the cache). Regression test: test_reap_stale_chat_sessions_passes_user_id pins the call site — creates a session, rewinds last_active so is_stale() fires, runs the reaper, and asserts (a) no TypeError and (b) the session is actually evicted from _chat_sessions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…reaper
The reaper thread spawned by web/server.py:_reap_stale_sessions called remove_chat_session(sid) without user_id, but remove_chat_session requires user_id (ownership check parity with the per-user DELETE endpoint). Every reaper tick raised:
TypeError: remove_chat_session() missing 1 required positional argument: 'user_id'
The daemon thread died on first invocation, so stale ChatSession objects accumulated in the in-memory cache instead of being evicted when their last_active aged past _IDLE_TIMEOUT — a slow memory leak in long-running web deployments.
Fix: the ChatSession object already carries .user_id from its constructor; capture (sid, user_id) pairs under _chat_lock and apply remove_chat_session(sid, user_id) outside the lock (matches the existing collect-then-act pattern; avoids reentrant locking since remove_chat_session re-acquires the same lock to pop the cache).
Regression test: test_reap_stale_chat_sessions_passes_user_id pins the call site — creates a session, rewinds last_active so is_stale() fires, runs the reaper, and asserts (a) no TypeError and (b) the session is actually evicted from _chat_sessions.