Improve OpenCode bridge startup reliability and error handling - #9
Merged
Merged
Conversation
…ker stdin, and timeout - Register event listeners BEFORE sendPrompt() in handleAsk to prevent missing fast responses or errors (race condition) - Add 30-second connection timeout so the chat doesn't hang indefinitely when the process starts but never responds - Stop treating all stderr output as fatal errors — only lines matching error patterns (Error:, FATAL:, panic:, Traceback) fire error events; informational stderr is surfaced as status events instead - Add -i flag to docker exec in in-container mode so stdin is forwarded to the container process (required for sending commands) - Add waitForReady() to bridge.start() so callers know when the process has either stabilized or failed during startup - Bump version to 0.1.4 https://claude.ai/code/session_01D12992HnEWn4Jh3iX9SFRe
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
This PR enhances the OpenCode bridge's startup robustness and error handling by adding a readiness timeout, improving stderr classification, and implementing a connection timeout in the chat participant. These changes ensure the bridge properly waits for process initialization and gracefully handles communication failures.
Key Changes
Bridge Startup & Readiness
waitForReady()method that waits up to 5 seconds for the spawned process to either stabilize or fail, preventing callers from seeingstate="idle"when the process is about to crashSPAWN_READY_TIMEOUT_MSconstant (5000ms) to define the readiness windowstartBridge()test helper that advances fake timers to simulate the readiness timeoutStderr Handling Improvements
handleStderr()to distinguish between genuine errors and informational messagesisStderrError()heuristic that identifies error patterns: "Error:", "ERROR:", "FATAL:", "panic:", "Traceback" (case-insensitive)errorevents; other stderr output firesstatusevents withagent: "system"to inform users without terminating responsesDocker Exec Flag
-i(interactive) flag todocker execcommand in in-container execution mode-iis placed afterexecbut before the container IDChat Participant Connection Timeout
handleAsk()that triggers if no events arrive from the bridgeTest Coverage
afterEach()hook to restore real timers after each test-iflag placement in docker exec argumentsstartBridge()helper for consistent timer handlingImplementation Details
waitForReady()promise settles either via state change listener (error/stopped) or timeout expirationVersion
Bumped to v0.1.4
https://claude.ai/code/session_01D12992HnEWn4Jh3iX9SFRe