codeforpdx / codeforpdx/tenantfirstaid
Use ephemeral server-side sessions to temporarily persist messages-list across requests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13
- Forks
- 21
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 3
Description
There may be a variable scoping issue in the backend. The current code has 2 scopes for backend variables ...
- View-class variables: these are global-scope, which can be dangerous if any response or session data is stored there.
- request arguments: these are scoped to the lifetime of a single request
For multi-turn conversations, each turn (human prompt + ai response) is effectively 1 (or more) requests. In order to properly maintain the context of multi-turn conversation, we probably need to use server-side session storage so that the message history (including reasoning w/ reasoning signatures) is retained for the duration of the session. Server-side storage will have a larger limit on context size than client-side (aka cookie) storage.
Here we see the class definition with a class variable.
https://github.com/codeforpdx/tenantfirstaid/blob/17a235b05b3b8048ce3e6ef68bfabc20d42bceeb/backend/tenantfirstaid/chat.py#L18-L35
The LangChainChatManager will be instantiated once for the backend, but called many times by one or more clients per request/response (aka turn). Thus the LangChainChatManager.agent is also a global singleton which services all request/responses. So there may be a problem in how the agent is created with a system prompt for "portland, oregon" but a subsequent session is supposed to prompted for "eugene, oregon".
Data like city/state could be stored in the client-side session (aka cookie) since they are small and sent on a per-request basis.
Note: message history should not be stored in any global-scoped variable because that will pollute concurrent conversations of different users/sessions!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with backend/tenantfirstaid/chat.py, especially the LangChainChatManager class and its agent creation. Trace how the manager and message history are used across requests, then identify the existing session handling for city/state. Done means concurrent sessions no longer share message history, and multi-turn history including reasoning signatures persists for the session.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100