Skip to content

Conversation

@SunandRiver
Copy link

@SunandRiver SunandRiver commented Jan 9, 2026

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

When the server shuts down, the TUI attach client enters a tight
retry loop with 100% CPU usage because the event subscription loop
lacks error handling and backoff.

Changes:
- 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

This prevents orphaned attach processes from spinning the CPU
when their server has been terminated.
@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

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

No duplicate PRs found

@SunandRiver
Copy link
Author

Hi @aidenpcline @maintainers,

I noticed that the check is failing, but this appears to be due to a CI configuration issue rather than a problem with my code changes.

Error details:

Root cause:
Commit changed the GraphQL field from to in , but is not a valid field in the GitHub GraphQL API.

My PR status:

  • ✅ Title format: (follows conventional commits)
  • ✅ Code changes: Add exponential backoff retry logic to prevent CPU spinning when server shuts down
  • ✅ Problem addressed: Fixes 100% CPU usage in TUI attach client during server shutdown
  • ❌ CI cannot check for linked issue due to API field error

Suggested fix:
Revert back to or use another valid field from the GitHub GraphQL API documentation.

Next steps from my side:

  1. I'll resolve the merge conflicts with the branch
  2. Keep the PR ready for review/merge

Thanks for looking into this!

- Merge latest dev changes including props.events support
- Apply retry backoff logic to SSE fallback
- Maintain handleEvent architecture from upstream
@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.

@SunandRiver
Copy link
Author

Related issue: #7645 (TUI client CPU 100% when server shuts down)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI client CPU 100% when server shuts down

1 participant