Skip to content

Fix community race leaderboard showing DNF players - #144

Merged
owens1127 merged 2 commits into
mainfrom
fix-community-race-dnf
Jun 15, 2026
Merged

Fix community race leaderboard showing DNF players#144
owens1127 merged 2 commits into
mainfrom
fix-community-race-dnf

Conversation

@owens1127

@owens1127 owens1127 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Filter the pantheon community race team leaderboard player query to completed instance_player rows only, matching contest/first team leaderboards
  • No player ordering (same as other team leaderboards)

Companion PR: Raid-Hub/Services#60 (materialized view + post-merge SQL)

Test plan

  • Open /leaderboard/team/custom/pantheon-community-race and confirm cleared runs no longer show DNF players

Deploy notes

Deploying this API change fixes the displayed player list immediately. Run the post-merge SQL from the Services PR to keep search (membership_ids) in sync.

Only include completed instance_player rows and sort roster players by kills, matching other team leaderboards.

Co-authored-by: Cursor <cursoragent@cursor.com>
FROM instance_player
INNER JOIN player USING (membership_id)
WHERE instance_player.instance_id = team_pantheon_custom_race_leaderboard.instance_id
AND instance_player.completed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The JSONB_AGG for players can return NULL if all players in an entry are filtered out, but the Zod schema expects an array, causing a validation error.
Severity: HIGH

Suggested Fix

Wrap the JSONB_AGG(...) call in the SQL query with COALESCE(JSONB_AGG(...), '[]'::jsonb). This ensures that if no players match the filter, an empty array [] is returned instead of NULL, satisfying the Zod schema and preventing validation errors.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/services/leaderboard/team/custom.ts#L42

Potential issue: The SQL query filters players using `AND instance_player.completed`. If
a leaderboard entry contains only players who did not complete the activity, the
`JSONB_AGG` function will operate on an empty set and return `NULL`. However, the Zod
schema `zTeamLeaderboardEntry` defines the `players` field as a non-nullable array. When
the query result with a `NULL` `players` field is parsed, it will fail Zod validation,
resulting in an API error for requests involving such leaderboard entries. This is
likely for custom race leaderboards which may contain teams composed entirely of DNF
players.

Did we get this right? 👍 / 👎 to inform future reviews.

Drop kills ordering to match contest and first leaderboard services.

Co-authored-by: Cursor <cursoragent@cursor.com>
@barecheck

barecheck Bot commented Jun 15, 2026

Copy link
Copy Markdown

Barecheck - Code coverage report

Total: 91.42%

Your code coverage diff: 0.00% ▴

Uncovered files and lines
FileLines
src/services/leaderboard/team/custom.ts74-80

AND instance_player.completed
) as "lateral" ON true
WHERE position > $1 AND position <= ($1 + $2)
ORDER BY position ASC`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: A temporal inconsistency between deployment and a SQL migration causes searches for DNF players to return their team but omit them from the player list, breaking tests.
Severity: MEDIUM

Suggested Fix

The issue is caused by a temporary desynchronization between the search index and the query filter. The documented solution is to run the companion SQL migration immediately after API deployment to update the membership_ids column and remove DNF players, ensuring data consistency. Alternatively, modify the deployment process to prevent the API from being live until the migration is complete.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/services/leaderboard/team/custom.ts#L44

Potential issue: A temporal data inconsistency occurs between the API deployment and a
companion SQL migration. The `searchPantheonCustomRaceTeamLeaderboard` function can find
a team using a DNF player's ID from the `membership_ids` column, which is not yet
updated. However, the `getPantheonCustomRaceTeamLeaderboard` function then filters out
this player using the new `AND instance_player.completed` clause. This results in an API
response where a team is found for a player, but that player is missing from the
returned `players` array, causing the `assertTeamSearchIncludesMembership` test to fail.

@owens1127
owens1127 merged commit 8c9fea6 into main Jun 15, 2026
7 checks passed
@owens1127
owens1127 deleted the fix-community-race-dnf branch June 15, 2026 14:06
owens1127 added a commit that referenced this pull request Jun 15, 2026
Filter to completed instance_player rows and coalesce empty player lists to [].

Co-authored-by: Cursor <cursoragent@cursor.com>
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