Skip to main content

codetether_agent/tui/app/watchdog/
detector.rs

1//! Watchdog stall detection logic.
2
3use std::time::Duration;
4
5use crate::tui::app::state::AppState;
6use crate::tui::app::watchdog::state::WatchdogNotification;
7
8/// Check if the current request is stalled and return a notification if so.
9pub fn check_watchdog_stall(state: &AppState, timeout: Duration) -> Option<WatchdogNotification> {
10    if !state.processing {
11        return None;
12    }
13    let timed_out = state
14        .main_last_event_at
15        .map(|t| t.elapsed() >= timeout)
16        .unwrap_or(true);
17    if !timed_out {
18        return None;
19    }
20    let count = state.main_watchdog_restart_count;
21    Some(WatchdogNotification::new(
22        format!(
23            "⚠ No events for {}s. Stalled request detected.",
24            timeout.as_secs()
25        ),
26        count,
27    ))
28}