FA-86096 / Game economy crafting balance / Open access
Stamina regeneration: Overspending drives stamina negative · case 01
Actions costing more than the pool are accepted with negative stamina.
ROOT CAUSE
The spend guard tests current stamina instead of the post-spend value.
VERIFIED REPAIR
Restore `if s + amount >= 0:` at the spend rejection step.
Unsuccessful approach: A strict guard rejects spends that would land exactly on zero.
Case contract
Stamina regenerates 1 per 300 s while below cap, anchored at last_tick. Events [time, amount] are applied in time order (then amount); before each event (and finally at now) regeneration catches up: if it reaches cap the value becomes cap and the anchor moves to the event time, otherwise the anchor advances by whole periods. While at or above cap the anchor follows the event time. Amounts may push stamina above cap up to 999; negative amounts are spends that are rejected if they would go below zero. Return [stamina, anchor].
Why this case matters
Game economies leak or destroy currency when one crafting or pricing rule is off by one boundary, rounding stage or state update; the defect is observable in exact integer outcomes.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
events = sorted(refills) + [[now, 0]]
t = last_tick
s = stamina
for at, amount in events:
if s < cap:
gained = (at - t) // 300
if s + gained >= cap:
s = cap
t = at
else:
s += gained
t += gained * 300
else:
t = at
if s >= 0:
s = min(999, s + amount)
return [s, t]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression spend rejection #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
('fault site spend rejection #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
('regression spend rejection #2', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('regression spend rejection #3', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
[('regression spend rejection #1', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('fault site spend rejection #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
('regression spend rejection #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('partial repair boundary #1', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
[('fault site spend rejection #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
('fault site spend rejection #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
('partial repair boundary #1', [9, 9, 584, 884, [[771, 9], [674, -9]]], [9, 884]),
('partial repair boundary #2', [12, 9, 347, 646, [[642, -3], [639, -9]]], [0, 639]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
('control #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
[('fault site spend rejection #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
('fault site spend rejection #2', [6, 14, 651, 651, [[651, -14]]], [6, 651]),
('partial repair boundary #1', [17, 17, 28, 28, [[28, 17], [28, 6], [28, -17]]], [23, 28]),
('partial repair boundary #2', [16, 16, 55, 655, [[155, -16]]], [1, 455]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
('control #2', [4, 13, 569, 868, [[776, 10]]], [14, 868])],
[('fault site spend rejection #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
('fault site spend rejection #2', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
('partial repair boundary #1', [17, 17, 627, 927, [[889, -17]]], [0, 889]),
('regression spend rejection #1', [0, 5, 348, 6234, [[3309, -5], [5758, -5], [6144, -5]]], [1, 6058]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [17, 18, 353, 353, []], [17, 353]),
('control #2', [0, 18, 176, 176, []], [0, 176])]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression spend rejection #1 | [-1, 266] | [0, 266] | Failed |
| fault site spend rejection #1 | [-3, 913] | [2, 913] | Failed |
| regression spend rejection #2 | [-17, 907] | [0, 907] | Failed |
| regression spend rejection #3 | [-1, 685] | [0, 969] | Failed |
| exact refill to cap #1 | [5, 600] | [5, 600] | Passed |
| overflow potion persists #1 | [15, 1200] | [15, 1200] | Passed |
| spend from full restarts timer #1 | [8, 1000] | [8, 1000] | Passed |
| control #1 | [3, 1315] | [3, 1315] | Passed |
SHA-256 / c8b5d58c3d6899df2b0fe46ff960a4a883ff523c2814ce465483676517905c27
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
events = sorted(refills) + [[now, 0]]
t = last_tick
s = stamina
for at, amount in events:
if s < cap:
gained = (at - t) // 300
if s + gained >= cap:
s = cap
t = at
else:
s += gained
t += gained * 300
else:
t = at
if s + amount > 0:
s = min(999, s + amount)
return [s, t]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression spend rejection #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
('fault site spend rejection #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
('regression spend rejection #2', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('regression spend rejection #3', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
[('regression spend rejection #1', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('fault site spend rejection #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
('regression spend rejection #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('partial repair boundary #1', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
[('fault site spend rejection #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
('fault site spend rejection #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
('partial repair boundary #1', [9, 9, 584, 884, [[771, 9], [674, -9]]], [9, 884]),
('partial repair boundary #2', [12, 9, 347, 646, [[642, -3], [639, -9]]], [0, 639]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
('control #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
[('fault site spend rejection #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
('fault site spend rejection #2', [6, 14, 651, 651, [[651, -14]]], [6, 651]),
('partial repair boundary #1', [17, 17, 28, 28, [[28, 17], [28, 6], [28, -17]]], [23, 28]),
('partial repair boundary #2', [16, 16, 55, 655, [[155, -16]]], [1, 455]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
('control #2', [4, 13, 569, 868, [[776, 10]]], [14, 868])],
[('fault site spend rejection #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
('fault site spend rejection #2', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
('partial repair boundary #1', [17, 17, 627, 927, [[889, -17]]], [0, 889]),
('regression spend rejection #1', [0, 5, 348, 6234, [[3309, -5], [5758, -5], [6144, -5]]], [1, 6058]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [17, 18, 353, 353, []], [17, 353]),
('control #2', [0, 18, 176, 176, []], [0, 176])]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression spend rejection #1 | [9, 266] | [0, 266] | Failed |
| fault site spend rejection #1 | [2, 913] | [2, 913] | Passed |
| regression spend rejection #2 | [5, 907] | [0, 907] | Failed |
| regression spend rejection #3 | [9, 984] | [0, 969] | Failed |
| exact refill to cap #1 | [5, 600] | [5, 600] | Passed |
| overflow potion persists #1 | [15, 1200] | [15, 1200] | Passed |
| spend from full restarts timer #1 | [8, 1000] | [8, 1000] | Passed |
| control #1 | [3, 1315] | [3, 1315] | Passed |
SHA-256 / 889da3d200858f6537577fa81b0b47318a2de7757944b3187bad0ad049849658
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(stamina, cap, last_tick, now, refills):
events = sorted(refills) + [[now, 0]]
t = last_tick
s = stamina
for at, amount in events:
if s < cap:
gained = (at - t) // 300
if s + gained >= cap:
s = cap
t = at
else:
s += gained
t += gained * 300
else:
t = at
if s + amount >= 0:
s = min(999, s + amount)
return [s, t]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
cases = [[('regression spend rejection #1', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
('fault site spend rejection #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
('regression spend rejection #2', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('regression spend rejection #3', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
[('regression spend rejection #1', [17, 17, 907, 907, [[907, -12], [907, -17], [907, -17]]], [0, 907]),
('fault site spend rejection #1', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
('regression spend rejection #2', [4, 5, 685, 984, [[969, -9], [731, -5], [931, 5]]], [0, 969]),
('partial repair boundary #1', [12, 13, 487, 4020, [[1176, -13], [3667, -7]]], [2, 3876]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
[('fault site spend rejection #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
('fault site spend rejection #2', [0, 10, 347, 646, [[390, -10], [479, -9]]], [0, 347]),
('partial repair boundary #1', [9, 9, 584, 884, [[771, 9], [674, -9]]], [9, 884]),
('partial repair boundary #2', [12, 9, 347, 646, [[642, -3], [639, -9]]], [0, 639]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('control #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
('control #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010])],
[('fault site spend rejection #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
('fault site spend rejection #2', [6, 14, 651, 651, [[651, -14]]], [6, 651]),
('partial repair boundary #1', [17, 17, 28, 28, [[28, 17], [28, 6], [28, -17]]], [23, 28]),
('partial repair boundary #2', [16, 16, 55, 655, [[155, -16]]], [1, 455]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('overflow potion persists #1', [5, 5, 0, 1200, [[100, 10]]], [15, 1200]),
('control #1', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
('control #2', [4, 13, 569, 868, [[776, 10]]], [14, 868])],
[('fault site spend rejection #1', [2, 19, 442, 741, [[703, -19]]], [2, 442]),
('fault site spend rejection #2', [9, 6, 0, 299, [[276, -6], [47, -6], [269, -6]]], [3, 47]),
('partial repair boundary #1', [17, 17, 627, 927, [[889, -17]]], [0, 889]),
('regression spend rejection #1', [0, 5, 348, 6234, [[3309, -5], [5758, -5], [6144, -5]]], [1, 6058]),
('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
('exact refill to cap #1', [3, 5, 0, 600, []], [5, 600]),
('control #1', [17, 18, 353, 353, []], [17, 353]),
('control #2', [0, 18, 176, 176, []], [0, 176])]]
for label, args, expected in cases[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 |
|---|---|---|---|
| regression spend rejection #1 | [0, 266] | [0, 266] | Passed |
| fault site spend rejection #1 | [2, 913] | [2, 913] | Passed |
| regression spend rejection #2 | [0, 907] | [0, 907] | Passed |
| regression spend rejection #3 | [0, 969] | [0, 969] | Passed |
| exact refill to cap #1 | [5, 600] | [5, 600] | Passed |
| overflow potion persists #1 | [15, 1200] | [15, 1200] | Passed |
| spend from full restarts timer #1 | [8, 1000] | [8, 1000] | Passed |
| control #1 | [3, 1315] | [3, 1315] | Passed |
SHA-256 / 0aab692e9d56d0eb673b0210ef49f6d0b7bc6a5f5be6631f7e9bd7a720be52ba
Verification & scope
Deterministic toy contract stipulated for this model; integer or exact arithmetic only, not a reproduction of any specific game engine. 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:50:46.341449+00:00.
Case digest / a31b059cc835304e79ce9eb4c8b94acce376d3b10157f7939b13cb3f5f824aa7