Please look at online competition submission logic across division and verify that a…
- User
Please look at online competition submission logic across division and verify that a user who signs up for an individual event and a partner event that share the same workout can submit a score for each division. We have a suspicious issue where a user submitted valid scores for a partner division but those same scores are showing up on his individual registration. This issue is showing up on the preview leaderboard
Assistant
Team memory unavailable. Proceeding with codebase investigation directly.
Assistant
Let me verify these findings directly.
Assistant
Let me check the input schema and leaderboard grouping code.
Assistant
Noted — I'll keep the registration detail page in mind as I summarize.
Assistant
- User
Continue from where you left off.
- Assistant· <synthetic>
No response requested.
- User
yeah start working on this
Assistant
Now fix the input schemas + scope registration + score lookup in athlete-score-fns.ts:
Assistant
Now fix
getAthleteEventScoreFnto filter by division:Assistant
Now add the
resolveAthleteDivisionIdhelper and fixsubmitAthleteScoreFn. First check what's between 105-160 (helper region):Assistant
Now fix
submitAthleteScoreFnto scope registration by divisionId:Assistant
Now fix the "Get the final score ID" lookup after upsert to scope by scalingLevelId:
Assistant
Now fix the
/api/compete/scores/submitroute similarly. First check its post-upsert lookup:Assistant
Now inspect the other write paths:
video-submission-fns.ts,video/submit.ts,scores/judge.ts,submission-verification-fns.ts,competition-score-fns.ts:Assistant
Now check
competition-score-fns.tsandscores/judge.ts:Assistant
Check scores/judge.ts:
Assistant
Now find all remaining
competitionEventId+userIdscore lookups that need divisionId added. Let me do a broad sweep:Assistant
Good —
divisionIdis already a prop. Add it to the delete + server fn input:Assistant
Now the
video-submission-fns.ts:1703-1708andorganizer-athlete-fns.ts:1601-1604lookups:Assistant
Now the organizer-athlete-fns.ts delete lookup:
Assistant
Task 2 complete. Move to task 3 — read paths.
Assistant
Now the critical read path — the competition leaderboard's
fetchScoresand the grouping logic:Assistant
Now fix the grouping. Look at the current code around line 878-894:
Assistant
Good. Now fix the organizer athlete detail score read:
Assistant
Good —
registration.divisionIdis available. Update the scores fetch:Assistant
Good. Let me verify the scoring panel's data fetch uses divisionId too:
Assistant
Now check remaining files:
Assistant
Read paths are covered. Move to the migration step.
Assistant
Type-check clean. Now generate the migration:
Assistant
Understood — deleting the generated migration files.
Assistant
Now push schema to PlanetScale dev branch and then update lat.md:
Assistant
Writing the raw SQL.
Assistant
Now update lat.md and run
lat check:Assistant
Done. Ready for you to confirm.
SQL to run:
apps/wodsmith-start/sql/score-division-unique.sqlsqlALTER TABLE `scores` DROP INDEX `idx_scores_competition_user_unique`; ALTER TABLE `scores` ADD CONSTRAINT `idx_scores_competition_user_unique` UNIQUE (`competition_event_id`, `user_id`, `scaling_level_id`);Safe — the old 2-col unique guarantees at most one row per
(event, user), so widening to 3 cols can't create collisions.Code changes:
Assistant
lat checkpasses. Added the new#One score per athlete per event per divisioninvariant todomain.mdand cross-linked it from the existing Multi-Division Submission and Multi-Division Registration sections so future readers land on the same contract.- User
Important implementation detail surfaced: scores.competition_event_id actually stores a track_workout_id, not a competition_events.id. Factor that into the index-fix migration.
Assistant
Now update the lat.md section to reflect the real semantics:
Assistant
Factored in. The DDL is unchanged — the column name is just misleading — but I added a prominent note to both the SQL file header and the lat.md invariant so the semantics are clear:
scores.competition_event_idactually storestrack_workouts.id(every insert writesdata.trackWorkoutId).- The scope is still correct: when the same workout appears in multiple divisions via event-division mappings, both divisions reference the same
track_workoutrow, so widening the unique to(track_workout_id, user_id, scaling_level_id)is exactly what lets a multi-division athlete hold one score per division.
lat checkpasses.Assistant
Now update Results Entry:
Assistant
lat checkpasses. Added cross-references from the three organizer-facing sections that render per-division score data — the Athlete Detail Page, Leaderboard Preview, and Results Entry — each pointing at the new#One score per athlete per event per divisioninvariant so future readers land on the unique-key contract no matter which surface they're touching.- User
please commit and open a pull request. do not commit and bug reports that have sensitive data in them
Assistant
Staging everything except the bug reports and flagged file:
Assistant
PR opened: https://github.com/wodsmith/thewodapp/pull/414
The three uncommitted items left behind are the sensitive bug-report files you flagged (
docs/bug-reports/mwfc-score-overwrite-audit.md,flagged-multi-division-submissions.md,multi-division-registrations.md) — they stay local and out of the PR.