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

2 commits

Author SHA1 Message Date
Chris Parsons
a4317815f7 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
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-06 00:25:23 -07:00
Chris Parsons
a91c108393 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
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>
2026-06-06 00:19:02 -07:00