infra: the recovery ladder starts over after real progress, keeps a recent catch, and never replays one archive twice (row 70)

Check 10 now reports window.progress (a milestone, and pokedex/area/trainer/badge rewards; the
species alone), read by no rule. fly-loop-recover returns to level 0 when lasting progress
follows the last step by more than SETTLE, demotes a milestone reset to a restart within six
hours of a species owned, and never restores the archive the last reset restored (a restore is
deterministic: the live rung-11 replay matched the first one event for event and walked into the
same trap). Ladder tests, lint check 10 case 9, loop-recovery.md, macros-traps row 70b-e.
This commit is contained in:
acamilo 2026-09-30 19:26:35 +00:00
parent 539d73bc36
commit d7f5ef5ff7
6 changed files with 197 additions and 19 deletions

View file

@ -3,8 +3,11 @@
Ladder (infra/docs/loop-recovery.md): restart flysim, then reset to the current rung's Ladder (infra/docs/loop-recovery.md): restart flysim, then reset to the current rung's
milestone, then to the rung below. It climbs one step per confirmed trap that outlives milestone, then to the rung below. It climbs one step per confirmed trap that outlives
the previous step, and starts over once the fly reaches a new best rung or has been the previous step, and starts over once the fly reaches a new best rung, makes lasting
quiet for QUIET seconds. A router model can delay a step, never deny it. progress after the last step, or has been quiet for QUIET seconds. A milestone reset
never erases a species owned within PROTECT seconds, and never repeats the last reset's
archive (a restore replays it exactly); either is a restart instead. A router model can
delay a step, never deny it.
""" """
import json import json
import os import os
@ -29,6 +32,7 @@ QUIET = 6 * 3600 # this long without a suspected report starts the ladder ov
HOLD = 3 * 3600 # restart-only spacing while the reset budget is spent HOLD = 3 * 3600 # restart-only spacing while the reset budget is spent
DAY = 24 * 3600 DAY = 24 * 3600
MAX_RESETS = 2 # milestone resets per DAY MAX_RESETS = 2 # milestone resets per DAY
PROTECT = 6 * 3600 # a species owned this recently is not reset away (row 70)
VETO_LIMIT = 3 # model vetoes of one step before it goes ahead anyway VETO_LIMIT = 3 # model vetoes of one step before it goes ahead anyway
MODEL_BUDGET = 90 # seconds across all models in one decision MODEL_BUDGET = 90 # seconds across all models in one decision
VERIFY_TIMEOUT = 240 VERIFY_TIMEOUT = 240
@ -142,16 +146,19 @@ def rungs():
return sorted(found) return sorted(found)
def plan(level, rank, best, resets_left): def plan(level, rank, best, resets_left, last_reset=None):
"""(action, target rung) for a ladder level; a spent budget or no restorable archive is a restart. """(action, target rung) for a ladder level; a spent budget or no restorable archive is a restart.
Level 1 resets to the current rung's archive; level 2 and beyond to the rung below the best, Level 1 resets to the current rung's archive; level 2 and beyond to the rung below the best,
and never lower, so repeated days of a trap cannot walk the run down the ladder. and never lower, so repeated days of a trap cannot walk the run down the ladder. The archive
the last reset restored is not restored again (`last_reset`, cleared by a new best rung): a
restore is deterministic, so the same archive replays the same run into the same trap (row 70:
the second reset to rung 11 matched the first event for event).
""" """
if level == 0 or not resets_left or rank is None: if level == 0 or not resets_left or rank is None:
return "restart", None return "restart", None
target = rank if level == 1 else max(best, rank) - 1 target = rank if level == 1 else max(best, rank) - 1
if target > rank or target not in restorable_rungs(): if target > rank or target == last_reset or target not in restorable_rungs():
return "restart", None return "restart", None
return "reset", target return "reset", target
@ -226,6 +233,7 @@ def run(now=None, sleep=time.sleep, clock=None):
if level: if level:
log({"at": now, "event": "ladder-reset", "why": "new best rung", "rank": rank}) log({"at": now, "event": "ladder-reset", "why": "new best rung", "rank": rank})
state.update(bestRank=rank, level=0) state.update(bestRank=rank, level=0)
state.pop("lastReset", None)
level = 0 level = 0
last = state.get("lastSuspectedAt") last = state.get("lastSuspectedAt")
if level and last and now - last > QUIET: if level and last and now - last > QUIET:
@ -234,6 +242,19 @@ def run(now=None, sleep=time.sleep, clock=None):
state["resets"] = [at for at in state.get("resets", []) if now - at < DAY] state["resets"] = [at for at in state.get("resets", []) if now - at < DAY]
at = report.get("at") at = report.get("at")
# Row 70: lasting progress in the probe's window (a new rung, a species owned, a map entered,
# a trainer or badge beaten; the watchdog's window.progress). The ladder climbs for a trap that
# OUTLIVES its last step; one that follows real progress after that step is a new trap and
# starts again from a restart. A species owned is also kept from a milestone reset for PROTECT.
progress = (report.get("window") or {}).get("progress") or {}
if type(at) is int and 0 <= now - at <= 600 and type(progress) is dict:
if type(progress.get("lasting")) is int and progress["lasting"] > 0:
state["progressAt"] = max(at, state.get("progressAt", 0))
if type(progress.get("species")) is int and progress["species"] > 0:
state["speciesAt"] = max(at, state.get("speciesAt", 0))
if level and state.get("progressAt", 0) > state.get("actedAt", 0) + SETTLE:
log({"at": now, "event": "ladder-reset", "why": "progress since the last step", "rank": rank})
state["level"] = level = 0
# The last probe that saw progress (new places, or a higher rung than the last probe), kept across # The last probe that saw progress (new places, or a higher rung than the last probe), kept across
# restarts and reboots so the stream's STUCK time counts the whole trap, not the last streak. # restarts and reboots so the stream's STUCK time counts the whole trap, not the last streak.
delta = (report.get("places") or {}).get("delta") delta = (report.get("places") or {}).get("delta")
@ -265,10 +286,18 @@ def run(now=None, sleep=time.sleep, clock=None):
return "waiting for next probe" return "waiting for next probe"
resets_left = MAX_RESETS - len(state["resets"]) resets_left = MAX_RESETS - len(state["resets"])
action, target = plan(level, rank, state.get("bestRank", 0), resets_left) action, target = plan(level, rank, state.get("bestRank", 0), resets_left, state.get("lastReset"))
protected = action == "reset" and now - state.get("speciesAt", -PROTECT) < PROTECT
if protected:
action, target = "restart", None
if action == "restart" and level and now - acted < HOLD: if action == "restart" and level and now - acted < HOLD:
write_json(STATE, state) write_json(STATE, state)
return "holding: reset budget spent, next restart after the hold" if protected:
return "holding: a species owned within the protection window, next restart after the hold"
return "holding: no reset to take, next restart after the hold"
if protected:
log({"at": now, "event": "protect", "why": "a species owned within the protection window",
"speciesAt": state["speciesAt"], "rank": rank})
stuck, model = verdict(report) stuck, model = verdict(report)
if stuck is False and state.get("vetoes", 0) < VETO_LIMIT: if stuck is False and state.get("vetoes", 0) < VETO_LIMIT:
@ -294,6 +323,7 @@ def run(now=None, sleep=time.sleep, clock=None):
state.pop("observedAt", None) state.pop("observedAt", None)
if action == "reset": if action == "reset":
state["resets"].append(started) state["resets"].append(started)
state["lastReset"] = target
write_json(STATE, state) write_json(STATE, state)
notice(base, "acting", started) notice(base, "acting", started)
ok = act(action, target) ok = act(action, target)

