Skip to content

perf: bound instance SSE subscriber queues #45215

Description

@BYK

Description

The instance event SSE handler creates an eager unbounded Queue.unbounded<EventV2.Payload>() for each subscriber and offers every full event payload into it. A slow or stalled subscriber can retain unlimited high-volume message.part.updated payloads.

Source: packages/opencode/src/server/routes/instance/httpapi/handlers/event.ts. Session.updatePart() publishes a full cloned part on every update.

Expected: each subscriber has a hard event/byte bound. Overflow disconnects explicitly or uses a safe sliding/coalescing policy. Cancellation always releases retained payloads, and terminal events are never silently lost.

This was found during a V8 OOM investigation. It is a confirmed unbounded source path, but it was not proven as that incident's heap owner because one saturated runtime sample had no live subscriber.

Plugins

@loreai/opencode

OpenCode version

Current v2 development source

Steps to reproduce

  1. Open an instance SSE subscription.
  2. Stop or severely throttle reads from the response.
  3. Generate sustained message.part.updated events with large part payloads.
  4. Observe that the subscriber queue grows without a configured event or byte limit until disconnect.

A regression should hold one subscriber stalled, publish sustained updates, assert bounded retained events/bytes, then cancel and assert full release.

Screenshot and/or share link

Not applicable; this is a server-side queue retention path.

Operating System

Linux

Terminal

OpenCode server mode

Activity

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