ππΌββοΈ The blackboard for coding agents - agentic development environment for claude code, codex, cursor, opencode, grok and more.
Rust adeai-agentsclaudeclaude-codecodexcursorgeminigrokopencodespec-driven-developmentvibe-codingvim
fix: add orchestrator idle state to not get stuck (#40)
Fynn FlΓΌgge86e5712a5f8f
diff --git a/plugins/agtx/skills/orchestrate.md b/plugins/agtx/skills/orchestrate.mdindex 3cbf1b0..a2b0a7a 100644--- a/plugins/agtx/skills/orchestrate.md+++ b/plugins/agtx/skills/orchestrate.md@@ -67,8 +67,11 @@ Backlog β Research β Planning β Running β Reviewwhat enters Planning/Running. Just advance what's there.5. **Error handling:** If `get_transition_status` shows an error, investigateand try a different approach.-6. **When idle:** After processing all current work, simply wait for the next- notification to arrive. Do not poll in a loop.+6. **When idle:** After processing all current work, output exactly+ `[agtx:idle]` on its own line, then wait for the next notification.+ Do not poll in a loop. You **must** output `[agtx:idle]` every time you+ finish processing and have no more pending work β this is how the board+ knows you are ready to receive the next notification.## Rules@@ -79,4 +82,5 @@ Backlog β Research β Planning β Running β Review- Only act on tasks in Planning or Running β never touch Backlog or Research tasks.- Always check `allowed_actions` before choosing a transition.- Do not move tasks beyond Review β merging is the user's responsibility.-- When idle with no pending work, just wait β notifications will be pushed to you.+- When idle with no pending work, output `[agtx:idle]` and wait β notifications+ will be pushed to you. Never skip the idle signal.diff --git a/src/tui/app.rs b/src/tui/app.rsindex 1fc25e9..2e63a2f 100644--- a/src/tui/app.rs+++ b/src/tui/app.rs@@ -8,7 +8,7 @@ use ratatui::{prelude::*, widgets::*};use std::collections::{HashMap, HashSet};use std::io::{self, Stdout};use std::path::{Path, PathBuf};-use std::sync::{mpsc, Arc};+use std::sync::{atomic::{AtomicBool, Ordering}, mpsc, Arc};use std::time::Instant;use crate::agent::{self, AgentOperations};@@ -242,6 +242,9 @@ struct AppState {plugin_select_popup: Option<PluginSelectPopup>,// Orchestrator agent tmux target (e.g. "project:orchestrator")orchestrator_session: Option<String>,+ // Set to true once the orchestrator agent is ready and has received the skill command.+ // Gates notification delivery so we don't send into a pane that's still initializing.+ orchestrator_ready: Arc<AtomicBool>,// Orchestrator idle detection for push notificationsorchestrator_last_content: String,orchestrator_stable_since: Option<Instant>,@@ -553,6 +556,7 @@ impl App {warning_message: None,plugin_select_popup: None,orchestrator_session: None,+ orchestrator_ready: Arc::new(AtomicBool::new(false)),orchestrator_last_content: String::new(),orchestrator_stable_since: None,orchestrator_last_check: Instant::now(),@@ -576,6 +580,7 @@ impl App {let orch_target = format!("{}:orchestrator", app.state.project_name);if app.state.tmux_ops.window_exists(&orch_target).unwrap_or(false) {app.state.orchestrator_session = Some(orch_target);+ app.state.orchestrator_ready.store(true, Ordering::Release);// Catch up: notify orchestrator about tasks that completed while TUI was downif let Some(ref db) = app.state.db {@@ -699,6 +704,7 @@ impl App {warning_message: None,plugin_select_popup: None,orchestrator_session: None,+ orchestrator_ready: Arc::new(AtomicBool::new(false)),orchestrator_last_content: String::new(),orchestrator_stable_since: None,orchestrator_last_check: Instant::now(),@@ -4459,6 +4465,7 @@ impl App {} else {// Window gone, clear the sessionself.state.orchestrator_session = None;+ self.state.orchestrator_ready.store(false, Ordering::Release);}}@@ -4502,6 +4509,7 @@ impl App {)?;self.state.orchestrator_session = Some(orch_target.clone());+ self.state.orchestrator_ready.store(false, Ordering::Release);// Open the popup immediately so the user can see the orchestrator startinglet mut popup = ShellPopup::new("Orchestrator".to_string(), orch_target.clone());@@ -4522,10 +4530,12 @@ impl App {let skill_cmd = skills::transform_plugin_command("/agtx:orchestrate", &default_agent).unwrap_or_else(|| "/agtx:orchestrate".to_string());let tmux_ops = Arc::clone(&self.state.tmux_ops);+ let ready_flag = Arc::clone(&self.state.orchestrator_ready);let target = orch_target;std::thread::spawn(move || {if let Some(ready_target) = wait_for_agent_ready(&tmux_ops, &target) {let _ = tmux_ops.send_keys(&ready_target, &skill_cmd);+ ready_flag.store(true, Ordering::Release);}});@@ -4617,6 +4627,11 @@ impl App {None => return,};+ // Don't deliver until the agent is ready and has received the skill command+ if !self.state.orchestrator_ready.load(Ordering::Acquire) {+ return;+ }+// Check window still existsif !self.state.tmux_ops.window_exists(&orch_target).unwrap_or(false) {return;@@ -4627,24 +4642,27 @@ impl App {.capture_pane(&orch_target).unwrap_or_default();- if current_content != self.state.orchestrator_last_content {- // Content changed β agent is working, reset idle timer- self.state.orchestrator_last_content = current_content;- self.state.orchestrator_stable_since = Some(Instant::now());- return;- }+ let result = check_orchestrator_idle(+ ¤t_content,+ &self.state.orchestrator_last_content,+ self.state.orchestrator_stable_since,+ );- // Content unchanged β check if stable long enough (β₯3s)- let stable_since = match self.state.orchestrator_stable_since {- Some(t) => t,- None => {+ match result {+ OrchestratorIdleResult::Idle => {+ // Fall through to deliver notifications+ }+ OrchestratorIdleResult::Busy => {+ self.state.orchestrator_last_content = current_content;self.state.orchestrator_stable_since = Some(Instant::now());return;}- };-- if stable_since.elapsed() < std::time::Duration::from_secs(3) {- return;+ OrchestratorIdleResult::Waiting => {+ if self.state.orchestrator_stable_since.is_none() {+ self.state.orchestrator_stable_since = Some(Instant::now());+ }+ return;+ }}// Orchestrator is idle β deliver pending notifications@@ -4960,6 +4978,57 @@ impl Drop for App {}/// Ensure tmux session exists for a project+// =============================================================================+// Orchestrator idle detection (extracted for testability)+// =============================================================================++/// Result of checking whether the orchestrator is idle and ready for notifications.+#[derive(Debug, PartialEq)]+enum OrchestratorIdleResult {+ /// Agent is idle β safe to deliver notifications.+ Idle,+ /// Content changed and no idle signal β agent is actively working.+ Busy,+ /// Content unchanged but not stable long enough β keep waiting.+ Waiting,+}++/// Idle detection duration for the stability fallback (no `[agtx:idle]` signal).+const ORCHESTRATOR_IDLE_FALLBACK_SECS: u64 = 15;++/// Pure idle-detection logic for the orchestrator pane.+///+/// Checks two conditions (first match wins):+/// 1. **Explicit signal**: pane content contains `[agtx:idle]` β `Idle`+/// 2. **Stability fallback**: pane unchanged for β₯15s β `Idle`+///+/// Returns `Busy` when content changed without the idle signal,+/// `Waiting` when content is unchanged but the timer hasn't elapsed.+fn check_orchestrator_idle(+ current_content: &str,+ last_content: &str,+ stable_since: Option<Instant>,+) -> OrchestratorIdleResult {+ let has_idle_signal = current_content.contains("[agtx:idle]");+ let content_changed = current_content != last_content;++ if content_changed {+ if has_idle_signal {+ OrchestratorIdleResult::Idle+ } else {+ OrchestratorIdleResult::Busy+ }+ } else {+ // Content unchanged β check stability timer+ match stable_since {+ Some(t) if t.elapsed() >= std::time::Duration::from_secs(ORCHESTRATOR_IDLE_FALLBACK_SECS) => {+ OrchestratorIdleResult::Idle+ }+ _ => OrchestratorIdleResult::Waiting,+ }+ }+}+fn ensure_project_tmux_session(project_name: &str, project_path: &Path, tmux_ops: &dyn TmuxOperations) {if !tmux_ops.has_session(project_name) {let _ = tmux_ops.create_session(project_name, &project_path.to_string_lossy());diff --git a/src/tui/app_tests.rs b/src/tui/app_tests.rsindex ed41fe5..cd543db 100644--- a/src/tui/app_tests.rs+++ b/src/tui/app_tests.rs@@ -3902,3 +3902,94 @@ fn test_footer_text_description_shows_all_triggers() {assert!(text.contains("[!] tasks"), "Missing tasks trigger: {}", text);}+// =============================================================================+// Tests for check_orchestrator_idle+// =============================================================================++#[test]+fn test_orchestrator_idle_signal_in_new_content() {+ // Content changed AND contains [agtx:idle] β Idle+ let result = check_orchestrator_idle(+ "some output\n[agtx:idle]\n",+ "previous content",+ None,+ );+ assert_eq!(result, OrchestratorIdleResult::Idle);+}++#[test]+fn test_orchestrator_busy_when_content_changed_no_signal() {+ // Content changed but no idle signal β Busy+ let result = check_orchestrator_idle(+ "agent is working on something...",+ "previous content",+ None,+ );+ assert_eq!(result, OrchestratorIdleResult::Busy);+}++#[test]+fn test_orchestrator_waiting_when_unchanged_no_stable_since() {+ // Content unchanged, no stable_since yet β Waiting (start tracking)+ let result = check_orchestrator_idle(+ "same content",+ "same content",+ None,+ );+ assert_eq!(result, OrchestratorIdleResult::Waiting);+}++#[test]+fn test_orchestrator_waiting_when_unchanged_under_threshold() {+ // Content unchanged, stable for only 1 second β Waiting+ let result = check_orchestrator_idle(+ "same content",+ "same content",+ Some(Instant::now() - std::time::Duration::from_secs(1)),+ );+ assert_eq!(result, OrchestratorIdleResult::Waiting);+}++#[test]+fn test_orchestrator_idle_fallback_after_threshold() {+ // Content unchanged for longer than ORCHESTRATOR_IDLE_FALLBACK_SECS β Idle+ let result = check_orchestrator_idle(+ "same content",+ "same content",+ Some(Instant::now() - std::time::Duration::from_secs(ORCHESTRATOR_IDLE_FALLBACK_SECS + 1)),+ );+ assert_eq!(result, OrchestratorIdleResult::Idle);+}++#[test]+fn test_orchestrator_idle_signal_takes_priority_over_content_change() {+ // Even if content just changed, the idle signal means we're ready+ let result = check_orchestrator_idle(+ "new output with [agtx:idle] at the end",+ "old output",+ None,+ );+ assert_eq!(result, OrchestratorIdleResult::Idle);+}++#[test]+fn test_orchestrator_idle_signal_in_unchanged_content() {+ // Content unchanged but contains idle signal β still counts as Waiting+ // because unchanged content goes through the stability timer path.+ // The idle signal only fast-tracks on content *change*.+ let content = "output\n[agtx:idle]\n";+ let result = check_orchestrator_idle(+ content,+ content,+ Some(Instant::now() - std::time::Duration::from_secs(1)),+ );+ assert_eq!(result, OrchestratorIdleResult::Waiting);+}++#[test]+fn test_orchestrator_empty_content_both_sides() {+ // Both empty (e.g. startup) β unchanged β Waiting+ let result = check_orchestrator_idle("", "", None);+ assert_eq!(result, OrchestratorIdleResult::Waiting);+}+