Skip to content

fix(web): pass user_id to remove_chat_session from the stale-session …#115

Merged
chauncygu merged 1 commit into
mainfrom
fix/headless-bridges-slash
May 10, 2026
Merged

fix(web): pass user_id to remove_chat_session from the stale-session …#115
chauncygu merged 1 commit into
mainfrom
fix/headless-bridges-slash

Conversation

@chauncygu
Copy link
Copy Markdown
Contributor

…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.

…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>
@chauncygu chauncygu merged commit 3e0d8e9 into main May 10, 2026
5 of 6 checks passed
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