From e7deb65e45f6fb6a86e670687ea1318e2fc0599e Mon Sep 17 00:00:00 2001 From: Timmy Date: Tue, 21 Apr 2026 12:05:58 +0100 Subject: [PATCH] Fix gateway bot proxying freeform messages as commands The gateway proxy was sending every message's first word to the project server's /api/bot/command endpoint, then displaying the "Unknown command" response before falling through to the LLM. Now the proxy only fires when the first word matches a known bot command. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/chat/transport/matrix/bot/messages.rs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/chat/transport/matrix/bot/messages.rs b/server/src/chat/transport/matrix/bot/messages.rs index 26dc17d3..f0cde960 100644 --- a/server/src/chat/transport/matrix/bot/messages.rs +++ b/server/src/chat/transport/matrix/bot/messages.rs @@ -201,7 +201,16 @@ pub(super) async fn on_room_message( None => (stripped.to_ascii_lowercase(), String::new()), }; - if !cmd.is_empty() && !GATEWAY_LOCAL_COMMANDS.contains(&cmd.as_str()) { + // Only proxy if the first word is a known bot command (sync or async). + let is_known_command = !cmd.is_empty() + && !GATEWAY_LOCAL_COMMANDS.contains(&cmd.as_str()) + && (crate::chat::commands::commands() + .iter() + .any(|c| c.name == cmd) + || ["assign", "start", "delete", "rebuild", "rmtree", "htop", "timer"] + .contains(&cmd.as_str())); + + if is_known_command { // Proxy to the active project server. let response = match ctx.proxy_bot_command(&cmd, &args).await { Some(r) => r, @@ -216,16 +225,7 @@ pub(super) async fn on_room_message( { ctx.bot_sent_event_ids.lock().await.insert(event_id); } - // If the command was recognized by the project server, we're done. - // If it was not a command at all (freeform text), fall through to the LLM. - if crate::chat::commands::commands() - .iter() - .any(|c| c.name == cmd) - || ["assign", "start", "delete", "rebuild", "rmtree", "htop", "timer"] - .contains(&cmd.as_str()) - { - return; - } + return; } // Gateway-local commands and freeform text fall through to normal handling below. }