Skip to content

fix(tui): recover event stream after lock/sleep disconnect#15436

Open
Niraj12chaudhary wants to merge 2 commits intoanomalyco:devfrom
Niraj12chaudhary:fix/tui-reconnect-after-lock-sleep
Open

fix(tui): recover event stream after lock/sleep disconnect#15436
Niraj12chaudhary wants to merge 2 commits intoanomalyco:devfrom
Niraj12chaudhary:fix/tui-reconnect-after-lock-sleep

Conversation

@Niraj12chaudhary
Copy link
Contributor

@Niraj12chaudhary Niraj12chaudhary commented Feb 28, 2026

Issue for this PR

Closes #15431

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Fixes a TUI freeze case after long macOS lock/sleep periods where sessions could remain stuck in In Progress with no new output.

Changes in this PR:

  • Added reconnect handling + heartbeat timeout in the TUI SDK SSE consumer.
  • Added reconnect handling + heartbeat timeout in the TUI worker event relay.
  • Triggered a sync bootstrap on server.connected / global.disposed so session status is refreshed after reconnect.

Why this works:

  • If the event stream silently stalls/drops during lock/sleep, the new heartbeat timeout aborts the stale stream and forces reconnect.
  • On reconnect, sync bootstrap refreshes session state from server APIs, so stale local busy status is corrected and output/state continue updating.

How did you verify your code works?

  • Ran package typecheck locally:
    • bun --cwd packages/opencode typecheck
  • Manually validated code paths for:
    • stream reconnection loop
    • heartbeat-triggered abort
    • post-reconnect sync refresh

Screenshots / recordings

N/A (TUI event-stream reliability fix)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. contributor needs:issue labels Feb 28, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potentially Related PRs Found

Based on my search, I found several PRs that are related to event stream handling and TUI reliability:

  1. fix(tui): resolve streaming freeze from unhandled finish event, missing timeouts, and unguarded effects #15308 - fix(tui): resolve streaming freeze from unhandled finish event, missing timeouts, and unguarded effects

    • Directly related: Also addresses streaming freeze issues in TUI with timeout handling
  2. refactor(opencode): replace reconcile() with path-syntax setStore and delta coalescing for streaming updates #15309 - refactor(opencode): replace reconcile() with path-syntax setStore and delta coalescing for streaming updates

    • Related: Handles streaming update reliability
  3. fix(opencode): coalesce stream updates and add reconnect backoff #13026 - fix(opencode): coalesce stream updates and add reconnect backoff

    • Related: Addresses reconnect backoff for streams
  4. fix: consolidate memory leak fixes from #14650 and #8953 #15435 - fix: consolidate memory leak fixes from #14650 and #8953

    • Potentially related: Recent consolidation of reliability fixes

Most relevant: PR #15308 appears to be closely related as it also fixes streaming freeze issues in the TUI with timeout handling, which overlaps with this PR's heartbeat timeout approach.

@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Feb 28, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] opencode session freezes after macOS lock screen while task remains “In Progress”

1 participant