[PR #7468] fix(tui): add retry backoff for event subscription to prevent CPU spin #12410

Open
opened 2026-02-16 18:17:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7468

State: open
Merged: No


Problem

When the server shuts down unexpectedly, the TUI attach client enters a tight retry loop causing 100% CPU usage. This happens because the event subscription loop in sdk.tsx lacks error handling and backoff.

Reproduction:

  1. Run opencode spawn
  2. Kill the spawn process (Ctrl+C or kill)
  3. The attach subprocess continues running at 100% CPU, trying to reconnect indefinitely

Solution

  • Add try-catch around sdk.event.subscribe()
  • Implement exponential backoff: 1s → 2s → 4s → ... → 30s max
  • Add random jitter to prevent thundering herd
  • Give up after 10 consecutive failures with error message

Testing

Manually tested by killing the server process and observing the attach client behavior - it now backs off exponentially and eventually exits gracefully instead of spinning the CPU.

Fixes #7645

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7468 **State:** open **Merged:** No --- ## Problem When the server shuts down unexpectedly, the TUI attach client enters a tight retry loop causing 100% CPU usage. This happens because the event subscription loop in `sdk.tsx` lacks error handling and backoff. **Reproduction**: 1. Run `opencode spawn` 2. Kill the spawn process (Ctrl+C or `kill`) 3. The attach subprocess continues running at 100% CPU, trying to reconnect indefinitely ## Solution - Add try-catch around `sdk.event.subscribe()` - Implement exponential backoff: 1s → 2s → 4s → ... → 30s max - Add random jitter to prevent thundering herd - Give up after 10 consecutive failures with error message ## Testing Manually tested by killing the server process and observing the attach client behavior - it now backs off exponentially and eventually exits gracefully instead of spinning the CPU. Fixes #7645
yindo added the pull-request label 2026-02-16 18:17:19 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12410