broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        if k in last and t - last[k] <= window:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 15',
   [[[12, 'b', 'f', 'off'], [21, 'b', 'f', 'off'], [1, 'a', 'f', 'on']], 10],
   [2, 0]),
  ('exposure stream sample 56',
   [[[0, 'b', 'g', 'off'],
     [1, 'a', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [13, 'b', 'f', 'off'],
     [17, 'a', 'g', 'on'],
     [21, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [23, 'b', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4, 6, 7])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3]),
  ('exposure stream sample 17',
   [[[6, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [22, 'b', 'f', 'off'],
     [10, 'a', 'f', 'on'],
     [9, 'b', 'f', 'off'],
     [23, 'a', 'g', 'off'],
     [9, 'b', 'f', 'off'],
     [2, 'b', 'g', 'on']],
    5],
   [7, 0, 4, 3, 1, 2, 5]),
  ('exposure stream sample 28',
   [[[8, 'b', 'f', 'off'],
     [9, 'a', 'f', 'on'],
     [14, 'b', 'g', 'on'],
     [17, 'b', 'f', 'off'],
     [22, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 4])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 22',
   [[[7, 'a', 'g', 'off'],
     [0, 'a', 'g', 'on'],
     [9, 'b', 'g', 'on'],
     [16, 'a', 'g', 'off'],
     [5, 'a', 'g', 'off']],
    0],
   [1, 4, 0, 2, 3]),
  ('exposure stream sample 51',
   [[[2, 'a', 'f', 'on'],
     [10, 'a', 'g', 'off'],
     [15, 'a', 'f', 'off'],
     [19, 'b', 'f', 'off'],
     [22, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: events[j][0]):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        if k in last and t - last[k] < window - 1:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 15',
   [[[12, 'b', 'f', 'off'], [21, 'b', 'f', 'off'], [1, 'a', 'f', 'on']], 10],
   [2, 0]),
  ('exposure stream sample 56',
   [[[0, 'b', 'g', 'off'],
     [1, 'a', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [13, 'b', 'f', 'off'],
     [17, 'a', 'g', 'on'],
     [21, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [23, 'b', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4, 6, 7])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 12',
   [[[7, 'a', 'f', 'off'],
     [13, 'a', 'g', 'off'],
     [3, 'a', 'g', 'off'],
     [4, 'a', 'f', 'on'],
     [3, 'a', 'g', 'off']],
    10],
   [2, 3, 0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3]),
  ('exposure stream sample 17',
   [[[6, 'a', 'g', 'on'],
     [22, 'b', 'g', 'off'],
     [22, 'b', 'f', 'off'],
     [10, 'a', 'f', 'on'],
     [9, 'b', 'f', 'off'],
     [23, 'a', 'g', 'off'],
     [9, 'b', 'f', 'off'],
     [2, 'b', 'g', 'on']],
    5],
   [7, 0, 4, 3, 1, 2, 5]),
  ('exposure stream sample 28',
   [[[8, 'b', 'f', 'off'],
     [9, 'a', 'f', 'on'],
     [14, 'b', 'g', 'on'],
     [17, 'b', 'f', 'off'],
     [22, 'a', 'g', 'on']],
    10],
   [0, 1, 2, 4])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 22',
   [[[7, 'a', 'g', 'off'],
     [0, 'a', 'g', 'on'],
     [9, 'b', 'g', 'on'],
     [16, 'a', 'g', 'off'],
     [5, 'a', 'g', 'off']],
    0],
   [1, 4, 0, 2, 3]),
  ('exposure stream sample 51',
   [[[2, 'a', 'f', 'on'],
     [10, 'a', 'g', 'off'],
     [15, 'a', 'f', 'off'],
     [19, 'b', 'f', 'off'],
     [22, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    10],
   [0, 1, 2, 3, 4])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Hourly exposure refresh drifts because the event at exactly one window is dropped.

events are [t, user, flag, variant] processed in timestamp order (stable for ties). An exposure is emitted unless the same (user, flag, variant) was emitted less than window seconds earlier; suppressed events do not move the window. Return emitted indices in processing order.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in range(len(events)):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        if k in last and t - last[k] < window:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 10',
   [[[20, 'a', 'f', 'off'], [12, 'b', 'g', 'off'], [11, 'a', 'g', 'off']], 0],
   [2, 1, 0]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 19',
   [[[0, 'b', 'f', 'on'], [20, 'b', 'g', 'on'], [4, 'a', 'f', 'off']], 10],
   [0, 2, 1]),
  ('exposure stream sample 27',
   [[[23, 'b', 'g', 'on'], [16, 'b', 'f', 'on'], [18, 'a', 'g', 'off']], 0],
   [1, 2, 0])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3]),
  ('exposure stream sample 27',
   [[[23, 'b', 'g', 'on'], [16, 'b', 'f', 'on'], [18, 'a', 'g', 'off']], 0],
   [1, 2, 0]),
  ('exposure stream sample 38',
   [[[5, 'b', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [1, 'b', 'g', 'off'],
     [7, 'b', 'g', 'off'],
     [11, 'b', 'f', 'off'],
     [14, 'a', 'g', 'on'],
     [21, 'b', 'g', 'off'],
     [5, 'b', 'f', 'off']],
    0],
   [2, 0, 7, 3, 1, 4, 5, 6])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 35',
   [[[11, 'a', 'f', 'off'],
     [16, 'a', 'g', 'off'],
     [4, 'b', 'g', 'on'],
     [15, 'b', 'f', 'off'],
     [14, 'a', 'f', 'off'],
     [13, 'b', 'f', 'on'],
     [11, 'a', 'f', 'on'],
     [0, 'a', 'g', 'on']],
    0],
   [7, 2, 0, 6, 5, 4, 3, 1]),
  ('exposure stream sample 49',
   [[[22, 'a', 'f', 'on'], [2, 'b', 'g', 'off'], [0, 'b', 'g', 'on']], 10],
   [2, 1, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(events, window):
    last = {}
    out = []
    for i in sorted(range(len(events)), key=lambda j: (events[j][1], events[j][0])):
        t, user, flag, variant = events[i]
        k = (user, flag, variant)
        if k in last and t - last[k] < window:
            continue
        last[k] = t
        out.append(i)
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('variant change emits immediately', [[[0, 'a', 'f', 'on'], [1, 'a', 'f', 'off']], 10], [0, 1]),
  ('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 1',
   [[[2, 'a', 'f', 'on'],
     [2, 'b', 'g', 'on'],
     [9, 'a', 'g', 'on'],
     [14, 'b', 'g', 'off'],
     [18, 'a', 'g', 'off'],
     [21, 'b', 'f', 'off'],
     [21, 'b', 'f', 'on'],
     [24, 'a', 'f', 'off']],
    5],
   [0, 1, 2, 3, 4, 5, 6, 7]),
  ('exposure stream sample 2',
   [[[21, 'a', 'f', 'off'],
     [8, 'a', 'g', 'off'],
     [3, 'a', 'f', 'off'],
     [9, 'b', 'f', 'on'],
     [21, 'a', 'g', 'on'],
     [24, 'b', 'g', 'off'],
     [20, 'b', 'f', 'on']],
    0],
   [2, 1, 3, 6, 0, 4, 5])],
 [('different flags are tracked separately', [[[0, 'a', 'f', 'on'], [1, 'a', 'g', 'on']], 10], [0, 1]),
  ('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 10',
   [[[20, 'a', 'f', 'off'], [12, 'b', 'g', 'off'], [11, 'a', 'g', 'off']], 0],
   [2, 1, 0]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3])],
 [('suppressed events do not extend the window',
   [[[0, 'a', 'f', 'on'], [8, 'a', 'f', 'on'], [12, 'a', 'f', 'on']], 10],
   [0, 2]),
  ('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('exposure stream sample 11',
   [[[10, 'b', 'g', 'on'], [19, 'b', 'g', 'off'], [9, 'b', 'f', 'on'], [16, 'a', 'f', 'on']], 10],
   [2, 0, 3, 1]),
  ('exposure stream sample 19',
   [[[0, 'b', 'f', 'on'], [20, 'b', 'g', 'on'], [4, 'a', 'f', 'off']], 10],
   [0, 2, 1]),
  ('exposure stream sample 27',
   [[[23, 'b', 'g', 'on'], [16, 'b', 'f', 'on'], [18, 'a', 'g', 'off']], 0],
   [1, 2, 0])],
 [('duplicate inside a re-anchored window is suppressed',
   [[[0, 'a', 'f', 'on'], [12, 'a', 'f', 'on'], [15, 'a', 'f', 'on'], [25, 'a', 'f', 'on']], 10],
   [0, 1, 3]),
  ('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('exposure stream sample 16',
   [[[4, 'a', 'g', 'off'],
     [21, 'a', 'g', 'off'],
     [20, 'a', 'g', 'off'],
     [23, 'b', 'g', 'on'],
     [19, 'b', 'f', 'on'],
     [22, 'b', 'f', 'on'],
     [10, 'b', 'f', 'on']],
    0],
   [0, 6, 4, 2, 1, 5, 3]),
  ('exposure stream sample 27',
   [[[23, 'b', 'g', 'on'], [16, 'b', 'f', 'on'], [18, 'a', 'g', 'off']], 0],
   [1, 2, 0]),
  ('exposure stream sample 38',
   [[[5, 'b', 'g', 'on'],
     [10, 'a', 'f', 'off'],
     [1, 'b', 'g', 'off'],
     [7, 'b', 'g', 'off'],
     [11, 'b', 'f', 'off'],
     [14, 'a', 'g', 'on'],
     [21, 'b', 'g', 'off'],
     [5, 'b', 'f', 'off']],
    0],
   [2, 0, 7, 3, 1, 4, 5, 6])],
 [('one second before the window closes is suppressed',
   [[[0, 'b', 'g', 'off'], [9, 'b', 'g', 'off']], 10],
   [0]),
  ('exactly one window later emits again', [[[0, 'a', 'f', 'on'], [10, 'a', 'f', 'on']], 10], [0, 1]),
  ('events are processed in time order',
   [[[12, 'a', 'f', 'on'], [0, 'a', 'f', 'on'], [5, 'b', 'f', 'on']], 10],
   [1, 2, 0]),
  ('zero window never suppresses', [[[0, 'a', 'f', 'on'], [0, 'a', 'f', 'on']], 0], [0, 1]),
  ('users are tracked separately',
   [[[0, 'a', 'f', 'on'], [1, 'b', 'f', 'on'], [2, 'a', 'f', 'on']], 5],
   [0, 1]),
  ('exposure stream sample 21',
   [[[4, 'a', 'g', 'on'],
     [5, 'a', 'g', 'on'],
     [22, 'a', 'f', 'off'],
     [4, 'a', 'g', 'on'],
     [19, 'a', 'f', 'off'],
     [8, 'a', 'g', 'on'],
     [11, 'a', 'f', 'off']],
    5],
   [0, 6, 4]),
  ('exposure stream sample 35',
   [[[11, 'a', 'f', 'off'],
     [16, 'a', 'g', 'off'],
     [4, 'b', 'g', 'on'],
     [15, 'b', 'f', 'off'],
     [14, 'a', 'f', 'off'],
     [13, 'b', 'f', 'on'],
     [11, 'a', 'f', 'on'],
     [0, 'a', 'g', 'on']],
    0],
   [7, 2, 0, 6, 5, 4, 3, 1]),
  ('exposure stream sample 49',
   [[[22, 'a', 'f', 'on'], [2, 'b', 'g', 'off'], [0, 'b', 'g', 'on']], 10],
   [2, 1, 0])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Late-arriving older events are emitted after newer ones and suppress the wrong exposures.

events are [t, user, flag, variant] processed in timestamp order (stable for ties). An exposure is emitted unless the same (user, flag, variant) was emitted less than window seconds earlier; suppressed events do not move the window. Return emitted indices in processing order.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 48',
   [[1, 5, 25, 100], [[0, 500], [0.01, 500], [0.01, 50], [0.024, 99], [0.05, 50], [0, 100]]],
   [100, 'complete', [5, 25, 25, 25, 25, 100]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 23',
   [[10, 50, 100], [[0.01, 500], [0.024, 99], [0, 50]]],
   [50, 'ramping', [50, 50, 50]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if rate > 0.02 and sample > 0:
            state = 'rolled_back'
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 48',
   [[1, 5, 25, 100], [[0, 500], [0.01, 500], [0.01, 50], [0.024, 99], [0.05, 50], [0, 100]]],
   [100, 'complete', [5, 25, 25, 25, 25, 100]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 23',
   [[10, 50, 100], [[0.01, 500], [0.024, 99], [0, 50]]],
   [50, 'ramping', [50, 50, 50]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A single early error among a handful of requests rolls back a healthy launch.

stages is an increasing list of percentages; the ramp starts at stages[0]. Each check [error_rate, sample] is processed in order: after a rollback everything stays at 0; a sample below 100 holds the current stage; an error rate above 0.02 rolls back to 0 permanently; otherwise advance one stage (staying at the last). State is complete at the last stage, rolled_back after a rollback, else ramping. Return [final percent, state, percent after each check].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 7',
   [[10, 50, 100], [[0, 50], [0, 50], [0.05, 99], [0.02, 50]]],
   [10, 'ramping', [10, 10, 10, 10]]),
  ('guardrail sample 19',
   [[5, 100], [[0, 100], [0.05, 50], [0.024, 500], [0.01, 100], [0.024, 50]]],
   [0, 'rolled_back', [100, 100, 0, 0, 0]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 39',
   [[10, 50, 100], [[0, 500], [0.024, 500], [0.02, 99], [0.024, 99]]],
   [0, 'rolled_back', [50, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 57',
   [[1, 5, 25, 100], [[0.024, 500], [0.024, 99], [0.02, 99]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            state = 'ramping'
            idx = 0
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 7',
   [[10, 50, 100], [[0, 50], [0, 50], [0.05, 99], [0.02, 50]]],
   [10, 'ramping', [10, 10, 10, 10]]),
  ('guardrail sample 19',
   [[5, 100], [[0, 100], [0.05, 50], [0.024, 500], [0.01, 100], [0.024, 50]]],
   [0, 'rolled_back', [100, 100, 0, 0, 0]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 39',
   [[10, 50, 100], [[0, 500], [0.024, 500], [0.02, 99], [0.024, 99]]],
   [0, 'rolled_back', [50, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 57',
   [[1, 5, 25, 100], [[0.024, 500], [0.024, 99], [0.02, 99]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
After an automatic rollback the ramp quietly climbs back up without human review.

stages is an increasing list of percentages; the ramp starts at stages[0]. Each check [error_rate, sample] is processed in order: after a rollback everything stays at 0; a sample below 100 holds the current stage; an error rate above 0.02 rolls back to 0 permanently; otherwise advance one stage (staying at the last). State is complete at the last stage, rolled_back after a rollback, else ramping. Return [final percent, state, percent after each check].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate >= 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 28',
   [[5, 100], [[0.02, 500], [0.01, 500], [0.01, 50], [0.024, 500], [0.024, 500]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0]]),
  ('guardrail sample 31',
   [[100], [[0.05, 99], [0.01, 50], [0.02, 500], [0.02, 100], [0.01, 500], [0.05, 500]]],
   [0, 'rolled_back', [100, 100, 100, 100, 100, 0]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 46', [[5, 100], [[0.01, 50], [0.02, 100]]], [100, 'complete', [5, 100]]),
  ('guardrail sample 51',
   [[1, 5, 25, 100], [[0.05, 99], [0.05, 99], [0.02, 100], [0.05, 99], [0.024, 500], [0.01, 100]]],
   [0, 'rolled_back', [1, 1, 5, 5, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 18',
   [[10, 50, 100], [[0.024, 500], [0.05, 50], [0.02, 100], [0.02, 500], [0.05, 500], [0.024, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 28',
   [[5, 100], [[0.02, 500], [0.01, 500], [0.01, 50], [0.024, 500], [0.024, 500]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 40',
   [[1, 5, 25, 100], [[0.02, 100], [0.01, 500], [0.024, 100], [0, 99], [0.02, 500], [0.01, 500]]],
   [0, 'rolled_back', [5, 25, 0, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if round(rate, 2) > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('guardrail sample 3', [[1, 5, 25, 100], [[0.05, 99], [0.05, 500]]], [0, 'rolled_back', [1, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 28',
   [[5, 100], [[0.02, 500], [0.01, 500], [0.01, 50], [0.024, 500], [0.024, 500]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0]]),
  ('guardrail sample 31',
   [[100], [[0.05, 99], [0.01, 50], [0.02, 500], [0.02, 100], [0.01, 500], [0.05, 500]]],
   [0, 'rolled_back', [100, 100, 100, 100, 100, 0]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 46', [[5, 100], [[0.01, 50], [0.02, 100]]], [100, 'complete', [5, 100]]),
  ('guardrail sample 51',
   [[1, 5, 25, 100], [[0.05, 99], [0.05, 99], [0.02, 100], [0.05, 99], [0.024, 500], [0.01, 100]]],
   [0, 'rolled_back', [1, 1, 5, 5, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 18',
   [[10, 50, 100], [[0.024, 500], [0.05, 50], [0.02, 100], [0.02, 500], [0.05, 500], [0.024, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 28',
   [[5, 100], [[0.02, 500], [0.01, 500], [0.01, 50], [0.024, 500], [0.024, 500]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 40',
   [[1, 5, 25, 100], [[0.02, 100], [0.01, 500], [0.024, 100], [0, 99], [0.02, 500], [0.01, 500]]],
   [0, 'rolled_back', [5, 25, 0, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Launches sitting exactly at the tolerated 2 percent error rate are rolled back.

stages is an increasing list of percentages; the ramp starts at stages[0]. Each check [error_rate, sample] is processed in order: after a rollback everything stays at 0; a sample below 100 holds the current stage; an error rate above 0.02 rolls back to 0 permanently; otherwise advance one stage (staying at the last). State is complete at the last stage, rolled_back after a rollback, else ramping. Return [final percent, state, percent after each check].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        history.append(stages[idx])
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 20', [[1, 5, 25, 100], [[0, 100], [0, 100], [0, 50]]], [25, 'ramping', [5, 25, 25]]),
  ('guardrail sample 24',
   [[1, 5, 25, 100], [[0.01, 50], [0.01, 100], [0.02, 500], [0.024, 99], [0.01, 99], [0, 50]]],
   [25, 'ramping', [1, 5, 25, 25, 25, 25]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 32',
   [[10, 50, 100], [[0.01, 99], [0.01, 500], [0, 500], [0.02, 100], [0.024, 50], [0.02, 500]]],
   [100, 'complete', [10, 50, 100, 100, 100, 100]]),
  ('guardrail sample 39',
   [[10, 50, 100], [[0, 500], [0.024, 500], [0.02, 99], [0.024, 99]]],
   [0, 'rolled_back', [50, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 46', [[5, 100], [[0.01, 50], [0.02, 100]]], [100, 'complete', [5, 100]]),
  ('guardrail sample 59',
   [[1, 5, 25, 100], [[0.02, 50], [0.01, 100], [0.024, 50], [0.024, 50], [0.05, 99], [0.05, 50]]],
   [5, 'ramping', [1, 5, 5, 5, 5, 5]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 23',
   [[10, 50, 100], [[0.01, 500], [0.024, 99], [0, 50]]],
   [50, 'ramping', [50, 50, 50]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[min(idx + 1, len(stages) - 1)])
    final = 0 if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 20', [[1, 5, 25, 100], [[0, 100], [0, 100], [0, 50]]], [25, 'ramping', [5, 25, 25]]),
  ('guardrail sample 24',
   [[1, 5, 25, 100], [[0.01, 50], [0.01, 100], [0.02, 500], [0.024, 99], [0.01, 99], [0, 50]]],
   [25, 'ramping', [1, 5, 25, 25, 25, 25]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 32',
   [[10, 50, 100], [[0.01, 99], [0.01, 500], [0, 500], [0.02, 100], [0.024, 50], [0.02, 500]]],
   [100, 'complete', [10, 50, 100, 100, 100, 100]]),
  ('guardrail sample 39',
   [[10, 50, 100], [[0, 500], [0.024, 500], [0.02, 99], [0.024, 99]]],
   [0, 'rolled_back', [50, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 46', [[5, 100], [[0.01, 50], [0.02, 100]]], [100, 'complete', [5, 100]]),
  ('guardrail sample 59',
   [[1, 5, 25, 100], [[0.02, 50], [0.01, 100], [0.024, 50], [0.024, 50], [0.05, 99], [0.05, 50]]],
   [5, 'ramping', [1, 5, 5, 5, 5, 5]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 23',
   [[10, 50, 100], [[0.01, 500], [0.024, 99], [0, 50]]],
   [50, 'ramping', [50, 50, 50]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
Audit history shows the percentage before each advance, hiding when the ramp reached full traffic.

stages is an increasing list of percentages; the ramp starts at stages[0]. Each check [error_rate, sample] is processed in order: after a rollback everything stays at 0; a sample below 100 holds the current stage; an error rate above 0.02 rolls back to 0 permanently; otherwise advance one stage (staying at the last). State is complete at the last stage, rolled_back after a rollback, else ramping. Return [final percent, state, percent after each check].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 7',
   [[10, 50, 100], [[0, 50], [0, 50], [0.05, 99], [0.02, 50]]],
   [10, 'ramping', [10, 10, 10, 10]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 18',
   [[10, 50, 100], [[0.024, 500], [0.05, 50], [0.02, 100], [0.02, 500], [0.05, 500], [0.024, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 31',
   [[100], [[0.05, 99], [0.01, 50], [0.02, 500], [0.02, 100], [0.01, 500], [0.05, 500]]],
   [0, 'rolled_back', [100, 100, 100, 100, 100, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 40',
   [[1, 5, 25, 100], [[0.02, 100], [0.01, 500], [0.024, 100], [0, 99], [0.02, 500], [0.01, 500]]],
   [0, 'rolled_back', [5, 25, 0, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(stages, checks):
    idx = 0
    history = []
    state = 'ramping' if len(stages) > 1 else 'complete'
    for rate, sample in checks:
        if state == 'rolled_back':
            history.append(0)
            continue
        if sample < 100:
            history.append(stages[idx])
            continue
        if rate > 0.02:
            state = 'rolled_back'
            history.append(0)
            continue
        idx = min(idx + 1, len(stages) - 1)
        if idx == len(stages) - 1:
            state = 'complete'
        history.append(stages[idx])
    final = stages[0] if state == 'rolled_back' else stages[idx]
    return [final, state, history]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 1', [[1, 5, 25, 100], [[0.01, 50], [0.02, 50], [0.024, 50]]], [1, 'ramping', [1, 1, 1]]),
  ('guardrail sample 2',
   [[1, 5, 25, 100], [[0.024, 100], [0.01, 99], [0.05, 500]]],
   [0, 'rolled_back', [0, 0, 0]])],
 [('rollback is terminal',
   [[1, 5, 25, 100], [[0.05, 500], [0, 500], [0, 500]]],
   [0, 'rolled_back', [0, 0, 0]]),
  ('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 6',
   [[100], [[0.024, 99], [0.01, 99], [0.02, 500], [0.024, 500], [0.01, 50], [0.024, 100]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 7',
   [[10, 50, 100], [[0, 50], [0, 50], [0.05, 99], [0.02, 50]]],
   [10, 'ramping', [10, 10, 10, 10]])],
 [('error rate exactly at threshold advances', [[10, 50, 100], [[0.02, 500]]], [50, 'ramping', [50]]),
  ('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('guardrail sample 11',
   [[100], [[0.05, 100], [0.024, 50], [0.02, 50], [0.02, 99], [0.05, 50], [0.05, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]]),
  ('guardrail sample 12', [[10, 50, 100], [[0.02, 100]]], [50, 'ramping', [50]]),
  ('guardrail sample 18',
   [[10, 50, 100], [[0.024, 500], [0.05, 50], [0.02, 100], [0.02, 500], [0.05, 500], [0.024, 50]]],
   [0, 'rolled_back', [0, 0, 0, 0, 0, 0]])],
 [('error rate just above threshold rolls back', [[10, 50, 100], [[0.024, 500]]], [0, 'rolled_back', [0]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 16',
   [[5, 100], [[0.01, 50], [0.02, 50], [0.024, 100], [0.02, 50], [0.024, 500]]],
   [0, 'rolled_back', [5, 5, 0, 0, 0]]),
  ('guardrail sample 17', [[5, 100], [[0.05, 500], [0.01, 99]]], [0, 'rolled_back', [0, 0]]),
  ('guardrail sample 31',
   [[100], [[0.05, 99], [0.01, 50], [0.02, 500], [0.02, 100], [0.01, 500], [0.05, 500]]],
   [0, 'rolled_back', [100, 100, 100, 100, 100, 0]])],
 [('low-sample breach only holds', [[1, 5, 25, 100], [[0.5, 20], [0, 500]]], [5, 'ramping', [1, 5]]),
  ('history records the stage after advancing',
   [[1, 5, 25, 100], [[0, 500], [0, 500]]],
   [25, 'ramping', [5, 25]]),
  ('final percent after rollback is zero', [[5, 100], [[0, 500], [0.1, 500]]], [0, 'rolled_back', [100, 0]]),
  ('single stage is complete from the start', [[100], [[0, 50]]], [100, 'complete', [100]]),
  ('rollback after completion',
   [[10, 50, 100], [[0, 500], [0, 500], [0.03, 500]]],
   [0, 'rolled_back', [50, 100, 0]]),
  ('guardrail sample 21',
   [[5, 100], [[0.024, 99], [0, 100], [0.02, 99], [0.01, 50], [0.02, 50], [0.02, 100]]],
   [100, 'complete', [5, 100, 100, 100, 100, 100]]),
  ('guardrail sample 22',
   [[100], [[0.01, 100], [0.05, 99], [0.01, 100], [0.05, 100], [0, 500], [0.01, 50]]],
   [0, 'rolled_back', [100, 100, 100, 0, 0, 0]]),
  ('guardrail sample 40',
   [[1, 5, 25, 100], [[0.02, 100], [0.01, 500], [0.024, 100], [0, 99], [0.02, 500], [0.01, 500]]],
   [0, 'rolled_back', [5, 25, 0, 0, 0, 0]])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The summary claims the feature is still at 25 percent after it was rolled back.

stages is an increasing list of percentages; the ramp starts at stages[0]. Each check [error_rate, sample] is processed in order: after a rollback everything stays at 0; a sample below 100 holds the current stage; an error rate above 0.02 rolls back to 0 permanently; otherwise advance one stage (staying at the last). State is complete at the last stage, rolled_back after a rollback, else ramping. Return [final percent, state, percent after each check].

split: open-access