Skip to content

[BUG] SSE Event Stream Closes Immediately After Connection (Effect HTTP API Backend) #27391

@topxebec

Description

@topxebec

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

  1. Start OpenCode server: opencode serve --cors '*'
  2. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions