Description
Bug Report: SSE Event Stream Closes Immediately After Connection (Effect HTTP API Backend)
Summary
In OpenCode v1.14.43+, the SSE /event endpoint closes the stream immediately (~1ms) after sending the server.connected event. This prevents all subsequent server-pushed events from reaching clients.
Severity
Critical — The SSE event stream is the only mechanism for clients to receive real-time updates. This bug causes:
- No AI streaming responses (message.part.delta)
- No message completion notifications (message.completed)
- No permission request handling (permission.asked)
- No question request handling (question.asked)
Affected Versions
- Affected: v1.14.43 ~ v1.14.48 (latest as of report)
- Not affected: v1.14.42 and earlier (using Hono backend)
Root Cause
The eventResponse() function in packages/opencode/src/server/routes/instance/httpapi/event.ts creates an SSE stream bound to the Effect HTTP request scope. When the handler returns, the request scope is disposed, cancelling the bus.subscribeAll() PubSub subscription and terminating the stream prematurely.
Steps to Reproduce
- Start OpenCode server:
opencode serve --cors '*'
- Connect to SSE endpoint:
curl -N http://127.0.0.1:4096/event
Expected: Stream stays open
Actual: Stream closes immediately after server.connected (< 1ms)
Suggested Fix
Lift the PubSub subscription outside the request scope so its lifetime is not affected by request disposal. Consider using Effect.unsafeScoped or binding the subscription to an application-level Scope.
Related Files
packages/opencode/src/server/routes/instance/httpapi/event.ts
packages/opencode/src/server/server.ts
packages/opencode/src/bus.ts
Labels
bug, server, sse, effect, regression, critical
bug-report-sse-effect-httpapi.en.md
Plugins
No response
OpenCode version
1.14.43+
Steps to reproduce
See description section
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Description
Bug Report: SSE Event Stream Closes Immediately After Connection (Effect HTTP API Backend)
Summary
In OpenCode v1.14.43+, the SSE
/eventendpoint closes the stream immediately (~1ms) after sending theserver.connectedevent. This prevents all subsequent server-pushed events from reaching clients.Severity
Critical — The SSE event stream is the only mechanism for clients to receive real-time updates. This bug causes:
Affected Versions
Root Cause
The
eventResponse()function inpackages/opencode/src/server/routes/instance/httpapi/event.tscreates an SSE stream bound to the Effect HTTP request scope. When the handler returns, the request scope is disposed, cancelling thebus.subscribeAll()PubSub subscription and terminating the stream prematurely.Steps to Reproduce
opencode serve --cors '*'curl -N http://127.0.0.1:4096/eventExpected: Stream stays open
Actual: Stream closes immediately after
server.connected(< 1ms)Suggested Fix
Lift the PubSub subscription outside the request scope so its lifetime is not affected by request disposal. Consider using
Effect.unsafeScopedor binding the subscription to an application-level Scope.Related Files
packages/opencode/src/server/routes/instance/httpapi/event.tspackages/opencode/src/server/server.tspackages/opencode/src/bus.tsLabels
bug, server, sse, effect, regression, critical
bug-report-sse-effect-httpapi.en.md
Plugins
No response
OpenCode version
1.14.43+
Steps to reproduce
See description section
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response