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

N = 1
observations = []
def solve(steps, now):
    order = list(range(len(steps)))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 15', [[[30, 50], [20, 120], [10, -10], [20, 5]], 30], [50, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 37', [[[60, -10], [10, None], [60, 0]], 25], [0, 1]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 54', [[[60, 0], [20, 50], [20, -10]], 60], [0, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 5', [[[45, 25], [45, 0], [30, 100], [10, 25], [45, 25]], 30], [100, 2]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3])]]
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(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][1] if steps[i][1] is not None else -1, i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 15', [[[30, 50], [20, 120], [10, -10], [20, 5]], 30], [50, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 37', [[[60, -10], [10, None], [60, 0]], 25], [0, 1]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 54', [[[60, 0], [20, 50], [20, -10]], 60], [0, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 5', [[[45, 25], [45, 0], [30, 100], [10, 25], [45, 25]], 30], [100, 2]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3])]]
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:
Appending an earlier correction step to a schedule overrides later steps.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access


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

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], -i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 29', [[[60, 100], [60, 120], [20, 25], [20, 50], [60, 75]], 60], [75, 4]),
  ('ramp schedule sample 43', [[[20, 5], [20, 0]], 20], [0, 1])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 4])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 20', [[[45, 25], [45, 75]], 45], [75, 1])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 44', [[[60, 5], [45, -10], [30, 100], [30, 50], [60, 25]], 100], [25, 4]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 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)

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(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], steps[i][1] if steps[i][1] is not None else -1))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 29', [[[60, 100], [60, 120], [20, 25], [20, 50], [60, 75]], 60], [75, 4]),
  ('ramp schedule sample 43', [[[20, 5], [20, 0]], 20], [0, 1])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 4])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 20', [[[45, 25], [45, 75]], 45], [75, 1])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 44', [[[60, 5], [45, -10], [30, 100], [30, 50], [60, 25]], 100], [25, 4]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 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:
