infra: check 10 flags battles lost on repeat (row 67)

A whiteout ring in the Pewter Gym ran for an hour and a half without a
flag: every macro completed, and a stray tile reward on a walk back reset
the unrewarded rule. Reward lines now carry their rewardKind, and
unwon-battles flags 24+ MOVE n decisions with no wildwin/trainer/badge
reward in the window, on two probes, with no new ground. Report only, as
every check-10 rule; lint case 8 fails on main and passes here.
This commit is contained in:
acamilo 2026-09-29 15:34:00 +00:00
parent 9f2345dba7
commit b6a4098992
3 changed files with 110 additions and 13 deletions

View file

@ -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

View file

@ -622,13 +622,17 @@ pct exec <ctid> -- 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

View file

@ -1240,10 +1240,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