From 65d2fb210cee85bccc294f56207f5334f572c4d1 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 27 Apr 2026 11:28:21 +0000 Subject: [PATCH] huskies: merge 655_bug_matrix_bot_spawns_its_own_timerstore_instead_of_using_shared_appcontext_timer_store --- server/src/chat/transport/matrix/bot/run.rs | 5 ++--- server/src/chat/transport/matrix/mod.rs | 3 +++ server/src/main.rs | 12 +++++------- server/src/service/gateway/io.rs | 4 ++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/server/src/chat/transport/matrix/bot/run.rs b/server/src/chat/transport/matrix/bot/run.rs index b88ecc94..488ec4fe 100644 --- a/server/src/chat/transport/matrix/bot/run.rs +++ b/server/src/chat/transport/matrix/bot/run.rs @@ -1,4 +1,5 @@ //! Matrix bot run loop — connects to the homeserver and processes sync events. +use crate::service::timer::TimerStore; use crate::services::Services; use crate::slog; use matrix_sdk::ruma::OwnedRoomId; @@ -28,6 +29,7 @@ pub async fn run_bot( gateway_active_project: Option>>, gateway_projects: Vec, gateway_project_urls: std::collections::BTreeMap, + timer_store: Arc, ) -> Result<(), String> { let project_root = &services.project_root; let store_path = project_root.join(".huskies").join("matrix_store"); @@ -224,9 +226,6 @@ pub async fn run_bot( let announce_bot_name = services.bot_name.clone(); - let timer_store = Arc::new(crate::service::timer::TimerStore::load( - project_root.join(".huskies").join("timers.json"), - )); // Auto-schedule timers when an agent hits a hard rate limit. crate::service::timer::spawn_rate_limit_auto_scheduler( Arc::clone(&timer_store), diff --git a/server/src/chat/transport/matrix/mod.rs b/server/src/chat/transport/matrix/mod.rs index 7464ceee..57b59a15 100644 --- a/server/src/chat/transport/matrix/mod.rs +++ b/server/src/chat/transport/matrix/mod.rs @@ -32,6 +32,7 @@ pub use config::BotConfig; use crate::io::watcher::WatcherEvent; use crate::rebuild::ShutdownReason; +use crate::service::timer::TimerStore; use crate::services::Services; use std::path::Path; use std::sync::Arc; @@ -69,6 +70,7 @@ pub fn spawn_bot( gateway_active_project: Option>>, gateway_projects: Vec, gateway_project_urls: std::collections::BTreeMap, + timer_store: Arc, ) -> Option { let config = match BotConfig::load(project_root) { Some(c) => c, @@ -105,6 +107,7 @@ pub fn spawn_bot( gateway_active_project, gateway_projects, gateway_project_urls, + timer_store, ) .await { diff --git a/server/src/main.rs b/server/src/main.rs index 394db8ee..d62a7eb5 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -629,14 +629,10 @@ async fn main() -> Result<(), std::io::Error> { let matrix_shutdown_tx = Arc::new(matrix_shutdown_tx); let matrix_shutdown_tx_for_rebuild = Arc::clone(&matrix_shutdown_tx); - // Bug 501: shared rate-limit retry timer store, accessible from MCP tools - // via AppContext so manual interventions (move_story → backlog, stop_agent) + // Shared rate-limit retry timer store, accessible from MCP tools via + // AppContext so manual interventions (move_story → backlog, stop_agent) // can cancel pending timers in-memory rather than only on disk. - // - // TODO(bug 501): the matrix bot currently spawns its own TimerStore instance - // in `chat::transport::matrix::bot::run::spawn_bot`. Refactor to consume this - // shared instance via `AppContext.timer_store` so cancellations from MCP - // tools and the bot's tick loop see the same in-memory state. + // Also shared with the Matrix bot tick loop (bug 655). let timer_store = std::sync::Arc::new(crate::service::timer::TimerStore::load( startup_root .as_ref() @@ -645,6 +641,7 @@ async fn main() -> Result<(), std::io::Error> { )); let timer_store_for_tick = Arc::clone(&timer_store); + let timer_store_for_bot = Arc::clone(&timer_store); let ctx = AppContext { state: app_state, @@ -738,6 +735,7 @@ async fn main() -> Result<(), std::io::Error> { None, vec![], std::collections::BTreeMap::new(), + timer_store_for_bot, ); } else { // Keep the receiver alive (drop it) so the sender never errors. diff --git a/server/src/service/gateway/io.rs b/server/src/service/gateway/io.rs index cd0d3579..448b8b4b 100644 --- a/server/src/service/gateway/io.rs +++ b/server/src/service/gateway/io.rs @@ -409,6 +409,9 @@ pub fn spawn_gateway_bot( status: std::sync::Arc::new(crate::service::status::StatusBroadcaster::new()), }); + let timer_store = std::sync::Arc::new(crate::service::timer::TimerStore::load( + config_dir.join(".huskies").join("timers.json"), + )); crate::chat::transport::matrix::spawn_bot( config_dir, watcher_tx, @@ -417,5 +420,6 @@ pub fn spawn_gateway_bot( Some(active_project), gateway_projects, gateway_project_urls, + timer_store, ) }