Skip to content

[Bug]: Large OpenCode SSE events stall the T3 Code server #46615

Done

Description

@Natashkinsasha

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Run T3 Code with a managed local OpenCode 1.x provider and snapshots enabled.
  2. Start a turn in a disposable Git worktree. During the turn, move the worktree to a substantially different base revision so that OpenCode's snapshots produce a large per-message diff.
  3. While OpenCode is publishing the snapshot summary, make a local HTTP request to the T3 Code server. In the observed case the summary contained 4,278 file diffs and its serialized message was about 71 MB.

For a smaller isolated test of the parser, feed the OpenCode SDK v2 event client one valid SSE frame with a large JSON data field split across ordinary stream chunks. The generated parser appends each chunk, then applies line-ending replacements and splits the entire accumulated string again. That work grows quadratically with frame size for a fixed chunk size.

Expected behavior

T3 Code continues serving requests while processing OpenCode events. An event that exceeds a supported size fails with a clear provider error without blocking the server.

Actual behavior

The T3 Code listener accepted TCP connections, but local HTTP requests frequently timed out before receiving headers. OpenCode's own health endpoint remained responsive. T3 Code logged repeated event-loop stalls of roughly 3–5 seconds. In a CPU profile, the main Node thread spent time inside V8 string flattening and replacement from an async generator. Once the affected OpenCode process exited and T3 Code drained the buffered data, the server returned HTTP 200 again without a restart.

Impact

Major degradation or frequent failure

Version or commit

Observed on T3 Code v0.1.9. The v0.1.13 source still uses the same OpenCode v2 SDK event subscription and locks @opencode-ai/sdk 1.15.13, whose generated SSE parser uses the same whole-buffer loop. I checked the code for v0.1.13 and reproduced the incident on v0.1.9.

Environment

Linux x86_64, managed local OpenCode 1.18.35.

Logs or stack traces

WARN: event loop stalled for 5342 ms
curl: (28) Operation timed out after 6002 milliseconds with 0 bytes received

The CPU samples included Runtime_FlattenString, Builtins_RegExpReplace, and Builtins_AsyncGeneratorAwaitResolveClosure.

Workaround

Set "snapshot": false in OpenCode 1.18.35 and use a fresh provider session for work that would otherwise load an existing large snapshot diff. This disables filesystem snapshots and their file rollback support.

Related producer-side report: anomalyco/opencode#42748. T3 Code #3601 covers loading full session history. This report concerns the live event stream.

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

Metadata

Metadata

Assignees

No one assigned

    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