plannotator icon indicating copy to clipboard operation
plannotator copied to clipboard

External annotations SSE stream times out after 10s idle timeout in Bun

Open foxytanuki opened this issue 8 months ago • 1 comments

/api/external-annotations/stream can be terminated after 10 seconds of inactivity with:

[Bun.serve]: request timed out after 10 seconds. Pass `idleTimeout` to configure.

Environment

Observed in the following environment:

  • OpenCode v1.3.6
  • Plannotator v0.16.0

Root cause

Bun.serve uses a default idleTimeout of 10 seconds.
Our external annotations SSE heartbeat is 30 seconds (HEARTBEAT_INTERVAL_MS in packages/shared/external-annotation.ts), so the connection can sit idle long enough for Bun to close it.

The SSE response is created in:

  • packages/server/external-annotations.ts

and returned by the Bun servers used for:

  • packages/server/index.ts
  • packages/server/review.ts
  • packages/server/annotate.ts

At the moment, these SSE responses do not disable or extend Bun's per-request timeout.

Reproduction

  1. Open a Plannotator UI that connects to /api/external-annotations/stream
  2. Leave it idle without incoming annotation events
  3. After ~10 seconds, Bun logs:
[Bun.serve]: request timed out after 10 seconds. Pass `idleTimeout` to configure.

Expected behavior

The SSE connection should remain open while idle.

Suggested fix

Before returning the SSE response, disable or extend the request timeout for that stream, e.g. with Bun's per-request timeout handling (server.timeout(req, 0)), or otherwise ensure the stream is not subject to the default 10-second idle timeout.

Reducing the heartbeat interval would also help, but the main issue is that the SSE request still uses Bun's default timeout.

foxytanuki avatar Mar 30 '26 14:03 foxytanuki

Released as 0.16.1

backnotprop avatar Mar 30 '26 16:03 backnotprop