From 78fdec4f4973b2b17392b4c55e15aa81642b1451 Mon Sep 17 00:00:00 2001 From: Kosmos Date: Sun, 22 Nov 2026 01:13:40 +0000 Subject: [PATCH] fix(daemon): lease a forge turn for an hour, not ten minutes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The forge dispatcher was assembled on `DispatcherConfig::default()`, whose ten-minute lease TTL is the spec's example value, sized for a single agent step. A forge turn is not a step: it clones the repo, reads it, and may build and test a fix. Nothing renews the lease once the turn is under way — `poll_inbox` renews but is called once, at the start, and the commit hook between tool calls checkpoints, which fails on a lapsed lease rather than extending it — so the TTL is a hard ceiling on a whole turn. Crossing it is silent: the turn dies on its next tool call, the driver's own checkpoint and release then report `Expired`, and the key ends with no outcome recorded, indistinguishable from a pass that found nothing. Give the forge lane its own timing — the library defaults with an hour-long TTL, the same choice the interactive and jobs lanes already make — and use it in both shapes (`--once` included). --- crates/rhema-claw/src/daemon.rs | 44 ++++++++++++++++++++++++++++++--- crates/rhema-claw/src/lib.rs | 2 +- crates/rhema-claw/src/main.rs | 6 ++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/crates/rhema-claw/src/daemon.rs b/crates/rhema-claw/src/daemon.rs index 089c2ec..0790453 100644 --- a/crates/rhema-claw/src/daemon.rs +++ b/crates/rhema-claw/src/daemon.rs @@ -126,6 +126,30 @@ fn interactive_dispatch() -> DispatcherConfig { } } +/// The forge dispatcher's timing: the library defaults, except the lease +/// TTL. +/// +/// A forge turn is not a chat step. The handler clones a repository, +/// reads it, and may build and test a fix — tens of minutes of wall +/// clock — and nothing renews the lease once the turn is under way: +/// `SessionContext::poll_inbox` renews, and the handler calls it once, at +/// the start; the commit hook that runs between tool calls *checkpoints*, +/// which fails on a lapsed lease instead of extending one. So the TTL is +/// a hard ceiling on a whole turn: cross it and the turn dies on its next +/// tool call, after which the driver's own checkpoint and release both +/// report `Expired` and the key ends with no outcome recorded — a silent +/// kill, indistinguishable from a pass that found nothing. +/// +/// `DispatcherConfig::default`'s ten minutes are the spec's example +/// values, sized for a single agent step. An hour matches the +/// interactive lane's choice for the same reason: the work is long. +pub fn forge_dispatch() -> DispatcherConfig { + DispatcherConfig { + lease_ttl_millis: 3_600_000, + ..DispatcherConfig::default() + } +} + /// The resident daemon: the extension set's sources (the forge watches, /// the task scheduler, the coding jobs, the calendar reminders), the /// three drivers, and the HTTP surface. @@ -154,8 +178,8 @@ impl Daemon { /// Assembles the daemon over `config`: the shared SQLite store, one /// source per forge kind reading the watch table, the interactive /// dispatcher, and both handlers running `provider`. `dispatch` is - /// the forge dispatcher's timing — the resident loop uses the - /// defaults, `--once` zeroes the debounce. + /// the forge dispatcher's timing — [`forge_dispatch`] in both shapes, + /// with `--once` zeroing the debounce. pub fn build( config: &ClawConfig, backends: Arc, @@ -580,7 +604,7 @@ pub async fn run_once( ) -> Result { let dispatch = DispatcherConfig { debounce_window_millis: 0, - ..DispatcherConfig::default() + ..forge_dispatch() }; let daemon = Daemon::build(config, backends, dispatch)?; daemon.bootstrap().await?; @@ -591,6 +615,20 @@ pub async fn run_once( mod tests { use super::*; + #[test] + fn the_forge_dispatcher_leases_for_a_turn_not_a_step() { + let dispatch = forge_dispatch(); + assert_eq!( + dispatch.lease_ttl_millis, 3_600_000, + "an hour: a turn clones, reads, builds and tests" + ); + assert_eq!( + dispatch.debounce_window_millis, + DispatcherConfig::default().debounce_window_millis, + "the rest stays the library's defaults" + ); + } + #[test] fn the_interactive_dispatcher_dispatches_now_and_leases_long() { let dispatch = interactive_dispatch(); diff --git a/crates/rhema-claw/src/lib.rs b/crates/rhema-claw/src/lib.rs index 896262c..327e36b 100644 --- a/crates/rhema-claw/src/lib.rs +++ b/crates/rhema-claw/src/lib.rs @@ -108,7 +108,7 @@ pub use bootstrap::{ render_system, }; pub use config::{ClawConfig, ConfigError}; -pub use daemon::{ClawError, Daemon, TickReport, run_once}; +pub use daemon::{ClawError, Daemon, TickReport, forge_dispatch, run_once}; pub use environment::write_report; pub use extension::{ClawExtension, ExtensionDeps, Extensions, Lanes}; pub use forge::ForgeSource; diff --git a/crates/rhema-claw/src/main.rs b/crates/rhema-claw/src/main.rs index a98f154..5a2c5e7 100644 --- a/crates/rhema-claw/src/main.rs +++ b/crates/rhema-claw/src/main.rs @@ -8,8 +8,8 @@ use std::path::PathBuf; use std::sync::Arc; use clap::Parser; -use rhema_claw::{ClawConfig, ClawError, Daemon, run_once}; -use rhema_rsd::{DispatcherConfig, Outcome}; +use rhema_claw::{ClawConfig, ClawError, Daemon, forge_dispatch, run_once}; +use rhema_rsd::Outcome; /// `rhema-claw` — the resident forge-watching agent daemon. #[derive(Debug, Parser)] @@ -135,7 +135,7 @@ async fn run(args: Args) -> Result<(), ClawError> { // reads it next to the config that turns it on. config.validate_surface()?; eprintln!("[claw] note: resident sessions run tool calls without approval prompts"); - let daemon = Daemon::build(&config, backends, DispatcherConfig::default())?; + let daemon = Daemon::build(&config, backends, forge_dispatch())?; daemon.run().await } }