FA-74021 / Feature flag rollout bucketing / Open access
Flag value cache freshness: Refetch merges into the old cache · case 01
A flag deleted on the server keeps serving its last cached value.
ROOT CAUSE
The fetch handler updates the existing dictionary instead of replacing it.
VERIFIED REPAIR
Replace the whole cache with the fetched payload.
Unsuccessful approach: Keeping the old cache when the payload is empty still resurrects deleted flags.
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.update(ev[2])
fetched_at = t
killed = set()
elif kind == 'kill':
killed.add(ev[2])
else:
flag, default = ev[2], ev[3]
if flag in killed:
out.append([default, 'killed'])
elif fetched_at is None or t - fetched_at >= 30:
out.append([default, 'stale'])
elif flag not in cache:
out.append([default, 'missing'])
else:
out.append([cache[flag], 'cache'])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
[[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
[[False, 'stale']]),
('fractional age just under the ttl is fresh',
[[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
[[True, 'cache']]),
('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 1',
[[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
[]),
('event stream sample 2',
[[['get', 0, 'a', False],
['get', 30, 'b', 0],
['get', 59.5, 'b', False],
['fetch', 89.5, {}],
['get', 99.5, 'a', 0],
['get', 129.0, 'c', 'dflt'],
['get', 129.0, 'c', 0]]],
[[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
[('fractional age just under the ttl is fresh',
[[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
[[True, 'cache']]),
('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 25',
[[['get', 29.5, 'a', 'dflt'],
['fetch', 29.5, {'a': False, 'c': 'b'}],
['fetch', 30.0, {'c': False, 'b': 'b'}],
['fetch', 30.0, {}],
['get', 30.5, 'b', 0]]],
[['dflt', 'stale'], [0, 'missing']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
[('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('event stream sample 11',
[[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
[[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 20',
[[['fetch', 30, {'c': 'b', 'a': False}],
['get', 40, 'b', 0],
['fetch', 41, {'b': 'b', 'c': 'b'}],
['get', 41, 'b', 'dflt'],
['get', 41, 'c', 0],
['kill', 42, 'c'],
['get', 43, 'a', 0]]],
[[0, 'missing'], ['b', 'cache'], ['b', 'cache'], [0, 'missing']]),
('event stream sample 58',
[[['fetch', 30, {'a': 3}],
['kill', 30.5, 'b'],
['get', 31.0, 'b', 0],
['get', 32.0, 'c', 0],
['fetch', 33.0, {}],
['get', 38.0, 'a', 'dflt'],
['kill', 68.0, 'c']]],
[[0, 'killed'], [0, 'missing'], ['dflt', 'missing']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 6',
[[['fetch', 5, {'a': 'b', 'c': 3}],
['fetch', 6, {'c': True}],
['get', 6.5, 'b', False],
['get', 7.0, 'a', 'dflt'],
['get', 17.0, 'a', False],
['fetch', 27.0, {}],
['get', 57.0, 'c', 'dflt'],
['get', 87.0, 'b', False]]],
[[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 16',
[[['get', 10, 'b', 0],
['get', 40, 'c', 'dflt'],
['get', 69.5, 'a', 0],
['fetch', 79.5, {'a': 'b'}],
['fetch', 84.5, {'c': 'b'}],
['kill', 85.0, 'b'],
['fetch', 95.0, {'b': 3, 'c': False}]]],
[[0, 'stale'], ['dflt', 'stale'], [0, 'stale']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('second fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
[[2, 'cache']]),
('event stream sample 21',
[[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
[[0, 'stale'], [True, 'cache']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| 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 | [['x', 'cache']] | [['d', 'missing']] | Failed |
| empty payload clears the cache | [[True, 'cache']] | [[False, 'missing']] | Failed |
| refetch clears kill switches | [[True, 'cache']] | [[True, 'cache']] | Passed |
| empty fetch refreshes the ttl clock | [[1, 'cache']] | [[0, 'missing']] | Failed |
| 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 |
SHA-256 / 63139d68db3be48e03ea72edf6f1699fecebc648888e73a5e0903ffd08aee203
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]) if ev[2] else cache
fetched_at = t
killed = set()
elif kind == 'kill':
killed.add(ev[2])
else:
flag, default = ev[2], ev[3]
if flag in killed:
out.append([default, 'killed'])
elif fetched_at is None or t - fetched_at >= 30:
out.append([default, 'stale'])
elif flag not in cache:
out.append([default, 'missing'])
else:
out.append([cache[flag], 'cache'])
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('value is stale at exactly the ttl',
[[['fetch', 0, {'a': True}], ['get', 30, 'a', False]]],
[[False, 'stale']]),
('fractional age just under the ttl is fresh',
[[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
[[True, 'cache']]),
('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 1',
[[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
[]),
('event stream sample 2',
[[['get', 0, 'a', False],
['get', 30, 'b', 0],
['get', 59.5, 'b', False],
['fetch', 89.5, {}],
['get', 99.5, 'a', 0],
['get', 129.0, 'c', 'dflt'],
['get', 129.0, 'c', 0]]],
[[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
[('fractional age just under the ttl is fresh',
[[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
[[True, 'cache']]),
('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 25',
[[['get', 29.5, 'a', 'dflt'],
['fetch', 29.5, {'a': False, 'c': 'b'}],
['fetch', 30.0, {'c': False, 'b': 'b'}],
['fetch', 30.0, {}],
['get', 30.5, 'b', 0]]],
[['dflt', 'stale'], [0, 'missing']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
[('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('event stream sample 11',
[[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
[[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 20',
[[['fetch', 30, {'c': 'b', 'a': False}],
['get', 40, 'b', 0],
['fetch', 41, {'b': 'b', 'c': 'b'}],
['get', 41, 'b', 'dflt'],
['get', 41, 'c', 0],
['kill', 42, 'c'],
['get', 43, 'a', 0]]],
[[0, 'missing'], ['b', 'cache'], ['b', 'cache'], [0, 'missing']]),
('event stream sample 58',
[[['fetch', 30, {'a': 3}],
['kill', 30.5, 'b'],
['get', 31.0, 'b', 0],
['get', 32.0, 'c', 0],
['fetch', 33.0, {}],
['get', 38.0, 'a', 'dflt'],
['kill', 68.0, 'c']]],
[[0, 'killed'], [0, 'missing'], ['dflt', 'missing']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 6',
[[['fetch', 5, {'a': 'b', 'c': 3}],
['fetch', 6, {'c': True}],
['get', 6.5, 'b', False],
['get', 7.0, 'a', 'dflt'],
['get', 17.0, 'a', False],
['fetch', 27.0, {}],
['get', 57.0, 'c', 'dflt'],
['get', 87.0, 'b', False]]],
[[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 16',
[[['get', 10, 'b', 0],
['get', 40, 'c', 'dflt'],
['get', 69.5, 'a', 0],
['fetch', 79.5, {'a': 'b'}],
['fetch', 84.5, {'c': 'b'}],
['kill', 85.0, 'b'],
['fetch', 95.0, {'b': 3, 'c': False}]]],
[[0, 'stale'], ['dflt', 'stale'], [0, 'stale']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('second fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
[[2, 'cache']]),
('event stream sample 21',
[[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
[[0, 'stale'], [True, 'cache']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| 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 | [[True, 'cache']] | [[False, 'missing']] | Failed |
| refetch clears kill switches | [[True, 'cache']] | [[True, 'cache']] | Passed |
| empty fetch refreshes the ttl clock | [[1, 'cache']] | [[0, 'missing']] | Failed |
| 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 |
SHA-256 / 317d43ee945e94f9bf3be83eabcfbfa95e946c9534c4763bcbf69bb91b55243a
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']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 1',
[[['kill', 30, 'a'], ['fetch', 40, {'c': 3, 'b': False}], ['kill', 41, 'a']]],
[]),
('event stream sample 2',
[[['get', 0, 'a', False],
['get', 30, 'b', 0],
['get', 59.5, 'b', False],
['fetch', 89.5, {}],
['get', 99.5, 'a', 0],
['get', 129.0, 'c', 'dflt'],
['get', 129.0, 'c', 0]]],
[[False, 'stale'], [0, 'stale'], [False, 'stale'], [0, 'missing'], ['dflt', 'stale'], [0, 'stale']])],
[('fractional age just under the ttl is fresh',
[[['fetch', 0, {'a': True}], ['get', 29.5, 'a', False]]],
[[True, 'cache']]),
('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 25',
[[['get', 29.5, 'a', 'dflt'],
['fetch', 29.5, {'a': False, 'c': 'b'}],
['fetch', 30.0, {'c': False, 'b': 'b'}],
['fetch', 30.0, {}],
['get', 30.5, 'b', 0]]],
[['dflt', 'stale'], [0, 'missing']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])],
[('refetch removes flags absent from payload',
[[['fetch', 0, {'a': True, 'b': 'x'}], ['fetch', 5, {'a': False}], ['get', 6, 'b', 'd']]],
[['d', 'missing']]),
('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('event stream sample 11',
[[['get', 10, 'a', 0], ['get', 11, 'c', 'dflt'], ['get', 11.5, 'c', False]]],
[[0, 'stale'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 20',
[[['fetch', 30, {'c': 'b', 'a': False}],
['get', 40, 'b', 0],
['fetch', 41, {'b': 'b', 'c': 'b'}],
['get', 41, 'b', 'dflt'],
['get', 41, 'c', 0],
['kill', 42, 'c'],
['get', 43, 'a', 0]]],
[[0, 'missing'], ['b', 'cache'], ['b', 'cache'], [0, 'missing']]),
('event stream sample 58',
[[['fetch', 30, {'a': 3}],
['kill', 30.5, 'b'],
['get', 31.0, 'b', 0],
['get', 32.0, 'c', 0],
['fetch', 33.0, {}],
['get', 38.0, 'a', 'dflt'],
['kill', 68.0, 'c']]],
[[0, 'killed'], [0, 'missing'], ['dflt', 'missing']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('empty fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {}], ['get', 40, 'a', 0]]],
[[0, 'missing']]),
('event stream sample 6',
[[['fetch', 5, {'a': 'b', 'c': 3}],
['fetch', 6, {'c': True}],
['get', 6.5, 'b', False],
['get', 7.0, 'a', 'dflt'],
['get', 17.0, 'a', False],
['fetch', 27.0, {}],
['get', 57.0, 'c', 'dflt'],
['get', 87.0, 'b', False]]],
[[False, 'missing'], ['dflt', 'missing'], [False, 'missing'], ['dflt', 'stale'], [False, 'stale']]),
('event stream sample 16',
[[['get', 10, 'b', 0],
['get', 40, 'c', 'dflt'],
['get', 69.5, 'a', 0],
['fetch', 79.5, {'a': 'b'}],
['fetch', 84.5, {'c': 'b'}],
['kill', 85.0, 'b'],
['fetch', 95.0, {'b': 3, 'c': False}]]],
[[0, 'stale'], ['dflt', 'stale'], [0, 'stale']])],
[('empty payload clears the cache',
[[['fetch', 0, {'a': True}], ['fetch', 5, {}], ['get', 6, 'a', False]]],
[[False, 'missing']]),
('refetch clears kill switches',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['fetch', 2, {'a': True}], ['get', 3, 'a', False]]],
[[True, 'cache']]),
('refetch clears a kill on an uncached flag',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['fetch', 2, {'a': True}], ['get', 4, 'b', 0]]],
[[0, 'missing']]),
('kill of a flag missing from the payload',
[[['fetch', 0, {'a': True}], ['kill', 1, 'b'], ['get', 2, 'b', 'd']]],
[['d', 'killed']]),
('killed flag beats staleness',
[[['fetch', 0, {'a': True}], ['kill', 1, 'a'], ['get', 40, 'a', False]]],
[[False, 'killed']]),
('second fetch refreshes the ttl clock',
[[['fetch', 0, {'a': 1}], ['fetch', 25, {'a': 2}], ['get', 40, 'a', 0]]],
[[2, 'cache']]),
('event stream sample 21',
[[['get', 5, 'a', 0], ['fetch', 5, {'a': False, 'b': True}], ['get', 5, 'b', 0]]],
[[0, 'stale'], [True, 'cache']]),
('event stream sample 57',
[[['get', 1, 'a', 0],
['get', 31, 'a', 'dflt'],
['kill', 31.5, 'c'],
['fetch', 32.5, {'c': False, 'b': True}],
['get', 62.0, 'b', False],
['fetch', 92.0, {}],
['get', 97.0, 'c', 'dflt'],
['get', 107.0, 'a', 0]]],
[[0, 'stale'], ['dflt', 'stale'], [True, 'cache'], ['dflt', 'missing'], [0, 'missing']])]]
for label, args, expected in fixtures[N - 1]:
check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| 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 |
| empty fetch refreshes the ttl clock | [[0, 'missing']] | [[0, 'missing']] | 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 |
SHA-256 / e5d79801ff70d54073006ae9fba63b26744e1a2f2c75cec39cf581ce063a33a5
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.867895+00:00.
Case digest / 8904860191faf316e80c38bd450ef67c64c4d839aa518e86576f11dce9db66d8