From ce0bb3791a8b0e1c57bddabc9a032ea6db6109f0 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Mon, 27 Apr 2026 19:52:37 -0300 Subject: [PATCH] Fix switcher Redis key mismatch: use DB session ID instead of WebSocket session ID The switchers were stored in Redis with the DB session ID (session.id) but retrieved using the WebSocket session ID, causing switchers to never be found. Fix by saving session.id before the move into spawn_blocking closure. --- botserver/src/core/bot/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/botserver/src/core/bot/mod.rs b/botserver/src/core/bot/mod.rs index f0aee2de..e0c56564 100644 --- a/botserver/src/core/bot/mod.rs +++ b/botserver/src/core/bot/mod.rs @@ -1843,6 +1843,9 @@ async fn handle_websocket( if let Ok(Some(mut session)) = session_result { info!("start.bas: Found session {} for websocket session {}", session.id, session_id); + + // Save session ID before session is moved into closure + let session_id_for_redis = session.id.to_string(); // Store WebSocket session_id in context so TALK can route messages correctly if let serde_json::Value::Object(ref mut map) = session.context_data { @@ -1889,9 +1892,10 @@ async fn handle_websocket( } // Fetch suggestions and switchers from Redis and send to frontend + // Use session_id_for_redis (DB session) not session_id_str (WebSocket session) for Redis key consistency let user_id_str = user_id.to_string(); - let suggestions = get_suggestions(state_for_redis.cache.as_ref(), &bot_id_str, &session_id_str); - let switchers = get_switchers(state_for_redis.cache.as_ref(), &bot_id_str, &session_id_str); + let suggestions = get_suggestions(state_for_redis.cache.as_ref(), &bot_id_str, &session_id_for_redis); + let switchers = get_switchers(state_for_redis.cache.as_ref(), &bot_id_str, &session_id_for_redis); if !suggestions.is_empty() || !switchers.is_empty() { info!("Sending {} suggestions to frontend for session {}", suggestions.len(), session_id); let response = BotResponse {