Skip to content

Fix Hunt Week double-counting of pre-game activities#247

Merged
prazgaitis merged 5 commits into
mainfrom
fix/hunt-week-double-counting-v2
Mar 28, 2026
Merged

Fix Hunt Week double-counting of pre-game activities#247
prazgaitis merged 5 commits into
mainfrom
fix/hunt-week-double-counting-v2

Conversation

@prazgaitis

@prazgaitis prazgaitis commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Hunt week leaderboard computed scores as initialState.points + getPointsInPeriod(startsAt, endsAt), but initialState.points was captured at activation time while startsAt was midnight UTC — activities between midnight and activation were double-counted
  • Replaced with getPointsUpToDate() which sums all non-deleted, non-mini-game activities with loggedDate <= endsAt — single source of truth, no date-boundary ambiguity
  • Renamed getHuntWeekLeaderboardgetMiniGameLeaderboard and exported it so any game type can use activity-based standings
  • Added audit/fix CLI (scripts/hunt-week-audit.sh) with --fix and --fix-favorable modes to remediate already-completed games
  • Supersedes Fix Hunt Week double-counting of pre-game activities #246 which proposed filtering by _creationTime (fragile — conflates document creation time with logical activity date) and required a schema change

Remediation

After merge, run against prod:

./scripts/hunt-week-audit.sh --prod                 # check discrepancies
./scripts/hunt-week-audit.sh --fix-favorable --prod  # only increase scores
./scripts/hunt-week-audit.sh --fix --prod            # fix all

Test plan

  • All 63 test files pass (761 tests)
  • Typecheck and lint pass
  • Hunt week tests updated to create backing activities instead of setting totalPoints directly
  • Run audit on prod to verify discrepancies before applying fixes

🤖 Generated with Claude Code

The hunt week leaderboard reconstructed scores as initialState.points +
getPointsInPeriod(startsAt, endsAt), but initialState.points was captured
from userChallenges.totalPoints at activation time while startsAt was
midnight UTC — activities between midnight and activation were counted in
both, inflating scores unevenly across players.

Replace the reconstruction with getPointsUpToDate() which sums all
non-deleted, non-mini-game activities with loggedDate <= endsAt. This uses
a single source of truth bounded by the game end date, eliminating both
the double-count and any post-game activity leakage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Mar 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
march-fitness-2025 Ready Ready Preview, Comment Mar 28, 2026 7:25pm

Request Review

Export the function so any mini-game type can compute activity-based
standings bounded by game end date. Drop the unused startsAt param.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds internalQuery (audit) and internalMutation (fix) to check and correct
hunt week scores that were calculated with the double-counting bug. The fix
mutation supports a favorableOnly flag to only apply corrections that
increase a player's bonus points.

Shell script provides a simple CLI:
  ./scripts/hunt-week-audit.sh              # dry run
  ./scripts/hunt-week-audit.sh --fix --prod # fix all on prod
  ./scripts/hunt-week-audit.sh --fix-favorable --prod  # only increases

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The notes now include: original vs corrected award, rank change, the
player's recalculated points and rank, prey/hunter names with their
points and whether catch/escape occurred, and a one-line explanation
of the bug. externalData also stores corrected/previous rank.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover:
- audit detects no discrepancies for correctly scored games
- audit detects discrepancies for buggy scores (simulated double-count)
- audit only returns completed hunt week games
- fix corrects all discrepant scores and creates correction notes
- fix with favorableOnly skips unfavorable corrections
- fix targets a specific game when miniGameId provided
- fix does not create bonus activity when correct bonus is 0
- fix updates totalPoints correctly after correction

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@prazgaitis prazgaitis merged commit 7e5d660 into main Mar 28, 2026
5 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