opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(lsp): Add crash detection and exponential backoff retry

Open sauerdaniel opened this issue 17 hours ago • 1 comments

Summary

Add exponential backoff retry logic for LSP servers that crash or fail to spawn, preventing permanent disabling of LSP functionality.

Fixes #9153

Problem

When an LSP server fails to spawn or crashes, it gets added to a broken set and is never retried during the session. This means if an LSP server temporarily fails (e.g., due to resource constraints), the user loses LSP features for the entire session.

Solution

Replace the simple broken: Set<string> with a Map that tracks:

  • failTime: When the failure occurred
  • attemptCount: Number of consecutive failures

Use exponential backoff (2s, 4s, 8s, ... up to 30s max) to retry failed servers instead of permanently disabling them.

Changes

  • packages/opencode/src/lsp/index.ts:
    • Change broken from Set<string> to Map<string, {failTime, attemptCount}>
    • Add isBrokenWithBackoff() function with exponential backoff calculation
    • Update failure tracking to increment attempt count
    • Reset attempt count on successful spawn

Testing

  • [x] TypeScript compilation passes (bun turbo typecheck)
  • [x] Unit tests pass (725 tests, 0 failures)
  • [x] LSP client tests pass (3 tests)

Note: Manual LSP crash testing (killing LSP server and verifying retry) was not performed.

sauerdaniel avatar Jan 17 '26 23:01 sauerdaniel