Fix draft timer display drifting due to server-client clock skew #74

Merged
chrisp merged 2 commits from fix/timer-clock-skew into main 2026-06-06 07:30:45 +00:00
Owner

Summary

  • The countdown display used data.expiresAt (server-side Unix timestamp) subtracted from client Date.now(). When the server clock runs ~2-3s ahead of the client (observed in production), the display was inflated by that delta.
  • Fixes three linked symptoms: timer starting at 2:02 instead of 2:00, chess-clock increment crediting 1:54 instead of 1:55, and the commissioner's adjust-time-bank dialog disagreeing with the visible countdown.
  • Fix: replace all server expiresAt timestamps with a client-local expiry from the server-provided timeRemaining integer (Date.now() + timeRemaining * 1000). The skew then cancels algebraically when the server computes credit.

Sites changed

  • handleTimerPickStarted — fires after every pick (the main fix)
  • handleDraftStateSync — reconnect path
  • useState initializer in the draft room — initial page load seed from loader data (uses loaderTimerNow server timestamp to compute remaining server-side, then re-anchors to client clock)

Test plan

  • Start a chess-clock draft (2:00 bank, 15s increment) — timer should show exactly 2:00 when a team goes on the clock
  • Pick at 1:40 — new bank should show 1:55 (100 + 15s)
  • Commissioner adjust-time-bank dialog — displayed remaining should match the countdown
  • Force autopick at any displayed time T — new bank should be T + increment
  • Reconnect mid-pick — timer should resume at the correct remaining time

🤖 Generated with Claude Code

## Summary - The countdown display used `data.expiresAt` (server-side Unix timestamp) subtracted from `client Date.now()`. When the server clock runs ~2-3s ahead of the client (observed in production), the display was inflated by that delta. - Fixes three linked symptoms: timer starting at 2:02 instead of 2:00, chess-clock increment crediting 1:54 instead of 1:55, and the commissioner's adjust-time-bank dialog disagreeing with the visible countdown. - Fix: replace all server `expiresAt` timestamps with a client-local expiry from the server-provided `timeRemaining` integer (`Date.now() + timeRemaining * 1000`). The skew then cancels algebraically when the server computes credit. ## Sites changed - `handleTimerPickStarted` — fires after every pick (the main fix) - `handleDraftStateSync` — reconnect path - `useState` initializer in the draft room — initial page load seed from loader data (uses `loaderTimerNow` server timestamp to compute remaining server-side, then re-anchors to client clock) ## Test plan - [ ] Start a chess-clock draft (2:00 bank, 15s increment) — timer should show exactly **2:00** when a team goes on the clock - [ ] Pick at 1:40 — new bank should show **1:55** (100 + 15s) - [ ] Commissioner adjust-time-bank dialog — displayed remaining should match the countdown - [ ] Force autopick at any displayed time T — new bank should be T + increment - [ ] Reconnect mid-pick — timer should resume at the correct remaining time 🤖 Generated with [Claude Code](https://claude.com/claude-code)
chrisp added 1 commit 2026-06-06 07:19:38 +00:00
Fix draft timer display drifting due to server-client clock skew
Some checks failed
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m35s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Failing after 1m15s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
a91c108393
The countdown display used data.expiresAt (a server-side Unix timestamp)
subtracted from client Date.now(). When the server clock is ahead of the
client by ~2-3s (observed in production), the display inflated by that
delta — causing 2:02 instead of 2:00 on pick start, short-crediting the
chess clock increment, and the commissioner's adjust-time-bank dialog
disagreeing with the visible countdown.

Fix: replace all server expiresAt timestamps with a client-local expiry
computed from the server-provided timeRemaining integer
(Date.now() + timeRemaining * 1000). The skew then cancels algebraically:
server_remaining = server_expiresAt - pickMadeAt
                 = (client_schedule + Δ + bank*1000) - (client_pick + Δ)
                 = client_expiresAt - client_pick  ✓

Three sites updated: handleTimerPickStarted, handleDraftStateSync
(reconnect), and the initial useState seed from loader data.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp added 1 commit 2026-06-06 07:25:28 +00:00
Fix TS error: narrow picksExpiresAt via optional chain guard
All checks were successful
🚀 Deploy / 🧪 Test (pull_request) Successful in 2m33s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Successful in 1m21s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped
a4317815f7
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
chrisp merged commit 079ecec129 into main 2026-06-06 07:30:45 +00:00
chrisp deleted branch fix/timer-clock-skew 2026-06-06 07:30:46 +00:00
Sign in to join this conversation.
No description provided.