The Tweet ID JavaScript Rounded Off

Easy

· Frontend

Incident

SEV-2

BUG-IDSTR

Priority: High · reported by web client team

Time to fix: 10 min

Failing checks on the shipped build

  • a snowflake id keeps every digit

    expected "1234567890123456789" but got "1234567890123456800"

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

Twitter · 2010

Modelled on Twitter's move to Snowflake ids in 2010. Tweet ids became 64-bit integers that soon grew past 2^53, the largest integer a JavaScript number holds exactly. A client that ran the API's JSON through JSON.parse got a different, rounded id, so links and replies pointed at the wrong tweet or none. Twitter's answer was to add string copies of every id — id_str, in_reply_to_status_id_str — and tell JavaScript clients to use those.

This reconstruction's timeline view model still reads the numeric fields.

Fix toViewModel so every id comes from its string field.

Code map

// Turns one raw API payload (a JSON string) into the view model the
// timeline renders.
exports.toViewModel = function (rawJson) {
  var t = JSON.parse(rawJson);
  var id = String(t.id);
  var replyTo = t.in_reply_to_status_id == null ? null : String(t.in_reply_to_status_id);
  return {
    id: id,
    text: t.text,
    permalink: "/status/" + id,
    replyTo: replyTo
  };
};

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 Tweet ID JavaScript Rounded Off — JavaScript Bug Hunt

Modelled on Twitter's move to Snowflake ids in 2010. Tweet ids became 64-bit integers that soon grew past 2^53, the largest integer a JavaScript number…

  • Language: JavaScript
  • Layer: Frontend
  • Difficulty: Easy
  • Concepts: Parsing, Identifiers
  • Modelled on: Twitter · 2010
  • Visible tests: an early, small id renders; a snowflake id keeps every digit
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-IDSTR
  • Reported by: web client team
  • Time to fix: 10 minutes, the target for an easy incident

Failing checks on the shipped build

  • a snowflake id keeps every digit — expected "1234567890123456789" but got "1234567890123456800"

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

Modelled on Twitter's move to Snowflake ids in 2010. Tweet ids became 64-bit integers that soon grew past 2^53, the largest integer a JavaScript number holds exactly. A client that ran the API's JSON through JSON.parse got a different, rounded id, so links and replies pointed at the wrong tweet or none. Twitter's answer was to add string copies of every id — id_str, in_reply_to_status_id_str — and tell JavaScript clients to use those.

This reconstruction's timeline view model still reads the numeric fields.

Fix toViewModel so every id comes from its string field.

Bug report

BUG-IDSTR · Priority: High · Reported by: web client team

toViewModel(rawJson) returns { id, text, permalink, replyTo }:

  • id is the tweet's id_str, exactly as sent
  • permalink is "/status/" + id
  • replyTo is in_reply_to_status_id_str, or null when that is null/absent
  • a payload without a digits-only id_str string is malformed: throw

Observed: tweet 1234567890123456789 renders a permalink to /status/1234567890123456800, which is somebody else's tweet (or a 404).

Logs

[timeline] GET /status/1234567890123456800 -> 404
[timeline] reply target 1498765432109876543 not found in thread

The code as shipped

src/timeline/tweets.js (editable)

// Turns one raw API payload (a JSON string) into the view model the
// timeline renders.
exports.toViewModel = function (rawJson) {
  var t = JSON.parse(rawJson);
  var id = String(t.id);
  var replyTo = t.in_reply_to_status_id == null ? null : String(t.in_reply_to_status_id);
  return {
    id: id,
    text: t.text,
    permalink: "/status/" + id,
    replyTo: replyTo
  };
};

Read-only context: src/timeline/NUMBERS.js.

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.