diff --git a/docs/design/macros.md b/docs/design/macros.md index ff99941..9c4ff77 100644 --- a/docs/design/macros.md +++ b/docs/design/macros.md @@ -1969,6 +1969,44 @@ numbers are in `infra/docs/macros-traps.md` row 66. Nothing ranks a button or presses for the fly. The walk back is withheld for a window, a purchase is one offer, and the bag is read off the screen. The decoder, the reward catalog, the adapter + +### 12.31 A battle lost on repeat is the readout's choice when the pad offers the move that wins (2026-09-29, row 67) + +Live on v0.6.5, rung 10, an hour and a half in the Pewter Gym (map 54): per 3,000 events `NEXT` +1,332, `MOVE 2` 83, `MOVE 3` 13, `MOVE 1` 0, `GO OBJECTIVE` 30, `NO` 17, no battle won. The feed +read `battle` most of the time, but the fly was not in one battle. It was in a ring. It lost +29 battles in a row to the gym's Jr. Trainer (Diglett L11, Sandshrew L11), whited out to Pewter +(`wLastBlackoutMap` `$02`, money 0) and walked straight back in. Reproduced from the live +checkpoint (`FLY_ROW67_CHECKPOINT`). + +- **The pad was right.** Squirtle L11 has TACKLE 35/35, TAIL WHIP 30/30 and BUBBLE 30/30, and + the trainer's Pokémon are Ground type. In a trainer battle with a party of one and no Potion, + the menu's pad is `MOVE 1`, `MOVE 2`, `MOVE 3`, which is every move with PP and an effect. + RUN, ITEM, SWITCH and THROW BALL each have nothing behind them there. Every turn advances. + In 932 own-turn frames, no move with PP and an effect was missing from the pad. +- **The choice was the readout's.** Per live battle, TAIL WHIP was 155 of 178 moves and BUBBLE + 23. TAIL WHIP has an effect until the stage reaches -6, and 12.23 withholds it from there. Squirtle + faints at about the sixth turn, so the rule arrives as the battle ends (live: `22222233`). + A readout with no favourite wins with the same pad: uniform over it, the trainer is beaten on + all three seeds, and on the committed seed in the third battle. The live readout's favourite, + replayed, loses 17 of 17 battles. +- **PP never runs out.** Each loss spends about six TAIL WHIPs of 30, and the whiteout heals the party and + restores PP. The out-of-PP path is sound anyway: from the no-PP checkpoint, a trainer battle + with a party of one and every move at 0, the pad is `MOVE 1` alone (FIGHT's backstop, 12.8), + and "has no moves left!" and Struggle end the battle in 1,487 frames. +- **Nothing in the macros changes.** Moving the fly off TAIL WHIP would be ranking a move. The + one pad rule measured that would work, withholding a stat-lowering move once the target's + stage has moved, wins the first battle on both seeds (two stages: the second). It is a rule + about which move is good rather than one about what the cartridge refuses, so it waits for + the operator, like the reward options (`infra/docs/macros-traps.md` row 67). +- **What ships is detection.** The watchdog's check 10 gains `unwon-battles`: 24 or more `MOVE + n` decisions and no battle-won reward (`wildwin`, `trainer`, `badge`) in the ten-brain-minute + window, on two probes, with no new ground. Replayed on the live log, it flags from 14:01. The + existing rules first flag at 14:46, because a stray tile reward on a walk back reset + `unrewarded`. The recovery ladder acts on the flag as on any other, and a restart alone + does not change the readout. + +Nothing is ranked, weighted or pressed for the fly. The decoder, the reward catalog, the adapter version, the roles and the compatibility string are untouched. ## 13. Shops and Pokémon Centers (the operator, 2026-09-17: "refactor the shop macros. make it a diff --git a/infra/bin/fly-watchdog b/infra/bin/fly-watchdog index 58f280a..944c012 100755 --- a/infra/bin/fly-watchdog +++ b/infra/bin/fly-watchdog @@ -72,6 +72,7 @@ log_info() { : "${WD_LOOP_MIN_EVENTS:=20}" # floor under the dominance rule (see check 10) : "${WD_LOOP_STALL_PCT:=90}" # decisions that ended refused/blocked/timeout: this share is a stall (row 57) : "${WD_LOOP_BUSY_MIN:=100}" # this many decisions with no reward and no new ground, two probes running, is busy going nowhere (row 58) +: "${WD_LOOP_FIGHT_MIN:=24}" # this many MOVE n decisions with no battle won and no new ground, two probes running, is battles lost on repeat (row 67) : "${WD_LOOP_REPORT:=${WD_RUN_DIR}/loop.json}" mkdir -p "$WD_RUN_DIR" "$WD_STATE_DIR" @@ -192,7 +193,7 @@ write_textfile_metrics() { # convention as fly_watchdog_encoder_degraded), while the flag itself # starts at 0, because a 0/1 flag carrying -1 reads as a loop to every # alert expression that would ever use it. - echo "# HELP fly_loop_suspected 1 when the last check-10 probe found a short macro cycle repeating, one macro dominating, or the decisions stalled (refused/blocked) or completing nothing, with no growth in the exploration count. Report only: the watchdog never restarts or presses anything for this." + echo "# HELP fly_loop_suspected 1 when the last check-10 probe found a short macro cycle repeating, one macro dominating, or the decisions stalled (refused/blocked), completing nothing, earning nothing or winning no battle, with no growth in the exploration count. Report only: the watchdog never restarts or presses anything for this." echo "# TYPE fly_loop_suspected gauge" echo "fly_loop_suspected $(cat "${WD_RUN_DIR}/loop.suspected" 2>/dev/null || echo 0)" echo "# HELP fly_loop_period Length in macro labels of the shortest repeating block found at the end of the window (0 when nothing repeats, -1 before the first probe)." @@ -221,6 +222,12 @@ write_textfile_metrics() { echo "# HELP fly_loop_rewards Reward events in the last check-10 window (-1 before the first probe)." echo "# TYPE fly_loop_rewards gauge" echo "fly_loop_rewards $(cat "${WD_RUN_DIR}/loop.rewards" 2>/dev/null || echo -1)" + echo "# HELP fly_loop_fights MOVE n decisions (a move chosen in a battle) in the last check-10 window (-1 before the first probe)." + echo "# TYPE fly_loop_fights gauge" + echo "fly_loop_fights $(cat "${WD_RUN_DIR}/loop.fights" 2>/dev/null || echo -1)" + echo "# HELP fly_loop_wins Battle-won reward events (rewardKind wildwin, trainer or badge) in the last check-10 window (-1 before the first probe)." + echo "# TYPE fly_loop_wins gauge" + echo "fly_loop_wins $(cat "${WD_RUN_DIR}/loop.wins" 2>/dev/null || echo -1)" echo "# HELP fly_places_delta Growth in game.uniqueLocations (the exploration count) since the previous check-10 probe. -1 when there is no previous probe to compare against." echo "# TYPE fly_places_delta gauge" echo "fly_places_delta $(cat "${WD_RUN_DIR}/loop.places_delta" 2>/dev/null || echo -1)" @@ -807,6 +814,22 @@ check_capture_freeze() { # unrewarded — WD_LOOP_BUSY_MIN+ decisions and no reward event in the # window, on this probe AND the previous one. # +# Row 67: the Pewter Gym, one trainer lost ~30 times in a row. The readout +# chose TAIL WHIP six turns in seven, Squirtle fainted every time, the fly +# whited out to Pewter and walked straight back in: MOVE 2 / NEXT / GO +# OBJECTIVE / TALK / NO, seven names, every macro `done`. Two stray tile +# rewards (a new tile of the gym on a whiteout's walk back) reset the +# unrewarded rule for ~45 minutes. What the window never had was a battle WON. +# So the reward lines carry their rewardKind, and one more rule reads them, +# behind the same gate: +# unwon-battles — WD_LOOP_FIGHT_MIN+ `MOVE n` decisions and no reward of +# kind wildwin, trainer or badge in the window, on this +# probe AND the previous one. +# The feed has no HP (docs/feed-protocol.md), so "a battle that makes no +# progress" is read as moves chosen and nothing won. Measured on the live log: +# healthy windows had 13-46 MOVE starts and 1-4 wins (the one 22-move window +# with no win also had new ground); the trap had 30-39 and none. +# # The tile rule is what separates a loop from a legitimately repeating # explorer (macros-traps.md: `GO FRONTIER` x19 over 93 tiles is a walk longer # than the frame cap, not a trap), and the watchdog has no tile counter. The @@ -857,7 +880,7 @@ loop_status_fields() { loop_macro_stream() { [ -f "$FLY_EVENT_LOG" ] || return 0 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)"' -R 2>/dev/null \ + | jq -r 'fromjson? // empty | select(.kind == "macro" or .kind == "reward") | "\(.brainMs)\t\(.label)\t\(.kind)\t\(.rewardKind // "")"' -R 2>/dev/null \ || true } @@ -865,12 +888,13 @@ loop_macro_stream() { # # 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 -# timeout US done US rewards +# timeout US done US rewards US fights US wins # # `total` counts start events inside the window, `decisions` starts plus # refusals (the sequence, `distinct` and `topCount` are over decisions), and # the next four count each outcome in the window, and `rewards` the reward -# events in it (row 58). `period`/`repeats` describe +# events in it (row 58), `fights` the `MOVE n` decisions and `wins` the +# rewards of kind wildwin/trainer/badge (row 67). `period`/`repeats` describe # 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 # names for context. The window ends at the newest macro event's own brain @@ -879,14 +903,18 @@ loop_analyze() { awk -F'\t' -v win="$WD_LOOP_WINDOW_MS" -v maxp="$WD_LOOP_MAX_PERIOD" ' # Reward lines are counted and nothing else: the window still ends at the # newest macro event, as it always has. - $3 == "reward" { rms[++nr] = $1 + 0; next } + $3 == "reward" { rms[++nr] = $1 + 0; rkind[nr] = $4; next } { ms[++n] = $1 + 0; lbl[n] = $2 } END { - if (n == 0) { printf "0\0370\0370\0370\0370\0370\0370\037\037\037\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\n"; exit } to = ms[n]; from = to - win k = 0; distinct = 0; topn = 0; top = "" starts = 0; refused = 0; blocked = 0; timeout = 0; done = 0; rewards = 0 - for (q = 1; q <= nr; q++) if (rms[q] >= from) rewards++ + fights = 0; wins = 0 + for (q = 1; q <= nr; q++) if (rms[q] >= from) { + rewards++ + if (rkind[q] == "wildwin" || rkind[q] == "trainer" || rkind[q] == "badge") wins++ + } for (i = 1; i <= n; i++) { if (ms[i] < from) continue if (lbl[i] ~ / blocked$/) { blocked++; continue } @@ -897,6 +925,7 @@ loop_analyze() { else continue name = lbl[i]; sub(/ (start|refused)$/, "", name) seq[++k] = name + if (name ~ /^MOVE [1-4]$/) fights++ if (!(name in cnt)) { cnt[name] = 0; distinct++ } cnt[name]++ if (cnt[name] > topn) { topn = cnt[name]; top = name } @@ -919,9 +948,9 @@ loop_analyze() { tailstr = "" start = k - 11; if (start < 1) start = 1 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\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\n", \ starts, distinct, topn, period, repeats, from, to, top, block, tailstr, \ - k, refused, blocked, timeout, done, rewards + k, refused, blocked, timeout, done, rewards, fights, wins }' } @@ -979,14 +1008,15 @@ check_loop() { echo "$delta" > "${WD_RUN_DIR}/loop.places_delta" local analysis total distinct topn period repeats win_from win_to top block tailstr - local decisions refused blocked timeouts completed rewards + local decisions refused blocked timeouts completed rewards fights wins analysis="$(loop_macro_stream | loop_analyze)" IFS=$'\037' read -r total distinct topn period repeats win_from win_to top block tailstr \ - decisions refused blocked timeouts completed rewards <<< "$analysis" + decisions refused blocked timeouts completed rewards fights wins <<< "$analysis" total="${total:-0}"; distinct="${distinct:-0}"; topn="${topn:-0}" period="${period:-0}"; repeats="${repeats:-0}" decisions="${decisions:-0}"; refused="${refused:-0}"; blocked="${blocked:-0}" timeouts="${timeouts:-0}"; completed="${completed:-0}"; rewards="${rewards:-0}" + fights="${fights:-0}"; wins="${wins:-0}" echo "$distinct" > "${WD_RUN_DIR}/loop.distinct" echo "$period" > "${WD_RUN_DIR}/loop.period" echo "$repeats" > "${WD_RUN_DIR}/loop.repeats" @@ -994,6 +1024,8 @@ check_loop() { echo "$(( blocked + timeouts ))" > "${WD_RUN_DIR}/loop.blocked" echo "$completed" > "${WD_RUN_DIR}/loop.done" echo "$rewards" > "${WD_RUN_DIR}/loop.rewards" + echo "$fights" > "${WD_RUN_DIR}/loop.fights" + echo "$wins" > "${WD_RUN_DIR}/loop.wins" local prev_suspected=0 [ -f "${WD_RUN_DIR}/loop.suspected" ] && prev_suspected="$(cat "${WD_RUN_DIR}/loop.suspected" 2>/dev/null || echo 0)" @@ -1022,6 +1054,14 @@ check_loop() { [ "$decisions" -ge "$WD_LOOP_BUSY_MIN" ] && [ "$rewards" -eq 0 ] && [ "$grown" -eq 0 ] && busy=1 echo "$busy" > "$busy_file" + # Battles lost on repeat (row 67), judged over two probes like the two + # above: moves chosen, no battle won, no new ground. + local unwon_file="${WD_RUN_DIR}/loop.prev_unwon" prev_unwon=0 unwon=0 + [ -f "$unwon_file" ] && prev_unwon="$(cat "$unwon_file" 2>/dev/null || echo 0)" + case "${prev_unwon:-}" in ''|*[!0-9]*) prev_unwon=0 ;; esac + [ "$fights" -ge "$WD_LOOP_FIGHT_MIN" ] && [ "$wins" -eq 0 ] && [ "$grown" -eq 0 ] && unwon=1 + echo "$unwon" > "$unwon_file" + local failed=$(( refused + blocked + timeouts )) local suspected=0 reason="" if [ "$decisions" -gt 0 ] && [ "$grown" -eq 0 ]; then @@ -1051,6 +1091,11 @@ check_loop() { # completes, none of them earns anything, and the ground stays put. suspected=1 reason="unrewarded" + elif [ "$unwon" -eq 1 ] && [ "$prev_unwon" -eq 1 ]; then + # Row 67: every macro completes and the odd tile reward keeps the + # window from reading unrewarded, but no battle is ever won. + suspected=1 + reason="unwon-battles" fi fi echo "$suspected" > "${WD_RUN_DIR}/loop.suspected" @@ -1083,6 +1128,8 @@ check_loop() { --argjson timeouts "$timeouts" \ --argjson completed "$completed" \ --argjson rewards "$rewards" \ + --argjson fights "$fights" \ + --argjson wins "$wins" \ --argjson windowFrom "${win_from:-0}" \ --argjson windowTo "${win_to:-0}" \ --argjson windowMs "$WD_LOOP_WINDOW_MS" \ @@ -1112,6 +1159,8 @@ check_loop() { decisions: $decisions, outcomes: { done: $completed, blocked: $blocked, timeout: $timeouts, refused: $refused }, rewards: $rewards, + fights: $fights, + wins: $wins, tail: (if $tail == "" then [] else ($tail | split(", ")) end) }, dominant: { name: (if $dominant == "" then null else $dominant end), @@ -1137,6 +1186,8 @@ check_loop() { if [ "$suspected" -eq 1 ]; then if [ "$reason" = "unrewarded" ]; then log_err "loop suspected (unrewarded): ${decisions} decisions and no reward event in the last ${mins} brain minutes, two probes running — ${completed} done, top [${top}] x${topn}, ${distinct} distinct name(s), tail [${tailstr}], exploration count ${places:-?} unchanged (delta ${delta}), rung ${rank:-?} '${mlabel:-?}' for ${since:-?}s. NOT acting: nothing restarted, nothing pressed, the game untouched — macros that complete and earn nothing are an undo pair or a ring. Report: ${WD_LOOP_REPORT}; see infra/docs/runbook.md 'loop suspected'." + elif [ "$reason" = "unwon-battles" ]; then + log_err "loop suspected (unwon-battles): ${fights} moves chosen in battle and no battle won in the last ${mins} brain minutes, two probes running — ${decisions} decisions, ${rewards} reward event(s), top [${top}] x${topn}, tail [${tailstr}], exploration count ${places:-?} unchanged (delta ${delta}), rung ${rank:-?} '${mlabel:-?}' for ${since:-?}s. NOT acting: nothing restarted, nothing pressed, the game untouched — battles lost on repeat are a readout choice or a pad that offers no winning move. Report: ${WD_LOOP_REPORT}; see infra/docs/runbook.md 'loop suspected'." elif [ "$reason" = "stalled" ] || [ "$reason" = "zero-progress" ]; then log_err "loop suspected (${reason}): [${shown}] — ${decisions} decisions in the last ${mins} brain minutes, ${total} started, ${completed} done, ${refused} refused, $(( blocked + timeouts )) blocked or timed out, exploration count ${places:-?} unchanged (delta ${delta}), rung ${rank:-?} '${mlabel:-?}' for ${since:-?}s. NOT acting: nothing restarted, nothing pressed, the game untouched — a pad whose buttons cannot run is a macro bug. Report: ${WD_LOOP_REPORT}; see infra/docs/runbook.md 'loop suspected'." elif [ "$reason" = "sequence" ]; then diff --git a/infra/docs/macros-traps.md b/infra/docs/macros-traps.md index 0512066..63e0930 100644 --- a/infra/docs/macros-traps.md +++ b/infra/docs/macros-traps.md @@ -3430,3 +3430,71 @@ button. `TALK` at a counter: 0 of 12 decisions on either arm. The floor `BUY BALL`: chosen 3 of 13, and done (paid) all 3 times. The ring: 4 mart entries in 16 brain seconds on base, one visit on the branch. + +## 2026-09-29, row 67: the Pewter Gym trainer, lost on repeat + +### What was live + +v0.6.5, macros mode, reset to rung 8 at 12:16Z and back at PEWTER CITY by 13:40. The fly +entered the Pewter Gym (map 54) at 13:41, talked to the guide (#3) and to the Jr. Trainer +(#2). For the next hour and a half the pad read `battle` most of the time. +Per 3,000 events: `NEXT` 1,332, `MOVE 2` 83, `MOVE 3` 13, `MOVE 1` 0, `GO OBJECTIVE` 30, `NO` 17, +`GO FRONTIER` 13, `TALK` 7. There was no battle-won reward, only two tile rewards on map 54. Check +10 stayed clear. + +### Reproduction (the pulled checkpoint, hot generation 230739) + +- The checkpoint is on the walk back, not in a battle: Pewter City (18, 13), `wIsInBattle` 0, + `wLastBlackoutMap` `$02`, money 0, no badge, `EVENT_BEAT_PEWTER_GYM_TRAINER_0` clear. The party + is one Squirtle L11, 34/34: TACKLE 35/35, TAIL WHIP 30/30, BUBBLE 30/30. +- The opponent is `wTrainerClass` `$05` (Jr. Trainer♂) #1, `wEnemyPartyCount` 2: Diglett L11 and + Sandshrew L11, both Ground (`wEnemyMonType1` `$04`). +- Driven with the real palette and the live readout's measured favourite (TAIL WHIP 87%, else + BUBBLE), the cycle is the live one. `GO OBJECTIVE` into the gym, then `TALK` and the guide's + YES/NO. Then the trainer's challenge starts the battle. The own-turn pad is `MOVE 1, MOVE 2, MOVE 3` + on every turn, and each turn resolves in about 530 frames. Squirtle falls 34 → 29 → 24 → 19 + → 11 → 6 → 0 while Diglett's DEFENSE falls to -6. Then `wIsInBattle` `$ff`, `wBattleResult` 1, + the whiteout to Pewter (13, 26) with PP back to 30, and the walk back. One battle takes about + 4,500 frames. +- Live, per battle (29 battles, from the event log): TAIL WHIP 155, BUBBLE 23, TACKLE 0, and 5 to 8 + moves each. Where TAIL WHIP ran out of effect before the faint, 12.23 withheld it and the fly + pressed BUBBLE (`22222233`). + +| # | trap | trigger | test | fix, or why it is left | +| --- | --- | --- | --- | --- | +| 67 | a readout that favours TAIL WHIP loses every battle against a trainer it could beat; the whiteout heals the party, so PP never runs out and the ring never ends | the Pewter Gym's Jr. Trainer, Squirtle alone | `row67_the_gym_trainer_is_beaten_from_what_the_pad_deals` | **left, the fly's**: the pad offers every move with PP and an effect on every own-turn frame (0 missing in 932) and a uniform choice wins. Options for the operator below | +| 67b | check 10 did not flag: a stray tile reward (a new gym tile on a walk back) every ~20 minutes reset `unrewarded`, and battles are not a sequence of four names | a whiteout ring with a walk in it | `lint.sh` check 10 case 8 | **fixed**: `unwon-battles` (24+ `MOVE n`, no `wildwin`/`trainer`/`badge` reward, two probes, no new ground) | +| 67c | the no-PP ROM test asserted "more than one button" on a trainer battle whose only honest button is `MOVE 1` (12.8's backstop); it was red on main and skipped without `FLY_NOPP_CHECKPOINT` | the no-PP checkpoint | `macros_mode_ends_a_turn_with_no_move_left_on_the_cartridge` | **fixed (test)**: at least one button, and the battle ends (Struggle, 1,487 frames) | + +### The options, measured + +From the live checkpoint, 60,000 frames per arm (16.7 brain minutes), real palette. The driver +is harness choice, not the fly's: + +| arm | trainer battles (L lost, W won) | trainer beaten | Brock beaten | +| --- | --- | --- | --- | +| live favourite (TAIL WHIP 87%), seed 1 | LLLLLLLLL | no | no | +| live favourite, seed 2 | LLLLLLLL | no | no | +| uniform over the pad, seeds 1 / 2 / 3 | LLW / LLLLW / LLLW | f32,940 / f46,293 / f41,030 | seed 1 | +| BUBBLE whenever dealt | W | f12,234 | yes | +| TACKLE whenever dealt | LLLLLW | f59,253 | no | +| live favourite, stat-down move withheld once the target's stage is -1 or lower, seeds 1 / 2 | W / W | f9,165 / f9,304 | yes / yes | +| the same at -2, seeds 1 / 2 | LW / LW | f17,053 / f19,033 | yes / yes | +| the same at -3, seed 1 | LLLLLW | f54,551 | no | + +- **Withhold a move with no effect on this target** (12.23's rule): it already applies, and TAIL + WHIP has an effect until -6. The fly faints at about that turn, so the rule changes nothing here. +- **Withhold a stat-lowering move once it has done something**: the -1 arm wins the first battle + on both seeds and then beats Brock. It is a pad rule about which move is good, not about what + the cartridge refuses, so it is a doctrine change for the operator. It would also hide GROWL, + SAND-ATTACK and similar moves after one use in every battle. +- **Reward damage dealt**: this is a reward-catalog change, out of scope for loop review, and it + cannot be measured without the brain. Nothing in the current catalog separates BUBBLE from + TAIL WHIP until a battle is won, and none is. +- **Watchdog detection plus the recovery ladder**: shipped (67b). Replayed probe by probe on the + live log with uniqueLocations proxied from the tile rewards, base check 10 first flags at 14:46 + (`unrewarded`). The branch flags `unwon-battles` at 14:01, 14:16, 14:21, 14:36 and 14:41; a + tile reward at 14:06 and 14:26 clears one probe each. The healthy windows before the gym + (13 to 46 `MOVE n`, 1 to 4 wins each) are not flagged. The ladder's restart does not change the + readout, and a reset to PEWTER CITY replays the same gym. Only the reset to the rung below adds + forest battles, and whether that is enough was not measured. diff --git a/infra/docs/runbook.md b/infra/docs/runbook.md index a8748a2..a484980 100644 --- a/infra/docs/runbook.md +++ b/infra/docs/runbook.md @@ -622,13 +622,17 @@ pct exec -- cat /run/fly/wd/loop.json | jq . | `fly_loop_blocked` | macros that ended `blocked` or `timeout` in the window | | `fly_loop_done` | macros that ended `done` in the window | | `fly_loop_rewards` | reward events in the window | +| `fly_loop_fights` | `MOVE n` decisions (a move chosen in a battle) in the window | +| `fly_loop_wins` | battle-won reward events (`wildwin`, `trainer`, `badge`) in the window | The flag needs **both** halves: at most 3 distinct macro names with the block repeating 20+ times, one macro at 95%+ of the window's decisions, 90%+ of 20+ decisions ending refused, blocked or timed out (`stalled`), or decisions with no `done` among them on two probes in a row (`zero-progress`), or 100+ decisions with no reward event among them on two probes in a row (`unrewarded`, row 58: `GO OBJECTIVE` in and `GO OUT` out of one door, diluted by eight other -names, every macro `done`) — **and** no growth in the exploration count. A decision is a `start` or a +names, every macro `done`), or 24+ `MOVE n` decisions and no battle won on two probes in a row +(`unwon-battles`, row 67: one Pewter Gym trainer lost thirty times, whiteout and back, with a +stray tile reward now and then keeping `unrewarded` quiet) — **and** no growth in the exploration count. A decision is a `start` or a `refused`: a refused press starts nothing, which is why counting starts alone read row 57's pad (`GO ROUTE refused` ~740 times in ten brain minutes, `macros-traps.md`) as one start and one name. A diff --git a/infra/tests/lint.sh b/infra/tests/lint.sh index 4cb3ab7..ef42b50 100755 --- a/infra/tests/lint.sh +++ b/infra/tests/lint.sh @@ -1243,10 +1243,52 @@ LPCAT fail "check 10: a rewarded busy window gave suspected=$(lp_metric fly_loop_suspected) rewards=$(lp_metric fly_loop_rewards)" fi + # (8) Row 67: the Pewter Gym, one trainer lost on repeat. MOVE 2 six turns in + # seven, a whiteout, the walk back and the guide's YES/NO -- six names, + # every macro done, and one stray tile reward in the window, so neither the + # sequence, dominance nor unrewarded rule fires. No battle is won: two probes + # flag as unwon-battles; the same window with one wild win in it does not. + 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 '{"id":999997,"wallMs":1758000999997,"brainMs":100000,"kind":"reward","label":"AREA 54: 24 UNIQUE LOCATIONS","value":0.05,"rewardKind":"explore"}\n' \ + >> "$lp_fixture/events.jsonl" + lp_status "$lp_fixture/status.json" 2311 + lp_pass + lp_pass + lp_first="$(lp_metric fly_loop_suspected)" + lp_pass + if [ "$lp_first" = "0" ] && [ "$(lp_metric fly_loop_suspected)" = "1" ] \ + && [ "$(lp_metric fly_loop_rewards)" = "1" ] \ + && [ "$(lp_metric fly_loop_fights)" = "75" ] \ + && [ "$(lp_metric fly_loop_wins)" = "0" ] \ + && grep -q 'loop suspected (unwon-battles): 75 moves chosen in battle and no battle won' "$lp_fixture/journal.log"; then + pass "check 10: battles lost on repeat, a stray tile reward in the window, no win over two probes flag as unwon-battles" + else + fail "check 10: the row-67 log gave first=${lp_first} then suspected=$(lp_metric fly_loop_suspected) rewards=$(lp_metric fly_loop_rewards) fights=$(lp_metric fly_loop_fights) wins=$(lp_metric fly_loop_wins), journal: $(cat "$lp_fixture/journal.log")" + fi + if lp_report="$(jq -e -r '[.reason, (.window.fights|tostring), (.window.wins|tostring), .action] | join(" ")' "$lp_fixture/run/loop.json" 2>/dev/null)" \ + && [ "$lp_report" = "unwon-battles 75 0 none" ]; then + pass "check 10: loop.json carries the moves chosen and the battles won in the window" + else + fail "check 10: loop.json read back as '${lp_report:-UNREADABLE}' — expected 'unwon-battles 75 0 none'" + fi + lp_reset + printf '{"id":999998,"wallMs":1758000999998,"brainMs":150000,"kind":"reward","label":"BEAT PEWTER GYM TRAINER 1","value":0.5,"rewardKind":"trainer"}\n' \ + >> "$lp_fixture/events.jsonl" + lp_pass + lp_pass + lp_pass + if [ "$(lp_metric fly_loop_suspected)" = "0" ] && [ "$(lp_metric fly_loop_wins)" = "1" ]; then + pass "check 10: the same battles with one of them won do not flag" + else + fail "check 10: a won battle gave suspected=$(lp_metric fly_loop_suspected) wins=$(lp_metric fly_loop_wins)" + fi + # The ethos, asserted rather than reviewed: over every case above, check 10 # restarted nothing. It reports; a human or a review agent decides. if [ ! -s "$lp_fixture/systemctl.log" ]; then - pass "check 10: never acts — no unit was restarted across any of the eight cases" + pass "check 10: never acts — no unit was restarted across any of the cases" else fail "check 10 ACTED, which it must never do: $(cat "$lp_fixture/systemctl.log")" fi diff --git a/services/flysim/crates/flysim/tests/rom_macros_mode.rs b/services/flysim/crates/flysim/tests/rom_macros_mode.rs index e53665c..15020bd 100644 --- a/services/flysim/crates/flysim/tests/rom_macros_mode.rs +++ b/services/flysim/crates/flysim/tests/rom_macros_mode.rs @@ -1976,11 +1976,20 @@ fn gate_checkpoint() -> Option { /// is `BACK`. 600,000 frames of it. /// /// What is asserted: `ATTACK` is on the pad of the fly's own turn, the macro behind it **starts -/// and runs on the cartridge** from this state, that turn never deals one button, and the battle +/// and runs on the cartridge** from this state, that turn never deals an empty pad, and the battle /// ends — which is the whole claim, because a turn that can be ended is a battle that finishes one /// way or the other. Which way is not asserted: with 6 of 34 HP against a trainer the measured run /// faints and blacks out, and that is the game rather than the macro layer. /// +/// **The checkpoint is a trainer battle** (a Bug Catcher, `wIsInBattle` 2) with one Poké Ball and +/// no Potion in the bag, not the wild battle of the live stall. Its own turn is `MOVE 1` alone, +/// and that is the pad the rules deal (row 67, 2026-09-29, measured): `RUN` is a wild battle's, +/// `THROW BALL` too, `ITEM` needs a Potion, `SWITCH` a reserve, and a spent move beside `MOVE 1` +/// is off the pad since 12.23 and 12.27. `MOVE 1` is FIGHT's backstop (12.8): FIGHT opens, +/// "has no moves left!", Struggle, and the battle ends in 1,487 frames. The assertion used to be +/// "more than one button", which only a button that does nothing could satisfy here; it had been +/// red on main since before row 63 and skipped wherever `FLY_NOPP_CHECKPOINT` was unset. +/// /// Gated on `FLY_ROM` and on a checkpoint in that state, which /// `examples/scene_probe.rs` writes with `FLY_PROBE_CATCH=noattack FLY_PROBE_SAVE=…` — 99 brain /// minutes of the stub from the gate-house checkpoint, the release box's own run carried forward. @@ -2026,7 +2035,7 @@ fn macros_mode_ends_a_turn_with_no_move_left_on_the_cartridge() { run.started ); assert!( - run.battle_pad.is_some_and(|dealt| dealt > 1), + run.battle_pad.is_some_and(|dealt| dealt >= 1), "the fly's own turn dealt a pad of {:?} buttons: by name {:?}", run.battle_pad, run.started @@ -4791,3 +4800,133 @@ fn row66_buy_ball_from_the_marts_floor_rings_up_a_ball() { assert_eq!(run.money(), money - 200, "and paid for"); assert!(done >= 1, "the macro reports done when paid"); } + +/// The live row-67 checkpoint, or `None` to skip. +/// +/// v0.6.5, rung 10, hot generation 230739, pulled while the fly walked back to the Pewter Gym +/// from its last whiteout: Pewter City (18, 13), Squirtle L11 (TACKLE, TAIL WHIP, BUBBLE, all +/// full), money 0, the gym's Jr. Trainer (Diglett L11, Sandshrew L11) not yet beaten. +fn row67_checkpoint() -> Option { + std::env::var_os("FLY_ROW67_CHECKPOINT").map(|path| { + flysim::store::load(std::path::Path::new(&path)) + .expect("the checkpoint should be a FLYSIM01 envelope") + }) +} + +/// Row 67: the Pewter Gym trainer lost thirty times in a row is the readout's, not the pad's. +/// +/// **What was live** (2026-09-29, v0.6.5): an hour and a half in the gym, `NEXT` 1,332, `MOVE 2` +/// 83, `MOVE 3` 13, `MOVE 1` 0 in 3,000 events, no battle won. Per battle the readout chose TAIL +/// WHIP six turns in seven, Squirtle fainted, the fly whited out to Pewter and walked straight +/// back in (`infra/docs/macros-traps.md` row 67, `docs/design/macros.md` 12.31). +/// +/// The claims, from the live checkpoint with the real palette and a uniform choice per hold (a +/// harness choice, not the fly's): +/// +/// - **on every frame of the fly's own turn the pad deals a `MOVE n` for every move that has PP +/// and that the cartridge would not answer with nothing** -- BUBBLE is always there to be +/// pressed, so the pad is not the trap; +/// - **the trainer is beaten** inside the budget: a readout with no favourite wins this battle +/// with what the pad offers. The live readout's measured favourite (TAIL WHIP 87%) lost 17 of +/// 17 over the same budget, two seeds (`infra/docs/macros-traps.md` row 67). +#[test] +fn row67_the_gym_trainer_is_beaten_from_what_the_pad_deals() { + use flybrain_gb::pokemon_red::macros::PokemonPalette; + use flybrain_gb::pokemon_red::state; + use flybrain_gb::pokemon_red::symbols::{events, ram}; + use flybrain_gb::{MacroPalette, MemoryReader, Started}; + let rom = skip_without_rom!(); + let Some(checkpoint) = row67_checkpoint() else { + eprintln!("skipped: no FLY_ROW67_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), PEWTER_CITY, "the checkpoint is in Pewter City, on the way back"); + assert!(!run.event(events::EVENT_BEAT_PEWTER_GYM_TRAINER_0), "the trainer is not yet beaten"); + + let budget = 60_000u32; + let hold_frames = 48u32; + let mut palette = PokemonPalette::new(SEED); + let mut rng = 1u32; + let mut running = false; + let mut since_decision = hold_frames; + let mut ms = run.ms; + let mut own_turn_frames = 0u32; + let mut useful_move_missing = 0u32; + let mut starts = std::collections::BTreeMap::<&'static str, u32>::new(); + let mut battles: Vec<(u32, bool)> = Vec::new(); + let mut fighting = run.gb.read8(ram::wIsInBattle); + let mut beaten_at = None; + for frame in 0..budget { + palette.clock(ms); + let observed = { + let ledger = AdapterLedger(&run.adapter); + palette.observe(&mut run.gb, &ledger) + }; + let names: Vec<&str> = observed.bindings.iter().map(|binding| binding.name).collect(); + if let Some(battle) = state::battle(&mut run.gb) + && battle.own_turn + && matches!(battle.menu, flybrain_gb::pokemon_red::macros::state::BattleMenu::Main { .. }) + && !state::a_latched(&mut run.gb) + && let Some(own) = battle.own + { + own_turn_frames += 1; + for (slot, name) in ["MOVE 1", "MOVE 2", "MOVE 3", "MOVE 4"].iter().enumerate() { + if let Some(entry) = own.moves[slot].filter(|entry| entry.id != 0 && entry.pp > 0) + && state::move_without_effect(&mut run.gb, entry.id) != Some(true) + && !names.contains(name) + { + useful_move_missing += 1; + } + } + } + let mut mask = 0u8; + { + let ledger = AdapterLedger(&run.adapter); + if running { + match palette.step(&mut run.gb, &ledger) { + Some(held) => mask = held, + None => running = false, + } + } else if since_decision >= hold_frames && !observed.bindings.is_empty() { + since_decision = 0; + rng ^= rng << 13; + rng ^= rng >> 17; + rng ^= rng << 5; + let binding = &observed.bindings[(rng >> 8) as usize % observed.bindings.len()]; + if let Started::Running(_) = palette.start(binding.slot, &mut run.gb, &ledger) { + *starts.entry(binding.name).or_default() += 1; + running = true; + match palette.step(&mut run.gb, &ledger) { + Some(held) => mask = held, + None => running = false, + } + } + } + } + since_decision += 1; + run.gb.set_buttons(mask); + run.gb.run_frame().expect("a frame should complete"); + ms += MS_PER_FRAME; + run.adapter.sample(&mut run.gb, ms); + let now = run.gb.read8(ram::wIsInBattle); + if fighting == 2 && now != 2 { + // `$ff` is the frame a battle is lost; anything else after a trainer battle is a win. + battles.push((frame, now != 0xff)); + } + fighting = now; + if run.event(events::EVENT_BEAT_PEWTER_GYM_TRAINER_0) { + beaten_at = Some(frame); + break; + } + } + eprintln!( + "{:.1} brain minutes: trainer beaten at {beaten_at:?}; trainer battles (frame, won) \ + {battles:?}; own-turn frames {own_turn_frames}, a useful move missing from the pad on \ + {useful_move_missing}; starts {starts:?}", + (ms - run.ms) / 60_000.0, + ); + assert!(own_turn_frames > 0, "the run never reached the trainer's battle"); + assert_eq!(useful_move_missing, 0, "a move with PP and an effect was not on the pad"); + assert!(beaten_at.is_some(), "the trainer was not beaten in {budget} frames: {battles:?}"); +}