FAILURE MAP
← Case archive

FA-86081 / Game economy crafting balance / Open access

Stamina regeneration: Reaching cap exactly keeps the old anchor · case 01

A player refilled exactly to cap keeps a stale timer and regains too early after spending.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Reaching the cap exactly is handled as a partial regen, leaving a stale anchor.

VERIFIED REPAIR

Restore `if s + gained >= cap:` at the cap reach test step.

Unsuccessful approach: Comparing only the gained ticks ignores the current stamina.

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 + 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 cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [14, 15, 389, 2081, []], [15, 2081]),
  ('partial repair boundary #2', [5, 6, 119, 719, []], [6, 719]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [10, 11, 108, 708, [[340, -11], [363, -11]]], [11, 708]),
  ('partial repair boundary #2', [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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
  ('control #2', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [9, 10, 70, 5274, [[4672, -8], [2667, 10], [5260, -10]]], [2, 5260]),
  ('partial repair boundary #2', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('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]),
  ('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('partial repair boundary #2', [4, 14, 252, 4128, [[1747, -14], [1416, -14], [1627, 14]]], [14, 4128]),
  ('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', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('control #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [16, 17, 643, 6372, [[1199, -17], [2262, -17]]], [17, 6372]),
  ('partial repair boundary #2', [11, 12, 804, 1404, [[1100, -12]]], [12, 1404]),
  ('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', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('control #2', [17, 18, 353, 353, []], [17, 353])]]
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 fixtureActualExpectedOutcome
regression cap reach test #1[1, 1321][0, 1232]Failed
regression cap reach test #2[6, 6175][6, 6407]Failed
partial repair boundary #1[15, 2081][15, 2081]Passed
partial repair boundary #2[6, 719][6, 719]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[0, 266][0, 266]Passed

SHA-256 / 95a0af1792550c9fb8b503e534a3d2c26bb8339751b2c8bde854c61c4fc68d99

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 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 cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [14, 15, 389, 2081, []], [15, 2081]),
  ('partial repair boundary #2', [5, 6, 119, 719, []], [6, 719]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [10, 11, 108, 708, [[340, -11], [363, -11]]], [11, 708]),
  ('partial repair boundary #2', [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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
  ('control #2', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [9, 10, 70, 5274, [[4672, -8], [2667, 10], [5260, -10]]], [2, 5260]),
  ('partial repair boundary #2', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('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]),
  ('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('partial repair boundary #2', [4, 14, 252, 4128, [[1747, -14], [1416, -14], [1627, 14]]], [14, 4128]),
  ('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', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('control #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [16, 17, 643, 6372, [[1199, -17], [2262, -17]]], [17, 6372]),
  ('partial repair boundary #2', [11, 12, 804, 1404, [[1100, -12]]], [12, 1404]),
  ('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', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('control #2', [17, 18, 353, 353, []], [17, 353])]]
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 fixtureActualExpectedOutcome
regression cap reach test #1[1, 1321][0, 1232]Failed
regression cap reach test #2[6, 6175][6, 6407]Failed
partial repair boundary #1[19, 1889][15, 2081]Failed
partial repair boundary #2[7, 719][6, 719]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[0, 266][0, 266]Passed

SHA-256 / 54d4f7ab5283d41cf34b01d883fd667bbdb4763a0ca29144e321cf96e9f25ea9

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 cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [14, 15, 389, 2081, []], [15, 2081]),
  ('partial repair boundary #2', [5, 6, 119, 719, []], [6, 719]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [10, 11, 108, 708, [[340, -11], [363, -11]]], [11, 708]),
  ('partial repair boundary #2', [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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266]),
  ('control #2', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [9, 10, 70, 5274, [[4672, -8], [2667, 10], [5260, -10]]], [2, 5260]),
  ('partial repair boundary #2', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('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]),
  ('control #2', [16, 17, 83, 1773, [[154, -6]]], [15, 1583])],
 [('regression cap reach test #1', [7, 8, 694, 1294, [[953, -8], [777, 8]]], [8, 1294]),
  ('regression cap reach test #2', [5, 6, 52, 1701, [[656, -3]]], [6, 1701]),
  ('partial repair boundary #1', [12, 13, 683, 4974, [[4778, -10], [2984, 11]]], [14, 4974]),
  ('partial repair boundary #2', [4, 14, 252, 4128, [[1747, -14], [1416, -14], [1627, 14]]], [14, 4128]),
  ('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', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('control #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163])],
 [('regression cap reach test #1', [18, 19, 721, 1321, [[1232, -19]]], [0, 1232]),
  ('regression cap reach test #2', [21, 18, 543, 6446, [[2575, -18], [4607, -18], [1660, 9]]], [6, 6407]),
  ('partial repair boundary #1', [16, 17, 643, 6372, [[1199, -17], [2262, -17]]], [17, 6372]),
  ('partial repair boundary #2', [11, 12, 804, 1404, [[1100, -12]]], [12, 1404]),
  ('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', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('control #2', [17, 18, 353, 353, []], [17, 353])]]
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 fixtureActualExpectedOutcome
regression cap reach test #1[0, 1232][0, 1232]Passed
regression cap reach test #2[6, 6407][6, 6407]Passed
partial repair boundary #1[15, 2081][15, 2081]Passed
partial repair boundary #2[6, 719][6, 719]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[0, 266][0, 266]Passed

SHA-256 / 0454926fb12367cd5b0bd3667366c6025e994ec8059fc7fd166da6752b3b51a8

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.301052+00:00.

Case digest / e283296586ed5a04b067f7e6a8eaf24b7317ce3e6f70cdac20bec88fa70568d9