One Frame Behind Forever

Hard

· Frontend

Incident

SEV-2

Time to fix: 35 min

Failing checks on the shipped build

  • underfunded frames do not run

    15ms cannot fund a 16ms frame: expected [0, 15] but got [1, -1]

  • full frames run with exact remainder

    expected [2, 8] but got [3, -8]

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

Game engines

Inspired by the fixed-timestep game loops described in every "Fix Your Timestep!" postmortem: the accumulator pattern must run whole simulation frames and carry the exact remainder. Round instead of floor, and the simulation runs frames it hasn't earned — leaving a negative time debt that compounds into stutter.

GameLoop.java computes frames-to-run from the accumulator.

Code map

class GameLoop {
    static int[] framesToRun(int accumulatorMs, int frameMs) {
        int frames = Math.round((float) accumulatorMs / frameMs);
        int remainder = accumulatorMs - frames * frameMs;
        return new int[] { frames, remainder };
    }
}

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.

One Frame Behind Forever — Java Bug Hunt

Inspired by the fixed-timestep game loops described in every "Fix Your Timestep!" postmortem: the accumulator pattern must run whole simulation frames and…

  • Language: Java
  • Layer: Frontend
  • Difficulty: Hard
  • Concepts: Game Loops, Rounding
  • Modelled on: Game engines
  • Visible tests: underfunded frames do not run; full frames run with exact remainder; exact multiples leave zero remainder
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2
  • Time to fix: 35 minutes, the target for a hard incident

Failing checks on the shipped build

  • underfunded frames do not run — 15ms cannot fund a 16ms frame: expected [0, 15] but got [1, -1]
  • full frames run with exact remainder — expected [2, 8] but got [3, -8]

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 fixed-timestep game loops described in every "Fix Your Timestep!" postmortem: the accumulator pattern must run whole simulation frames and carry the exact remainder. Round instead of floor, and the simulation runs frames it hasn't earned — leaving a negative time debt that compounds into stutter.

GameLoop.java computes frames-to-run from the accumulator.

Bug report

BUG-TIMESTEP · Reported by: engine team

framesToRun(accumulatorMs, frameMs) -> int[]{frames, remainderMs}:

  • frames = floor(accumulator / frame) — only FULLY funded frames
  • remainder = accumulator - frames * frame (always 0 <= r < frame)

Observed: 15ms of accumulated time runs a 16ms frame — remainder -1ms. The debt snowballs and the camera micro-stutters forever.

Logs

[loop] acc=15 frame=16 -> ran 1 frame, remainder -1

The code as shipped

GameLoop.java (editable)

class GameLoop {
    static int[] framesToRun(int accumulatorMs, int frameMs) {
        int frames = Math.round((float) accumulatorMs / frameMs);
        int remainder = accumulatorMs - frames * frameMs;
        return new int[] { frames, remainder };
    }
}

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.