-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Bug Report: Stale sessionId in Feedback Requests After Starting New Chat
Summary
When a user clicks "New" to start a fresh chat and then submits feedback on a message in that new chat, the feedback request contains the old session ID from the previous chat instead of the current session ID. This causes the on_feedback callback to fail with "Session not found".
Steps to Reproduce
- Open a Chainlit app with
@cl.on_feedbackcallback and data persistence enabled - Send a message and receive a response (Session A is active)
- Click "New" to start a new chat (Session B is created, Session A is destroyed)
- Send a message in the new chat and receive a response
- Click the feedback button (thumbs up/down) on the new message
- Observe error:
Error in user-provided on_feedback callback: Session not found
Expected Behavior
The feedback request should contain the current session ID (Session B) since the message was created in the current session.
Actual Behavior
The feedback request contains the old session ID (Session A) which no longer exists.
Debug Evidence
Server logs:
New session started (session_id: fefe67e7-7195-4ec1-b2ed-c9fb489e9e62, thread_id: f27c85ce...) # Session A
New session started (session_id: 8c4291c0-8785-43cc-90ef-01457a2cef05, thread_id: 65e553d8...) # Session B (after clicking New)
on_message called (session_id: 8c4291c0-8785-43cc-90ef-01457a2cef05, thread_id: 65e553d8...) # Message sent in Session B
Error in user-provided on_feedback callback: Session not found
Feedback request payload (from browser Network tab):
{
"feedback": {
"forId": "8a8f57c8-a6d1-48f1-adc1-819238bc277b",
"threadId": "65e553d8-a848-4b20-a1e4-17651fa25514", // ✅ CORRECT (Session B's thread)
"value": 1,
"comment": "test"
},
"sessionId": "fefe67e7-7195-4ec1-b2ed-c9fb489e9e62" // ❌ WRONG (Session A's ID - stale!)
}Note: threadId is correct but sessionId is stale.
Root Cause
The frontend appears to cache the sessionId and doesn't update it when a new chat session is started via the "New" button. The threadId is correctly updated, but sessionId remains stale.
Code Location
In server.py, the feedback endpoint uses the stale sessionId to look up the session:
# server.py ~line 889
session = WebsocketSession.get_by_id(update.sessionId) # Returns None (stale ID)
init_ws_context(session) # Fails with "Session not found"
await config.code.on_feedback(update.feedback) # Never reachedSuggested Fix
Either:
- Frontend fix: Update the cached
sessionIdwhen a new chat is started - Backend fix: Use
threadIdto look up the correct session whensessionIdis not found, sincethreadIdis correct in the request
Environment
- Chainlit version: 2.9.3
- Python version: 3.12
- OS: Linux