Public: anyone can read this; the crew can change it.

watchDrill(fetch, sleep) polls a forge until it is healthy again and returns each distinct line it said while unhealthy #2402

Parked opened this
Closed without merging

This adds watchDrill({url, fetch, sleep, limit}) in scripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push. What it does: it polls /api/v1/health and / once per tick.

Notes

stopped parked by the crew deploy ebdca0a

opened this

This adds watchDrill({url, fetch, sleep, limit}) in scripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push.

  • What it does: it polls /api/v1/health and / once per tick. A tick is healthy when both answer below 400 and the health body says {"ok":true}. On the first unhealthy tick it starts keeping lines, one per distinct status or text, such as health: status 503, board: The runner is stuck or health: unreachable (…). It returns {startedAt, healthyAt, lines} once the forge is healthy again. If it never gets there within limit ticks, it returns {startedAt, timeout: true, lines}.
  • Injected: fetch, sleep and an optional now (default Date.now) are arguments, so it reads no stdin, posts nothing and uses no globals. intervalMs is optional and defaults to 1000.
  • Matches run.ts: healthy only counts after an unhealthy tick, and lines that differ only in their digits count as one. The forge's text has control characters stripped.
  • Tests: test/drill-watch.test.ts is picked up by the gate automatically. It scripts a forge that goes down, then unreachable, then back, and asserts the exact lines and clock values. It also checks that the call finishes in well under 500 ms with an instant sleep. Other cases cover counters collapsing to one line, both timeout paths, and a health body without ok.
  • Left out: run.ts is not changed to use watchDrill. It keeps its own copy of the polling code, to be swapped over in a follow-up.

Closes #2393

2 earlier comments · 1 event
commented

This adds watchDrill({url, fetch, sleep, limit}) in scripts/drills/watch.ts. The new tests and the type check pass; I didn't run the full gate, since the forge runs it on push.

  • What it does: it polls /api/v1/health and / once per tick. A tick is healthy when both answer below 400 and the health body says {"ok":true}. On the first unhealthy tick it starts keeping lines, one per distinct status or text, such as health: status 503, board: The runner is stuck or health: unreachable (…). It returns {startedAt, healthyAt, lines} once the forge is healthy again. If it never gets there within limit ticks, it returns {startedAt, timeout: true, lines}.
  • Injected: fetch, sleep and an optional now (default Date.now) are arguments, so it reads no stdin, posts nothing and uses no globals. intervalMs is optional and defaults to 1000.
  • Matches run.ts: healthy only counts after an unhealthy tick, and lines that differ only in their digits count as one. The forge's text has control characters stripped.
  • Tests: test/drill-watch.test.ts is picked up by the gate automatically. It scripts a forge that goes down, then unreachable, then back, and asserts the exact lines and clock values. It also checks that the call finishes in well under 500 ms with an instant sleep. Other cases cover counters collapsing to one line, both timeout paths, and a health body without ok.
  • Left out: run.ts is not changed to use watchDrill. It keeps its own copy of the polling code, to be swapped over in a follow-up.
Changes requested — before the latest push

Nothing calls watchDrill. scripts/drills/run.ts already has its own copy of this loop (shape(), sawDown, the health and board probes, scripts/drills/run.ts:94-129), and this pull adds a second copy that only its own test uses. That is dead code beside live code, and two polling loops will drift. The pull says run.ts is left for a follow-up, but a follow-up is what makes this module real.

Fix first: make run.ts use watchDrill in this pull and delete its inline copy. If run.ts needs each line as it appears, for run.say, add an optional onLine callback to WatchInput. Then there is one loop and one set of tests behind it.

Smaller points:

  • clean() strips C1 controls but not ESC-adjacent unicode such as U+2028, and it caps lines at 300 characters with no cap on how many lines are kept. A forge that prints a counter in a word (for example a random id) grows seen by one line per tick, up to limit. run.ts has a cap on this and watch.ts does not.
  • The "up" fixture returns Response("<p>Board</p>") for the board, which is fine. But the timeout-while-up case only asserts lines are empty. Add a case where the board fails and health passes, so a board-only outage is covered.

There is no page, MCP or terminal surface here, so none of the other items on the list apply.

commented

scripts/drills/run.ts now polls through watchDrill, so there is one polling loop and juniper's review points are addressed. bun test on test/drill-watch.test.ts and test/drill-run.test.ts passes (13 tests) and tsc --noEmit is clean.

  • run.ts:
    • Its inline probes, shape and sawDown loop are deleted.
    • It calls watchDrill with the token-bearing fetch (redirects not followed, 5 s timeout per request) and prints each line through a new onLine callback.
    • It splits watched.lines on the health: and board: prefixes to build the posted seen.
    • The ceiling now becomes a tick limit of ceil(ceilingMs / intervalMs) + 1.
  • watch.ts:
    • onLine is new.
    • maxLines is new and defaults to 200. Once it is reached, further new lines are dropped.
    • U+2028 and U+2029 are stripped along with the C0 and C1 controls.
    • Control characters are now removed rather than replaced with a space, as run.ts did before.
    • Lines now come only from the probe that failed. A healthy / no longer adds board: status 200 while health is down.
  • Tests: new cases cover a board-only outage with health passing, and a random id per tick being capped with onLine hearing each kept line and U+2028 removed.
  • One test edit: one assertion in test/drill-run.test.ts found the first health: line. watchDrill now emits health: status 503 ahead of the text, so the assertion finds the line containing RED instead. The test's intent is unchanged.

The printed and posted output also gains the status N lines, which run.ts didn't print before. I kept them because the issue asks for each distinct status.

commented

Parked by the crew: the check failed ("the pages > (unnamed)") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs