GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: SSE stream leak on proxy disconnect + compact message list responses by abrekhov · Pull Request #18395 · anomalyco/opencode

Conversation

@abrekhov

@abrekhov abrekhov commented Mar 20, 2026

Copy link
Copy Markdown

Summary

Two fixes for opencode serve performance when running behind a reverse proxy with multiple workspaces:

  1. SSE event streams leak memory on client disconnect — Bus subscriptions, GlobalBus listeners, and heartbeat intervals are only cleaned up via stream.onAbort(), which does not fire when a reverse proxy holds the upstream TCP connection open. Adds c.req.raw.signal as a secondary AbortSignal listener across all three SSE endpoints (/event, /global/event, workspace-server /event).

  2. Message list API returns excessively large responses — A single message's summary.diffs field can contain full before/after file contents totaling 30+ MB for sessions with many file changes, and tool parts include unbounded output and metadata fields. Adds server-side compaction to the GET /session/:id/message endpoint that strips diff file contents (keeping file/additions/deletions/status metadata) and truncates tool outputs beyond 4 KB. Full data remains available via the per-message GET /session/:id/message/:messageID endpoint.

Impact

SSE leak (fix 1): In a test environment with 12 active workspaces (~20 internal SSE connections), opencode serve RSS grew at ~80 MB/min, reaching 24 GB+ after <2 hours. After the fix, RSS stays stable at ~700 MB.

Message compaction (fix 2): For a session with 1972 messages / 6987 parts, the ?limit=200 response dropped from 35 MB / 408 ms to 1.5 MB / 190 ms (24x smaller, 2x faster server-side). End-to-end load time in the web UI went from ~30 seconds to under 1 second because the browser no longer has to parse and render 35 MB of JSON.

Related issues

  • [Bug]: Massive memory leak (60GB+ OOM crash) on Server #17908 — Massive memory leak (60GB+ OOM crash) on Server
  • SSE event streams leak memory on client disconnect #15645 — SSE event streams leak memory on client disconnect
  • opencode web becomes unresponsive after hours: SSE connection leak causes 7GB+ memory growth and event loop freeze #17628 — opencode web becomes unresponsive after hours
  • Memory leak: serve and web commands leak child processes on exit; SSE heartbeat interval leaks on server-initiated close #14091 — Memory leak: serve and web commands leak child processes on exit
  • Sidebar session prefetch loads full tool outputs and can drive opencode serve to multi-GB memory #17837 — Sidebar session prefetch loads full tool outputs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@abrekhov
fix: SSE stream leak on proxy disconnect + compact message list respo…
744a948
…nses

Fix two issues causing degraded performance in serve mode:

1. SSE event streams leak memory when clients disconnect behind a reverse
   proxy. The cleanup of Bus subscriptions, GlobalBus listeners, and
   heartbeat intervals is gated entirely on stream.onAbort(), which does
   not fire when an upstream proxy holds the TCP connection open. Add
   c.req.raw.signal as a secondary AbortSignal listener to detect
   connection close at the transport level, covering all three SSE
   endpoints (/event, /global/event, workspace-server /event).

2. GET /session/:id/message returns excessively large JSON responses for
   sessions with many messages. A single message's summary.diffs field
   can contain full before/after file contents totaling 30+ MB, and tool
   parts include unbounded output and metadata fields. Add server-side
   compaction that strips diff file contents (keeping file/additions/
   deletions/status metadata), truncates tool outputs beyond 4 KB, and
   removes tool metadata from list responses. Full data remains available
   via the per-message GET endpoint. Reduces a representative 35 MB
   response to 1.5 MB (24x), cutting load time from 30s to under 1s.
@github-actions github-actions Bot added the needs:issue label Mar 20, 2026
@github-actions

github-actions Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 20, 2026
@github-actions

github-actions Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

This pull request 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 pull request that follows our guidelines.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 20, 2026
@github-actions github-actions Bot closed this Mar 20, 2026
This was referenced Apr 15, 2026
fix(sse): prevent memory leak from zombie SSE connections #22550
Closed
fix(sse): prevent memory leak from zombie SSE connections #22551
Closed
fix(sse): prevent memory leak from zombie SSE connections #22552
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs:issue

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@abrekhov
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.