fix(session): end SQLite sessions when suspending to prevent zombie sessions (#9090)#10171
Open
easyvibecoding wants to merge 1 commit into
Open
fix(session): end SQLite sessions when suspending to prevent zombie sessions (#9090)#10171easyvibecoding wants to merge 1 commit into
easyvibecoding wants to merge 1 commit into
Conversation
…essions (NousResearch#9090) Root cause: suspend_session() and suspend_recently_active() only set suspended=True in sessions.json but never wrote ended_at to SQLite. When the suspended session was later auto-reset on next access, get_or_create_session() would call end_session() with reason 'session_reset', BUT only if the entry was still in _entries. If the gateway crashed and the session was NOT re-loaded from disk on restart (e.g. Feishu WebSocket sessions not yet persisted), the zombie session remained in SQLite with ended_at=NULL. Fix: both suspend_session() and suspend_recently_active() now also call self._db.end_session(session_id, 'suspended') when the DB is available, ensuring ended_at is always populated when a session is suspended. When the session is later accessed and auto-reset, the UPDATE re-runs with end_reason='session_reset', which is the correct final state. Also changes return value of suspend_session() from bool to True iff an entry existed (for clearer caller feedback).
02f0dad to
aca751a
Compare
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.
Summary
SessionStore.suspend_session()andsuspend_recently_active()only setsuspended=Trueinsessions.jsonbut never wroteended_atto SQLite. When a session is later auto-reset on next access,get_or_create_session()callsend_session()with reason'session_reset', BUT only if the entry is still in_entries. If the gateway crashed and the session was NOT re-loaded from disk (e.g. Feishu WebSocket sessions not yet persisted), the zombie session remains in SQLite withended_at=NULLforever.Fix: both
suspend_session()andsuspend_recently_active()now also callself._db.end_session(session_id, 'suspended')when the DB is available, ensuringended_atis always populated when a session is suspended. When the session is later accessed and auto-reset, the UPDATE re-runs withend_reason='session_reset', which is the correct final state.Closes #9090.
Changes
gateway/session.py:suspend_session()— now also callsself._db.end_session()to populate SQLiteended_atgateway/session.py:suspend_recently_active()— same, iterates all suspended sessions and ends each in SQLiteTest plan
python -m pytest -o addopts='' tests/gateway/test_session.py -q python -m py_compile gateway/session.py