fix: Add retry logic for Bun socket connection errors#110
Merged
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #109
Addresses issue #109 where streaming API responses fail after ~10 seconds due to Bun's default idle timeout in Bun.serve() context. Changes: - Add SocketConnectionError type in message-v2.ts with isRetryable: true - Detect socket errors by message pattern ("socket connection was closed") - Update processor.ts to retry socket errors up to 3 times - Add socket-specific retry configuration in retry.ts with exponential backoff The fix follows the existing retry pattern for APIError but with socket-specific timing (1s, 2s, 4s delays) to handle transient Bun socket timeouts. References: - oven-sh/bun#14439 (Bun 10s idle timeout) - link-assistant/hive-mind#1098 (original report)
Adds comprehensive tests for: - Socket error detection from error messages - SocketConnectionError type properties - Retry configuration constants - Socket error delay calculation with exponential backoff
Documents the socket connection error investigation: - Timeline of events - Root cause analysis (Bun 10s idle timeout) - Solution implemented - References to related issues Data files: - README.md with comprehensive case study - execution-log.json with detailed event timeline
Adds experiments/socket-error-simulation.ts to verify: - Socket error detection works correctly - Retry configuration values - Exponential backoff delay calculation - Error type differentiation Useful for testing and demonstrating the fix behavior.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds automatic retry logic for socket connection errors that occur due to Bun's known 10-second idle timeout issue in
Bun.serve()contexts.Problem
When using the agent CLI with streaming API providers (e.g.,
opencode/grok-code), connections frequently fail after approximately 10-12 seconds with:This is a known Bun limitation (oven-sh/bun#14439) where the default
idleTimeoutof 10 seconds causes long-running streaming connections to be dropped.Solution
SocketConnectionErrorinmessage-v2.tsthat is always marked as retryablefromError()to detect socket errors by message patternprocessor.tsto retry socket errors up to 3 timesChanges
js/src/session/message-v2.ts- Add SocketConnectionError type and detection logicjs/src/session/processor.ts- Add retry handling for socket connection errorsjs/src/session/retry.ts- Add socket-specific retry configuration and delay functionjs/tests/socket-retry.test.js- Unit tests for socket error detection and retry logicdocs/case-studies/issue-109/- Case study documentation with timeline and analysisjs/experiments/socket-error-simulation.ts- Experiment script to verify fix behaviorTest Plan
bun test tests/socket-retry.test.js)bun run lint)bun run format:check)References