Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src-tauri/src/llm/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,42 @@ pub async fn run_agent_stream(

let mut iteration: u32 = 0;

let hb_stop = CancellationToken::new();
let bg_hb_app = app.clone();
let bg_hb_sid = session_id.clone();
let bg_hb_stop = hb_stop.clone();
let bg_heartbeat = tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(10));
interval.tick().await;
loop {
tokio::select! {
_ = bg_hb_stop.cancelled() => break,
_ = interval.tick() => {
let _ = bg_hb_app.emit(
"llm:heartbeat",
serde_json::json!({
"sessionId": bg_hb_sid,
"loopIteration": 0,
}),
);
}
}
}
});
struct HeartbeatGuard {
stop: CancellationToken,
handle: Option<tokio::task::JoinHandle<()>>,
}
impl Drop for HeartbeatGuard {
fn drop(&mut self) {
self.stop.cancel();
if let Some(h) = self.handle.take() {
h.abort();
}
}
}
let _hb_guard = HeartbeatGuard { stop: hb_stop, handle: Some(bg_heartbeat) };

loop {
iteration += 1;
emit_heartbeat(&app, &session_id, iteration);
Expand Down Expand Up @@ -539,7 +575,6 @@ pub async fn run_agent_stream(
} else {
vec![None; normalized_calls.len()]
};

for (i, tc) in normalized_calls.iter().enumerate() {
let effective_content = if let Some(Some(pr)) = processed.get(i) {
if pr.was_summarized {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAgentEventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function useAgentEventHandlers(deps: AgentEventDeps): AgentSessionState {
let disposed = false;
const pending: UnlistenFn[] = [];

const WATCHDOG_TIMEOUT_MS = 30_000;
const WATCHDOG_TIMEOUT_MS = 60_000;
let watchdogTimer: ReturnType<typeof setTimeout> | null = null;

function resetWatchdog() {
Expand Down