story-kit: merge 161_bug_auto_assign_only_triggers_on_agent_completion_not_on_failure_or_periodically

This commit is contained in:
Dave
2026-02-24 17:28:45 +00:00
parent d00b459a74
commit fb91096b09
2 changed files with 121 additions and 6 deletions

View File

@@ -58,7 +58,9 @@ async fn main() -> Result<(), std::io::Error> {
let agents = Arc::new(AgentPool::new(port));
// Start the background watchdog that detects and cleans up orphaned Running agents.
agents.spawn_watchdog();
// When orphans are found, auto-assign is triggered to reassign free agents.
let watchdog_root: Option<PathBuf> = app_state.project_root.lock().unwrap().clone();
AgentPool::spawn_watchdog(Arc::clone(&agents), watchdog_root);
// Filesystem watcher: broadcast channel for work/ pipeline changes.
let (watcher_tx, _) = broadcast::channel::<io::watcher::WatcherEvent>(1024);
@@ -69,6 +71,33 @@ async fn main() -> Result<(), std::io::Error> {
}
}
// Subscribe to watcher events so that auto-assign triggers when a work item
// file is moved into an active pipeline stage (2_current/, 3_qa/, 4_merge/).
{
let watcher_auto_rx = watcher_tx.subscribe();
let watcher_auto_agents = Arc::clone(&agents);
let watcher_auto_root: Option<PathBuf> =
app_state.project_root.lock().unwrap().clone();
if let Some(root) = watcher_auto_root {
tokio::spawn(async move {
let mut rx = watcher_auto_rx;
while let Ok(event) = rx.recv().await {
if let io::watcher::WatcherEvent::WorkItem { ref stage, .. } = event
&& matches!(stage.as_str(), "2_current" | "3_qa" | "4_merge")
{
slog!(
"[auto-assign] Watcher detected work item in {stage}/; \
triggering auto-assign."
);
watcher_auto_agents
.auto_assign_available_work(&root)
.await;
}
}
});
}
}
// Reconciliation progress channel: startup reconciliation → WebSocket clients.
let (reconciliation_tx, _) =
broadcast::channel::<agents::ReconciliationEvent>(64);