Bound in-memory chat sessions#105
Open
pragnyanramtha wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds bounded in-memory retention for backend chat sessions to address unbounded growth in long-running processes.
Changes:
- Adds configurable session count, TTL, and chat history limits.
- Tracks session recency with
OrderedDictand evicts expired/overflow sessions. - Documents session memory behavior and related environment variables.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| README.md | Documents session retention environment variables and memory behavior. |
| backend/agents.py | Adds LRU/TTL session tracking, configurable history trimming, and reset cleanup updates. |
Comments suppressed due to low confidence (1)
backend/agents.py:656
- The graph invocation above yields control, so another chat request or reset can evict this session before the response is stored. This direct history append can then fail with
KeyErrorand leave newly assignedsession_memoryuntracked by_session_last_seen; revalidate/recreate the session state atomically after the await or guard these mutations with a lock.
self.chat_history[session_id].extend([f"User: {query}", f"Assistant: {response_text}"])
self._trim_history(session_id)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Closes #76.
Adds bounded in-memory session retention for long-running backend processes:
SESSION_TTL_SECONDS, default3600SESSION_MAX_COUNT, default1000SESSION_HISTORY_LIMIT, default20Verification
python3 -m py_compile backend/agents.py backend/main.py tests/test_session_lifecycle.py/tmp/ksa-pr105-venv/bin/python -m pytest -q tests/test_session_lifecycle.py-> 4 passedgit diff --checkmorepagination state