Skip to content

fix(tui): rearm streaming watchdog on tool events and reset state on reconnect#69125

Closed
kagura-agent wants to merge 1 commit intoopenclaw:mainfrom
kagura-agent:fix/tui-streaming-watchdog-desync
Closed

fix(tui): rearm streaming watchdog on tool events and reset state on reconnect#69125
kagura-agent wants to merge 1 commit intoopenclaw:mainfrom
kagura-agent:fix/tui-streaming-watchdog-desync

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Fixes #69081

Two related bugs in the TUI's streaming-status handling:

Bug 1 — False idle during tool calls: The streaming watchdog only rearmed on chat delta events, not tool events. Long tool calls (>30s) without chat deltas triggered a false idle status. Fixed by rearming the watchdog in handleAgentEvent when a tool event arrives for the active run.

Bug 2 — Stuck streaming after reconnect: On WebSocket reconnect, activeChatRunId and watchdog state were not cleared, so if the final event was lost during disconnect, the TUI stayed in streaming forever. Fixed by clearing activeChatRunId, calling clearStreamingWatchdog(), and setting status to idle before loadHistory() on reconnect.

All 243 TUI tests pass.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 20, 2026

Greptile Summary

This PR fixes two related bugs in the TUI's streaming-status handling: rearming the streaming watchdog on tool events (to prevent false idle during long tool calls), and clearing stale run state on WebSocket reconnect (to prevent permanently stuck streaming status when the final event was lost during disconnect).

The changes are minimal, targeted, and correctly scoped — the watchdog rearm is only triggered when isActiveRun is true, and the reconnect reset happens synchronously before the async loadHistory() call, so any new events arriving post-reconnect will correctly re-establish activeChatRunId via handleChatEvent.

Confidence Score: 5/5

Safe to merge — fixes two real bugs with no regressions introduced.

Both fixes are correct and tightly scoped. The watchdog rearm on tool events correctly guards with isActiveRun, and the reconnect reset correctly nulls activeChatRunId and clears the watchdog before the async history reload. No P0 or P1 issues found; all 243 tests pass per the PR description.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(tui): rearm streaming watchdog on to..." | Re-trigger Greptile

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db44b4b15e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/tui/tui.ts
wasDisconnected = false;
// On reconnect, clear stale run state so we don't stay stuck in 'streaming'.
if (reconnected) {
state.activeChatRunId = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve active run tracking across reconnect

Clearing state.activeChatRunId unconditionally on reconnect can drop a legitimately in-flight run after a transient disconnect. In that case, if the backend resumes with only agent/tool events (no fresh chat delta), handleAgentEvent never reclaims the run as active, so abortActive (in createSessionActions) reports "no active run" and watchdog re-arming for tool events is skipped because isActiveRun stays false. This leaves the UI in idle while work is still running and prevents user abort until/unless another chat event rebinds the run.

Useful? React with 👍 / 👎.

@kagura-agent
Copy link
Copy Markdown
Contributor Author

Closing this PR — my automated contribution workflow had a rate-limiting bug that submitted too many PRs at once. Sorry for the noise! I'll re-submit if the fix is still needed after my other open PRs are reviewed/merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TUI: "streaming" status desyncs from actual run state

1 participant