0076. Recurring incremental sync of linked accounts
Source:
docs/decisions/0076-recurring-account-sync.md. Generated at build time; edit the source file.
Date: 2026-11-22. Status: accepted (M5b Task S). Builds on ADR 0032 (the job queue), ADR 0035 (resumable imports), ADR 0043 (the anonymous User-Agent) and ADR-R2-16 (import, then schedule-analysis).
Context
Section titled “Context”The owner asked for “a way to poll the latest games and analyse the progress”. Until now an import ran only when something enqueued it (the CLI, the reconciler after a stale run). New games played on chess.com or Lichess never reached the coach on their own.
Decision
Section titled “Decision”- A recurring
sync-accountsjob (worker, with the reconciler). Each linked account (anaccount_linksrow, or the CLI’slinked_accounts.user_id) is synced about once perSYNC_INTERVAL_MINUTES(default 30, at least 1). The job recurs every sixth of the interval. A tick enqueues incremental imports for the due accounts: no live import job, and the newestimport_runs.started_atmore thaninterval - tickago (or none). The longest-waiting go first, at mostceil(linked / 6)per tick, so the accounts spread over the interval instead of reaching the platforms in a burst. A new interval moves the live job’srecur_everyat the next start. - Dedupe. Sync imports keep the
import:<account>dedupe key, so an account never has two live imports. Games upsert withON CONFLICT DO NOTHING, so a sync never re-imports, resets or re-analyses a stored game. - Incremental imports.
ImportAccountPayload.incremental(JSONincremental: true, omitted when false) fetches only games newer than the cursor’snewestSeenAt. chess.com reads only the monthly archives from that month on. Lichess sendssince=. An open backfill frontier is left to a full import. A Lichess sync re-checks 1 day below the watermark, except on the account’s first sync of a UTC day (last_synced_atbefore today), which keeps the 30-day look-back for correspondence games that finish late. A full import is unchanged. - Politeness. Sync imports run on the import runner (2 at a time) through the shared
per-platform clients, throttles, 429
Retry-Afterhandling, breakers and the fixedchess-improver/0.1 (+https://github.com/chess-improver)User-Agent. No email is sent. - Analysis and events. The import enqueues
schedule-analysisas before, and the analyses’ profile hook enqueuesbuild-profile. Each run publishes the account-scopedimport.progressevents (checkpoints, thendone: true), andjob.failedwhen it fails for good. The analyses publishgame.analysed, and build-profile publishesprofile.updatedandweakness.changed. - Manual “Sync now”. The web enqueues the same job (
import-account, payload{"accountId": "<id>", "incremental": true}, dedupe keyimport:<id>, user key the account id, priority 100, max attempts 3), limited to once per 2 minutes per account.
Consequences
Section titled “Consequences”- With 30 minutes, an active account costs one chess.com archive request, or one small Lichess stream, per half hour, plus one 30-day Lichess re-check a day.
- Every sync publishes an
import.progressevent even with no new games, so the web can show “synced just now”. - A correspondence game created before the day’s re-check window and finishing more than 30 days later is still missed, as before. A full import catches it.