Remove Redis flag - start.bas now runs on every WebSocket connection/message
Previously start.bas was prevented from re-running via a Redis flag (set for 24h). This prevented switchers from being re-sent when users reloaded the page. Now start.bas executes unconditionally on every WebSocket connection and every first message.
This commit is contained in:
parent
ce0bb3791a
commit
2cc4fa65df
1 changed files with 6 additions and 45 deletions
|
|
@ -770,24 +770,11 @@ let system_prompt = if !message.active_switchers.is_empty() {
|
||||||
|
|
||||||
#[cfg(any(feature = "research", feature = "llm"))]
|
#[cfg(any(feature = "research", feature = "llm"))]
|
||||||
{
|
{
|
||||||
// Execute start.bas on first message - ONLY run once per session to load suggestions
|
// Execute start.bas on first message - run EVERY time (no Redis flag check)
|
||||||
let actual_session_id = session.id.to_string();
|
let actual_session_id = session.id.to_string();
|
||||||
|
|
||||||
// Check if start.bas has already been executed for this session
|
// Always execute start.bas - no Redis check
|
||||||
let start_bas_key = format!("start_bas_executed:{}", actual_session_id);
|
let should_execute_start_bas = true;
|
||||||
let should_execute_start_bas = if let Some(cache) = &self.state.cache {
|
|
||||||
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
|
||||||
let executed: Result<Option<String>, redis::RedisError> = redis::cmd("GET")
|
|
||||||
.arg(&start_bas_key)
|
|
||||||
.query_async(&mut conn)
|
|
||||||
.await;
|
|
||||||
matches!(executed, Ok(None))
|
|
||||||
} else {
|
|
||||||
true // If cache fails, try to execute
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
true // If no cache, try to execute
|
|
||||||
};
|
|
||||||
|
|
||||||
if should_execute_start_bas {
|
if should_execute_start_bas {
|
||||||
// Execute start.bas from work directory
|
// Execute start.bas from work directory
|
||||||
|
|
@ -844,19 +831,7 @@ let system_prompt = if !message.active_switchers.is_empty() {
|
||||||
match result {
|
match result {
|
||||||
Ok(Ok(())) => {
|
Ok(Ok(())) => {
|
||||||
trace!("start.bas completed successfully for session {}", actual_session_id);
|
trace!("start.bas completed successfully for session {}", actual_session_id);
|
||||||
|
// Note: No Redis flag set - start.bas runs on every message
|
||||||
// Mark start.bas as executed for this session to prevent re-running
|
|
||||||
if let Some(cache) = &self.state.cache {
|
|
||||||
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
|
||||||
let _: Result<(), redis::RedisError> = redis::cmd("SET")
|
|
||||||
.arg(&start_bas_key)
|
|
||||||
.arg("1")
|
|
||||||
.arg("EX")
|
|
||||||
.arg("86400") // Expire after 24 hours
|
|
||||||
.query_async(&mut conn)
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(Err(e)) => {
|
Ok(Err(e)) => {
|
||||||
error!("start.bas error for session {}: {}", actual_session_id, e);
|
error!("start.bas error for session {}: {}", actual_session_id, e);
|
||||||
|
|
@ -1792,8 +1767,7 @@ async fn handle_websocket(
|
||||||
|
|
||||||
if let Some(bot_name) = bot_name_result {
|
if let Some(bot_name) = bot_name_result {
|
||||||
// Web clients expect start.bas to execute their first screen every time they connect/reload.
|
// Web clients expect start.bas to execute their first screen every time they connect/reload.
|
||||||
// We always run it, but we SET the start_bas_key flag right after so stream_response skips execution.
|
// Execute unconditionally on every WebSocket connection.
|
||||||
let start_bas_key = format!("start_bas_executed:{}", session_id);
|
|
||||||
let should_execute_start_bas = true;
|
let should_execute_start_bas = true;
|
||||||
|
|
||||||
if should_execute_start_bas {
|
if should_execute_start_bas {
|
||||||
|
|
@ -1876,20 +1850,7 @@ async fn handle_websocket(
|
||||||
match result {
|
match result {
|
||||||
Ok(Ok(())) => {
|
Ok(Ok(())) => {
|
||||||
info!("start.bas executed successfully for bot {}", bot_name);
|
info!("start.bas executed successfully for bot {}", bot_name);
|
||||||
|
// Note: No Redis flag set - start.bas runs on every WebSocket connection
|
||||||
// Mark start.bas as executed for this session to prevent re-running
|
|
||||||
if let Some(cache) = &state_for_redis.cache {
|
|
||||||
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
|
||||||
let _: Result<(), redis::RedisError> = redis::cmd("SET")
|
|
||||||
.arg(&start_bas_key)
|
|
||||||
.arg("1")
|
|
||||||
.arg("EX")
|
|
||||||
.arg("86400") // Expire after 24 hours
|
|
||||||
.query_async(&mut conn)
|
|
||||||
.await;
|
|
||||||
info!("Marked start.bas as executed for session {}", session_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch suggestions and switchers from Redis and send to frontend
|
// 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
|
// Use session_id_for_redis (DB session) not session_id_str (WebSocket session) for Redis key consistency
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue