Skip to content

fix(web): back off events ticket retries while the server is down - #5593

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/5569-events-ticket-backoff
Nov 30, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/5569-events-ticket-backoff

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #5569
Related issue: N/A
Validation tasks: changes #1235 C2 (Notifications — Web), whose live delivery rides the events socket. The normal connect path is unchanged; only the wait after a failed mint or a dropped socket changes.

Other clients: Apple N/A (its home watch-state events socket already doubles its retry from 1 to 30 seconds); Android N/A (already backs off from 1 to 30 seconds); Roku N/A (home watch socket already doubles its retry up to a cap)

While Silo is unreachable, a web tab asks for a new events-socket ticket (POST /api/v2/events/ws-ticket) every second until the server comes back. In the issue that came to 120 requests in two minutes from one tab during a restart. The web app now waits longer after each failure in a row, takes a random part off each wait so dropped tabs don't all come back in the same second, and never retries sooner than a refused mint's Retry-After.

Approach

The events provider's reconnect wait now starts at 1 second and doubles to 30 seconds. Jitter takes up to half of each wait off. A Retry-After on a refused mint sets the minimum wait, capped at 60 seconds, as the playback-control socket already does. The count of failures resets when a socket receives hello, so a socket that drops after a healthy session reconnects within a second, as before. Close codes that already set their own wait keep it: 4001 reconnects at once, 4002 waits 30 seconds, 4004 waits 5 seconds, and the profile_required rebind keeps its 5-minute backoff.

docs/realtime-api.md now states the web app's events reconnect timing, which it did not before.

The playback-control socket keeps its own step table and gets no jitter here. A shared helper for both sockets would be a separate change.

Validation

  • Provider tests: the wait grows from 1 to 30 seconds and stays there; jitter can shorten a wait by up to half; Retry-After holds the next mint back; a socket that gets hello resets the wait. All 47 tests in the file pass.
  • Local build with the production web bundle in headless Chromium: ticket mints blocked with a 502 for 60 seconds, and separately the server process stopped for 60 seconds. Results are below.
  • After the outage, the next mint succeeds and the socket gets hello, subscribed and snapshot.
  • Web: pnpm run lint, pnpm run format:check, tsc -p tsconfig.app.json, pnpm run build, pnpm run budget:check, make test-web pass.
  • make verify-local-paths, make verify-size-ratchet, make verify-bidi, make verify-case-collisions pass. The Go checks were not run because no Go code changed.

Evidence

Nothing on screen changes. These are the ticket requests a logged-in tab sent during each 60-second outage, on the same local build and data before and after the fix.

Ticket mint answered 502 for 60 s
  before: 60 requests, 1.006 s apart throughout (30 in the first 30 s, 30 in the second)
  after:  7 requests at t=0.09, 0.78, 1.86, 5.08, 10.93, 25.37, 49.28 s

Server process stopped for 60 s
  before: 54 requests, ERR_CONNECTION_REFUSED, about 1.00 s apart from t=6.0 s to t=59.2 s
  after:  6 requests at t=5.92, 7.29, 9.62, 15.15, 24.70, 50.21 s
          first successful mint 7.2 s after the server was started again

Risks

After a long outage, a tab can take up to 30 seconds to reconnect once the server is back, or 60 seconds when the server sent a longer Retry-After. Before this change it took about a second. Live updates in that tab catch up when it reconnects.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI, GitHub CLI, Playwright (headless Chromium)
  • Model(s): claude-opus-5-5; gpt-6.2-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: dual-code-review of the full diff (Codex and a Claude subagent, each reviewing correctness, standards and spec). No correctness bugs. Fixed: the docs sentence on close-code waits now names each code's wait, and a code comment's request-rate estimate now accounts for jitter. Dismissed: returning to a tab after the hidden-tab grace period can send one mint before an earlier Retry-After runs out. That is one request per return to the tab, not a retry loop, and older versions behaved the same way. Left as is: the Retry-After cap rule now exists in both socket hooks, which use different step tables on purpose.

