You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Hunt Week double-counting of pre-game activities
Activities logged before game start but with loggedDate on the start date
were counted in both initialState.points and getPointsInPeriod, inflating
scores unevenly across players and distorting predator/prey outcomes.
Add startedAt to miniGames schema, store it on activation, and filter
Hunt Week period activities by _creationTime > gameStartedAt to exclude
activities already baked into the initial snapshot.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
-`initialState.points` is captured at game start time (e.g. 18:05:35 UTC on Mar 15).
14
+
-`getPointsInPeriod` counts activities where `loggedDate >= startsAt`, and `startsAt` is midnight UTC (00:00:00) on Mar 15.
15
+
- Activities logged between 00:00 UTC and 18:05 UTC on Mar 15 are already included in `initialState.points`**and** matched by the `loggedDate >= startsAt` filter — they are **double-counted**.
16
+
17
+
The magnitude varies per player (depends on how many activities they logged that morning before the game started), which distorts the Hunt Week leaderboard and can flip predator/prey outcomes.
18
+
19
+
## Fix (this PR)
20
+
21
+
-[x] Add `startedAt` field to `miniGames` schema
22
+
-[x] Store `startedAt: now` when a game transitions to `"active"`
23
+
-[x] Add `getHuntWeekPointsInPeriod()` helper that filters by `_creationTime > gameStartedAt` to exclude pre-game activities
24
+
-[x] Thread `gameStartedAt` through `getHuntWeekLeaderboard` → `calculateHuntWeekOutcomes` → `previewHuntWeekEnd`
25
+
-[x] Pass `miniGame.startedAt ?? miniGame.updatedAt` from both mutation and query callers
26
+
27
+
## Affected Data
28
+
29
+
The Mar 15-21 Hunt Week game (the only Hunt Week run so far) has already been ended. Its bonus awards were calculated with the double-counted leaderboard. Specific impacts:
30
+
31
+
- Players who logged activities the morning of Mar 15 before game start had inflated Hunt Week scores.
32
+
- This may have changed who "caught" their prey and who "was caught," affecting the +75 / -25 bonus distribution.
33
+
34
+
## Remediation Steps (Post-Merge)
35
+
36
+
After this PR is merged and deployed, a repo admin should remediate the existing Mar 15-21 game:
37
+
38
+
1.**Identify the game:** Find the Hunt Week miniGame document for Mar 15-21 in the Convex dashboard or via CLI:
39
+
```bash
40
+
npx convex run miniGames:list '{}' --prod
41
+
```
42
+
43
+
2.**Revoke existing bonus awards:** Delete the `source: "mini_game"` bonus activities that were awarded when the game ended. These are the activities with descriptions like "Hunt Week Bonus" tied to participants of this game.
44
+
45
+
3.**Backfill `startedAt`:** Patch the miniGame document to set `startedAt` to the original activation timestamp. Check the `updatedAt` field or Convex audit log for the exact time the game went active (should be ~18:05 UTC on Mar 15).
46
+
```bash
47
+
npx convex run --prod miniGames:backfillStartedAt '{"miniGameId": "<id>", "startedAt": <timestamp>}'
48
+
```
49
+
(You may need to write a small one-off mutation for this.)
50
+
51
+
4.**Re-end the game:** Set the game status back to `"active"`, then call the `end` mutation again. The new code will use `startedAt` to correctly compute the leaderboard and award bonuses without double-counting.
52
+
53
+
5.**Verify:** Compare the new outcomes against the original to confirm the fix resolves the discrepancy. Check that affected players' total points are updated correctly.
0 commit comments