fix(gateway): remove expired session entries after flush to prevent restart re-flushing#2527
Closed
teyrebaz33 wants to merge 1 commit into
Closed
Conversation
…estart re-flushing
Contributor
|
Thanks @teyrebaz33! Same fix as #2510 — you independently arrived at the same conclusion on the same day. The fix landed in #4481 with a |
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.
Fixes #2506
Problem
_session_expiry_watcherused an in-memory_pre_flushed_sessionsset to track already-flushed sessions. Since this set resets to empty on every gateway restart, every expired session was re-flushed on each restart — causing an O(N) flood of LLM API calls where N = number of stale session entries.Root Cause
_pre_flushed_sessionswas never persisted to disk. On restart it reset to empty, so the watcher re-flushed every expired session insessions.json.Fix
After a successful flush, remove the entry from
_entriesand call_save()— persisting the removal tosessions.json. On restart, the entry no longer exists, so it cannot be re-flushed.Also removes the now-unnecessary
_pre_flushed_sessionsset and itsdiscard()call inget_or_create_session()— this was dead code once entries are deleted on flush.Changes
gateway/run.py: remove_pre_flushed_sessionscheck/add, replace with_entries.pop()+_save()gateway/session.py: remove_pre_flushed_sessionsattribute anddiscard()calltests/gateway/test_async_memory_flush.py: remove stale_pre_flushed_sessionstests, addtest_pre_flushed_sessions_attr_removedto assert the set is gone