huskies: merge 841
This commit is contained in:
@@ -81,20 +81,28 @@ pub(crate) fn spawn_event_bridges(
|
||||
|
||||
/// Spawn the unified 1-second background tick loop.
|
||||
///
|
||||
/// Fires due timers, runs the agent watchdog every 30 ticks, and promotes
|
||||
/// done→archived items every `sweep_interval_secs` ticks.
|
||||
/// Fires due timers, runs the agent watchdog every 30 ticks, promotes
|
||||
/// done→archived items every `sweep_interval_secs` ticks, and removes
|
||||
/// orphaned worktrees every `worktree_sweep_interval_secs` ticks (default
|
||||
/// 1200, i.e. 20 minutes).
|
||||
pub(crate) fn spawn_tick_loop(
|
||||
agents: Arc<AgentPool>,
|
||||
timer_store: Arc<service::timer::TimerStore>,
|
||||
root: Option<PathBuf>,
|
||||
) {
|
||||
let sweep_cfg = root
|
||||
let project_cfg = root
|
||||
.as_ref()
|
||||
.and_then(|r| config::ProjectConfig::load(r).ok())
|
||||
.map(|c| c.watcher)
|
||||
.and_then(|r| config::ProjectConfig::load(r).ok());
|
||||
let sweep_cfg = project_cfg
|
||||
.as_ref()
|
||||
.map(|c| c.watcher.clone())
|
||||
.unwrap_or_default();
|
||||
let sweep_every = sweep_cfg.sweep_interval_secs.max(1);
|
||||
let done_retention = std::time::Duration::from_secs(sweep_cfg.done_retention_secs);
|
||||
// Capture config for the worktree sweep (read once at startup).
|
||||
let worktree_sweep_config = project_cfg.unwrap_or_default();
|
||||
// Worktree orphan sweep: every 20 minutes by default.
|
||||
let worktree_sweep_every: u64 = 1200;
|
||||
let pending_count = timer_store.list().len();
|
||||
crate::slog!("[tick] Unified tick loop started; {pending_count} pending timer(s)");
|
||||
|
||||
@@ -132,6 +140,17 @@ pub(crate) fn spawn_tick_loop(
|
||||
if tick_count.is_multiple_of(sweep_every) {
|
||||
io::watcher::sweep_done_to_archived(done_retention);
|
||||
}
|
||||
|
||||
// Worktree orphan sweep: remove worktrees for done/archived/absent stories.
|
||||
if tick_count.is_multiple_of(worktree_sweep_every)
|
||||
&& let Some(ref r) = root
|
||||
{
|
||||
let removed =
|
||||
crate::worktree::sweep_orphaned_worktrees(r, &worktree_sweep_config).await;
|
||||
if removed > 0 {
|
||||
crate::slog!("[worktree-sweep] Removed {removed} orphaned worktree(s).");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user