View file

@ -880,7 +880,7 @@ loop_status_fields() {
loop_macro_stream() { loop_macro_stream() {
[ -f "$FLY_EVENT_LOG" ] || return 0 [ -f "$FLY_EVENT_LOG" ] || return 0
tail -n "$WD_LOOP_TAIL_LINES" "$FLY_EVENT_LOG" 2>/dev/null \ tail -n "$WD_LOOP_TAIL_LINES" "$FLY_EVENT_LOG" 2>/dev/null \
| jq -r 'fromjson? // empty | select(.kind == "macro" or .kind == "reward") | "\(.brainMs)\t\(.label)\t\(.kind)\t\(.rewardKind // "")"' -R 2>/dev/null \ | jq -r 'fromjson? // empty | select(.kind == "macro" or .kind == "reward" or .kind == "milestone") | "\(.brainMs)\t\(.label)\t\(.kind)\t\(.rewardKind // "")"' -R 2>/dev/null \
|| true || true
} }
@ -888,13 +888,19 @@ loop_macro_stream() {
# #
# total US distinct US topCount US period US repeats US windowFrom US # total US distinct US topCount US period US repeats US windowFrom US
# windowTo US topName US block US tail US decisions US refused US blocked US # windowTo US topName US block US tail US decisions US refused US blocked US
# timeout US done US rewards US fights US wins # timeout US done US rewards US fights US wins US progress US species
# #
# `total` counts start events inside the window, `decisions` starts plus # `total` counts start events inside the window, `decisions` starts plus
# refusals (the sequence, `distinct` and `topCount` are over decisions), and # refusals (the sequence, `distinct` and `topCount` are over decisions), and
# the next four count each outcome in the window, and `rewards` the reward # the next four count each outcome in the window, and `rewards` the reward
# events in it (row 58), `fights` the `MOVE n` decisions and `wins` the # events in it (row 58), `fights` the `MOVE n` decisions and `wins` the
# rewards of kind wildwin/trainer/badge (row 67). `period`/`repeats` describe # rewards of kind wildwin/trainer/badge (row 67). `progress` counts the lasting
# progress in the window (row 70): a `milestone` event (a new rung), or a reward of kind
# pokedex (a species owned for the first time), area (a map entered for the first time),
# trainer or badge -- each paid once per run, so a ring cannot earn them twice -- and
# `species` the pokedex ones alone. They are reported, never read by a rule here: the
# recovery ladder uses them to tell a trap that follows real progress from one that
# outlived its last step. `period`/`repeats` describe
# the shortest repeating block at the END of the sequence (0/0 when nothing # the shortest repeating block at the END of the sequence (0/0 when nothing
# repeats), `block` is that block comma-joined, and `tail` is the last 12 # repeats), `block` is that block comma-joined, and `tail` is the last 12
# names for context. The window ends at the newest macro event's own brain # names for context. The window ends at the newest macro event's own brain
@ -904,16 +910,20 @@ loop_analyze() {
# Reward lines are counted and nothing else: the window still ends at the # Reward lines are counted and nothing else: the window still ends at the
# newest macro event, as it always has. # newest macro event, as it always has.
$3 == "reward" { rms[++nr] = $1 + 0; rkind[nr] = $4; next } $3 == "reward" { rms[++nr] = $1 + 0; rkind[nr] = $4; next }
$3 == "milestone" { rms[++nr] = $1 + 0; rkind[nr] = "milestone"; next }
{ ms[++n] = $1 + 0; lbl[n] = $2 } { ms[++n] = $1 + 0; lbl[n] = $2 }
END { END {
if (n == 0) { printf "0\0370\0370\0370\0370\0370\0370\037\037\037\0370\0370\0370\0370\0370\0370\0370\0370\n"; exit } if (n == 0) { printf "0\0370\0370\0370\0370\0370\0370\037\037\037\0370\0370\0370\0370\0370\0370\0370\0370\0370\0370\n"; exit }
to = ms[n]; from = to - win to = ms[n]; from = to - win
k = 0; distinct = 0; topn = 0; top = "" k = 0; distinct = 0; topn = 0; top = ""
starts = 0; refused = 0; blocked = 0; timeout = 0; done = 0; rewards = 0 starts = 0; refused = 0; blocked = 0; timeout = 0; done = 0; rewards = 0
fights = 0; wins = 0 fights = 0; wins = 0; progress = 0; species = 0
for (q = 1; q <= nr; q++) if (rms[q] >= from) { for (q = 1; q <= nr; q++) if (rms[q] >= from) {
if (rkind[q] == "milestone") { progress++; continue }
rewards++ rewards++
if (rkind[q] == "wildwin" || rkind[q] == "trainer" || rkind[q] == "badge") wins++ if (rkind[q] == "wildwin" || rkind[q] == "trainer" || rkind[q] == "badge") wins++
if (rkind[q] == "pokedex" || rkind[q] == "area" || rkind[q] == "trainer" || rkind[q] == "badge") progress++
if (rkind[q] == "pokedex") species++
} }
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++) {
if (ms[i] < from) continue if (ms[i] < from) continue
@ -948,9 +958,9 @@ loop_analyze() {
tailstr = "" tailstr = ""
start = k - 11; if (start < 1) start = 1 start = k - 11; if (start < 1) start = 1
for (j = start; j <= k; j++) tailstr = tailstr (tailstr == "" ? "" : ", ") seq[j] for (j = start; j <= k; j++) tailstr = tailstr (tailstr == "" ? "" : ", ") seq[j]
printf "%d\037%d\037%d\037%d\037%d\037%d\037%d\037%s\037%s\037%s\037%d\037%d\037%d\037%d\037%d\037%d\037%d\037%d\n", \ printf "%d\037%d\037%d\037%d\037%d\037%d\037%d\037%s\037%s\037%s\037%d\037%d\037%d\037%d\037%d\037%d\037%d\037%d\037%d\037%d\n", \
starts, distinct, topn, period, repeats, from, to, top, block, tailstr, \ starts, distinct, topn, period, repeats, from, to, top, block, tailstr, \
k, refused, blocked, timeout, done, rewards, fights, wins k, refused, blocked, timeout, done, rewards, fights, wins, progress, species
}' }'
} }
@ -1008,15 +1018,15 @@ check_loop() {
echo "$delta" > "${WD_RUN_DIR}/loop.places_delta" echo "$delta" > "${WD_RUN_DIR}/loop.places_delta"
local analysis total distinct topn period repeats win_from win_to top block tailstr local analysis total distinct topn period repeats win_from win_to top block tailstr
local decisions refused blocked timeouts completed rewards fights wins local decisions refused blocked timeouts completed rewards fights wins progress species
analysis="$(loop_macro_stream | loop_analyze)" analysis="$(loop_macro_stream | loop_analyze)"
IFS=$'\037' read -r total distinct topn period repeats win_from win_to top block tailstr \ IFS=$'\037' read -r total distinct topn period repeats win_from win_to top block tailstr \
decisions refused blocked timeouts completed rewards fights wins <<< "$analysis" decisions refused blocked timeouts completed rewards fights wins progress species <<< "$analysis"
total="${total:-0}"; distinct="${distinct:-0}"; topn="${topn:-0}" total="${total:-0}"; distinct="${distinct:-0}"; topn="${topn:-0}"
period="${period:-0}"; repeats="${repeats:-0}" period="${period:-0}"; repeats="${repeats:-0}"
decisions="${decisions:-0}"; refused="${refused:-0}"; blocked="${blocked:-0}" decisions="${decisions:-0}"; refused="${refused:-0}"; blocked="${blocked:-0}"
timeouts="${timeouts:-0}"; completed="${completed:-0}"; rewards="${rewards:-0}" timeouts="${timeouts:-0}"; completed="${completed:-0}"; rewards="${rewards:-0}"
fights="${fights:-0}"; wins="${wins:-0}" fights="${fights:-0}"; wins="${wins:-0}"; progress="${progress:-0}"; species="${species:-0}"
echo "$distinct" > "${WD_RUN_DIR}/loop.distinct" echo "$distinct" > "${WD_RUN_DIR}/loop.distinct"
echo "$period" > "${WD_RUN_DIR}/loop.period" echo "$period" > "${WD_RUN_DIR}/loop.period"
echo "$repeats" > "${WD_RUN_DIR}/loop.repeats" echo "$repeats" > "${WD_RUN_DIR}/loop.repeats"
@ -1130,6 +1140,8 @@ check_loop() {
--argjson rewards "$rewards" \ --argjson rewards "$rewards" \
--argjson fights "$fights" \ --argjson fights "$fights" \
--argjson wins "$wins" \ --argjson wins "$wins" \
--argjson progress "$progress" \
--argjson species "$species" \
--argjson windowFrom "${win_from:-0}" \ --argjson windowFrom "${win_from:-0}" \
--argjson windowTo "${win_to:-0}" \ --argjson windowTo "${win_to:-0}" \
--argjson windowMs "$WD_LOOP_WINDOW_MS" \ --argjson windowMs "$WD_LOOP_WINDOW_MS" \
@ -1161,6 +1173,7 @@ check_loop() {
rewards: $rewards, rewards: $rewards,
fights: $fights, fights: $fights,
wins: $wins, wins: $wins,
progress: { lasting: $progress, species: $species },
tail: (if $tail == "" then [] else ($tail | split(", ")) end) tail: (if $tail == "" then [] else ($tail | split(", ")) end)
}, },
dominant: { name: (if $dominant == "" then null else $dominant end), dominant: { name: (if $dominant == "" then null else $dominant end),

View file

@ -17,8 +17,20 @@ a ladder one step per trap that outlives the previous step:
- **Budget:** at most two milestone resets per 24 hours. With the budget spent the step is a - **Budget:** at most two milestone resets per 24 hours. With the budget spent the step is a
restart, at most every three hours, until a reset is free again. The same three-hour spacing applies restart, at most every three hours, until a reset is free again. The same three-hour spacing applies
when a reset level finds no restorable rung and restarts instead. when a reset level finds no restorable rung and restarts instead.
- **Starting over:** the ladder returns to level 0 when the fly reaches a new best rung, or after - **Starting over:** the ladder returns to level 0 when the fly reaches a new best rung, after
six hours with no suspected report. six hours with no suspected report, or when a probe's window shows lasting progress more than
20 minutes after the last step (row 70). Lasting progress is the watchdog's `window.progress`:
a new rung, a species owned for the first time, a map entered for the first time, or a trainer
or badge beaten. The run pays each of these once, so a ring cannot earn them twice. A trap that
follows real progress is a new trap, and it starts again from a restart.
- **Protected catches:** a milestone reset never erases a species owned in the last six hours
(`PROTECT`, from `window.progress.species`). Within that window the step is a restart, spaced by
the hold like a spent budget, and `history.jsonl` records a `protect` event.
- **No archive twice in a row:** a reset never restores the same archive as the last reset,
until a new best rung is reached. 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.
A milestone step only uses an archive the running build can restore. `fly-loop-reset --list` A milestone step only uses an archive the running build can restore. `fly-loop-reset --list`
compares each archive's compatibility string with `flysim --print-compatibility` and accepts an compares each archive's compatibility string with `flysim --print-compatibility` and accepts an

View file

@ -3629,3 +3629,54 @@ ROM tests on the build box (rom-env sourced):
The stub reaches row 70 by itself. From the live rung-12 archive (Mt. Moon's mouth, one ball), The stub reaches row 70 by itself. From the live rung-12 archive (Mt. Moon's mouth, one ball),
three uniform-stub seeds each catch a Zubat within 4,000 frames and meet the same Lass. There three uniform-stub seeds each catch a Zubat within 4,000 frames and meet the same Lass. There
Wartortle faints at f27,361, f34,656 and f35,284. Wartortle faints at f27,361, f34,656 and f35,284.
### The watchdog and the ladder: every act was on a real trap
The day's six acts, replayed probe by probe through check 10 and the ladder from the live logs
(open loop; uniqueLocations proxied from the tile rewards). The base replay reproduces the live
history: restarts at 05:55, 08:55 and 11:55, and resets to rung 11 at 16:50 and 18:49 (live:
16:54 and 18:50).
| live act | window | what the fly was doing |
| --- | --- | --- |
| restarts 05:57, 08:58, 11:59 (map 59) | `unwon-battles`, 05:50 to 13:50 | Row 67 again, against a Lass on Mt. Moon 1F. `MOVE 2` (TAIL WHIP) on six turns in seven, BUBBLE doing 5 to 8 to her Oddish, 34 to 48 moves per window, no battle won, whiteout and back. Beaten after the 11:59 restart (13:54, then the other 1F trainers, B2F's and the Super Nerd) |
| reset to 11, 16:54 (map 61, B2F) | `unrewarded`, 15:05 to 16:50 | A wild encounter every ~20 s, `RUN` every time (220), `GO FRONTIER`/`GO WARP` between them, and no new tile or reward for 1 h 50 min. The battles were ending and the fly was moving between them, but on ground it had already covered. Mechanism not established: no checkpoint from before 16:54 survives (row 64/65 territory, B2F's far side) |
| reset to 11, 18:50 (map 59) | `dominant`/`sequence`, 17:59 on | Row 70's list: `NEXT` alone for 58 brain minutes |
So check 10 read no cave as a trap. Healthy cave windows (17:04 to 17:54: Route 3 and Mt. Moon
battles won, a catch, new areas) peaked at 94% `NEXT`, and the tile gate kept them clear. Two
suggested relaxations are **not** supported by the evidence:
- "Battles ending and the fly moving between them": the 16:54 window was exactly that for
1 h 50 min, with nothing new.
- Counting the damage reward's KO as a win: the Lass ring had 45 KOs of her first Pokémon in
eight hours and never won.
The watchdog's flags are unchanged. Every replayed log (rows 58, 60 to 64, 67, 70) flags on the
same probes with the same reasons, base and branch.
What went wrong was the ladder. It stayed at level 3 to 4 from the morning's ring through a
rung-11 reset and a full, rewarded climb back to Mt. Moon. The 18:50 reset then restored the
same rung-11 archive as the 16:54 one. A restore is deterministic: the replay after it matched
the one before event for event (1,138 of 1,138, same `brainMs`). So the reset erased the catch
and walked back into the same list about an hour later. It also could not have helped: row 70's
trap is in the game state, not the ledgers, so neither a restart nor a replay clears it.
| # | trap | trigger | test | fix, or why it is left |
| --- | --- | --- | --- | --- |
| 70b | the ladder never started over after real progress. A trap after a reset and a rewarded climb back was treated as the old trap outliving its step | a reset, then progress, then any trap | `test_progress_after_the_last_step_starts_the_ladder_over`, `test_progress_while_a_step_settles_does_not_start_the_ladder_over` | **fixed**: `window.progress` in loop.json (report only; `lint.sh` check 10 case 9). Lasting progress more than `SETTLE` after the step returns the ladder to level 0 |
| 70c | a reset restored the same archive as the last reset, which replays deterministically into the same trap | level 2 and above, where every step targets the rung below the best | `test_the_last_resets_archive_is_not_restored_again`, `test_a_reset_records_its_archive_and_a_new_best_rung_forgets_it` | **fixed**: that step is a restart |
| 70d | a reset erased a catch made an hour earlier | any reset after a catch | `test_a_species_owned_recently_is_never_reset_away`, `test_a_probe_that_owns_a_species_starts_the_protection` | **fixed**: within six hours of a species owned, a reset is a restart (held three hours apart) |
| 70e | the B2F wander: `RUN` from every encounter, walks on covered ground, nothing new for 1 h 50 min | Mt. Moon B2F after the Super Nerd | -- | **left, named**: no checkpoint survived. The next occurrence should be pulled before any reset |
Ladder replay of the day (the same logs and the same start state, base against branch):
- **Base**: restarts at 01:30, 05:55, 08:55, 11:55 and 15:10; resets to 11 at 16:50 and 18:49.
- **Branch**: restarts at 01:30, 05:55, 07:15, 10:30, 13:30 and 15:10; a reset to 12 (the
current rung, not 11) at 16:50; a restart at 18:04.
- 07:15: AREA 60 at 06:48 started the ladder over.
- 18:04: the climb after 16:50 started the ladder over.
- After 18:04, no reset. The Zubat was owned at 17:46 and rung 12 was the last reset's
archive, so the branch holds to restarts three hours apart.
The replay is open loop: the log after 16:50 is what the base's reset produced.

View file

@ -2015,6 +2015,29 @@ LPCAT
fail "check 10: a won battle gave suspected=$(lp_metric fly_loop_suspected) wins=$(lp_metric fly_loop_wins)" fail "check 10: a won battle gave suspected=$(lp_metric fly_loop_suspected) wins=$(lp_metric fly_loop_wins)"
fi fi
# (9) Row 70: the report carries the window's lasting progress for the recovery ladder --
# a milestone event, and rewards of kind pokedex/area/trainer/badge -- and the species
# alone. The flag itself does not read them: the same battles still flag with a species
# owned in the window, as long as nothing was won.
lp_reset
lp_cycle 25 "GO OBJECTIVE" "TALK" "NO" "NEXT" "NEXT" "NEXT" "MOVE 2" "NEXT" \
"MOVE 2" "NEXT" "MOVE 3" "NEXT" | lp_outcomes "$lp_fixture/events.jsonl" "done"
printf '%s\n' \
'{"id":999991,"wallMs":1758000999991,"brainMs":100000,"kind":"reward","label":"OWNED #41","value":0.5,"rewardKind":"pokedex"}' \
'{"id":999992,"wallMs":1758000999992,"brainMs":100001,"kind":"reward","label":"AREA 59","value":0.2,"rewardKind":"area"}' \
'{"id":999993,"wallMs":1758000999993,"brainMs":100002,"kind":"milestone","label":"Reached MT. MOON","value":12}' \
>> "$lp_fixture/events.jsonl"
lp_status "$lp_fixture/status.json" 2311
lp_pass
lp_pass
lp_pass
if lp_report="$(jq -e -r '[.reason, (.window.rewards|tostring), (.window.progress.lasting|tostring), (.window.progress.species|tostring)] | join(" ")' "$lp_fixture/run/loop.json" 2>/dev/null)" \
&& [ "$lp_report" = "unwon-battles 2 3 1" ]; then
pass "check 10: loop.json carries the window's lasting progress (a rung, a species, a map) for the ladder, and the flag does not read it"
else
fail "check 10: loop.json read back as '${lp_report:-UNREADABLE}' — expected 'unwon-battles 2 3 1'"
fi
# The ethos, asserted rather than reviewed: over every case above, check 10 # The ethos, asserted rather than reviewed: over every case above, check 10
# restarted nothing. It reports; a human or a review agent decides. # restarted nothing. It reports; a human or a review agent decides.
if [ ! -s "$lp_fixture/systemctl.log" ]; then if [ ! -s "$lp_fixture/systemctl.log" ]; then

View file

@ -117,6 +117,55 @@ class RecoveryTests(unittest.TestCase):
self.confirm(T0, rank=13) self.confirm(T0, rank=13)
self.assertEqual(self.acts, [("restart", None)]) self.assertEqual(self.acts, [("restart", None)])
# Row 70: the rung-11 reset replayed the run exactly (1,138 of 1,138 events), caught the Zubat
# again and walked into the same trap; the next step reset to rung 11 again and erased the catch.
def test_progress_after_the_last_step_starts_the_ladder_over(self):
recover.write_json(recover.STATE, {"level": 4, "bestRank": 12, "resets": [], "actedAt": T0 - 7200})
# an area and a species inside the windows of probes well after the step
self.tick(T0 - 3000, suspected=0, window={"progress": {"lasting": 2, "species": 0}})
self.assertIn("flysim restarted", self.confirm(T0))
self.assertEqual(self.acts, [("restart", None)])
history = [json.loads(line) for line in recover.HISTORY.read_text().splitlines()]
self.assertIn("progress since the last step", [event.get("why") for event in history])
def test_progress_while_a_step_settles_does_not_start_the_ladder_over(self):
recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "resets": [], "actedAt": T0 - 1500})
self.tick(T0 - 1400, suspected=0, window={"progress": {"lasting": 3, "species": 0}})
self.confirm(T0)
self.assertEqual(self.acts, [("reset", 11)])
def test_a_species_owned_recently_is_never_reset_away(self):
owned = T0 - recover.HOLD - 600
recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "resets": [],
"actedAt": T0 - recover.HOLD - 300, "speciesAt": owned})
self.assertIn("flysim restarted", self.confirm(T0))
self.assertEqual(self.acts, [("restart", None)])
history = [json.loads(line) for line in recover.HISTORY.read_text().splitlines()]
self.assertIn("protect", [event.get("event") for event in history])
# the hold still spaces the restarts, and says why
self.assertIn("protection window", self.confirm(T0 + 300 + recover.SETTLE + 10))
# the protection lasts PROTECT from the species; then the ladder resets as before
self.assertIn("reset to rung 11", self.tick(owned + recover.PROTECT + 60))
def test_a_probe_that_owns_a_species_starts_the_protection(self):
self.tick(T0, suspected=0, window={"progress": {"lasting": 1, "species": 1}})
self.assertEqual(recover.load(recover.STATE, {}).get("speciesAt"), T0)
self.assertEqual(recover.load(recover.STATE, {}).get("progressAt"), T0)
def test_the_last_resets_archive_is_not_restored_again(self):
acted = T0 - recover.HOLD - 100
recover.write_json(recover.STATE, {"level": 3, "bestRank": 12, "resets": [acted],
"actedAt": acted, "lastReset": 11})
self.confirm(T0)
self.assertEqual(self.acts, [("restart", None)])
def test_a_reset_records_its_archive_and_a_new_best_rung_forgets_it(self):
recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "resets": [], "actedAt": 0})
self.confirm(T0)
self.assertEqual(recover.load(recover.STATE, {}).get("lastReset"), 11)
self.tick(T0 + 300 + recover.SETTLE + 10, suspected=0, rank=13)
self.assertNotIn("lastReset", recover.load(recover.STATE, {}))
def test_quiet_hours_start_the_ladder_over(self): def test_quiet_hours_start_the_ladder_over(self):
recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "actedAt": 0, recover.write_json(recover.STATE, {"level": 2, "bestRank": 12, "actedAt": 0,
"lastSuspectedAt": T0 - recover.QUIET - 1}) "lastSuspectedAt": T0 - recover.QUIET - 1})