FAILURE MAP
← Case archive

FA-86106 / Game economy crafting balance / Open access

Stamina regeneration: Regen recounts periods since login · case 01

Every event re-grants stamina for time already credited.

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

ROOT CAUSE

Elapsed periods are measured from the original last_tick instead of the moving anchor.

VERIFIED REPAIR

Restore `gained = (at - t) // 300` at the elapsed periods step.

Unsuccessful approach: Ceiling division credits a partial period as a whole point.

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 - last_tick) // 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 = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('regression elapsed periods #2', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('partial repair boundary #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('partial repair boundary #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('regression elapsed periods #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('partial repair boundary #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression elapsed periods #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('partial repair boundary #1', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('partial repair boundary #2', [0, 15, 688, 1288, [[1231, 15], [743, 9], [808, 15]]], [39, 1288]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 12, 931, 4421, [[3673, 12], [2327, 12], [3157, -12]]], [17, 4421]),
  ('regression elapsed periods #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('partial repair boundary #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression elapsed periods #3', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('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', [17, 18, 353, 353, []], [17, 353])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [18, 15, 153, 3890, [[417, -12], [2092, 15], [2537, 15]]], [41, 3890]),
  ('regression elapsed periods #2', [0, 13, 2, 895, [[43, -5], [681, -12], [76, -13]]], [2, 602]),
  ('regression elapsed periods #3', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('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', [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 fixtureActualExpectedOutcome
spend from full restarts timer #1[9, 1300][8, 1000]Failed
regression elapsed periods #1[5, 1915][3, 1315]Failed
regression elapsed periods #2[18, 2462][14, 2462]Failed
partial repair boundary #1[15, 1583][15, 1583]Passed
partial repair boundary #2[32, 1010][32, 1010]Passed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / 3142c604fe5a8709e5dd3e1a35d88373f63ae6e4987aad89015f5e90d7bdd3e7

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 = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('regression elapsed periods #2', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('partial repair boundary #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('partial repair boundary #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('regression elapsed periods #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('partial repair boundary #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression elapsed periods #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('partial repair boundary #1', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('partial repair boundary #2', [0, 15, 688, 1288, [[1231, 15], [743, 9], [808, 15]]], [39, 1288]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 12, 931, 4421, [[3673, 12], [2327, 12], [3157, -12]]], [17, 4421]),
  ('regression elapsed periods #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('partial repair boundary #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression elapsed periods #3', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('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', [17, 18, 353, 353, []], [17, 353])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [18, 15, 153, 3890, [[417, -12], [2092, 15], [2537, 15]]], [41, 3890]),
  ('regression elapsed periods #2', [0, 13, 2, 895, [[43, -5], [681, -12], [76, -13]]], [2, 602]),
  ('regression elapsed periods #3', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('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', [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 fixtureActualExpectedOutcome
spend from full restarts timer #1[8, 1000][8, 1000]Passed
regression elapsed periods #1[4, 1615][3, 1315]Failed
regression elapsed periods #2[16, 2462][14, 2462]Failed
partial repair boundary #1[17, 1773][15, 1583]Failed
partial repair boundary #2[33, 1010][32, 1010]Failed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / f22aa209e714f2ee242f36284a4cd84df72579df2e67bd8c860fcc4685188cd1

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 = [[('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [23, 20, 972, 1572, [[1185, -20], [1315, -20], [1066, 20]]], [3, 1315]),
  ('regression elapsed periods #2', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('partial repair boundary #1', [16, 17, 83, 1773, [[154, -6]]], [15, 1583]),
  ('partial repair boundary #2', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('regression elapsed periods #2', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [12, 13, 710, 1010, [[793, 7], [721, 13]]], [32, 1010]),
  ('partial repair boundary #2', [11, 12, 57, 163, [[92, 12], [139, 12]]], [35, 163]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 19, 453, 6068, [[1708, -7], [2101, -3], [2012, -19]]], [15, 5853]),
  ('regression elapsed periods #2', [19, 17, 150, 2485, [[2240, -10]]], [9, 2240]),
  ('partial repair boundary #1', [4, 13, 569, 868, [[776, 10]]], [14, 868]),
  ('partial repair boundary #2', [0, 15, 688, 1288, [[1231, 15], [743, 9], [808, 15]]], [39, 1288]),
  ('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', [9, 9, 266, 266, [[266, -9], [266, -10]]], [0, 266])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [0, 12, 931, 4421, [[3673, 12], [2327, 12], [3157, -12]]], [17, 4421]),
  ('regression elapsed periods #2', [18, 15, 804, 1404, [[1122, -11], [838, -10], [1325, -15]]], [9, 1138]),
  ('partial repair boundary #1', [8, 9, 913, 1212, [[1053, -9], [963, -6], [1014, -5]]], [2, 913]),
  ('regression elapsed periods #3', [4, 11, 767, 2462, [[2177, 7], [1959, -11], [1673, 11]]], [14, 2462]),
  ('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', [17, 18, 353, 353, []], [17, 353])],
 [('spend from full restarts timer #1', [10, 10, 0, 1000, [[400, -4]]], [8, 1000]),
  ('regression elapsed periods #1', [18, 15, 153, 3890, [[417, -12], [2092, 15], [2537, 15]]], [41, 3890]),
  ('regression elapsed periods #2', [0, 13, 2, 895, [[43, -5], [681, -12], [76, -13]]], [2, 602]),
  ('regression elapsed periods #3', [20, 17, 920, 1520, [[1180, -17], [1013, -17], [1246, -5]]], [4, 1313]),
  ('partial repair boundary #1', [0, 14, 832, 1131, [[897, -4]]], [0, 832]),
  ('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', [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 fixtureActualExpectedOutcome
spend from full restarts timer #1[8, 1000][8, 1000]Passed
regression elapsed periods #1[3, 1315][3, 1315]Passed
regression elapsed periods #2[14, 2462][14, 2462]Passed
partial repair boundary #1[15, 1583][15, 1583]Passed
partial repair boundary #2[32, 1010][32, 1010]Passed
exact refill to cap #1[5, 600][5, 600]Passed
overflow potion persists #1[15, 1200][15, 1200]Passed
control #1[0, 266][0, 266]Passed

SHA-256 / de1b0c39de46b8545dffd927873a1b504153f1b8bd00ac94ae5acb0d999825f9

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

Case digest / 468fd99d37dc2bc27147cd2f9063f93b7d85efd9eee127497e488ad69137cbb3