diff --git a/apps/stage/README.md b/apps/stage/README.md index 4387080..51e68ae 100644 --- a/apps/stage/README.md +++ b/apps/stage/README.md @@ -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` diff --git a/apps/stage/mockups/recovery-acting-reset.png b/apps/stage/mockups/recovery-acting-reset.png index 7e7125b..653ecf5 100644 Binary files a/apps/stage/mockups/recovery-acting-reset.png and b/apps/stage/mockups/recovery-acting-reset.png differ diff --git a/apps/stage/mockups/recovery-acting-restart.png b/apps/stage/mockups/recovery-acting-restart.png index 57afff2..7ce7416 100644 Binary files a/apps/stage/mockups/recovery-acting-restart.png and b/apps/stage/mockups/recovery-acting-restart.png differ diff --git a/apps/stage/mockups/recovery-countdown-reset.png b/apps/stage/mockups/recovery-countdown-reset.png index c229069..a8d71f3 100644 Binary files a/apps/stage/mockups/recovery-countdown-reset.png and b/apps/stage/mockups/recovery-countdown-reset.png differ diff --git a/apps/stage/mockups/recovery-countdown-restart.png b/apps/stage/mockups/recovery-countdown-restart.png index 599187d..7e4680b 100644 Binary files a/apps/stage/mockups/recovery-countdown-restart.png and b/apps/stage/mockups/recovery-countdown-restart.png differ diff --git a/apps/stage/mockups/recovery-done-reset.png b/apps/stage/mockups/recovery-done-reset.png index 027ed49..60a5f8f 100644 Binary files a/apps/stage/mockups/recovery-done-reset.png and b/apps/stage/mockups/recovery-done-reset.png differ diff --git a/apps/stage/mockups/recovery-done-restart.png b/apps/stage/mockups/recovery-done-restart.png index d9c4370..b179c80 100644 Binary files a/apps/stage/mockups/recovery-done-restart.png and b/apps/stage/mockups/recovery-done-restart.png differ diff --git a/apps/stage/mockups/recovery-failed-reset.png b/apps/stage/mockups/recovery-failed-reset.png index 9a78359..06a54e4 100644 Binary files a/apps/stage/mockups/recovery-failed-reset.png and b/apps/stage/mockups/recovery-failed-reset.png differ diff --git a/apps/stage/mockups/recovery-failed-restart.png b/apps/stage/mockups/recovery-failed-restart.png index 676cfa4..afe2235 100644 Binary files a/apps/stage/mockups/recovery-failed-restart.png and b/apps/stage/mockups/recovery-failed-restart.png differ diff --git a/apps/stage/src/lib/recovery.ts b/apps/stage/src/lib/recovery.ts index 42004e0..dc6aebe 100644 --- a/apps/stage/src/lib/recovery.ts +++ b/apps/stage/src/lib/recovery.ts @@ -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 = 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: '', diff --git a/apps/stage/tests/unit/recovery.test.ts b/apps/stage/tests/unit/recovery.test.ts index 2486384..72e4ca0 100644 --- a/apps/stage/tests/unit/recovery.test.ts +++ b/apps/stage/tests/unit/recovery.test.ts @@ -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); }); diff --git a/apps/stage/tools/mockup.mts b/apps/stage/tools/mockup.mts index 44c6f6c..92d77e8 100644 --- a/apps/stage/tools/mockup.mts +++ b/apps/stage/tools/mockup.mts @@ -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, diff --git a/infra/bin/fly-loop-recover b/infra/bin/fly-loop-recover index 1d46b62..edbfb46 100755 --- a/infra/bin/fly-loop-recover +++ b/infra/bin/fly-loop-recover @@ -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) diff --git a/infra/tests/test_loop_recover.py b/infra/tests/test_loop_recover.py index c3b15ff..0231bf5 100644 --- a/infra/tests/test_loop_recover.py +++ b/infra/tests/test_loop_recover.py @@ -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()]