feat(pi-bots): alert on the job clock, failed jobs and the SGG preview watchdog (#10) #22

Manually merged
bryan merged 3 commits from n10-4-job-alerts into main 2026-11-11 18:30:07 +00:00
Owner

Part of #10 (N10.4: alert rules for the preview watchdog's metrics), together with the job clock rules #9 left until the clock wrote its metrics.

What

In modules/services/pi-bots.nix, beside the existing PiBots* rules, all warnings and each held only while the service reports itself up with a fresh health file (so a stopped or crashed service still raises one alert):

  • PiBotsClockSilent: pi_bots_clock_last_tick_timestamp_seconds over 60 s old for 5 min (the clock ticks every 10 s; 0 means no tick since start).
  • PiBotsJobFailed: pi_bots_job_last_run_failed == 1 for 10 min, named by job_id; clears when the job's next run does not fail. The for lets a 5-minute job fail once without an alert.
  • PiBotsJobWaiting: a job held back 30 min because its bot is not bridged.
  • PiBotsJobFileUnusable: pi_bots_clock_bad_job_files > 0 for 15 min.

New option services.pi-bots.alerts.sggPreviewWatchdog (on for Studio) adds rules for the SGG preview watchdog, a pi-bots job (every 5 min) whose script writes sgg-preview-watchdog.prom into the service's metrics directory, which node_exporter already reads:

  • SggPreviewWatchdogSilent: no finished run for 20 min (one run may take ~14 min and the clock skips a slot while one runs, so run ends can be ~19.5 min apart), or no file at all, while the service is up and its clock ticks (a stopped clock is PiBotsClockSilent alone); 5 min.
  • SggPreviewWatchdogBlocked: waiting for Tailscale or unable to read the registry, 30 min.
  • SggPreviewNeedsAttention: a persistent preview failed, expired or cleanup_failed for 15 min (a preview reads failed for a moment while restarted), per preview, with keep_firing_for 15 min so a short gap in the preview list sends no resolved notice for a preview still broken.

The last two hold only while the watchdog's own file is fresh, so a stale file raises only SggPreviewWatchdogSilent. A watchdog run that fails outright is PiBotsJobFailed{job_id="sgg-preview-watchdog"}. A job disabled after a failure keeps PiBotsJobFailed until its file is removed or it runs again (its last run stays in clock.db).

Docs: modules/services/AGENTS.md (pi-bots row), README.

Tests

scripts/test_pi_bots_service.py (51, was 23): promtool test rules for each new rule firing and staying quiet (a short pause of the clock, one failed run followed by a good one, the worst-case gap between watchdog runs, a preview failed for a moment, a short gap in the preview list), each rule's service-down gate (crash and clean stop), the clock gate, the stale-watchdog-file gate, and the opt-in; promtool check metrics on the clock's and the watchdog's files as written. Mutations of every threshold, for, keep_firing_for, gate, the absent() branch and the opt-in each fail a test. The expressions were also run against the live Prometheus. darwin-rebuild build --flake .#studio builds; the monitoring, fseventsd, NAS and OpenCode Go suites pass.

After update-system

The new rules load with health ok. Expect SggPreviewNeedsAttention for the persistent previews that are already cleanup_failed (long-standing; Hermes alerted on each once): that is the rule working. They arrive as one grouped notice, by email and in Studio Alerts, repeated every 4 h (Alertmanager's repeat_interval) until each preview is recovered or removed.

Review

A visible Pi reviewer requested changes: two should-fixes (the long-run test did not pin the Silent threshold; the waiting-job and bad-file gates were untested) and six nits (the absent branch's freshness untested; a stopped clock also raised Silent; resolved notices on a list gap; the 4-hourly repeat; a disabled job's failure never clears; the for comment). All fixed or documented, each fix with a test that fails without it.

Part of #10 (N10.4: alert rules for the preview watchdog's metrics), together with the job clock rules #9 left until the clock wrote its metrics. ## What In `modules/services/pi-bots.nix`, beside the existing `PiBots*` rules, all warnings and each held only while the service reports itself up with a fresh health file (so a stopped or crashed service still raises one alert): - `PiBotsClockSilent`: `pi_bots_clock_last_tick_timestamp_seconds` over 60 s old for 5 min (the clock ticks every 10 s; 0 means no tick since start). - `PiBotsJobFailed`: `pi_bots_job_last_run_failed == 1` for 10 min, named by `job_id`; clears when the job's next run does not fail. The `for` lets a 5-minute job fail once without an alert. - `PiBotsJobWaiting`: a job held back 30 min because its bot is not bridged. - `PiBotsJobFileUnusable`: `pi_bots_clock_bad_job_files > 0` for 15 min. New option `services.pi-bots.alerts.sggPreviewWatchdog` (on for Studio) adds rules for the SGG preview watchdog, a pi-bots job (every 5 min) whose script writes `sgg-preview-watchdog.prom` into the service's metrics directory, which node_exporter already reads: - `SggPreviewWatchdogSilent`: no finished run for 20 min (one run may take ~14 min and the clock skips a slot while one runs, so run ends can be ~19.5 min apart), or no file at all, while the service is up and its clock ticks (a stopped clock is `PiBotsClockSilent` alone); 5 min. - `SggPreviewWatchdogBlocked`: waiting for Tailscale or unable to read the registry, 30 min. - `SggPreviewNeedsAttention`: a persistent preview `failed`, `expired` or `cleanup_failed` for 15 min (a preview reads failed for a moment while restarted), per preview, with `keep_firing_for` 15 min so a short gap in the preview list sends no resolved notice for a preview still broken. The last two hold only while the watchdog's own file is fresh, so a stale file raises only `SggPreviewWatchdogSilent`. A watchdog run that fails outright is `PiBotsJobFailed{job_id="sgg-preview-watchdog"}`. A job disabled after a failure keeps `PiBotsJobFailed` until its file is removed or it runs again (its last run stays in `clock.db`). Docs: `modules/services/AGENTS.md` (pi-bots row), README. ## Tests `scripts/test_pi_bots_service.py` (51, was 23): `promtool test rules` for each new rule firing and staying quiet (a short pause of the clock, one failed run followed by a good one, the worst-case gap between watchdog runs, a preview failed for a moment, a short gap in the preview list), each rule's service-down gate (crash and clean stop), the clock gate, the stale-watchdog-file gate, and the opt-in; `promtool check metrics` on the clock's and the watchdog's files as written. Mutations of every threshold, `for`, `keep_firing_for`, gate, the `absent()` branch and the opt-in each fail a test. The expressions were also run against the live Prometheus. `darwin-rebuild build --flake .#studio` builds; the monitoring, fseventsd, NAS and OpenCode Go suites pass. ## After `update-system` The new rules load with health ok. Expect `SggPreviewNeedsAttention` for the persistent previews that are already `cleanup_failed` (long-standing; Hermes alerted on each once): that is the rule working. They arrive as one grouped notice, by email and in Studio Alerts, repeated every 4 h (Alertmanager's `repeat_interval`) until each preview is recovered or removed. ## Review A visible Pi reviewer requested changes: two should-fixes (the long-run test did not pin the Silent threshold; the waiting-job and bad-file gates were untested) and six nits (the absent branch's freshness untested; a stopped clock also raised Silent; resolved notices on a list gap; the 4-hourly repeat; a disabled job's failure never clears; the `for` comment). All fixed or documented, each fix with a test that fails without it.
Part of #10 (N10.4: alert rules for the preview watchdog's metrics), with the
job clock rules #9 left for when the clock wrote its metrics.

services.pi-bots gains PiBotsClockSilent, PiBotsJobFailed, PiBotsJobWaiting
and PiBotsJobFileUnusable, each held only while the service reports itself
up. alerts.sggPreviewWatchdog (on for Studio) adds SggPreviewWatchdogSilent,
SggPreviewWatchdogBlocked and SggPreviewNeedsAttention for the watchdog job's
metrics file, which node_exporter already reads.
Review of #22: the long-run test now models the worst gap between watchdog
runs; the job-waiting, bad-file and absent-file gates are tested alone; a
stopped clock no longer raises SggPreviewWatchdogSilent beside
PiBotsClockSilent; SggPreviewNeedsAttention keeps firing through a short gap
in the preview list.
bryan manually merged commit c861ef1bb5 into main 2026-11-11 18:30:07 +00:00
Sign in to join this conversation.
No reviewers
No labels
ready-for-agent
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bryan/nix-configs!22
No description provided.