Skip to content

fix(serving): a stream that can't reconcile backs off instead of reconnecting every half second - #780

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/777-backoff-resets-on-reconcile
Oct 18, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/777-backoff-resets-on-reconcile

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

The shell reset its reconnect backoff on every hello. When a host accepts a document's stream but every subscription POST fails, each reconnect gets a fresh hello, so the delay never got past its first step. This happens with a persistent misroute (the POSTs are refused as a current-generation loss) or a 429 on every POST. A document that couldn't reconcile reopened its stream every 0.25–0.5 s for as long as it stayed open, and each reopen cost the server a stream open and a resolve.

Fix

  • The backoff starts over only when a stream reconciles. This is the shell's existing reconciled state: the latest sequence is admitted and every subscription is answered. It's the same boundary that re-arms perf(serving): a stream lost to a misrouted subscription reconnects at once #776's immediate reconnect. A hello only proves the GET landed somewhere.
  • A persistent misroute or rate limit now backs off. The delay doubles from 500 ms to its 30 s cap, jittered down to as little as half.
  • perf(serving): a stream lost to a misrouted subscription reconnects at once #776's one immediate reconnect is unchanged. It still doesn't count as a failure.
  • The session-refresh budget still resets on hello. A hello proves the refreshed session was accepted, and that's what the budget guards. Moving the reset to reconciliation would let a long unreconciled streak use up the three refreshes across ordinary token expiries. The stream would then stop refreshing and loop on 401s.
  • Unchanged:
    • a successful refresh still reconnects at once and adds no failure;
    • generation fencing;
    • the tier 2 bind deadline, which still takes the later of the two delays.
  • ADR-0010 now records when the backoff resets.

Tests

stream.spec.ts runs with the page clock paused. An init script records the page clock at each stream open and at each abort, so every reconnect delay is exact. The test sorts each delay into its backoff step: the nth failure in a row waits between 250·2ⁿ and 500·2ⁿ ms.

Test Steps on this branch On main
Every POST misrouted (409 invalid_request); a stream admitted with its answers held is lost; one reconciles; misrouted again at once, 0, 1, 2, 3, 4, then at once, 0 at once, 0, 0, 0, 0, 0, at once, 0
Every POST 429; a stream admitted with its answers held is lost; one reconciles; 429 again 0, 1, 2, 3, 4, then 0 all 0
A session refresh in the middle of a 429 streak 0, 1, at once (the refresh), 2 0, 0, at once, 0

The step after the admitted stream (4, not 0) pins the boundary: resetting on admitted rather than on reconciliation fails both scenario tests.

All three fail on main and pass here. The session test also checks that:

  • the refresh happens exactly once;
  • it reconnects without a timer;
  • no notice is shown.

#776's tests and the existing session tests are unchanged and pass.

pnpm verify passes locally: format, lint, typecheck, synth, the offline tests, postgres-concurrency, cli-smoke, tier2-smoke and browser (80 tests). The new tests and #776's main test also passed 5 runs each. The follow-up test commit passes the stream spec (28 tests) and pnpm check.

Numbers

Setup:

  • a local brightline instance, opening Kudos (tier 1) as a persona;
  • a temporary, uncommitted hook in RuntimeStream.update that refused every subscription POST;
  • stream opens counted in Chromium over 30 s from the first open.
Every POST refused as main this branch
StreamReplaced (misroute) 78 reconnects, 264–521 ms apart 7 reconnects: 37 ms (the immediate one), then 370, 872, 1284, 2788, 5165 and 13019 ms
RateLimited (429) 82 reconnects, 262–507 ms apart 6 reconnects: 463, 639, 1697, 2122, 7061 and 12282 ms

Over 150 s of misroute on this branch, the gaps reach the cap: 17.0, 19.4, 15.1, 24.1 and 25.6 s. Without the hook, Kudos and New Business (tier 2) each open one stream and their POSTs return 200.

Closes #777

Made by Claude Opus 5.5 via Claude Code; reviewed with GPT-6.1-Sol.

…nnecting every half second

The shell reset its reconnect backoff on every `hello`. A stream whose
subscription POSTs keep failing, misrouted or rate limited, gets a fresh
`hello` on each reconnect, so it reopened every 250-500 ms forever.

The backoff now starts over only when a stream reconciles, the boundary
that already re-arms #776's immediate reconnect. The refresh budget
still resets on `hello`, which proves the session was accepted.

Closes #777

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added area:server Touches the server area area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines labels Oct 18, 2026
A stream that admits its replace while its answers are held hasn't
reconciled, so losing it keeps the grown delay; the next stream that gets
its answers starts the streak over. Resetting on `admitted` now fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 7694bab into main Oct 18, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the fix/777-backoff-resets-on-reconcile branch October 18, 2026 23:22
allisonmahmood added a commit that referenced this pull request Oct 19, 2026
…ng Reconnecting (#783)

Release 14's What's new entry, written from \`7694bab\`. It covers
everything merged since release 13's \`through\` (\`c9b8fc4\`), and sets
the \`patchy\` release to \`0.14.0\` (\`packages/patchy/package.json\`
and \`CURRENT_RELEASE\`).

| Change | PRs |
| --- | --- |
| Improved: Tools with server code answer faster | #756, #764, #768,
#769, #771, #772, #773, #775, #778 |
| Improved: Your company's tools and pages open sooner | #759, #761,
#766, #770 |
| Fixed: Tools stop flashing Reconnecting while they load | #755, #776,
#780 |
| Improved: Publishing is quicker | #729 |
| Improved: New tools start with a tidy layout | #763 |
| Improved: Your usual is easier to scan | #721 |
| Fixed: A page that isn't there says what to do | #762 |
| Fixed: A logo Patchy can't read is refused, not a crash | #728 |
| Behind the scenes: richer logs for live data | #758 |

#720 is release 13's own entry, so it's left out.

Made by Claude Opus 5.5 via Claude Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area area:server Touches the server area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A stream that can't reconcile reconnects every half second forever

1 participant