Skip to content

fix: recover missing daily snapshot once at sync start, so one missed day can't freeze all data (#377) - #386

Open
vedant7007 wants to merge 1 commit into
codepvg:mainfrom
vedant7007:fix/recover-missing-snapshot-377
Open

fix: recover missing daily snapshot once at sync start, so one missed day can't freeze all data (#377)#386
vedant7007 wants to merge 1 commit into
codepvg:mainfrom
vedant7007:fix/recover-missing-snapshot-377

Conversation

@vedant7007

Copy link
Copy Markdown

What & why

In scripts/sync-leaderboard.js, processTimeframe() loads the daily snapshot from exactly daysAgo back (1/7/30). If that one file is missing, the catch rethrows and the top-level catch calls process.exit(1)before changes.json and the entire per-user update loop. So a single missing historical snapshot (a missed cron day, or <30 days of history) means no user gets history/streak/rank updates, while overall.json is already written so the board looks healthy.

Approach (per @jagdish-15's suggestion on the issue)

Recover the missing snapshot once, up front, rather than special-casing each timeframe:

  • New ensureSnapshot(DATA_DIR, daysAgo): after today's snapshot is written, for each required look-back it checks the expected daily/ file; if missing, it finds the latest available earlier snapshot, copies it into the missing date's filename, and logs:
    WARNING: Snapshot for 2026-07-24 is missing
    Created a fallback snapshot using 2026-07-23
    
  • processTimeframe is left unchanged — it can now assume its baseline exists — keeping weekly/monthly logic simple and letting the sync always reach changes.json + the per-user updates.
  • Fallback order: latest snapshot before the missing date → else the oldest available (insufficient history) → else the current snapshot just written this run (fresh repo → zero deltas), so it never crashes.

Test

Added a focused test of the selection logic covering: missing date → latest prior, present file → no-op, target older than all history → oldest available, and fresh-repo → current snapshot. All pass. node --check clean.

Closes #377

A single missing look-back snapshot (missed cron day, or <30 days of
history) made processTimeframe rethrow and the top-level catch call
process.exit(1) — before changes.json and the per-user update loop. So
every user's history/streak/rank froze while overall.json still looked
healthy.

Per maintainer guidance, recover once up front instead of special-casing
each timeframe: after today's snapshot is written, ensureSnapshot() checks
each required look-back (1/7/30d) and, if missing, copies the latest
available earlier snapshot into place with a warning. processTimeframe is
left untouched — it can assume its baseline exists — so weekly/monthly
logic stays simple and the sync always reaches changes.json + user updates.
A fresh repo with no earlier history falls back to the current snapshot
(zero deltas) rather than crashing.

Closes codepvg#377
@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write . before requesting a review.
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

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.

[Data-integrity] One missing daily snapshot aborts entire sync — all profile/streak/rank writes skipped

1 participant