Skip to content

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

Closed

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

Activity

  1. github-actions commented on May 13, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The description appears to be AI-generated (structured wall of text with sections like "## Severity", "## Root Cause", "## Suggested Fix", "## Labels"). AI-generated issue descriptions are not acceptable — please rewrite this in your own words with only the details you actually observed.
    • Required fields Operating System and Terminal are left blank (_No response_). Please provide your system information.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


    This issue might be a duplicate of existing issues. Please check:

    If you believe this was flagged incorrectly, please let a maintainer know.

  2. github-actions commented on May 14, 2026

    @github-actions
    Contributor

    This issue has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

    Feel free to open a new issue that follows our issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions