opencode
opencode copied to clipboard
fix(lsp): Add crash detection and exponential backoff retry
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
brokenfromSet<string>toMap<string, {failTime, attemptCount}> - Add
isBrokenWithBackoff()function with exponential backoff calculation - Update failure tracking to increment attempt count
- Reset attempt count on successful spawn
- Change
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.