Skip to content

Recover quiz delivery to phones on bad wifi and quiet slides - #9

Merged
irinanazarova merged 3 commits into
mainfrom
recover-quiz-delivery
Oct 15, 2026
Merged

irinanazarova merged 3 commits into
mainfrom
recover-quiz-delivery

Conversation

@irinanazarova

@irinanazarova irinanazarova commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

At the October 9 talk, attendees scanned the QR code while the presenter stayed on a results slide. Two votes came in, and many phones stayed on "Waiting for the next question".

Causes

  • Since 0.7.0, a phone depends only on the stream history for the current state. A failed sync request cleared the presenter's keepalive and never rescheduled it, so the history could go empty.
  • Sync requests could overlap and deliver an older state last.
  • The AnyCable client's default reconnect backoff doubles with no ceiling.
  • A reconnect whose handshake never completes stays "connecting" forever, with no further attempt. Overloaded wifi produces exactly this: the access point accepts the connection, then drops everything.
  • Every window that opens the deck creates a presenter, including a second tab or an attendee reading the published slides. Each of them sent its own state when a vote arrived, which could move every phone back to "Waiting".

Changes

Presenter

  • Only a deck window that has put a question on screen (or restored one after a reload) broadcasts.
  • One sync request in flight, always with the latest state.
  • State changes go out within 200ms.
  • A 10s timeout and backoff retries up to 10s.
  • A resend when a phone joins or the presenter's connection returns, at most every 2s, so phones joining at once share one resend.
  • A 60s keepalive, also on regular slides, so the five-minute stream history always holds the current state.
  • Each broadcast carries a seq that survives a presenter reload, so phones drop older broadcasts. quiz-sync (Netlify and Vercel) forwards it.

Phones

  • Reconnect delays of 0.5–1s, then 1–2s, then 1.5–3s.
  • A handshake with no answer within 6s is abandoned and retried. Later attempts get 8s, so a slow but working connection still completes.
  • Only the last message of a history replay is applied, so an older question no longer flashes on screen first.
  • One [slide-quiz:connection] console line per connection event.

Testing

  • Unit tests (149) cover:
    • failed, rejected and hung requests
    • overlap, and votes that would otherwise postpone the broadcast indefinitely
    • quiet minutes, broadcast ordering and seq across reloads
    • phones joining and leaving
    • deck windows that never showed a question
    • backoff and the connection log
  • New npm run test:integration: a phone against a real anycable-go, through a proxy that stalls or refuses connections. It's skipped when anycable-go isn't installed.
Scenario 0.7.1 This branch
Phone joins a quiet results slide Question shown in under 300ms Question shown in about 155ms
Phone first opens on stalled wifi Not measured Shows the question 7.5–8.1s after the wifi returns
30s of stalled wifi Never recovers Recovers in 5.3–9.7s
20s of refused connections (Node only; browsers fail these at once) Never recovers Recovers in 0.4–10s

The same scenarios in headless Chromium:

  • 30s of stalled wifi: 0.7.1 never recovers; this branch shows the new question 6.2s after the wifi returns.
  • 20s of refused connections: 0.7.1 takes 17.2s to recover; this branch takes 1.7s.

The proxy blocks stalled connections forever. On real wifi, a hanging attempt usually completes by itself once packets flow again, so these numbers are the worst case.

After merge

Phones could stay on "Waiting for the next question" while the presenter
sat on a results slide. Since 0.7.0 phones rely on stream history, but a
failed sync request stopped the presenter's keepalive, and concurrent
requests could deliver an older state last.

Presenter: one sync request in flight with the latest state, a 10s
timeout, backoff retries up to 10s, a resend on presence changes and
reconnects, and a 60s keepalive that keeps the stream history current.
Broadcasts carry a seq so phones drop older ones.

Phones: reconnect delays capped at 3s, a 6s timeout on handshakes that
never complete (the AnyCable client otherwise stays "connecting" with no
further attempt), only the last message of a history replay is applied,
and one [slide-quiz:connection] console line per connection event.

npm run test:integration runs a phone against a real anycable-go
through a proxy that stalls or refuses connections.
…hake timing

Every window that opens the deck runs a presenter manager, including a
second tab or anyone reading the published slides. Each of them sent its
own state when a vote arrived, and with the keepalive and presence
resends they would have done so every minute and on every join, moving
phones back to "Waiting". A window now broadcasts only after it has put
a question on screen, or restored one after a reload.

- Sync scheduling is one function that derives the next request from
  the last one: state changes after 200ms, resends with nothing changed
  after 2s, retries with backoff, otherwise the keepalive.
- The presenter resends only when a phone joins, so a room joining at
  once shares one or two requests and leaves trigger none.
- The broadcast seq is saved with the presenter state, so it keeps
  increasing after a reload even if the clock moved back.
- A handshake gets 6s, then 8s after an abandoned attempt, so a slow but
  working connection still completes. The check runs every 500ms.
- The reconnect attempt line now follows the "lost" line in the log.
- Integration test for a phone that first opens on stalled wifi.
@irinanazarova
irinanazarova merged commit 123c340 into main Oct 15, 2026
2 checks passed
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