Note

Add jittered exponential backoff for events ticket retries in RealtimeEventsProvider

  • Failed ticket mints and socket connections now back off exponentially from 1s up to a 30s cap, with jitter that can shrink a wait by up to half. A server-supplied Retry-After is honored up to a 60s cap when it exceeds the computed delay.
  • Receiving hello resets the failure count, so a later disconnect retries with the initial 1-second wait. Explicit reconnect delays still take precedence.
  • Adds tests for the backoff schedule, jitter, Retry-After handling, and hello-based reset in RealtimeEventsProvider.test.tsx, and documents the retry behavior in realtime-api.md.

Macroscope summarized 9654010.

A failed events-socket ticket mint was retried every second for as long
as the server stayed unreachable. The wait now doubles from 1 to 30
seconds with jitter, honours a refused mint's Retry-After (capped at 60
seconds), and starts over once a socket receives hello.

Closes Silo-Server#5569
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 29, 2026
@silo-kody

silo-kody Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Realtime Events provider now uses exponential backoff with jitter for reconnects and ticket-mint failures. It honors mint retry delays and resets the retry counter after hello. Tests cover retry timing, and the documentation describes retry and close-code behavior.

Changes: Realtime reconnect retries

Layer / File(s) Summary
Reconnect backoff and retry behavior
web/src/components/RealtimeEventsProvider.tsx, web/src/components/RealtimeEventsProvider.test.tsx, docs/realtime-api.md
The provider adds exponential reconnect delays with jitter and honors ticket-mint retry delays. Tests cover backoff, jitter, Retry-After, and resetting after a successful connection. The documentation describes retry timing and close-code behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant RealtimeEventsProvider
  participant TicketMintEndpoint
  participant RealtimeSocket
  RealtimeEventsProvider->>TicketMintEndpoint: Request socket ticket
  TicketMintEndpoint-->>RealtimeEventsProvider: Mint failure and optional Retry-After
  RealtimeEventsProvider->>RealtimeEventsProvider: Schedule retry with backoff and retry floor
  RealtimeEventsProvider->>TicketMintEndpoint: Retry ticket request
  TicketMintEndpoint-->>RealtimeEventsProvider: Ticket
  RealtimeEventsProvider->>RealtimeSocket: Connect
  RealtimeSocket-->>RealtimeEventsProvider: hello
  RealtimeEventsProvider->>RealtimeEventsProvider: Reset reconnect failure count
Loading

Suggested reviewers: quick104, blurbery

Merge Risk: Minimal · up to 96540

This change slows repeated reconnect attempts when the server is unavailable and respects a Retry-After from the server. After a long outage, reconnection can take up to 30 seconds, or 60 seconds with a longer Retry-After. No merge-blocking risk was found.

Security architecture risk: Low · up to 96540

Failed connections back off during a sustained outage, and access rules are unchanged. The remaining risk is narrow: if connections repeatedly drop just after the server greets them, tabs can request tickets faster than before.

Retained concerns

  • Low · reliability · inferred: A connection that repeatedly reaches hello and then immediately drops never accumulates backoff. Each cycle can retry in about 0.5–1 second instead of the prior fixed one second, increasing ticket traffic across affected web tabs while the service is partially recovering. The increase is bounded per tab; fleet impact depends on the prevalence and speed of post-hello drops.
Security review details

Security Blast Radius

  • inferred — The changed input is a response from the existing ticket mint endpoint, and its new effect is limited to the timing of the next generic retry in that web tab. The shared endpoint can see aggregate load changes, but the delay does not grant access or change the scope of the ticket.

Trust Boundaries and Controls

  • observed — The mint helper checks captured authority before the request and again before returning the ticket. The provider ignores stale mint results and socket messages from an inactive authority or a superseded socket. Delaying the retry does not bypass those checks.

Resilience and Maintainability Implications

  • observed — The documented Retry-After floor applies to scheduled retries, not to a fresh effect. Pausing and resuming the provider can cancel a pending wait and start a fresh mint under the same authority. Immediate minting on restart already existed at the merge base, so this limits the new load protection rather than introducing a faster restart path.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: adding exponential backoff to events-socket ticket retries while the server is unavailable. It is specific and matches the changeset (RealtimeEventsProvider reconnect …
Linked Issues check Passed Directly linked issue #5569 requires (1) a growing retry delay for failed events-socket ticket requests, (2) jitter, and (3) no retry before a server-provided Retry-After. The reviewed diff of web/src…
Out of Scope Changes check Passed Changes at the reviewed head are the events-provider backoff logic, its provider tests, and a docs/realtime-api.md update describing the web events reconnect timing. Each change supports objective #55…
Description check Passed The description is specific and on-topic. It states the problem (repeated events-socket ticket requests every second during server outages), the approach (exponential backoff from 1s to 30s, jitter up…
Full details: Title check

Explanation

The title names the main change: adding exponential backoff to events-socket ticket retries while the server is unavailable. It is specific and matches the changeset (RealtimeEventsProvider reconnect backoff, Retry-After handling, docs, and tests). It uses the conventional fix(web) prefix and is one short sentence.

Full details: Linked Issues check

Explanation

Directly linked issue #5569 requires (1) a growing retry delay for failed events-socket ticket requests, (2) jitter, and (3) no retry before a server-provided Retry-After. The reviewed diff of web/src/components/RealtimeEventsProvider.tsx implements each one. Constants RECONNECT_BASE_DELAY_MS (1 s), RECONNECT_MAX_DELAY_MS (30 s) and reconnectDelayMs() double the step per failure and apply random downward jitter of up to half. The ticket-mint catch path now calls scheduleReconnect(v2RetryDelayMs(error, 0)). The result is floored with Math.max against min(retryAfterMs, 60 s), applied after jitter, so the wait never falls below a refused mint's Retry-After. reconnectFailures resets to 0 on hello. Explicit close-code waits (nextReconnectDelayRef) still take precedence. The docs and test changes are supporting evidence. The raw summary reports provider tests for growth, jitter, Retry-After and hello reset; I did not run them. The objective is met by code at the reviewed head.

Full details: Out of Scope Changes check

Explanation

Changes at the reviewed head are the events-provider backoff logic, its provider tests, and a docs/realtime-api.md update describing the web events reconnect timing. Each change supports objective #5569. The docs and tests are supporting changes for the backoff. The diff of RealtimeEventsProvider.tsx does not modify the playback-control socket step table, the close-code constants, or the profile_required backoff, consistent with the PR description. No unrelated change was identified in the reviewed evidence. The test file and docs were assessed from the summary only, not from a full read.

Full details: Description check

Explanation

The description is specific and on-topic. It states the problem (repeated events-socket ticket requests every second during server outages), the approach (exponential backoff from 1s to 30s, jitter up to half of each wait, Retry-After honored up to 60s, reset on hello), the preserved close-code waits, the validation steps with results, and the risks. It fully matches the changeset described in the raw summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 54bcc00a-063a-4c22-aaaa-c13f7a3bbb70
Commits

Reviewing files that changed from the base of the PR and between 5d0006f and 9654010.

Files selected for processing: 3

  • docs/realtime-api.md
  • web/src/components/RealtimeEventsProvider.test.tsx
  • web/src/components/RealtimeEventsProvider.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@silo-triage silo-triage Bot added bug Something isn't working priority: P2 Limited scope, workaround exists, or polish triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Nov 29, 2026
@Quick104

Copy link
Copy Markdown
Contributor

/silo review

Reviewed head: 96540101d30f50510570632bca29a135102a1a1b

Fit: 9/10 · Readiness: 9/10 — ready

The fix holds up. While the ticket mint fails, the web events socket now backs off from 1 s to 30 s with jitter instead of retrying every second. I reproduced the storm on the PR's base and saw it gone on the head. I found no defect to fix and pushed no commits.

Verification

  • Live, on a sandbox: I built it from the base (5d0006f6), then rebuilt it from this head. A signed-in headless browser had every POST /api/v2/events/ws-ticket answered with an HTML 502 for 60 seconds from page load.
    • Base: 60 mints, 1.00 s apart.
    • Head: 7 mints, with gaps of 0.98, 1.2, 3.8, 4.6, 12.5 and 26.9 s, which fits the jittered 1/2/4/8/16/30 s steps.
    • Recovery: once the block lifted, the head's next mint came 6.8 s later, and the socket got hello, subscribed and snapshot.
    • Console: on both builds it showed only the intercepted 502s.
  • Tests: the four new tests fail on the base for the reported reason (20 mints in 20 s against Retry-After: 20) and pass on the head. The whole file (47 tests) passed six runs in a row on the head with real Math.random. tsc and eslint are clean.
  • Safety read: the diff touches three files, with no build, dependency or script changes, and contains nothing that runs on install.

Evidence: https://evidence.siloserver.org/r/silo-server/pr-5593/

What I checked and left as is

  • A socket that gets hello and then closes still reconnects within about a second; jitter shortens that wait to 0.5–1 s. This is the documented intent, and the base retried every second in the same case. I don't know of a server path that loops this way.
  • Close codes that set their own wait (4001, 4002, 4004, profile rebind) still bump the failure count. A mint failure right after one waits a 2 s step instead of 1 s, which is harmless.
  • A Retry-After floor isn't jittered, and only the delta-seconds form is honored, as request.ts already parses it. The server's own handlers send delta-seconds.
  • Returning to a tab after the hidden-tab grace period can send one mint before an earlier Retry-After runs out. The PR body already discloses this. It costs one request per return to the tab, not a loop.
  • The playback-control socket keeps its own unjittered step table. A shared helper for both sockets is out of scope here, as the PR says.

Validation

changes #1235 C2 (Notifications — Web). Live delivery rides this socket. Only the wait after a failure changes, and nothing regresses. No other passed case is affected. I updated the PR body's line to this wording.

Other clients and docs

  • Apple: N/A. Its home watch-state events socket already doubles from 1 to 30 s, so I corrected the PR body's "no events socket" reason.
  • Android: N/A. It already backs off from 1 to 30 s in HomeRealtimeCoordinator and NotificationsRepository.
  • Roku: N/A, as the PR states.
  • docs/realtime-api.md: matches the code. It documents client timing only and changes no /api/v2 wire contract.
  • User manual: unaffected.

Council

One round on this head, every member at medium effort:

  • Sol (gpt-6.2-sol, attack): 8.5/10. It raised two low points. One is the hidden-tab return case the PR already discloses. The other is that the docs don't say Retry-After must be in seconds, which is consistent with how request.ts treats the HTTP-date form. I left both as is.
  • Opus (claude-opus-5-5, cut): 9/10. No findings. It found no simpler approach and no existing helper that covers this.
  • Gemini (gemini-4-neon, check): 9/10. It flagged a test-teardown pattern that would only matter for a future test added without the spy, so no change. It also noted that the Watch Together room socket has its own short, unjittered retry table, which is outside this PR.

Kody and CodeRabbit left no inline findings.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 29054db into Silo-Server:main Nov 30, 2026
20 checks passed
Quick104 pushed a commit to rangoDJ/silo-server that referenced this pull request Nov 30, 2026
Main changed RealtimeEventsProvider.tsx and its tests (Silo-Server#5593) since this
branch's merge base.

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

bug Something isn't working priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Web app retries a failed events-socket ticket request every second, with no backoff, while the server is down

2 participants