Skip to content

Conversation

@phlangiee
Copy link
Contributor

@phlangiee phlangiee commented Nov 24, 2025

changed to 2 judges assigned per match
to match again: then get prev pairings and not pair them, move onto next judge that isnt already paired with them

@phlangiee phlangiee linked an issue Nov 24, 2025 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request modifies the judge-to-team matching algorithm to assign 2 judges per match instead of 3, and implements logic to avoid re-pairing judges with teams they've previously evaluated. The changes retrieve existing judge-team pairings from the submissions collection and use them to prevent duplicate assignments when generating new matches.

Changes:

  • Reduced the number of judges assigned per team from 3 to 2
  • Added logic to fetch previous judge-team pairings and prevent duplicate assignments
  • Updated validation logic to reflect the new 2-judge requirement
  • Removed safety check for existing submissions to allow re-matching

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
app/(api)/_utils/matching/judgesToTeamsAlgorithm.ts Changed rounds from 3 to 2, integrated GetJudgeToTeamPairings to retrieve existing pairings, added String() conversions for ID comparison, and implemented splice logic to remove previous pairings after matching
app/(api)/_datalib/judgeToTeam/getJudgeToTeamPairings.ts New function that retrieves all existing judge-team pairings from the submissions collection and converts them to the JudgeToTeam format
app/(api)/_actions/logic/matchTeams.ts Commented out the check that prevented matching when submissions exist, added debug logging, and updated error messages
app/(api)/_actions/logic/checkMatches.ts Updated validation to require 2 judges per team instead of 3

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ReehalS ReehalS linked an issue Feb 5, 2026 that may be closed by this pull request
Also add a comment so Copilot Code Review doesn't complain again.
@ReehalS
Copy link
Member

ReehalS commented Feb 6, 2026

Seems ready to merge, will just check w copilot once

ReehalS
ReehalS previously approved these changes Feb 6, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 34 to 44
const maxRounds = 4;
const maxSubmissions = teams.length * maxRounds;
const isSecondRound = existingCount > 0;

if (existingCount >= maxSubmissions) {
return {
ok: false,
body: null,
error: `GetManyTeams error: ${teamsRes.error}`,
error:
'Two rounds have already been completed. Clear submissions to rerun.',
};
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The variable name maxRounds is misleading. It's set to 4, but it actually represents the maximum total number of judge assignments per team across multiple executions, not the number of rounds per execution (which is 2). Consider renaming to maxJudgesPerTeam or maxTotalAssignments for clarity. Additionally, the error message "Two rounds have already been completed" is confusing because it suggests two execution rounds, but the check allows for exactly that (2 executions × 2 judges per execution = 4 total). Consider changing the message to "Maximum judge assignments reached (4 judges per team). Clear submissions to rerun."

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +170
if (!previousPairings.ok || !previousPairings.body) {
throw new Error(
`Failed to load existing judge-to-team pairings: ${
previousPairings.error ?? 'Unknown error'
}`
);
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The check for !previousPairings.body is redundant and potentially confusing. When previousPairings.ok is true, the body will always be an array (empty or populated), never null. The current condition correctly handles the empty array case (no previous pairings) since an empty array is truthy. However, for clarity and type safety, consider removing the !previousPairings.body check and relying solely on !previousPairings.ok, or explicitly check for null if that's the intended behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 53 to 69
@@ -65,7 +66,7 @@ export default async function matchTeams(
return {
ok: false,
body: null,
error: 'Invalid submissions.',
error: 'Invalid submissions.2',
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The error messages 'Invalid submissions.1' and 'Invalid submissions.2' are not descriptive enough for debugging. Consider using more specific messages that explain what validation failed or include the actual error from the underlying operation. For example, 'Invalid submissions.1' could be 'Failed to create submissions in database' and include the actual error details.

Copilot uses AI. Check for mistakes.
Comment on lines 232 to 234
// Remove the previous pairings
if (previousPairings.ok && previousPairings.body) {
judgeToTeam.splice(0, previousPairings.body.length);
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

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

The splice operation that removes previous pairings from the judgeToTeam array is fragile and relies on the array maintaining insertion order. While this currently works because only push operations are used, consider a more robust approach such as tracking the index where new pairings start, or filtering out previous pairings by creating a Set of previous pairing IDs and filtering the array based on that. This would make the code more maintainable and less prone to bugs if the array manipulation logic changes in the future.

Suggested change
// Remove the previous pairings
if (previousPairings.ok && previousPairings.body) {
judgeToTeam.splice(0, previousPairings.body.length);
// Remove the previous pairings without relying on array insertion order.
if (previousPairings.ok && previousPairings.body) {
const previousPairingKeySet = new Set(
previousPairings.body.map((pairing) => {
const judgeId = String(pairing.judge_id);
const teamId = String(pairing.team_id);
return `${judgeId}::${teamId}`;
})
);
const filteredJudgeToTeam = judgeToTeam.filter((entry) => {
const judgeId = String(entry.judge_id);
const teamId = String(entry.team_id);
const key = `${judgeId}::${teamId}`;
return !previousPairingKeySet.has(key);
});
// Mutate the existing array in place so any references remain valid.
judgeToTeam.length = 0;
judgeToTeam.push(...filteredJudgeToTeam);

Copilot uses AI. Check for mistakes.
Copy link
Member

@ReehalS ReehalS left a comment

Choose a reason for hiding this comment

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

I'm not having Copilot review it again otherwise this PR will never get merged. Its comments so far have been mostly useful but doing more will lead to this getting delayed more and more

@ReehalS ReehalS merged commit 4e07acc into main Feb 6, 2026
2 checks passed
@ReehalS ReehalS deleted the fix/judge-redistribution branch February 6, 2026 05:20
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.

Judge to team algorithm: Update to a 2-batch system Fix/Judge Redistribution

2 participants