Ghost Rows in the Audit Log

Medium

· Backend

Incident

SEV-2

BUG-3341

Priority: High · reported by platform-eng

Time to fix: 20 min

Failing checks on the shipped build

  • page 1 starts at the first record

    first row of page 1: expected 1 but got 11

  • page 2 continues without overlap

    page 2 starts where page 1 ended: expected 11 but got 21

  • final partial page disables hasNext

    25 rows -> last page has 5: expected 5 but got 0

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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  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

Every admin dashboard

The audit-log API of an internal admin tool paginates records for the dashboard. Customers report that page 1 is missing the newest records, and the same rows appear on two different pages.

The Express handler and the mock data layer are locked — the bug is isolated in paginate.js, the pure helper the handler delegates to.

Make the whole suite green without touching the locked files.

Code map

// Pure pagination helper used by the audit-log handler.
// page is 1-based. Returns { skip, take, hasNext }.
exports.getPageWindow = function (page, limit, totalCount) {
  var skip = page * limit;
  var take = limit;
  var hasNext = skip + take <= totalCount;
  return { skip: skip, take: take, hasNext: hasNext };
};

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.

Ghost Rows in the Audit Log — JavaScript Bug Hunt

The audit-log API of an internal admin tool paginates records for the dashboard.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Modelled on: Every admin dashboard
  • Visible tests: page 1 starts at the first record; page 2 continues without overlap; final partial page disables hasNext
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-3341
  • Reported by: platform-eng
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • page 1 starts at the first record — first row of page 1: expected 1 but got 11
  • page 2 continues without overlap — page 2 starts where page 1 ended: expected 11 but got 21
  • final partial page disables hasNext — 25 rows -> last page has 5: expected 5 but got 0

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 request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  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

The audit-log API of an internal admin tool paginates records for the dashboard. Customers report that page 1 is missing the newest records, and the same rows appear on two different pages.

The Express handler and the mock data layer are locked — the bug is isolated in paginate.js, the pure helper the handler delegates to.

Make the whole suite green without touching the locked files.

Bug report

BUG-3341 · Priority: High · Reported by: platform-eng

The dashboard shows 10 rows per page. With 25 records in the table:

  • Page 1 starts at record #11 instead of record #1
  • Records #21–25 appear on BOTH page 2 and page 3
  • The "next page" arrow stays enabled on the final page, leading to an empty page 4

API contract (see handler.js): page is 1-based; response = { items, page, hasNext }.

Logs

GET /api/audit?page=1&limit=10 -> items[0].id = 11 (expected 1)
GET /api/audit?page=3&limit=10 -> hasNext = true (expected false)

The code as shipped

src/api/paginate.js (editable)

// Pure pagination helper used by the audit-log handler.
// page is 1-based. Returns { skip, take, hasNext }.
exports.getPageWindow = function (page, limit, totalCount) {
  var skip = page * limit;
  var take = limit;
  var hasNext = skip + take <= totalCount;
  return { skip: skip, take: take, hasNext: hasNext };
};

Read-only context: src/api/db.js, src/api/handler.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.