fix: prime bypasses the stale service worker; never saves an empty capture

After the 2026-11-10 Wodify redeploy, prime captured zero actions and every
query reported NOT PRIMED. It looked like another endpoint move. It was not:
every allowlisted path and response shape is unchanged.

The app's service worker was serving the old OutSystems runtime to pages
running the new screen code. That mixed app throws in
Controller.callServerDataSource before any data action is sent, so there was
nothing to observe. Measured per tab setting: bypassing the service worker
alone fixes it; disabling the HTTP cache alone does not.

- cdp.open_page: Network.setBypassServiceWorker on the prime tab. Per-tab,
  nothing in the profile is unregistered or cleared.
- cdp.close: close the tab the session opened. Every prime leaked one.
- prime: refuse to save a capture with no actions, leave the existing cache
  alone, and say why. Page errors are collected and reported, which is what
  separates "the browser's copy of the app is broken" from "Wodify moved its
  endpoints".
- Skill/: the cron prompts applied the generic exit-code table to `list`
  commands. For `list`, 3 is session expired, 4/5 are stale / not primed,
  6 is an unindexed class id. Exit 5 was not handled at all. Also document
  the `waitlist` value of the YOU column.
- CLAUDE.md / README: record the diagnosis, the measurements, the Firebase
  red herring, and both exit-code tables.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5.2 committed 2026-11-10 21:18:08 -08:00
1 parent cd7924d890
commit a15efa0874
9 files changed
+498 -16

No files matched your search

+63 -5
View File
@@ -17,10 +17,13 @@ from __future__ import annotations
import asyncio
import datetime as _dt
import json
import re
from typing import Any
from . import actions, cdp, client, config
_STAMP = re.compile(r"^\[\d{4}-\d\d-\d\dT[\d:.]+Z\]:?\s*")
#: Screens to walk so the interesting data actions actually fire. Ordered:
#: Home first (it is the reliable entry point and populates client vars).
WALK = (
@@ -132,6 +135,41 @@ def _observe(event: dict[str, Any], found: dict[str, dict[str, Any]],
}
#: How many distinct page errors to keep. Enough to name the failure, not a log.
MAX_PAGE_ERRORS = 5
def _observe_errors(event: dict[str, Any], errors: list[str]) -> None:
"""Collect a one-line summary of each distinct page error.
Only ever reported back to the operator. A page that throws on every data
action captures nothing, and without this the only symptom is an empty
result that looks like "Wodify moved its endpoints again".
"""
method = event.get("method")
params = event.get("params") or {}
chunks: list[str] = []
if method == "Runtime.exceptionThrown":
details = params.get("exceptionDetails") or {}
exc = details.get("exception") or {}
chunks.append(str(exc.get("description") or details.get("text") or ""))
elif method == "Runtime.consoleAPICalled" and params.get("type") == "error":
for arg in params.get("args") or []:
chunks.append(str(arg.get("description") or arg.get("value") or ""))
lines = [ln.strip() for chunk in chunks for ln in chunk.splitlines() if ln.strip()]
if not lines:
return
# The app stamps its own console errors ("[2026-11-11T05:02:11.964Z]: ...");
# drop the stamp so identical errors de-duplicate.
message = next((m for m in (_STAMP.sub("", ln).strip() for ln in lines) if m), "")
# First stack frame says *where*, which is the half that identifies a
# broken runtime ("... at Controller.callServerDataSource").
frame = next((ln.split(" (", 1)[0] for ln in lines if ln.startswith("at ")), "")
summary = (f"{message} {frame}".strip())[:200]
if summary and summary not in errors and len(errors) < MAX_PAGE_ERRORS:
errors.append(summary)
def _date_label(date: str | None) -> str:
"""JS string literal for the aria-label fragment of a schedule date button.
@@ -155,10 +193,15 @@ async def _run(walk=WALK, workout_date: str | None = None) -> dict[str, Any]:
found: dict[str, dict[str, Any]] = {}
csrf: list[str] = []
page_errors: list[str] = []
def on_event(ev: dict[str, Any]) -> None:
_observe(ev, found, csrf)
_observe_errors(ev, page_errors)
for path, wait in walk:
await session.navigate(config.origin() + path)
await session.drain(wait, lambda ev: _observe(ev, found, csrf))
await session.drain(wait, on_event)
# Walk to a real workout screen so GetAllWorkoutData (and the class
# detail actions) actually fire. The walk and the request-observer run
@@ -166,9 +209,7 @@ async def _run(walk=WALK, workout_date: str | None = None) -> dict[str, Any]:
# walk. CDPSession multiplexes one socket reader, so this is safe.
script = WORKOUT_WALK_JS.replace("__DATE_LABEL__", _date_label(workout_date))
walk_task = asyncio.create_task(session.evaluate(script, await_promise=True))
drain_task = asyncio.create_task(
session.drain(30, lambda ev: _observe(ev, found, csrf))
)
drain_task = asyncio.create_task(session.drain(30, on_event))
try:
walk_log = await asyncio.wait_for(asyncio.shield(walk_task), timeout=45)
except asyncio.TimeoutError:
@@ -185,10 +226,24 @@ async def _run(walk=WALK, workout_date: str | None = None) -> dict[str, Any]:
finally:
await session.close()
crashed = (" The page itself reported errors, so the app is failing to "
"run rather than calling different endpoints: "
+ " | ".join(page_errors)) if page_errors else ""
if not csrf:
raise RuntimeError(
"no X-CSRFToken observed. The browser is logged in but made no data "
"action calls -- try again, or widen the walk in prime.WALK."
"action calls -- try again, or widen the walk in prime.WALK." + crashed
)
if not found:
# Never persist an empty capture: it would replace a cache that may
# still answer queries with one that cannot answer any.
raise RuntimeError(
"captured none of the allowlisted data actions; the existing cache "
"was left untouched." + (crashed or
" The app made data-action calls, but none matched actions.ACTIONS "
"-- Wodify has probably moved its endpoints. Dump every "
"/screenservices/ path while clicking Home -> Schedule -> a class "
"and compare.")
)
if not module_version:
module_version = next(
@@ -205,6 +260,7 @@ async def _run(walk=WALK, workout_date: str | None = None) -> dict[str, Any]:
"module_version": module_version,
"actions": found,
"walk_log": walk_log,
"page_errors": page_errors,
}
@@ -216,6 +272,7 @@ def prime(workout_date: str | None = None) -> dict[str, Any]:
"""
payload = asyncio.run(_run(workout_date=workout_date))
walk_log = payload.pop("walk_log", None)
page_errors = payload.pop("page_errors", [])
path = client.save_cache(payload)
captured = sorted(payload["actions"])
@@ -234,4 +291,5 @@ def prime(workout_date: str | None = None) -> dict[str, Any]:
"actions_missing": missing,
"raw_paths_captured": len(captured),
"walk": walk_log,
"page_errors": page_errors,
}