wip(501): timer cancellation infrastructure (parallel session WIP + main.rs wiring)
Bundles in-progress work from a parallel Claude session toward fixing
bug 501 (rate-limit retry timer doesn't cancel on stop_agent / move_story
/ successful completion). This commit lands the foundation but the MCP
tool wiring is still TODO.
- server/src/chat/timer.rs: defense-in-depth check in tick_once that
skips firing a timer for stories already past 3_qa (3_qa, 4_merge,
5_done, 6_archived). The primary cancellation path will be in the
MCP tools; this guards races where a timer was scheduled before the
story was advanced and the tool didn't get a chance to cancel it.
- server/src/http/context.rs: adds `timer_store: Arc<TimerStore>` field
on AppContext so MCP tools (move_story, stop_agent, ...) can reach
the shared timer store and cancel pending entries when the user
intervenes manually. The test helper is updated to construct one.
- server/src/main.rs: wires up a TimerStore instance in the AppContext
initialiser so the binary actually compiles after the context.rs
field addition. TODO: the matrix bot's spawn_bot still creates its
own TimerStore instance (in chat/transport/matrix/bot/run.rs:220-227)
rather than consuming the shared one — that refactor is the next
step in the bug 501 fix.
What is NOT in this commit and is needed to actually fix bug 501:
- The MCP tool side (move_story, stop_agent, delete_story) does not
yet call timer_store.cancel(story_id) when invoked
- The matrix bot's spawn_bot does not yet consume the shared
timer_store from AppContext — it still creates its own
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -631,6 +631,21 @@ 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)
|
||||
// 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.
|
||||
let timer_store = std::sync::Arc::new(crate::chat::timer::TimerStore::load(
|
||||
startup_root
|
||||
.as_ref()
|
||||
.map(|r| r.join(".huskies").join("timers.json"))
|
||||
.unwrap_or_else(|| std::path::PathBuf::from("/tmp/huskies-timers.json")),
|
||||
));
|
||||
|
||||
let ctx = AppContext {
|
||||
state: app_state,
|
||||
store,
|
||||
@@ -643,6 +658,7 @@ async fn main() -> Result<(), std::io::Error> {
|
||||
qa_app_process: Arc::new(std::sync::Mutex::new(None)),
|
||||
bot_shutdown: bot_shutdown_notifier.clone(),
|
||||
matrix_shutdown_tx: Some(Arc::clone(&matrix_shutdown_tx)),
|
||||
timer_store,
|
||||
};
|
||||
|
||||
let app = build_routes(ctx, whatsapp_ctx.clone(), slack_ctx.clone(), port);
|
||||
|
||||
Reference in New Issue
Block a user