FA-74016 / Feature flag rollout bucketing / Open access
Flag value cache freshness: Cached values survive their full ttl second · case 01
A value exactly 30 seconds old is still served from cache.
ROOT CAUSE
Staleness is tested with age > 30 instead of age >= 30.
VERIFIED REPAIR
Treat entries as stale once their age reaches the 30 second ttl.
Unsuccessful approach: Comparing age > 29 matches only on whole seconds and expires fractional ages early.
Case contract
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.
Why this case matters
Client SDKs serve cached flags offline; kill switches and staleness decide whether a bad flag keeps serving.
1 / The failure
Exit 1"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| value is stale at exactly the ttl | [[True, 'cache']] | [[False, 'stale']] | Failed |
| fractional age just under the ttl is fresh | [[True, 'cache']] | [[True, 'cache']] | Passed |
| refetch removes flags absent from payload | [['d', 'missing']] | [['d', 'missing']] | Passed |
| empty payload clears the cache | [[False, 'missing']] | [[False, 'missing']] | Passed |
| refetch clears kill switches | [[True, 'cache']] | [[True, 'cache']] | Passed |
| event stream sample 1 | [] | [] | Passed |
| event stream sample 2 | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | Passed |
| event stream sample 3 | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | Passed |
SHA-256 / e9f64ed2eb4de22a92e1b2de043c3390bbd95b273956bfae5ba0b967f09ff8f1
2 / The unsuccessful fix
Exit 1"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| value is stale at exactly the ttl | [[False, 'stale']] | [[False, 'stale']] | Passed |
| fractional age just under the ttl is fresh | [[False, 'stale']] | [[True, 'cache']] | Failed |
| refetch removes flags absent from payload | [['d', 'missing']] | [['d', 'missing']] | Passed |
| empty payload clears the cache | [[False, 'missing']] | [[False, 'missing']] | Passed |
| refetch clears kill switches | [[True, 'cache']] | [[True, 'cache']] | Passed |
| event stream sample 1 | [] | [] | Passed |
| event stream sample 2 | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | Passed |
| event stream sample 3 | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | Passed |
SHA-256 / 5f94878a8410d81e3894970fed457600ff5cd6087225ea5e98f371b13f10d76d
3 / The verified repair
Exit 0"""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)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| value is stale at exactly the ttl | [[False, 'stale']] | [[False, 'stale']] | Passed |
| fractional age just under the ttl is fresh | [[True, 'cache']] | [[True, 'cache']] | Passed |
| refetch removes flags absent from payload | [['d', 'missing']] | [['d', 'missing']] | Passed |
| empty payload clears the cache | [[False, 'missing']] | [[False, 'missing']] | Passed |
| refetch clears kill switches | [[True, 'cache']] | [[True, 'cache']] | Passed |
| event stream sample 1 | [] | [] | Passed |
| event stream sample 2 | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | [[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']] | Passed |
| event stream sample 3 | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | [['dflt', 'stale'], [False, 'stale'], ['dflt', 'missing']] | Passed |
SHA-256 / e093257b7dc997cdca0517fef3c467c96664b22b892785d610f20f03b65539d2
Verification & scope
A deterministic toy flag-evaluation model with a stipulated contract; it does not reproduce any vendor SDK byte for byte. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:48:52.723980+00:00.
Case digest / 2b336fe0b80f7045ce43b57449c244c23c42aea69d55df8a909bbd576f5d7eb9