infra: only a catch-protected reset is held; a step skipped for the archive just used climbs, so the rung below is reached promptly (row 70 review r2)

This commit is contained in:
acamilo 2026-09-30 20:59:58 +00:00
parent a84e617fc9
commit e35858e96e
3 changed files with 20 additions and 10 deletions

View file

@ -291,11 +291,10 @@ def run(now=None, sleep=time.sleep, clock=None):
resets_left = MAX_RESETS - len(state["resets"])
action, target = plan(level, rank, state.get("bestRank", 0), resets_left, state.get("lastReset"))
protected = action == "reset" and now - state.get("speciesAt", -PROTECT) < PROTECT
# A reset turned into a restart (protected catch, or the archive just restored) does not climb:
# the level keeps its slot for when the window ends, so it never drops a rung deeper (row 70).
held_reset = protected or (level and resets_left and action == "restart" and rank is not None
and (rank if level == 1 else max(state.get("bestRank", 0), rank) - 1)
== state.get("lastReset"))
# Only a catch-protected reset is held (the level keeps its slot, so it never drops a rung deeper
# while the window lasts, row 70). A step skipped because it would restore the archive just used
# does climb, so the ladder reaches the rung below promptly.
held_reset = protected
if protected:
action, target = "restart", None
if action == "restart" and level and now - acted < HOLD:

View file

@ -30,7 +30,7 @@ a ladder one step per trap that outlives the previous step:
same rung, once the window ends. Evolution also counts as a species owned.
- **No archive twice in a row:** a reset never restores the same archive as the last reset,
until a new best rung is reached or twelve hours have passed (`AGAIN`; a trap no restart clears
is reset again in bounded time, no later than before this rule). Such a step does not climb. A restore is deterministic, so the same archive replays the
is reset again in bounded time, no later than before this rule). Such a step does climb, so the rung below is reached promptly. A restore is deterministic, so the same archive replays the
same run into the same trap. Row 70's second reset to rung 11 matched the first one event for
event: the same Zubat caught, the same trap an hour later, and the catch erased. That step is
a restart instead.

View file

@ -159,7 +159,7 @@ class RecoveryTests(unittest.TestCase):
self.confirm(T0)
self.assertEqual(self.acts, [("restart", None)])
def test_a_held_reset_does_not_climb_and_the_marker_expires(self):
def test_a_protected_reset_does_not_climb_but_the_archive_just_used_does(self):
# protected: the restart keeps the level's slot, so the reset comes at the same rung later
owned = T0 - 600
recover.write_json(recover.STATE, {"level": 1, "bestRank": 12, "resets": [], "actedAt": 0,
@ -167,11 +167,11 @@ class RecoveryTests(unittest.TestCase):
self.confirm(T0)
self.assertEqual(self.acts, [("restart", None)])
self.assertEqual(recover.load(recover.STATE, {}).get("level"), 1)
# the archive just restored: same, and the marker is forgotten after AGAIN
# the archive just restored: a restart that climbs, and the marker is forgotten after AGAIN
self.acts.clear()
reset_at = T0 - recover.HOLD - 100
recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "resets": [reset_at], "actedAt": reset_at,
"lastReset": 11, "lastResetAt": reset_at})
recover.write_json(recover.STATE, {"level": 1, "bestRank": 12, "resets": [reset_at], "actedAt": reset_at,
"lastReset": 12, "lastResetAt": reset_at})
self.confirm(T0 + 1000)
self.assertEqual(self.acts, [("restart", None)])
self.assertEqual(recover.load(recover.STATE, {}).get("level"), 2)
@ -429,6 +429,17 @@ class ClosedLoopTests(unittest.TestCase):
acts = self.simulate({11: self.R11, 12: self.R12, 10: self.R10, 9: self.R10}, 24)
self.assertLessEqual(next(a[0] for a in acts if a[1] == "reset"), 1, acts)
def test_a_trap_only_the_rung_below_escapes_is_reached_promptly(self):
# review r2 N1: the rung-12 replay re-earns progress, then traps; only rung 11 escapes.
# v0.7.0 reset to 11 at 2.08 h; holding the level on the archive just used took 24.75 h.
late12 = dict(events=[(30, "area"), (40, "pokedex")], trap=60, rank_after=[], start_rank=12)
clean11 = dict(self.R11, trap=None)
acts = self.simulate({11: clean11, 12: late12, 10: self.R10, 9: self.R10}, 96)
resets = [a for a in acts if a[1] == "reset"]
self.assertEqual([a[2] for a in resets], [12, 11], acts)
self.assertLessEqual(resets[-1][0], 8, acts)
self.assertLess([a[2] for a in resets].count(12), 2, acts)
class WrapperTests(unittest.TestCase):
"""infra/bin/fly-loop-reset against a fake flysim, systemctl, reset tool and archives."""