The Index That Rounded Itself Poor

Medium

· Backend

Incident

SEV-2

BUG-VSE-1982

Priority: High · reported by quant desk

Time to fix: 20 min

Failing checks on the shipped build

  • tiny ticks accumulate at full precision

    expected 1000.003 but got 1000.0

  • display rounds instead of truncating

    expected 1000.0 but got 999.999

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

Vancouver Stock Exchange

Inspired by the Vancouver Stock Exchange index, which truncated to three decimals after every single trade in 1982 — and quietly lost half its value in 22 months while the market went up.

index_calc.py applies deltas to the index. Precision must be kept in full and rounded only for display.

Code map

# Maintains the exchange index.

def apply_deltas(start, deltas):
    value = start
    for d in deltas:
        value = int((value + d) * 1000) / 1000
    return value

def display(value):
    return int(value * 1000) / 1000

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 Index That Rounded Itself Poor — Python Bug Hunt

Inspired by the Vancouver Stock Exchange index, which truncated to three decimals after every single trade in 1982 — and quietly lost half its value in 22…

  • Language: Python
  • Layer: Backend
  • Difficulty: Medium
  • Concepts: Floating Point, Rounding
  • Modelled on: Vancouver Stock Exchange
  • Visible tests: tiny ticks accumulate at full precision; display rounds instead of truncating; plain arithmetic still works
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-2 (priority: High)
  • Ticket: BUG-VSE-1982
  • Reported by: quant desk
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • tiny ticks accumulate at full precision — expected 1000.003 but got 1000.0
  • display rounds instead of truncating — expected 1000.0 but got 999.999

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

Inspired by the Vancouver Stock Exchange index, which truncated to three decimals after every single trade in 1982 — and quietly lost half its value in 22 months while the market went up.

index_calc.py applies deltas to the index. Precision must be kept in full and rounded only for display.

Bug report

BUG-VSE-1982 · Priority: High · Reported by: quant desk

  • apply_deltas(start, deltas): accumulate at FULL precision
  • display(value): round (not truncate!) to 3 decimals, only here

Observed: truncation inside the loop bleeds value on every update. Five +0.0006 ticks from 1000.0 should display 1000.003 — we show 1000.0.

Logs

[index] 22 months of drift: computed 524.811, true value 1098.892

The code as shipped

src/market/index_calc.py (editable)

# Maintains the exchange index.

def apply_deltas(start, deltas):
    value = start
    for d in deltas:
        value = int((value + d) * 1000) / 1000
    return value

def display(value):
    return int(value * 1000) / 1000

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