Fix #54878: Prevent silent message loss due to stale sessions.json entries - #54916
Closed
davidgut1982 wants to merge 1 commit into
Closed
davidgut1982 wants to merge 1 commit into
davidgut1982 wants to merge 1 commit into
Conversation
…ions.json entries - Add session validation in SessionStore to check if sessions are active in database - Add remove_session() and remove_ended_session() methods to clean up stale routing entries - Enhanced get_or_create_session() to create new sessions when old ones are ended - Modified _release_evicted_agent_soft() to clean up sessions.json during agent eviction - Added _cleanup_evicted_agent_session() method to prevent stale entries during idle timeout - This prevents messages from being silently dropped when agents are evicted due to idle TTL Fixes P0 critical bug that caused data loss without error logs or visible failure.
tonydwb
reviewed
Jun 29, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: LGTM
Clean, well-scoped change with no concerns.
--- Reviewed by Hermes Agent
12 tasks
Contributor
|
Thanks for diagnosing this @davidgut1982 — your "Option B" insight (validate the session's I salvaged it as #55485 (merged in 3a83b6b, your authorship preserved). A couple of notes on what changed from this PR during the salvage:
The core idea — never silently route into a DB-ended session — is yours. Closing this in favor of the merged salvage. Thanks again! |
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
Fixes P0 critical bug #54878 that caused silent message loss when AIAgent instances were evicted from the cache due to idle TTL timeout.
Problem
When agents were evicted due to idle timeout (
_AGENT_CACHE_IDLE_TTL_SECS = 3600s), the system would:end_session()on the database ✅sessions.jsonfile ❌Solution
This fix implements a comprehensive solution to prevent silent message drops:
1. SessionStore Enhancements (
gateway/session.py)_is_session_active(): Validates if sessions are still active in the databaseremove_session(): Removes sessions from both memory andsessions.jsonremove_ended_session(): Removes ended sessions to prevent stale routingget_or_create_session(): Now checks session activity before routing messages2. Agent Cache Eviction Cleanup (
gateway/run.py)_cleanup_evicted_agent_session(): Cleans upsessions.jsonduring agent eviction_release_evicted_agent_soft(): Automatically calls cleanup when agents are evictedHow It Works
Prevention Layer
When an agent is evicted due to idle timeout, stale session entries are automatically cleaned up from
sessions.json.Detection & Correction Layer
If stale entries somehow still exist,
get_or_create_session()validates session activity before routing messages and creates new sessions for ended ones.Impact
sessions.jsonentriesTesting
Created comprehensive test scripts that verify:
Risk Assessment
Verification
All tests pass successfully. The fix correctly prevents silent message drops while maintaining system stability and performance.
Fixes #54878