Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Summary

Adds a heartbeat pattern to the onChat subscription to reliably distinguish dead connections from intentionally idle streams during long operations.

Background

The previous stall detection used a 60s timeout while checking if a stream was active. This caused false positives during long tool operations (bash with 5+ min timeout, subagent calls) where it's normal to have no events for extended periods. The retry would call resetChatStateForReplay() which clears the aggregator and triggers a full UI repaint—noticeable and disruptive to users.

Implementation

  • Server: Emits a heartbeat event every 5s unconditionally in the onChat handler
  • Client: Expects any event (heartbeat or real data) within 10s
    • Timeout reduced from 60s → 10s
    • Check interval reduced from 5s → 2s
    • Removed the "active stream" check since heartbeats flow regardless of stream state

Now if 10s pass with no events (including heartbeats), the connection is genuinely dead → resubscribe. Long operations no longer trigger false stalls since heartbeats keep flowing.


Generated with mux • Model: anthropic:claude-opus-4-5 • Thinking: high • Cost: $1.30

@github-actions github-actions bot added the bug label Jan 25, 2026
Copy link

@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: bf90caa0c4

ℹ️ 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".

Previously, stall detection used a 60s timeout while checking if a stream
was active. This caused false positives during long tool operations (bash
with 5+ min timeout, subagent calls) where it's normal to have no events.
The retry would reset chat state and cause full UI repaints.

Now the server sends heartbeats every 5s unconditionally, and the client
expects *any* event within 10s. If 10s pass with no events (including
heartbeats), the connection is dead and we resubscribe. Long operations
no longer trigger false stalls since heartbeats keep flowing.
@ammar-agent ammar-agent force-pushed the fix/onchat-heartbeat-stall-detection branch from db03d6f to 6070167 Compare January 26, 2026 16:10
@ammario ammario merged commit 066a681 into main Jan 26, 2026
23 checks passed
@ammario ammario deleted the fix/onchat-heartbeat-stall-detection branch January 26, 2026 16:46
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.

2 participants