fix(worker/ocs): resolve SSE timeout and server startup issues#96
Merged
hrygo merged 3 commits intohrygo:mainfrom May 1, 2026
Merged
Conversation
This commit fixes two high-priority issues affecting OpenCode Server worker: **Issue hrygo#85: SSE client timeout breaks long-lived streaming** - Add separate sseClient without Timeout for SSE connections - Use cancellable context in readSSE for clean shutdown - Prevents SSE stream interruption after 30s HTTPTimeout - Enables proper goroutine cleanup on Terminate/Kill **Issue hrygo#79 Finding 1: serverErr channel never consumed** - Fix silent HTTP server startup failure - Use select to race signal against server error - Log error and exit if ListenAndServe fails - Prevents gateway appearing to start when port is unavailable **Changes:** - internal/worker/opencodeserver/singleton.go: Add sseClient field - internal/worker/opencodeserver/worker.go: Use sseClient + context cancellation - cmd/hotplex/gateway_run.go: Handle serverErr channel - Remove unused waitForSignal function **Verification:** - make test: All tests pass - make lint: Zero issues - Closes hrygo#91 (verified as already fixed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #96 +/- ##
==========================================
- Coverage 59.56% 59.55% -0.01%
==========================================
Files 134 134
Lines 15944 15969 +25
==========================================
+ Hits 9497 9511 +14
- Misses 5856 5865 +9
- Partials 591 593 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…t cancellation Add unit tests to cover new code paths: - Test sseClient initialization in NewSingletonProcessManager - Test sseClient is returned by Acquire() - Test Terminate() and Kill() call sseCancel - Test New() worker initialization - Test nil sseCancel handling in Terminate/Kill These tests improve patch coverage without requiring opencode binary. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Test that Terminate and Kill properly handle releaseOnce to ensure singleton reference is released exactly once. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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 fixes two high-priority issues affecting OpenCode Server worker stability and observability:
Issue #85: SSE Client Timeout Breaks Long-lived Streaming
Problem:
SingletonProcessManagercreated anhttp.Clientwith 30s Timeout. ThereadSSE()goroutine reused this client for SSE requests, causing the long-lived streaming connection to be interrupted after 30s. Additionally,Terminate()/Kill()did not cancel the in-flight SSE HTTP request, leaving thereadSSEgoroutine blocked.Solution:
sseClientfield without Timeout for SSE connectionsreadSSE()for clean shutdownsseCancelin Worker and call it inTerminate()/Kill()Issue #79 Finding 1: Silent HTTP Server Startup Failure
Problem:
serverErrchannel was created but never read. If HTTP server failed to bind (port in use, permission denied), the error was silently lost. The gateway appeared to start successfully but was actually non-functional.Solution:
selectto race signal againstserverErrListenAndServefailsChanges
internal/worker/opencodeserver/singleton.go: AddsseClientfield, updateAcquire()signatureinternal/worker/opencodeserver/worker.go: UsesseClient, add context cancellationcmd/hotplex/gateway_run.go: HandleserverErrchannel, remove unusedwaitForSignal()internal/worker/opencodeserver/singleton_test.go: Update for newAcquire()signatureTest Plan
make test- All tests passmake lint- Zero issuesRelated Issues
🤖 Generated with Claude Code