A correction appended with the same timestamp as a mistaken step never takes effect.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access


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

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        current = min(max(pct or 0, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 43', [[[20, 5], [20, 0]], 20], [0, 1]),
  ('ramp schedule sample 58', [[[30, 25], [30, 120], [10, 120], [30, None]], 30], [100, 3])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 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(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 2', [[[20, 0], [30, 50]], 10], [0, -1]),
  ('ramp schedule sample 3', [[[30, 0], [0, None], [60, 100]], 25], [0, 1])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('ramp schedule sample 6', [[[60, 0], [30, 50], [60, 75]], 60], [75, 2]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 43', [[[20, 5], [20, 0]], 20], [0, 1]),
  ('ramp schedule sample 58', [[[30, 25], [30, 120], [10, 120], [30, None]], 30], [100, 3])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 40', [[[60, 0], [20, 25], [60, None]], 60], [0, 2]),
  ('ramp schedule sample 46', [[[30, 100], [20, 25], [30, -10], [30, 50], [30, None]], 30], [50, 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:
A schedule pause entry turns the feature off instead of holding the current percentage.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access


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

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = min(pct, 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 28', [[[60, 120], [20, 120], [45, 100], [10, 25], [0, -10]], 0], [0, 4]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 48', [[[0, -10], [60, None], [20, -10]], 60], [0, 1]),
  ('ramp schedule sample 58', [[[30, 25], [30, 120], [10, 120], [30, None]], 30], [100, 3])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 8', [[[20, -10]], 30], [0, 0]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 32', [[[60, 0], [0, -10], [20, 0]], 10], [0, 1]),
  ('ramp schedule sample 39', [[[0, 120], [30, None], [30, None], [20, -10]], 0], [100, 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(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = i
        if pct is not None:
            current = max(pct, 0)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 28', [[[60, 120], [20, 120], [45, 100], [10, 25], [0, -10]], 0], [0, 4]),
  ('ramp schedule sample 30', [[[20, 120], [10, 120], [0, 50], [20, None]], 20], [100, 3])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 48', [[[0, -10], [60, None], [20, -10]], 60], [0, 1]),
  ('ramp schedule sample 58', [[[30, 25], [30, 120], [10, 120], [30, None]], 30], [100, 3])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('ramp schedule sample 8', [[[20, -10]], 30], [0, 0]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0]),
  ('ramp schedule sample 17', [[[45, 5], [20, 120], [20, 50], [10, 100], [45, 75]], 20], [50, 2])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 32', [[[60, 0], [0, -10], [20, 0]], 10], [0, 1]),
  ('ramp schedule sample 39', [[[0, 120], [30, None], [30, None], [20, -10]], 0], [100, 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:
A mistyped -20 percent step reports a negative rollout that downstream gates treat inconsistently.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access


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

N = 1
observations = []
def solve(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for pos, i in enumerate(order):
        at, pct = steps[i]
        if at > now:
            break
        active = pos
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 24', [[[60, 100], [20, None], [20, None], [60, -10], [20, 100]], 45], [100, 4])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 48', [[[0, -10], [60, None], [20, -10]], 60], [0, 1])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 12', [[[0, 120], [10, 25], [0, 0]], 10], [25, 1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 37', [[[60, -10], [10, None], [60, 0]], 25], [0, 1])]]
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(steps, now):
    order = sorted(range(len(steps)), key=lambda i: (steps[i][0], i))
    current = 0
    active = -1
    for i in order:
        at, pct = steps[i]
        if at > now:
            break
        active = steps.index(steps[i])
        if pct is not None:
            current = min(max(pct, 0), 100)
    return [current, active]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('step scheduled exactly now is active', [[[0, 5], [60, 25]], 60], [25, 1]),
  ('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 1', [[[45, 0], [45, 5], [20, None], [45, 25], [60, -10], [45, None]], 45], [25, 5])],
 [('unsorted schedule is ordered by time', [[[60, 50], [0, 10], [30, 25]], 45], [25, 2]),
  ('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 24', [[[60, 100], [20, None], [20, None], [60, -10], [20, 100]], 45], [100, 4])],
 [('later entry wins a timestamp tie', [[[0, 5], [30, 50], [30, 20]], 40], [20, 2]),
  ('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 11', [[[0, 5]], -5], [0, -1]),
  ('ramp schedule sample 48', [[[0, -10], [60, None], [20, -10]], 60], [0, 1])],
 [('hold step keeps previous percentage', [[[0, 25], [30, None]], 40], [25, 1]),
  ('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 12', [[[0, 120], [10, 25], [0, 0]], 10], [25, 1]),
  ('ramp schedule sample 16', [[[60, 120]], 60], [100, 0])],
 [('explicit rollback to zero percent', [[[0, 25], [30, 0]], 40], [0, 1]),
  ('over-hundred percent is clamped', [[[0, 150]], 10], [100, 0]),
  ('negative percent is clamped to zero', [[[0, 10], [5, -20]], 10], [0, 1]),
  ('before first step is zero', [[[10, 50]], 5], [0, -1]),
  ('active index refers to original position', [[[20, 30], [10, 10]], 15], [10, 1]),
  ('duplicate identical steps report the later entry', [[[10, 10], [10, 10]], 15], [10, 1]),
  ('ramp schedule sample 21', [[], 0], [0, -1]),
  ('ramp schedule sample 37', [[[60, -10], [10, None], [60, 0]], 25], [0, 1])]]
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:
Dashboards highlight the wrong schedule row as the active step.

steps is a possibly unsorted list of [epoch second, percent or None]. Order steps by time, breaking ties by list position (later entries apply later). Every step with time <= now is active in that order; a None percent is a hold that keeps the previous value; numeric percents are clamped to [0, 100]. Before the first step the percentage is 0. Return [percent, original list index of the last active step or -1].

split: open-access


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

N = 1
observations = []
def solve(events):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache = dict(ev[2])
            fetched_at = t
            killed = set()
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at > 30:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 3',
   [[['get', 1, 'a', 'dflt'],
     ['kill', 6, 'a'],
     ['get', 11, 'b', False],
     ['fetch', 12, {'c': False}],
     ['get', 13, 'b', 'dflt']]],
   [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']])],
 [('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 39',
   [[['fetch', 29.5, {}], ['kill', 29.5, 'c'], ['get', 59.0, 'a', 0], ['get', 64.0, 'c', False]]],
   [[0, 'missing'], [False, 'killed']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 15',
   [[['fetch', 0, {'c': 'b', 'b': True}],
     ['get', 30, 'c', False],
     ['kill', 31, 'c'],
     ['kill', 36, 'c'],
     ['kill', 66, 'c'],
     ['kill', 66.5, 'a'],
     ['get', 76.5, 'c', 'dflt'],
     ['kill', 106.5, 'b']]],
   [[False, 'stale'], ['dflt', 'killed']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 17',
   [[['fetch', 10, {'b': 'b', 'c': False}],
     ['fetch', 10.5, {}],
     ['kill', 40.0, 'b'],
     ['get', 40.5, 'c', 'dflt'],
     ['get', 41.0, 'b', 0],
     ['kill', 70.5, 'b']]],
   [['dflt', 'stale'], [0, 'killed']]),
  ('event stream sample 36',
   [[['get', 29.5, 'c', 'dflt'],
     ['fetch', 59.5, {'b': True}],
     ['get', 89.0, 'b', 'dflt'],
     ['kill', 99.0, 'a']]],
   [['dflt', 'stale'], [True, 'cache']])],
 [('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 18',
   [[['kill', 10, 'c'],
     ['get', 39.5, 'a', 'dflt'],
     ['fetch', 69.5, {'b': 3}],
     ['get', 99.5, 'b', 0],
     ['fetch', 129.5, {'a': 'b'}],
     ['get', 130.0, 'b', 0]]],
   [['dflt', 'stale'], [0, 'stale'], [0, 'missing']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 44',
   [[['kill', 0.5, 'a'],
     ['get', 5.5, 'b', 'dflt'],
     ['fetch', 15.5, {}],
     ['fetch', 45.5, {}],
     ['get', 75.0, 'b', 'dflt'],
     ['get', 75.0, 'b', 0]]],
   [['dflt', 'stale'], ['dflt', 'missing'], [0, 'missing']])]]
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):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache = dict(ev[2])
            fetched_at = t
            killed = set()
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at > 29:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 3',
   [[['get', 1, 'a', 'dflt'],
     ['kill', 6, 'a'],
     ['get', 11, 'b', False],
     ['fetch', 12, {'c': False}],
     ['get', 13, 'b', 'dflt']]],
   [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']])],
 [('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 39',
   [[['fetch', 29.5, {}], ['kill', 29.5, 'c'], ['get', 59.0, 'a', 0], ['get', 64.0, 'c', False]]],
   [[0, 'missing'], [False, 'killed']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 15',
   [[['fetch', 0, {'c': 'b', 'b': True}],
     ['get', 30, 'c', False],
     ['kill', 31, 'c'],
     ['kill', 36, 'c'],
     ['kill', 66, 'c'],
     ['kill', 66.5, 'a'],
     ['get', 76.5, 'c', 'dflt'],
     ['kill', 106.5, 'b']]],
   [[False, 'stale'], ['dflt', 'killed']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 17',
   [[['fetch', 10, {'b': 'b', 'c': False}],
     ['fetch', 10.5, {}],
     ['kill', 40.0, 'b'],
     ['get', 40.5, 'c', 'dflt'],
     ['get', 41.0, 'b', 0],
     ['kill', 70.5, 'b']]],
   [['dflt', 'stale'], [0, 'killed']]),
  ('event stream sample 36',
   [[['get', 29.5, 'c', 'dflt'],
     ['fetch', 59.5, {'b': True}],
     ['get', 89.0, 'b', 'dflt'],
     ['kill', 99.0, 'a']]],
   [['dflt', 'stale'], [True, 'cache']])],
 [('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 18',
   [[['kill', 10, 'c'],
     ['get', 39.5, 'a', 'dflt'],
     ['fetch', 69.5, {'b': 3}],
     ['get', 99.5, 'b', 0],
     ['fetch', 129.5, {'a': 'b'}],
     ['get', 130.0, 'b', 0]]],
   [['dflt', 'stale'], [0, 'stale'], [0, 'missing']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 44',
   [[['kill', 0.5, 'a'],
     ['get', 5.5, 'b', 'dflt'],
     ['fetch', 15.5, {}],
     ['fetch', 45.5, {}],
     ['get', 75.0, 'b', 'dflt'],
     ['get', 75.0, 'b', 0]]],
   [['dflt', 'stale'], ['dflt', 'missing'], [0, 'missing']])]]
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 value exactly 30 seconds old is still served from cache.

Process events in order. ["fetch", t, payload] replaces the whole cache with payload, records t and clears kill switches; ["kill", t, flag] forces that flag to its default; ["get", t, flag, default] returns [default, killed] for killed flags, else [default, stale] if nothing was fetched or t - last fetch >= 30 seconds, else [default, missing] if the flag is not cached, else [value, cache]. Return the list of get results.

split: open-access


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

N = 1
observations = []
def solve(events):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache.update(ev[2])
            fetched_at = t
            killed = set()
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at >= 30:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
 [('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 25',
   [[['get', 29.5, 'a', 'dflt'],
     ['fetch', 29.5, {'a': False, 'c': 'b'}],
     ['fetch', 30.0, {'c': False, 'b': 'b'}],
     ['fetch', 30.0, {}],
     ['get', 30.5, 'b', 0]]],
   [['dflt', 'stale'], [0, 'missing']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 20',
   [[['fetch', 30, {'c': 'b', 'a': False}],
     ['get', 40, 'b', 0],
     ['fetch', 41, {'b': 'b', 'c': 'b'}],
     ['get', 41, 'b', 'dflt'],
     ['get', 41, 'c', 0],
     ['kill', 42, 'c'],
     ['get', 43, 'a', 0]]],
   [[0, 'missing'], ['b', 'cache'], ['b', 'cache'], [0, 'missing']]),
  ('event stream sample 58',
   [[['fetch', 30, {'a': 3}],
     ['kill', 30.5, 'b'],
     ['get', 31.0, 'b', 0],
     ['get', 32.0, 'c', 0],
     ['fetch', 33.0, {}],
     ['get', 38.0, 'a', 'dflt'],
     ['kill', 68.0, 'c']]],
   [[0, 'killed'], [0, 'missing'], ['dflt', 'missing']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])]]
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):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache = dict(ev[2]) if ev[2] else cache
            fetched_at = t
            killed = set()
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at >= 30:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
 [('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 25',
   [[['get', 29.5, 'a', 'dflt'],
     ['fetch', 29.5, {'a': False, 'c': 'b'}],
     ['fetch', 30.0, {'c': False, 'b': 'b'}],
     ['fetch', 30.0, {}],
     ['get', 30.5, 'b', 0]]],
   [['dflt', 'stale'], [0, 'missing']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 20',
   [[['fetch', 30, {'c': 'b', 'a': False}],
     ['get', 40, 'b', 0],
     ['fetch', 41, {'b': 'b', 'c': 'b'}],
     ['get', 41, 'b', 'dflt'],
     ['get', 41, 'c', 0],
     ['kill', 42, 'c'],
     ['get', 43, 'a', 0]]],
   [[0, 'missing'], ['b', 'cache'], ['b', 'cache'], [0, 'missing']]),
  ('event stream sample 58',
   [[['fetch', 30, {'a': 3}],
     ['kill', 30.5, 'b'],
     ['get', 31.0, 'b', 0],
     ['get', 32.0, 'c', 0],
     ['fetch', 33.0, {}],
     ['get', 38.0, 'a', 'dflt'],
     ['kill', 68.0, 'c']]],
   [[0, 'killed'], [0, 'missing'], ['dflt', 'missing']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 57',
   [[['get', 1, 'a', 0],
     ['get', 31, 'a', 'dflt'],
     ['kill', 31.5, 'c'],
     ['fetch', 32.5, {'c': False, 'b': True}],
     ['get', 62.0, 'b', False],
     ['fetch', 92.0, {}],
     ['get', 97.0, 'c', 'dflt'],
     ['get', 107.0, 'a', 0]]],
   [[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])]]
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 flag deleted on the server keeps serving its last cached value.

Process events in order. ["fetch", t, payload] replaces the whole cache with payload, records t and clears kill switches; ["kill", t, flag] forces that flag to its default; ["get", t, flag, default] returns [default, killed] for killed flags, else [default, stale] if nothing was fetched or t - last fetch >= 30 seconds, else [default, missing] if the flag is not cached, else [value, cache]. Return the list of get results.

split: open-access


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

N = 1
observations = []
def solve(events):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache = dict(ev[2])
            fetched_at = t
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at >= 30:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
 [('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 7',
   [[['get', 5, 'a', 'dflt'],
     ['get', 5, 'c', 'dflt'],
     ['fetch', 5, {'a': False}],
     ['get', 10, 'a', 'dflt'],
     ['get', 39.5, 'c', 'dflt'],
     ['get', 49.5, 'c', 0]]],
   [['dflt', 'stale'], ['dflt', 'stale'], [False, 'cache'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 51',
   [[['fetch', 0, {'c': False, 'a': True}],
     ['kill', 1, 'a'],
     ['get', 2, 'b', False],
     ['fetch', 3, {}],
     ['get', 13, 'b', False],
     ['get', 43, 'a', 'dflt']]],
   [[False, 'missing'], [False, 'missing'], ['dflt', 'stale']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 12',
   [[['get', 29.5, 'b', False],
     ['kill', 30.5, 'b'],
     ['get', 35.5, 'a', False],
     ['get', 36.5, 'b', 'dflt'],
     ['fetch', 36.5, {'a': True}],
     ['get', 36.5, 'a', 'dflt'],
     ['get', 36.5, 'a', 'dflt'],
     ['kill', 66.5, 'a']]],
   [[False, 'stale'], [False, 'stale'], ['dflt', 'killed'], [True, 'cache'], [True, 'cache']]),
  ('event stream sample 45',
   [[['kill', 0, 'c'],
     ['kill', 10, 'a'],
     ['get', 10.5, 'b', 'dflt'],
     ['fetch', 40.5, {}],
     ['fetch', 45.5, {'b': False, 'a': 'b'}],
     ['get', 45.5, 'c', 0],
     ['get', 45.5, 'b', False],
     ['get', 45.5, 'b', 0]]],
   [['dflt', 'stale'], [0, 'missing'], [False, 'cache'], [False, 'cache']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 17',
   [[['fetch', 10, {'b': 'b', 'c': False}],
     ['fetch', 10.5, {}],
     ['kill', 40.0, 'b'],
     ['get', 40.5, 'c', 'dflt'],
     ['get', 41.0, 'b', 0],
     ['kill', 70.5, 'b']]],
   [['dflt', 'stale'], [0, 'killed']]),
  ('event stream sample 38',
   [[['get', 5, 'c', 0],
     ['fetch', 34.5, {'c': True}],
     ['kill', 44.5, 'b'],
     ['kill', 54.5, 'a'],
     ['fetch', 55.0, {'c': 3, 'b': True}],
     ['kill', 55.5, 'c'],
     ['fetch', 85.5, {}],
     ['get', 95.5, 'a', 'dflt']]],
   [[0, 'stale'], ['dflt', 'missing']])],
 [('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 22',
   [[['get', 29.5, 'a', 'dflt'],
     ['get', 59.0, 'a', False],
     ['kill', 59.0, 'b'],
     ['fetch', 89.0, {}],
     ['kill', 118.5, 'a'],
     ['fetch', 118.5, {'a': 3}]]],
   [['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 23',
   [[['get', 1, 'a', 'dflt'], ['fetch', 30.5, {'b': True}], ['get', 31.5, 'a', 'dflt']]],
   [['dflt', 'stale'], ['dflt', 'missing']])]]
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):
    cache = {}
    fetched_at = None
    killed = set()
    out = []
    for ev in events:
        kind, t = ev[0], ev[1]
        if kind == 'fetch':
            cache = dict(ev[2])
            fetched_at = t
            killed -= set(cache)
        elif kind == 'kill':
            killed.add(ev[2])
        else:
            flag, default = ev[2], ev[3]
            if flag in killed:
                out.append([default, 'killed'])
            elif fetched_at is None or t - fetched_at >= 30:
                out.append([default, 'stale'])
            elif flag not in cache:
                out.append([default, 'missing'])
            else:
                out.append([cache[flag], 'cache'])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
   [[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
   [[False, 'stale']]),
  ('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   []),
  ('event stream sample 2',
   [[['get', 0, 'a', False],
     ['get', 30, 'b', 0],
     ['get', 59.5, 'b', False],
     ['fetch', 89.5, {}],
     ['get', 99.5, 'a', 0],
     ['get', 129.0, 'c', 'dflt'],
     ['get', 129.0, 'c', 0]]],
   [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
 [('fractional age just under the ttl is fresh',
   [[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
   [[True, 'cache']]),
  ('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('event stream sample 6',
   [[['fetch', 5, {'a': 'b', 'c': 3}],
     ['fetch', 6, {'c': True}],
     ['get', 6.5, 'b', False],
     ['get', 7.0, 'a', 'dflt'],
     ['get', 17.0, 'a', False],
     ['fetch', 27.0, {}],
     ['get', 57.0, 'c', 'dflt'],
     ['get', 87.0, 'b', False]]],
   [[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 7',
   [[['get', 5, 'a', 'dflt'],
     ['get', 5, 'c', 'dflt'],
     ['fetch', 5, {'a': False}],
     ['get', 10, 'a', 'dflt'],
     ['get', 39.5, 'c', 'dflt'],
     ['get', 49.5, 'c', 0]]],
   [['dflt', 'stale'], ['dflt', 'stale'], [False, 'cache'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 51',
   [[['fetch', 0, {'c': False, 'a': True}],
     ['kill', 1, 'a'],
     ['get', 2, 'b', False],
     ['fetch', 3, {}],
     ['get', 13, 'b', False],
     ['get', 43, 'a', 'dflt']]],
   [[False, 'missing'], [False, 'missing'], ['dflt', 'stale']])],
 [('refetch removes flags absent from payload',
   [[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
   [['d', 'missing']]),
  ('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('event stream sample 11',
   [[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
   [[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 12',
   [[['get', 29.5, 'b', False],
     ['kill', 30.5, 'b'],
     ['get', 35.5, 'a', False],
     ['get', 36.5, 'b', 'dflt'],
     ['fetch', 36.5, {'a': True}],
     ['get', 36.5, 'a', 'dflt'],
     ['get', 36.5, 'a', 'dflt'],
     ['kill', 66.5, 'a']]],
   [[False, 'stale'], [False, 'stale'], ['dflt', 'killed'], [True, 'cache'], [True, 'cache']]),
  ('event stream sample 45',
   [[['kill', 0, 'c'],
     ['kill', 10, 'a'],
     ['get', 10.5, 'b', 'dflt'],
     ['fetch', 40.5, {}],
     ['fetch', 45.5, {'b': False, 'a': 'b'}],
     ['get', 45.5, 'c', 0],
     ['get', 45.5, 'b', False],
     ['get', 45.5, 'b', 0]]],
   [['dflt', 'stale'], [0, 'missing'], [False, 'cache'], [False, 'cache']])],
 [('empty payload clears the cache',
   [[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
   [[False, 'missing']]),
  ('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('event stream sample 16',
   [[['get', 10, 'b', 0],
     ['get', 40, 'c', 'dflt'],
     ['get', 69.5, 'a', 0],
     ['fetch', 79.5, {'a': 'b'}],
     ['fetch', 84.5, {'c': 'b'}],
     ['kill', 85.0, 'b'],
     ['fetch', 95.0, {'b': 3, 'c': False}]]],
   [[0, 'stale'], ['dflt', 'stale'], [0, 'stale']]),
  ('event stream sample 17',
   [[['fetch', 10, {'b': 'b', 'c': False}],
     ['fetch', 10.5, {}],
     ['kill', 40.0, 'b'],
     ['get', 40.5, 'c', 'dflt'],
     ['get', 41.0, 'b', 0],
     ['kill', 70.5, 'b']]],
   [['dflt', 'stale'], [0, 'killed']]),
  ('event stream sample 38',
   [[['get', 5, 'c', 0],
     ['fetch', 34.5, {'c': True}],
     ['kill', 44.5, 'b'],
     ['kill', 54.5, 'a'],
     ['fetch', 55.0, {'c': 3, 'b': True}],
     ['kill', 55.5, 'c'],
     ['fetch', 85.5, {}],
     ['get', 95.5, 'a', 'dflt']]],
   [[0, 'stale'], ['dflt', 'missing']])],
 [('refetch clears kill switches',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
   [[True, 'cache']]),
  ('refetch clears a kill on an uncached flag',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
   [[0, 'missing']]),
  ('kill of a flag missing from the payload',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
   [['d', 'killed']]),
  ('killed flag beats staleness',
   [[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
   [[False, 'killed']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, 'cache']]),
  ('event stream sample 21',
   [[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
   [[0, 'stale'], [True, 'cache']]),
  ('event stream sample 22',
   [[['get', 29.5, 'a', 'dflt'],
     ['get', 59.0, 'a', False],
     ['kill', 59.0, 'b'],
     ['fetch', 89.0, {}],
     ['kill', 118.5, 'a'],
     ['fetch', 118.5, {'a': 3}]]],
   [['dflt', 'stale'], [False, 'stale']]),
  ('event stream sample 23',
   [[['get', 1, 'a', 'dflt'], ['fetch', 30.5, {'b': True}], ['get', 31.5, 'a', 'dflt']]],
   [['dflt', 'stale'], ['dflt', 'missing']])]]
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 operator fixes a flag and clients refetch, the old kill switch keeps forcing defaults.

Process events in order. ["fetch", t, payload] replaces the whole cache with payload, records t and clears kill switches; ["kill", t, flag] forces that flag to its default; ["get", t, flag, default] returns [default, killed] for killed flags, else [default, stale] if nothing was fetched or t - last fetch >= 30 seconds, else [default, missing] if the flag is not cached, else [value, cache]. Return the list of get results.

split: open-access