Skip to content

fix(stream): reconnect with backoff when the connection drops - #16

Open
harshpuri84 wants to merge 1 commit into
bee-computer:mainfrom
harshpuri84:fix/stream-reconnect
Open

harshpuri84 wants to merge 1 commit into
bee-computer:mainfrom
harshpuri84:fix/stream-reconnect

Conversation

@harshpuri84

Copy link
Copy Markdown

bee stream connects once. When the connection times out or drops, the command exits and writes its usage text to stdout, so a consumer piping --json gets help text in its event feed. A long-running consumer then loses every event until someone restarts it.

This change keeps the stream up:

  • Reconnects when the stream ends or fails for a transient reason: a dropped connection, a timeout, a 5xx, 408 or 429.
  • Backs off 1s, 2s, 4s up to 30s, and resets after a connection that stayed up for a minute.
  • Stops on other HTTP errors (401, 403, 404) and on a missing login, as before.
  • Ctrl+C stops it whether connected or waiting to reconnect.
  • In --json and --agent mode, reconnect notices go to stderr, so stdout stays parseable. Pretty mode prints them to stdout as before.

Events sent while disconnected are still lost, because the stream has no resume cursor. That needs a server change.

Testing

  • 5 new tests in sources/commands/stream/index.test.ts: backoff steps, which errors retry, reconnect then stop on a 401, Ctrl+C while connected, Ctrl+C while waiting.
  • bun run typecheck, bun run build and bun test (316 pass, 0 fail) are clean.
  • Live against the production stream through bee proxy: killing the proxy mid-stream produced "Reconnecting in 1s, 2s, 4s" on stderr, the stream resumed when the proxy came back, and Ctrl+C exited with code 0. Released 0.7.3 exited on the same drop and wrote its usage text to stdout.

🤖 Generated with Claude Code

bee stream connected once and exited on any drop or timeout, then wrote
its usage text to stdout, corrupting --json output. It now reconnects on
transient failures with 1s to 30s backoff, stops on other HTTP errors and
on Ctrl+C (connected or waiting), and sends reconnect notices to stderr
in --json and --agent mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant