FA-92971 / EV charging session scheduling / Open access
Charging profile stack resolution: relative profile without session · case 01
A relative profile applies before any transaction has started.
ROOT CAUSE
A missing session start is defaulted to zero instead of skipping the relative profile.
VERIFIED REPAIR
Skip relative profiles when there is no session.
Unsuccessful approach: Anchoring at the current time applies the first period immediately.
Case contract
Each profile has purpose max/default/tx, stack level, validity [valid_from, valid_to) (valid_to None = open), kind absolute (origin valid_from) or relative (origin session_start; skipped when no session) and periods [[offset, amps]] in any order. A profile yields the amps of the last period with offset <= t-origin, or nothing before its first period. Per purpose the highest stack wins (ties: earlier profile). tx replaces default. Effective limit is the minimum of max, tx-or-default and hw_max, ties resolved in that order. Return [amps, source].
Why this case matters
Depot, workplace and public EV chargers schedule sessions against prices, circuit limits and departure deadlines; a wrong decision silently strands a driver or overloads a feeder.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(profiles, t, session_start, hw_max):
best = {}
for p in profiles:
if not (p['valid_from'] <= t and (p['valid_to'] is None or t < p['valid_to'])):
continue
if p['kind'] == 'relative':
if session_start is None:
session_start = 0
origin = session_start
else:
origin = p['valid_from']
el = t - origin
lim = None
for off, val in sorted(p['periods']):
if off <= el:
lim = val
if lim is None:
continue
cur = best.get(p['purpose'])
if cur is None or p['stack'] > cur[0]:
best[p['purpose']] = [p['stack'], lim]
cands = []
if 'max' in best:
cands.append(['max', best['max'][1]])
if 'tx' in best:
cands.append(['tx', best['tx'][1]])
elif 'default' in best:
cands.append(['default', best['default'][1]])
cands.append(['hw', hw_max])
win = cands[0]
for c in cands[1:]:
if c[1] < win[1]:
win = c
return [win[1], win[0]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 45,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 32], [45, 20], [5, 16]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 58,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [45, 32], [0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 42,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 10], [0, 32]]}],
56, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 37,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 20], [30, 32]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 57,
'valid_to': 117,
'kind': 'absolute',
'periods': [[5, 6], [10, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 32,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10]]},
{'purpose': 'max',
'stack': 2,
'valid_from': 38,
'valid_to': 95,
'kind': 'absolute',
'periods': [[45, 6], [45, 20]]}],
64, None, 32],
[6, 'default']],
['control 1',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 10], [0, 10], [5, 10]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 7,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [30, 20]]}],
3, None, 24],
[24, 'hw']],
['control 2',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 11,
'valid_to': 21,
'kind': 'relative',
'periods': [[30, 32], [10, 20], [45, 6]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 14,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 19,
'valid_to': 56,
'kind': 'absolute',
'periods': [[0, 6], [45, 10], [20, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 53,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 32], [0, 20]]}],
97, None, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 60,
'valid_to': 108,
'kind': 'absolute',
'periods': [[45, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[45, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 35,
'valid_to': 81,
'kind': 'relative',
'periods': [[5, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': 86,
'kind': 'absolute',
'periods': [[10, 16], [30, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 50,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [5, 10], [10, 10]]}],
55, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 37,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [20, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 43,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [45, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 4,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]}],
5, None, 16],
[16, 'hw']],
['control 1',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 20,
'valid_to': 56,
'kind': 'relative',
'periods': [[20, 10], [10, 20]]}],
53, 38, 24],
[20, 'default']],
['control 2',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 43,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 32], [45, 6], [20, 20]]}],
88, 57, 24],
[24, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 101,
'kind': 'relative',
'periods': [[20, 16]]}],
50, None, 32],
[32, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 60,
'valid_to': 84,
'kind': 'absolute',
'periods': [[20, 10], [20, 6]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 20], [10, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 45,
'valid_to': 120,
'kind': 'relative',
'periods': [[30, 16], [5, 20]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 34,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 31,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 20], [0, 10]]}],
90, None, 16],
[16, 'tx']],
['control 1',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 52,
'kind': 'absolute',
'periods': [[30, 16], [45, 32], [0, 16]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 13,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 58,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 16]]}],
74, None, 24],
[16, 'max']],
['control 2',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6], [10, 6], [20, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 59,
'valid_to': 85,
'kind': 'absolute',
'periods': [[5, 6], [5, 20], [30, 20]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [30, 10]]}],
15, 48, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 12,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 16], [5, 6]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 49,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [0, 32], [20, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 7,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16], [10, 20], [45, 10]]}],
58, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 39,
'valid_to': 47,
'kind': 'relative',
'periods': [[20, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 43,
'valid_to': 101,
'kind': 'relative',
'periods': [[5, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32], [30, 16], [0, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 59,
'valid_to': 64,
'kind': 'absolute',
'periods': [[0, 16], [5, 16]]}],
8, None, 32],
[32, 'hw']],
['control 1',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 22,
'valid_to': None,
'kind': 'relative',
'periods': [[30, 6]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 34,
'valid_to': 106,
'kind': 'absolute',
'periods': [[30, 16], [30, 10]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 11,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [30, 20]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 26,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 6], [5, 6], [45, 10]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 12,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 32], [20, 6]]}],
77, None, 24],
[20, 'tx']],
['control 2',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 55,
'valid_to': None,
'kind': 'absolute',
'periods': [[5, 10], [30, 10]]}],
25, 14, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 8,
'valid_to': 18,
'kind': 'relative',
'periods': [[20, 6]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 21,
'valid_to': 76,
'kind': 'relative',
'periods': [[10, 16]]}],
57, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 30,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10], [45, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 36,
'valid_to': 103,
'kind': 'absolute',
'periods': [[20, 32], [0, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 16], [20, 16]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 45,
'valid_to': 92,
'kind': 'relative',
'periods': [[45, 10], [20, 20], [10, 20]]}],
69, None, 24],
[24, 'hw']],
['control 1',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6]]}],
71, 15, 16],
[6, 'tx']],
['control 2',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 39,
'valid_to': 108,
'kind': 'absolute',
'periods': [[20, 16], [30, 32], [20, 20]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 45,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 21,
'valid_to': 46,
'kind': 'absolute',
'periods': [[5, 20]]}],
34, None, 24],
[20, 'default']]]]
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 |
|---|---|---|---|
| boundary: profile expires at t | [32, 'hw'] | [32, 'hw'] | Passed |
| boundary: relative profile without session | [8, 'default'] | [32, 'hw'] | Failed |
| boundary: tx overrides lower default | [20, 'tx'] | [20, 'tx'] | Passed |
| regression: relative profile without session | [10, 'tx'] | [24, 'hw'] | Failed |
| regression: relative profile without session (partial repair) | [10, 'tx'] | [6, 'default'] | Failed |
| control 1 | [24, 'hw'] | [24, 'hw'] | Passed |
| control 2 | [16, 'hw'] | [16, 'hw'] | Passed |
SHA-256 / 301c0e8cef3d142bed048d3681d8f91e9394893498342e19360d1dd5fe5ef5dd
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(profiles, t, session_start, hw_max):
best = {}
for p in profiles:
if not (p['valid_from'] <= t and (p['valid_to'] is None or t < p['valid_to'])):
continue
if p['kind'] == 'relative':
if session_start is None:
session_start = t
origin = session_start
else:
origin = p['valid_from']
el = t - origin
lim = None
for off, val in sorted(p['periods']):
if off <= el:
lim = val
if lim is None:
continue
cur = best.get(p['purpose'])
if cur is None or p['stack'] > cur[0]:
best[p['purpose']] = [p['stack'], lim]
cands = []
if 'max' in best:
cands.append(['max', best['max'][1]])
if 'tx' in best:
cands.append(['tx', best['tx'][1]])
elif 'default' in best:
cands.append(['default', best['default'][1]])
cands.append(['hw', hw_max])
win = cands[0]
for c in cands[1:]:
if c[1] < win[1]:
win = c
return [win[1], win[0]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 45,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 32], [45, 20], [5, 16]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 58,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [45, 32], [0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 42,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 10], [0, 32]]}],
56, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 37,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 20], [30, 32]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 57,
'valid_to': 117,
'kind': 'absolute',
'periods': [[5, 6], [10, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 32,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10]]},
{'purpose': 'max',
'stack': 2,
'valid_from': 38,
'valid_to': 95,
'kind': 'absolute',
'periods': [[45, 6], [45, 20]]}],
64, None, 32],
[6, 'default']],
['control 1',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 10], [0, 10], [5, 10]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 7,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [30, 20]]}],
3, None, 24],
[24, 'hw']],
['control 2',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 11,
'valid_to': 21,
'kind': 'relative',
'periods': [[30, 32], [10, 20], [45, 6]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 14,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 19,
'valid_to': 56,
'kind': 'absolute',
'periods': [[0, 6], [45, 10], [20, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 53,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 32], [0, 20]]}],
97, None, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 60,
'valid_to': 108,
'kind': 'absolute',
'periods': [[45, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[45, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 35,
'valid_to': 81,
'kind': 'relative',
'periods': [[5, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': 86,
'kind': 'absolute',
'periods': [[10, 16], [30, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 50,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [5, 10], [10, 10]]}],
55, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 37,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [20, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 43,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [45, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 4,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]}],
5, None, 16],
[16, 'hw']],
['control 1',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 20,
'valid_to': 56,
'kind': 'relative',
'periods': [[20, 10], [10, 20]]}],
53, 38, 24],
[20, 'default']],
['control 2',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 43,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 32], [45, 6], [20, 20]]}],
88, 57, 24],
[24, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 101,
'kind': 'relative',
'periods': [[20, 16]]}],
50, None, 32],
[32, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 60,
'valid_to': 84,
'kind': 'absolute',
'periods': [[20, 10], [20, 6]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 20], [10, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 45,
'valid_to': 120,
'kind': 'relative',
'periods': [[30, 16], [5, 20]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 34,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 31,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 20], [0, 10]]}],
90, None, 16],
[16, 'tx']],
['control 1',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 52,
'kind': 'absolute',
'periods': [[30, 16], [45, 32], [0, 16]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 13,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 58,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 16]]}],
74, None, 24],
[16, 'max']],
['control 2',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6], [10, 6], [20, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 59,
'valid_to': 85,
'kind': 'absolute',
'periods': [[5, 6], [5, 20], [30, 20]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [30, 10]]}],
15, 48, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 12,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 16], [5, 6]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 49,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [0, 32], [20, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 7,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16], [10, 20], [45, 10]]}],
58, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 39,
'valid_to': 47,
'kind': 'relative',
'periods': [[20, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 43,
'valid_to': 101,
'kind': 'relative',
'periods': [[5, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32], [30, 16], [0, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 59,
'valid_to': 64,
'kind': 'absolute',
'periods': [[0, 16], [5, 16]]}],
8, None, 32],
[32, 'hw']],
['control 1',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 22,
'valid_to': None,
'kind': 'relative',
'periods': [[30, 6]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 34,
'valid_to': 106,
'kind': 'absolute',
'periods': [[30, 16], [30, 10]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 11,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [30, 20]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 26,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 6], [5, 6], [45, 10]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 12,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 32], [20, 6]]}],
77, None, 24],
[20, 'tx']],
['control 2',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 55,
'valid_to': None,
'kind': 'absolute',
'periods': [[5, 10], [30, 10]]}],
25, 14, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 8,
'valid_to': 18,
'kind': 'relative',
'periods': [[20, 6]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 21,
'valid_to': 76,
'kind': 'relative',
'periods': [[10, 16]]}],
57, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 30,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10], [45, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 36,
'valid_to': 103,
'kind': 'absolute',
'periods': [[20, 32], [0, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 16], [20, 16]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 45,
'valid_to': 92,
'kind': 'relative',
'periods': [[45, 10], [20, 20], [10, 20]]}],
69, None, 24],
[24, 'hw']],
['control 1',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6]]}],
71, 15, 16],
[6, 'tx']],
['control 2',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 39,
'valid_to': 108,
'kind': 'absolute',
'periods': [[20, 16], [30, 32], [20, 20]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 45,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 21,
'valid_to': 46,
'kind': 'absolute',
'periods': [[5, 20]]}],
34, None, 24],
[20, 'default']]]]
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 |
|---|---|---|---|
| boundary: profile expires at t | [32, 'hw'] | [32, 'hw'] | Passed |
| boundary: relative profile without session | [8, 'default'] | [32, 'hw'] | Failed |
| boundary: tx overrides lower default | [20, 'tx'] | [20, 'tx'] | Passed |
| regression: relative profile without session | [24, 'hw'] | [24, 'hw'] | Passed |
| regression: relative profile without session (partial repair) | [20, 'default'] | [6, 'default'] | Failed |
| control 1 | [24, 'hw'] | [24, 'hw'] | Passed |
| control 2 | [16, 'hw'] | [16, 'hw'] | Passed |
SHA-256 / 8b88469402d265e587ab8f62274d829931de9acf958022e543237de08afc3146
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(profiles, t, session_start, hw_max):
best = {}
for p in profiles:
if not (p['valid_from'] <= t and (p['valid_to'] is None or t < p['valid_to'])):
continue
if p['kind'] == 'relative':
if session_start is None:
continue
origin = session_start
else:
origin = p['valid_from']
el = t - origin
lim = None
for off, val in sorted(p['periods']):
if off <= el:
lim = val
if lim is None:
continue
cur = best.get(p['purpose'])
if cur is None or p['stack'] > cur[0]:
best[p['purpose']] = [p['stack'], lim]
cands = []
if 'max' in best:
cands.append(['max', best['max'][1]])
if 'tx' in best:
cands.append(['tx', best['tx'][1]])
elif 'default' in best:
cands.append(['default', best['default'][1]])
cands.append(['hw', hw_max])
win = cands[0]
for c in cands[1:]:
if c[1] < win[1]:
win = c
return [win[1], win[0]]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 45,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 32], [45, 20], [5, 16]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 58,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [45, 32], [0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 42,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 10], [0, 32]]}],
56, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 37,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 20], [30, 32]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 57,
'valid_to': 117,
'kind': 'absolute',
'periods': [[5, 6], [10, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 32,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10]]},
{'purpose': 'max',
'stack': 2,
'valid_from': 38,
'valid_to': 95,
'kind': 'absolute',
'periods': [[45, 6], [45, 20]]}],
64, None, 32],
[6, 'default']],
['control 1',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 10], [0, 10], [5, 10]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 7,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [30, 20]]}],
3, None, 24],
[24, 'hw']],
['control 2',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 11,
'valid_to': 21,
'kind': 'relative',
'periods': [[30, 32], [10, 20], [45, 6]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 14,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 19,
'valid_to': 56,
'kind': 'absolute',
'periods': [[0, 6], [45, 10], [20, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 53,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 32], [0, 20]]}],
97, None, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 60,
'valid_to': 108,
'kind': 'absolute',
'periods': [[45, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[45, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 35,
'valid_to': 81,
'kind': 'relative',
'periods': [[5, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': 86,
'kind': 'absolute',
'periods': [[10, 16], [30, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 50,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [5, 10], [10, 10]]}],
55, None, 24],
[24, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 37,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [20, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 43,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [45, 6]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 4,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]}],
5, None, 16],
[16, 'hw']],
['control 1',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 20,
'valid_to': 56,
'kind': 'relative',
'periods': [[20, 10], [10, 20]]}],
53, 38, 24],
[20, 'default']],
['control 2',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 43,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 44,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 32], [45, 6], [20, 20]]}],
88, 57, 24],
[24, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 101,
'kind': 'relative',
'periods': [[20, 16]]}],
50, None, 32],
[32, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'max',
'stack': 1,
'valid_from': 60,
'valid_to': 84,
'kind': 'absolute',
'periods': [[20, 10], [20, 6]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 19,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 20], [10, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 45,
'valid_to': 120,
'kind': 'relative',
'periods': [[30, 16], [5, 20]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 34,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 16]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 31,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 20], [0, 10]]}],
90, None, 16],
[16, 'tx']],
['control 1',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': 52,
'kind': 'absolute',
'periods': [[30, 16], [45, 32], [0, 16]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 13,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6], [0, 10], [45, 16]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 58,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 16]]}],
74, None, 24],
[16, 'max']],
['control 2',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6], [10, 6], [20, 32]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 59,
'valid_to': 85,
'kind': 'absolute',
'periods': [[5, 6], [5, 20], [30, 20]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 29,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 10], [30, 10]]}],
15, 48, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 12,
'valid_to': None,
'kind': 'relative',
'periods': [[45, 16], [5, 6]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 49,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 16], [0, 32], [20, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 7,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16], [10, 20], [45, 10]]}],
58, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 39,
'valid_to': 47,
'kind': 'relative',
'periods': [[20, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 43,
'valid_to': 101,
'kind': 'relative',
'periods': [[5, 32]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 32], [30, 16], [0, 20]]},
{'purpose': 'max',
'stack': 1,
'valid_from': 39,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 16]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 59,
'valid_to': 64,
'kind': 'absolute',
'periods': [[0, 16], [5, 16]]}],
8, None, 32],
[32, 'hw']],
['control 1',
[[{'purpose': 'max',
'stack': 2,
'valid_from': 22,
'valid_to': None,
'kind': 'relative',
'periods': [[30, 6]]},
{'purpose': 'default',
'stack': 0,
'valid_from': 34,
'valid_to': 106,
'kind': 'absolute',
'periods': [[30, 16], [30, 10]]},
{'purpose': 'tx',
'stack': 2,
'valid_from': 11,
'valid_to': None,
'kind': 'absolute',
'periods': [[10, 6], [30, 20]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 26,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 6], [5, 6], [45, 10]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 12,
'valid_to': None,
'kind': 'absolute',
'periods': [[20, 32], [20, 6]]}],
77, None, 24],
[20, 'tx']],
['control 2',
[[{'purpose': 'default',
'stack': 2,
'valid_from': 55,
'valid_to': None,
'kind': 'absolute',
'periods': [[5, 10], [30, 10]]}],
25, 14, 16],
[16, 'hw']]],
[['boundary: profile expires at t',
[[{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': 30,
'kind': 'absolute',
'periods': [[0, 10]]}],
30, None, 32],
[32, 'hw']],
['boundary: relative profile without session',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 0,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 8]]}],
20, None, 32],
[32, 'hw']],
['boundary: tx overrides lower default',
[[{'purpose': 'default',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 6]]},
{'purpose': 'tx',
'stack': 0,
'valid_from': 0,
'valid_to': None,
'kind': 'absolute',
'periods': [[0, 20]]}],
5, 0, 32],
[20, 'tx']],
['regression: relative profile without session',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 8,
'valid_to': 18,
'kind': 'relative',
'periods': [[20, 6]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 21,
'valid_to': 76,
'kind': 'relative',
'periods': [[10, 16]]}],
57, None, 16],
[16, 'hw']],
['regression: relative profile without session (partial repair)',
[[{'purpose': 'default',
'stack': 1,
'valid_from': 30,
'valid_to': None,
'kind': 'relative',
'periods': [[10, 10], [45, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 36,
'valid_to': 103,
'kind': 'absolute',
'periods': [[20, 32], [0, 16]]},
{'purpose': 'tx',
'stack': 1,
'valid_from': 1,
'valid_to': None,
'kind': 'relative',
'periods': [[0, 10], [0, 16], [20, 16]]},
{'purpose': 'default',
'stack': 2,
'valid_from': 45,
'valid_to': 92,
'kind': 'relative',
'periods': [[45, 10], [20, 20], [10, 20]]}],
69, None, 24],
[24, 'hw']],
['control 1',
[[{'purpose': 'tx',
'stack': 1,
'valid_from': 8,
'valid_to': None,
'kind': 'absolute',
'periods': [[30, 6]]}],
71, 15, 16],
[6, 'tx']],
['control 2',
[[{'purpose': 'tx',
'stack': 2,
'valid_from': 39,
'valid_to': 108,
'kind': 'absolute',
'periods': [[20, 16], [30, 32], [20, 20]]},
{'purpose': 'max',
'stack': 0,
'valid_from': 45,
'valid_to': None,
'kind': 'relative',
'periods': [[5, 20]]},
{'purpose': 'default',
'stack': 1,
'valid_from': 21,
'valid_to': 46,
'kind': 'absolute',
'periods': [[5, 20]]}],
34, None, 24],
[20, 'default']]]]
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 |
|---|---|---|---|
| boundary: profile expires at t | [32, 'hw'] | [32, 'hw'] | Passed |
| boundary: relative profile without session | [32, 'hw'] | [32, 'hw'] | Passed |
| boundary: tx overrides lower default | [20, 'tx'] | [20, 'tx'] | Passed |
| regression: relative profile without session | [24, 'hw'] | [24, 'hw'] | Passed |
| regression: relative profile without session (partial repair) | [6, 'default'] | [6, 'default'] | Passed |
| control 1 | [24, 'hw'] | [24, 'hw'] | Passed |
| control 2 | [16, 'hw'] | [16, 'hw'] | Passed |
SHA-256 / 1e2c38c543082d91d75a9ae5ffc8c32388088f968bcf68554188dc5950a01ac1
Verification & scope
Deterministic stipulated toy contract for teaching; no claim of conformance with any standard, vendor protocol or production controller. 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:51:50.987163+00:00.
Case digest / f16ef5232ee92bac02ec0e7dfbac21d4a0b90e399c2f3bd0ad839d3d5533e7ea