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 fetched_at is None or t - fetched_at >= 30:
                out.append([default, 'stale'])
            elif flag in killed:
                out.append([default, 'killed'])
            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']]),
  ('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 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   [])],
 [('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']]),
  ('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 27',
   [[['get', 10, 'c', 'dflt'],
     ['get', 10.5, 'b', False],
     ['kill', 10.5, 'b'],
     ['get', 40.0, 'b', 0],
     ['get', 40.0, 'c', 'dflt'],
     ['get', 41.0, 'a', 0],
     ['get', 41.5, 'c', False],
     ['fetch', 71.0, {'b': 'b'}]]],
   [['dflt', 'stale'], [False, 'stale'], [0, 'killed'], ['dflt', 'stale'], [0, 'stale'], [False, 'stale']]),
  ('event stream sample 29',
   [[['kill', 10, 'c'], ['kill', 10.5, 'b'], ['get', 40.0, 'c', 'dflt']]],
   [['dflt', '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 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 50',
   [[['get', 29.5, 'b', False],
     ['kill', 59.5, 'b'],
     ['get', 60.0, 'b', False],
     ['get', 60.5, 'b', 0],
     ['get', 90.0, 'b', 'dflt'],
     ['fetch', 119.5, {'a': True}],
     ['get', 120.5, 'a', 'dflt']]],
   [[False, 'stale'], [False, 'killed'], [0, 'killed'], ['dflt', 'killed'], [True, '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 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']])],
 [('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 39',
   [[['fetch', 29.5, {}], ['kill', 29.5, 'c'], ['get', 59.0, 'a', 0], ['get', 64.0, 'c', False]]],
   [[0, 'missing'], [False, 'killed']])]]
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 and flag in cache:
                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']]),
  ('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 1',
   [[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
   [])],
 [('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']]),
  ('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 27',
   [[['get', 10, 'c', 'dflt'],
     ['get', 10.5, 'b', False],
     ['kill', 10.5, 'b'],
     ['get', 40.0, 'b', 0],
     ['get', 40.0, 'c', 'dflt'],
     ['get', 41.0, 'a', 0],
     ['get', 41.5, 'c', False],
     ['fetch', 71.0, {'b': 'b'}]]],
   [['dflt', 'stale'], [False, 'stale'], [0, 'killed'], ['dflt', 'stale'], [0, 'stale'], [False, 'stale']]),
  ('event stream sample 29',
   [[['kill', 10, 'c'], ['kill', 10.5, 'b'], ['get', 40.0, 'c', 'dflt']]],
   [['dflt', '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 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 50',
   [[['get', 29.5, 'b', False],
     ['kill', 59.5, 'b'],
     ['get', 60.0, 'b', False],
     ['get', 60.5, 'b', 0],
     ['get', 90.0, 'b', 'dflt'],
     ['fetch', 119.5, {'a': True}],
     ['get', 120.5, 'a', 'dflt']]],
   [[False, 'stale'], [False, 'killed'], [0, 'killed'], ['dflt', 'killed'], [True, '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 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']])],
 [('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 39',
   [[['fetch', 29.5, {}], ['kill', 29.5, 'c'], ['get', 59.0, 'a', 0], ['get', 64.0, 'c', False]]],
   [[0, 'missing'], [False, 'killed']])]]
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 killed flag is reported as stale, hiding the operator action in diagnostics.

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])
            if fetched_at is None:
                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']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, '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']]],
   [])],
 [('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 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 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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('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 46',
   [[['fetch', 5, {'b': False, 'c': False}],
     ['fetch', 10, {'c': 'b', 'a': False}],
     ['kill', 20, 'b'],
     ['get', 30, 'a', 0],
     ['get', 35, 'b', 'dflt'],
     ['get', 35, 'a', False]]],
   [[False, 'cache'], ['dflt', 'killed'], [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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('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 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']])],
 [('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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[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 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']])]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(events):
    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 if ev[2] else fetched_at
            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']]),
  ('second fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
   [[2, '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']]],
   [])],
 [('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 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 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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('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 46',
   [[['fetch', 5, {'b': False, 'c': False}],
     ['fetch', 10, {'c': 'b', 'a': False}],
     ['kill', 20, 'b'],
     ['get', 30, 'a', 0],
     ['get', 35, 'b', 'dflt'],
     ['get', 35, 'a', False]]],
   [[False, 'cache'], ['dflt', 'killed'], [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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[0, 'missing']]),
  ('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 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']])],
 [('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']]),
  ('empty fetch refreshes the ttl clock',
   [[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
   [[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 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']])]]
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:
Clients go stale 30 seconds after startup even though they refetch continuously.

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(stored, variants, bucket_variant, version):
    if stored and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 10',
   [{'variant': 'b'}, ['c', 'b', 'a'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}]),
  ('assignment sample 58',
   [{'variant': 'c'}, ['c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 47',
   [{'variant': 'b'}, ['c', 'b'], 'b', 3],
   ['b', 'assigned', {'variant': 'b', 'version': 3}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}])]]
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(stored, variants, bucket_variant, version):
    if stored and stored.get('version', version) == version and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 10',
   [{'variant': 'b'}, ['c', 'b', 'a'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}]),
  ('assignment sample 58',
   [{'variant': 'c'}, ['c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 47',
   [{'variant': 'b'}, ['c', 'b'], 'b', 3],
   ['b', 'assigned', {'variant': 'b', 'version': 3}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}])]]
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 experiment restart users keep the arm from the previous version.

stored is None or {variant, version}. A stored record is honoured (reason sticky, record unchanged) only if its version equals the current experiment version and its variant is still active; this takes precedence over traffic exclusion. Otherwise a None bucket_variant means excluded and the stored record is kept untouched; else the bucketed variant is assigned and a new record {variant, version} is returned. Return [variant, reason, record].

split: open-access


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

N = 1
observations = []
def solve(stored, variants, bucket_variant, version):
    if stored and stored.get('version') == version:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 39',
   [{'variant': 'b', 'version': 2}, ['c'], None, 2],
   [None, 'excluded', {'variant': 'b', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 31',
   [{'variant': 'a', 'version': 3}, ['b'], 'b', 3],
   ['b', 'assigned', {'variant': 'b', 'version': 3}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 17', [None, ['b', 'a'], 'a', 1], ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 28',
   [{'variant': 'a', 'version': 2}, ['c', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 4',
   [{'variant': 'b', 'version': 3}, ['c'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 22',
   [{'variant': 'c', 'version': 0}, ['b'], 'b', 1],
   ['b', 'assigned', {'variant': 'b', 'version': 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(stored, variants, bucket_variant, version):
    if stored and stored.get('version') == version and stored.get('variant') is not None:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 39',
   [{'variant': 'b', 'version': 2}, ['c'], None, 2],
   [None, 'excluded', {'variant': 'b', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 31',
   [{'variant': 'a', 'version': 3}, ['b'], 'b', 3],
   ['b', 'assigned', {'variant': 'b', 'version': 3}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 17', [None, ['b', 'a'], 'a', 1], ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 28',
   [{'variant': 'a', 'version': 2}, ['c', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 4',
   [{'variant': 'b', 'version': 3}, ['c'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 22',
   [{'variant': 'c', 'version': 0}, ['b'], 'b', 1],
   ['b', 'assigned', {'variant': 'b', 'version': 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:
Users keep receiving a variant that has been removed from the experiment.

stored is None or {variant, version}. A stored record is honoured (reason sticky, record unchanged) only if its version equals the current experiment version and its variant is still active; this takes precedence over traffic exclusion. Otherwise a None bucket_variant means excluded and the stored record is kept untouched; else the bucketed variant is assigned and a new record {variant, version} is returned. Return [variant, reason, record].

split: open-access


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

N = 1
observations = []
def solve(stored, variants, bucket_variant, version):
    if stored and stored.get('version') == version and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', None]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 37', [None, ['c'], None, 3], [None, 'excluded', None]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 9',
   [{'variant': 'a', 'version': 2}, ['c'], None, 2],
   [None, 'excluded', {'variant': 'a', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 37', [None, ['c'], None, 3], [None, 'excluded', None]),
  ('assignment sample 45',
   [{'variant': 'b', 'version': 2}, ['a', 'c'], None, 1],
   [None, 'excluded', {'variant': 'b', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 29',
   [{'variant': 'c', 'version': 4}, ['a'], None, 3],
   [None, 'excluded', {'variant': 'c', 'version': 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(stored, variants, bucket_variant, version):
    if stored and stored.get('version') == version and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', {'variant': None, 'version': version}]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 37', [None, ['c'], None, 3], [None, 'excluded', None]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 9',
   [{'variant': 'a', 'version': 2}, ['c'], None, 2],
   [None, 'excluded', {'variant': 'a', 'version': 2}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 37', [None, ['c'], None, 3], [None, 'excluded', None]),
  ('assignment sample 45',
   [{'variant': 'b', 'version': 2}, ['a', 'c'], None, 1],
   [None, 'excluded', {'variant': 'b', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 29',
   [{'variant': 'c', 'version': 4}, ['a'], None, 3],
   [None, 'excluded', {'variant': 'c', 'version': 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:
Temporarily shrinking traffic loses users' history, so they are reshuffled when traffic returns.

stored is None or {variant, version}. A stored record is honoured (reason sticky, record unchanged) only if its version equals the current experiment version and its variant is still active; this takes precedence over traffic exclusion. Otherwise a None bucket_variant means excluded and the stored record is kept untouched; else the bucketed variant is assigned and a new record {variant, version} is returned. Return [variant, reason, record].

split: open-access


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

N = 1
observations = []
def solve(stored, variants, bucket_variant, version):
    if stored and stored.get('version', 0) >= version and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}]),
  ('assignment sample 41',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 59',
   [{'variant': 'a', 'version': 4}, ['a', 'c'], None, 3],
   [None, 'excluded', {'variant': 'a', 'version': 4}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 34',
   [{'variant': 'c', 'version': 4}, ['b', 'a', 'c'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 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(stored, variants, bucket_variant, version):
    if stored and stored.get('version', 0) <= version and stored.get('variant') in variants:
        return [stored['variant'], 'sticky', stored]
    if bucket_variant is None:
        return [None, 'excluded', stored]
    return [bucket_variant, 'assigned', {'variant': bucket_variant, 'version': version}]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('record from previous version is reassigned',
   [{'variant': 'b', 'version': 1}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('assignment sample 1',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}]),
  ('assignment sample 2',
   [{'variant': 'a', 'version': 2}, ['b', 'c', 'a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 3',
   [{'variant': 'a', 'version': 2}, ['a', 'c'], 'c', 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}])],
 [('legacy record without version is reassigned',
   [{'variant': 'b'}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('assignment sample 6',
   [{'variant': 'a', 'version': 4}, ['a'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 3}]),
  ('assignment sample 40', [{'variant': 'c'}, ['c', 'a'], None, 2], [None, 'excluded', {'variant': 'c'}]),
  ('assignment sample 41',
   [{'variant': 'b', 'version': 3}, ['b', 'c', 'a'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('retired variant is reassigned',
   [{'variant': 'c', 'version': 2}, ['a', 'b'], 'b', 2],
   ['b', 'assigned', {'variant': 'b', 'version': 2}]),
  ('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('assignment sample 7',
   [{'variant': 'c'}, ['b', 'c', 'a'], 'c', 1],
   ['c', 'assigned', {'variant': 'c', 'version': 1}]),
  ('assignment sample 11',
   [{'variant': 'a', 'version': 2}, ['a', 'c', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 12',
   [None, ['a', 'c', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}])],
 [('exclusion keeps the stored record',
   [{'variant': 'c', 'version': 1}, ['a', 'b'], None, 2],
   [None, 'excluded', {'variant': 'c', 'version': 1}]),
  ('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 59',
   [{'variant': 'a', 'version': 4}, ['a', 'c'], None, 3],
   [None, 'excluded', {'variant': 'a', 'version': 4}]),
  ('assignment sample 60',
   [{'variant': 'c'}, ['a', 'c'], 'c', 2],
   ['c', 'assigned', {'variant': 'c', 'version': 2}])],
 [('record from a newer version is reassigned',
   [{'variant': 'b', 'version': 3}, ['a', 'b'], 'a', 2],
   ['a', 'assigned', {'variant': 'a', 'version': 2}]),
  ('sticky beats traffic exclusion',
   [{'variant': 'a', 'version': 2}, ['a', 'b'], None, 2],
   ['a', 'sticky', {'variant': 'a', 'version': 2}]),
  ('valid record stays sticky',
   [{'variant': 'b', 'version': 2}, ['a', 'b'], 'a', 2],
   ['b', 'sticky', {'variant': 'b', 'version': 2}]),
  ('first assignment writes a record',
   [None, ['a', 'b'], 'a', 1],
   ['a', 'assigned', {'variant': 'a', 'version': 1}]),
  ('excluded user without record', [None, ['a'], None, 1], [None, 'excluded', None]),
  ('assignment sample 16',
   [{'variant': 'a'}, ['a', 'c', 'b'], 'c', 3],
   ['c', 'assigned', {'variant': 'c', 'version': 3}]),
  ('assignment sample 21',
   [{'variant': 'c', 'version': 2}, ['c', 'b', 'a'], 'c', 2],
   ['c', 'sticky', {'variant': 'c', 'version': 2}]),
  ('assignment sample 34',
   [{'variant': 'c', 'version': 4}, ['b', 'a', 'c'], 'a', 3],
   ['a', 'assigned', {'variant': 'a', 'version': 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:
After rolling an experiment back, records written by the abandoned newer version stay sticky.

stored is None or {variant, version}. A stored record is honoured (reason sticky, record unchanged) only if its version equals the current experiment version and its variant is still active; this takes precedence over traffic exclusion. Otherwise a None bucket_variant means excluded and the stored record is kept untouched; else the bucketed variant is assigned and a new record {variant, version} is returned. Return [variant, reason, record].

split: open-access