Skip to content

fix(client): back off reconnects when the stream never connects - #48161

Open
holny wants to merge 1 commit into
anomalyco:v2from
holny:auth-401-reconnect
Open

fix(client): back off reconnects when the stream never connects#48161
holny wants to merge 1 commit into
anomalyco:v2from
holny:auth-401-reconnect

Conversation

@holny

@holny holny commented Sep 9, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #47062

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The event-stream client retried on a fixed one-second delay regardless of why the stream died, so an unauthenticated browser session re-triggered the Basic auth prompt every second while the shell sat there unauthenticated. Streams that never connected successfully now scale the retry delay with the attempt count up to 30 seconds, which gives the browser prompt time to be answered; streams that connected and later dropped reset the attempt counter and keep the existing one-second retry.

The failure reason is intentionally not inspected — a declared 401 with an empty body surfaces client-side as an indistinguishable ClientError("UnsupportedContentType"), and the never-connected case is the one that needs the guard regardless of cause.

How did you verify your code works?

  • New test/solid-connection.test.ts: a 401-empty-response API under a real clock — reconnect attempts stay monotonically increasing across 400ms and the inter-attempt gaps grow (no backoff would produce ~20 attempts, backoff produces ~7)
  • reconnectBackoffDelay unit cases for scaling, the 30s cap, and the attempt-0 floor
  • bun typecheck + full packages/client suite (152 passing)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Supersedes #47204 — the PR head fork was accidentally deleted on 2026-09-09 (not intentional, see the notification comment there); re-filing so the review can continue. Original conversation: #47204

The event-stream client retried on a fixed one-second delay no matter why the stream died, so an unauthenticated browser session re-triggered the Basic auth prompt every second. Streams that never connected successfully now scale the delay with the attempt count up to 30 seconds; streams that connected and later dropped keep the existing one-second retry.
@github-actions

github-actions Bot commented Sep 9, 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.

@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found a related PR that may be addressing a similar issue:

PR #48015: fix(app): back off event stream reconnects after repeated failures
#48015

This PR also deals with backing off event stream reconnects, but it's scoped to the app package rather than the client package. The current PR (48161) is in packages/client and focuses on scaling retry delays when streams never connect successfully. You should verify whether PR #48015 already addresses this issue or if it's a complementary fix for a different scope.

Note: PR #47204 mentioned in the description as being superseded appears to have had its fork deleted, so it's not showing up in current searches.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant