The Leaderboard Shuffle

Medium

· Frontend

Incident

SEV-3

Time to fix: 20 min

Failing checks on the shipped build

  • ties keep arrival order

    zoe scored first: expected [bob, zoe, amy] but got [bob, amy, zoe]

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Live-ops games

Inspired by the leaderboard-flicker tickets every game studio collects: players with equal scores swap places on every refresh. Ties must preserve the order they arrived in (stable sort) — but someone "helpfully" added an alphabetical tiebreak.

Leaderboard.java sorts by score, descending, stable.

Code map

import java.util.*;

class Leaderboard {
    static String[] sortByScore(String[] names, int[] scores) {
        Integer[] idx = new Integer[names.length];
        for (int i = 0; i < idx.length; i++) idx[i] = i;
        Arrays.sort(idx, new Comparator<Integer>() {
            public int compare(Integer a, Integer b) {
                if (scores[b] != scores[a]) return scores[b] - scores[a];
                return names[a].compareTo(names[b]);
            }
        });
        String[] out = new String[names.length];
        for (int i = 0; i < out.length; i++) out[i] = names[idx[i]];
        return out;
    }
}

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Leaderboard Shuffle — Java Bug Hunt

Inspired by the leaderboard-flicker tickets every game studio collects: players with equal scores swap places on every refresh.

  • Language: Java
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Sorting, Stability
  • Modelled on: Live-ops games
  • Visible tests: ties keep arrival order; scores still dominate
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-3
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • ties keep arrival order — zoe scored first: expected [bob, zoe, amy] but got [bob, amy, zoe]

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the value the screen shows back through the state and the pure helpers that compute it; the view is usually only the messenger.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Inspired by the leaderboard-flicker tickets every game studio collects: players with equal scores swap places on every refresh. Ties must preserve the order they arrived in (stable sort) — but someone "helpfully" added an alphabetical tiebreak.

Leaderboard.java sorts by score, descending, stable.

Bug report

BUG-FLICKER · Reported by: live-ops

sortByScore(names, scores) -> names sorted by score DESC:

  • equal scores keep their ORIGINAL relative order (arrival order)
  • no other tiebreak, alphabetical or otherwise

Observed: "zoe" reached 50 points before "amy", but every refresh shows amy above zoe — the tiebreak reorders them.

Logs

[board] tie at 50: zoe (first) rendered below amy

The code as shipped

Leaderboard.java (editable)

import java.util.*;

class Leaderboard {
    static String[] sortByScore(String[] names, int[] scores) {
        Integer[] idx = new Integer[names.length];
        for (int i = 0; i < idx.length; i++) idx[i] = i;
        Arrays.sort(idx, new Comparator<Integer>() {
            public int compare(Integer a, Integer b) {
                if (scores[b] != scores[a]) return scores[b] - scores[a];
                return names[a].compareTo(names[b]);
            }
        });
        String[] out = new String[names.length];
        for (int i = 0; i < out.length; i++) out[i] = names[idx[i]];
        return out;
    }
}

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Java bug hunts.