The Leaning Tower of Pins

Medium

· Frontend

Incident

SEV-3

Time to fix: 20 min

Failing checks on the shipped build

  • items chase the shortest column

    expected [0,1,1,0] but got [0,1,0,1]

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

Pinterest

Inspired by every masonry grid that grew one giraffe column: round-robin placement ignores item heights, so a run of tall cards stacks into the same column and the layout tips over.

masonry.js must always drop the next item into the currently shortest column (ties → lowest index).

Code map

// Assigns items (by height) to masonry columns.
exports.layout = function (heights, columns) {
  var columnHeights = [];
  for (var c = 0; c < columns; c++) columnHeights.push(0);
  var assignment = [];
  for (var i = 0; i < heights.length; i++) {
    var col = i % columns;
    assignment.push(col);
    columnHeights[col] += heights[i];
  }
  return { assignment: assignment, columnHeights: columnHeights };
};

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 Leaning Tower of Pins — JavaScript Bug Hunt

Inspired by every masonry grid that grew one giraffe column: round-robin placement ignores item heights, so a run of tall cards stacks into the same column…

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Medium
  • Concepts: Layout, Algorithms
  • Modelled on: Pinterest
  • Visible tests: items chase the shortest column; ties break to the lower index
  • 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

  • items chase the shortest column — expected [0,1,1,0] but got [0,1,0,1]

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 every masonry grid that grew one giraffe column: round-robin placement ignores item heights, so a run of tall cards stacks into the same column and the layout tips over.

masonry.js must always drop the next item into the currently shortest column (ties → lowest index).

Bug report

BUG-MASONRY · Reported by: web platform

layout(heights, columns) -> { assignment, columnHeights }:

  • each item goes to the column with the smallest current height
  • ties break toward the lower column index

Observed: round-robin puts item 3 in column 0 even though column 1 is 5 units shorter — after a hundred pins the page is a staircase.

Logs

[grid] column heights after 40 pins: [3120, 1180]

The code as shipped

src/grid/masonry.js (editable)

// Assigns items (by height) to masonry columns.
exports.layout = function (heights, columns) {
  var columnHeights = [];
  for (var c = 0; c < columns; c++) columnHeights.push(0);
  var assignment = [];
  for (var i = 0; i < heights.length; i++) {
    var col = i % columns;
    assignment.push(col);
    columnHeights[col] += heights[i];
  }
  return { assignment: assignment, columnHeights: columnHeights };
};

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 JavaScript bug hunts.