Merge feat/recovery-copy

This commit is contained in:
acamilo 2026-09-29 01:31:26 +00:00
commit d7238a935b
16 changed files with 78 additions and 13 deletions

View file

@ -278,10 +278,14 @@ it reads as the cartridge's text box, not as a rail panel or an alarm:
| Phase | Layout | Reset copy | Restart copy |
|---|---|---|---|
| `countdown` | Text box over the bottom ~40% of the game, big `M:SS` to `executeAt`, the loop and how long it was stuck. The stuck loop stays visible above it | The fly is stuck in a loop! / Rewinding to PEWTER CITY in 0:42 | … / Shaking it off in 0:42 |
| `acting` | Covers the whole 800x720 game panel, which is frozen or blank while flysim is down; a stepped progress bar | Rewinding… / Back to PEWTER CITY | Shaking it off… / Same place, fresh start |
| `done` | Text box, 8 s after the helper's `updatedAt` | Back at PEWTER CITY! | All shaken off! |
| `failed` | Text box, 20 s | That didn't work / A human will take a look | same |
| `countdown` | Text box over the bottom ~40% of the game, big `M:SS` to `executeAt`, the loop and how long it was stuck. The stuck loop stays visible above it | The fly is stuck in a loop! / Rewinding to the BOULDER BADGE milestone in 0:42 | … / Shaking it off in 0:42 |
| `acting` | Covers the whole 800x720 game panel, which is frozen or blank while flysim is down; a stepped progress bar | Rewinding… / Back to the BOULDER BADGE milestone | Shaking it off… / Same place, fresh start |
| `done` | Text box, 8 s after the helper's `updatedAt` | Back at the BOULDER BADGE milestone! | All shaken off! |
| `failed` | Text box, 20 s | That didn't work / Trying something else next | same |
A reset names its target by the ladder label: a place as is (`PEWTER CITY`), any other rung as
`the BOULDER BADGE milestone`, and the rung the fly is already on as `the start of MT. MOON` (the
ladder's first reset goes back to where it first reached that rung).
**Where the notice comes from.** Not the feed: flysim is the thing being restarted. The helper
writes `/run/fly/wd/recovery-notice.json` atomically (tmp + rename); `flystage-web`

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View file

@ -213,11 +213,34 @@ export function recoveryVisible(notice: RecoveryNotice, nowS: number): boolean {
}
}
/**
* Ladder rungs (`docs/design/ladder.md`) whose label is a place the fly can be "back at". The rest
* are events (BOULDER BADGE, GOT A STARTER, HM CUT) and read as "the BOULDER BADGE milestone".
*/
const PLACE_RUNGS: ReadonlySet<string> = new Set([
'PALLET TOWN', "OAK'S LAB", 'VIRIDIAN CITY', 'VIRIDIAN FOREST', 'PEWTER CITY', 'MT. MOON',
'CERULEAN CITY', 'NUGGET BRIDGE', 'VERMILION CITY', 'ROCK TUNNEL', 'LAVENDER TOWN',
'CELADON CITY', 'FUCHSIA CITY', 'CINNABAR ISLAND', 'INDIGO PLATEAU',
]);
/**
* Where a reset goes, in words: `PEWTER CITY`, `the BOULDER BADGE milestone`, and `the start of
* MT. MOON` when the target is the rung the fly is already on (the ladder's first reset: it goes
* back to where it first reached that rung). Empty without a label.
*/
export function resetTarget(notice: RecoveryNotice): string {
const label = notice.toLabel;
if (label === '') return '';
const named = PLACE_RUNGS.has(label) ? label : `the ${label} milestone`;
const same = notice.toRung !== null && notice.toRung === notice.fromRung;
return same ? `the start of ${named}` : named;
}
/** The splash at `nowS`, or null when nothing should be on screen. */
export function recoveryView(notice: RecoveryNotice | null, nowS: number): RecoveryView | null {
if (notice === null || !recoveryVisible(notice, nowS)) return null;
const reset = notice.action === 'reset';
const to = notice.toLabel;
const to = resetTarget(notice);
const base = {
id: notice.id,
phase: notice.phase,
@ -276,7 +299,7 @@ export function recoveryView(notice: RecoveryNotice | null, nowS: number): Recov
layout: 'box',
chip: 'AUTO RECOVERY',
headline: "That didn't work",
body: 'A human will take a look',
body: 'Trying something else next',
countdown: '',
loop: '',
stuck: '',

View file

@ -141,6 +141,19 @@ test('acting: covers the game while flysim is down, and gives up after a cap', (
assert.equal(view(acting, T + 60 + RECOVERY_ACTING_MAX_S + 1), null);
});
test('a rung that is not a place reads as a milestone, and the current rung as its start', () => {
const badge = notice({ toRung: 11, toLabel: 'BOULDER BADGE' });
assert.equal(view(badge, T + 18)?.body, 'Rewinding to the BOULDER BADGE milestone in');
assert.equal(view({ ...badge, phase: 'acting' }, T + 63)?.body, 'Back to the BOULDER BADGE milestone');
assert.equal(view({ ...badge, phase: 'done', updatedAt: T + 120 }, T + 120)?.headline, 'Back at the BOULDER BADGE milestone!');
const same = notice({ toRung: 12, toLabel: 'MT. MOON' });
assert.equal(view(same, T + 18)?.body, 'Rewinding to the start of MT. MOON in');
assert.equal(view({ ...same, phase: 'done', updatedAt: T + 120 }, T + 120)?.headline, 'Back at the start of MT. MOON!');
assert.equal(view({ ...same, toLabel: 'BOULDER BADGE', toRung: 12, fromRung: 12 }, T + 18)?.body,
'Rewinding to the start of the BOULDER BADGE milestone in');
});
test('done shows about 8 s, failed a little longer, then both clear', () => {
const done = notice({ phase: 'done', updatedAt: T + 120 });
assert.equal(view(done, T + 120)?.headline, 'Back at PEWTER CITY!');
@ -149,7 +162,7 @@ test('done shows about 8 s, failed a little longer, then both clear', () => {
assert.equal(view(done, T + 120 + RECOVERY_DONE_S + 1), null);
const failed = notice({ phase: 'failed', updatedAt: T + 120 });
assert.equal(view(failed, T + 125)?.body, 'A human will take a look');
assert.equal(view(failed, T + 125)?.body, 'Trying something else next');
assert.equal(view(failed, T + 120 + RECOVERY_FAILED_S + 1), null);
});

View file

@ -161,7 +161,7 @@ const RECOVERY_SHOTS = (['countdown', 'acting', 'done', 'failed'] as const).flat
action,
fromRung: 12,
fromLabel: 'MT. MOON',
...(action === 'reset' ? { toRung: 11, toLabel: 'PEWTER CITY' } : {}),
...(action === 'reset' ? { toRung: 11, toLabel: 'BOULDER BADGE' } : {}),
reason: 'unrewarded',
loop: ['GO OBJECTIVE', 'GO WARP'],
stuckSeconds: 1800,

View file

@ -234,6 +234,15 @@ def run(now=None, sleep=time.sleep, clock=None):
state["resets"] = [at for at in state.get("resets", []) if now - at < DAY]
at = report.get("at")
# 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.
delta = (report.get("places") or {}).get("delta")
if type(at) is int and 0 <= now - at <= 600 and (
(type(delta) is int and delta > 0)
or (type(rank) is int and type(state.get("rank")) is int and rank > state["rank"])):
state["lastProgressAt"] = at
if type(rank) is int:
state["rank"] = rank
if (report.get("suspected") != 1 or type(at) is not int
or not 0 <= now - at <= 600 or report.get("action") != "none"):
state.pop("observedAt", None)
@ -272,7 +281,8 @@ def run(now=None, sleep=time.sleep, clock=None):
base = {"v": 1, "id": f"{now}-{action}", "action": action,
"fromRung": rank, "fromLabel": (report.get("milestone") or {}).get("label"),
"reason": report.get("reason"), "loop": (report.get("sequence") or [])[:4],
"stuckSeconds": max(0, now - observed) + 600,
"stuckSeconds": now - state["lastProgressAt"] if state.get("lastProgressAt")
else max(0, now - observed) + 600,
"announcedAt": now, "executeAt": now + COUNTDOWN}
if action == "reset":
base.update(toRung=target, toLabel=LADDER[target] if 0 <= target < len(LADDER) else None)

View file

@ -1,7 +1,7 @@
# Automated loop recovery
`fly-watchdog` remains report-only. The separate `fly-loop-recover.timer` reads its
`/run/fly/wd/loop.json` every five minutes and unsticks a confirmed trap on its own, climbing
`/run/fly/wd/loop.json` every minute and unsticks a confirmed trap on its own, climbing
a ladder one step per trap that outlives the previous step:
| level | step | cost |

View file

@ -240,6 +240,18 @@ class RecoveryTests(unittest.TestCase):
with patch.object(recover.subprocess, "run", return_value=recover.subprocess.CompletedProcess([], 1, "12", "")):
self.assertEqual(RESTORABLE_RUNGS(), set())
def test_stuck_time_counts_from_the_last_progress_across_restarts(self):
self.report(at=T0 - 7200, suspected=0, places={"uniqueLocations": 10, "delta": 4})
recover.run(T0 - 7195)
recover.write_json(recover.STATE, dict(json.loads(recover.STATE.read_text()), vetoes=0))
self.confirm(T0)
self.assertEqual(json.loads(recover.NOTICE.read_text())["stuckSeconds"], 7505)
self.assertEqual(json.loads(recover.STATE.read_text())["lastProgressAt"], T0 - 7200)
def test_stuck_time_falls_back_to_the_streak_without_a_progress_mark(self):
self.confirm(T0)
self.assertEqual(json.loads(recover.NOTICE.read_text())["stuckSeconds"], 305 + 600)
def test_history_records_every_step(self):
self.confirm(T0)
lines = [json.loads(line) for line in recover.HISTORY.read_text().splitlines()]

View file

@ -2,9 +2,12 @@
Description=Check for repeated macro loops after watchdog probes
[Timer]
OnBootSec=7min
OnUnitActiveSec=5min
AccuracySec=10s
# Every minute: a run only reads /run/fly/wd/loop.json unless a step is due, and the ladder's
# state ignores a probe it has already seen. On a 5-minute cadence the timer's phase can sit just
# before each loop probe (live, 2026-09-28: one second), costing ~5 minutes per confirmation.
OnBootSec=2min
OnUnitActiveSec=1min
AccuracySec=5s
Unit=fly-loop-recover.service
[Install]