fix: remove stale session entry from sessions.json on idle-TTL eviction - #55232
Stoltemberg wants to merge 2 commits into
Conversation
When _sweep_idle_cached_agents() evicts an agent after the idle TTL, the session is ended in state.db but sessions.json was NOT updated. The stale session_key -> session_id entry remained, routing all subsequent messages on that key into a closed session — silently dropping them until gateway restart. Add SessionStore.remove() method and call it during idle eviction so sessions.json is cleaned up immediately. Fixes NousResearch#54878
Competing with #54916 for the same issue (#54878). Same goal — clear the stale |
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Clean fix — removes stale session entries from sessions.json after idle-TTL eviction to prevent messages from routing into ended sessions. The SessionStore.remove() method is well-implemented with proper locking and save.
Correctness: The remove() call in _sweep_idle_cached_agents is the correct injection point.
Testing: Dedicated test file with clear assertions for the remove operation.
Reviewed by Hermes Agent
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Fixes stale session routing after idle-TTL eviction. Removes session entry from sessions.json when agent is evicted, preventing messages from routing into ended sessions.
- Clean fix with dedicated test
- Well-scoped: 3 files, 56 additions
Reviewed 3 files, 56 additions. Approved.
|
Closing — duplicate detected by alt-glitch bot. Consolidating into earlier PRs. 🙏 |
What does this PR do?
When
_sweep_idle_cached_agents()evicts an agent after the idle TTL (3600s), the session is ended instate.dbbutsessions.jsonwas NOT updated. The stalesession_key → session_identry remained, routing all subsequent messages on that key into a closed session — silently dropping them until gateway restart (when_prune_stale_sessions_locked()fires).Adds
SessionStore.remove()method and calls it during idle eviction sosessions.jsonis cleaned up immediately.Related Issue
Fixes #54878
Type of Change
Changes Made
gateway/session.py: AddSessionStore.remove(session_key)method that removes an entry from_entriesand calls_save(), following the existing thread-safety pattern (lock +_ensure_loaded_locked)gateway/run.py: In_sweep_idle_cached_agents(), callself.session_store.remove(key)after popping the agent from cache, wrapped in try/except to avoid blocking eviction on a save failureHow to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)ruff check gateway/session.py gateway/run.pyand both passDocumentation & Housekeeping
cli-config.yaml.exampleif I added/changed config keys — or N/A