Scheduler-silence canary — oldest-waiting-age + claimed-head-sha, a sibling of the backstop, shouting to Mattermost (idss #269) #105

Closed
opened 2026-08-27 04:38:41 +00:00 by ben · 3 comments
Owner

Detection half of the scheduler-silence failure mode. Ruled by Ben on idss #269 (2026-08-27) after two live incidents — idss lore 2026-07-28 (schedule rows dropped, runs never created) and idss #878 / dev-factory #103 (2026-08-26, ~2,700 no-op swarm.yml runs buried every other workflow for ~24 h; ci ungated on main for ~16 h while the swarm kept committing). The response half is idss GOTCHAS #95; this ticket is the alarm.

Ruling (the design — accept as-is)

Home: .sandcastle/scheduler-canary.sh here (canonical, ADR 0180), vendored into product repos like schedule-backstop.sh. Run from the host crontab's backstop-tick.sh as a sibling of the backstop — never folded into the backstop's dispatch guard (that guard reads waiting as "covered", the exact inverse of this alarm). It must live outside Forgejo's scheduler: a scheduled canary dies in the outage it watches.

No heartbeat is emitted — the queue is the heartbeat. Two orthogonal assertions, per repo the host serves (list from the same config the backstop reads):

  1. Oldest-waiting-age — catches saturation / claiming (the #878 mode). For each event in push, schedule, workflow_dispatch, issues: GET /repos/{owner}/{repo}/actions/runs?event=<e>&status=waiting&limit=1 (page is newest-first, so read total_count and walk to the last page for the oldest, OR sort client-side over limit=50 when total_count ≤ 50; when total_count > 50 the count itself is already the alarm). Alarm when the oldest created is older than CANARY_MAX_WAIT_MIN (default 30) or total_count > CANARY_MAX_WAITING (default 40). NEVER call the unfiltered runs list — it is tens of MB and times out.
  2. Head-sha liveness — catches creation-drop (the 2026-07-28 mode). For each repo's default branch: head sha via GET /repos/{r}/branches/{default}; if the head commit is older than CANARY_MAX_UNGATED_MIN (default 45) there must be a claimed ci task for it in GET /repos/{r}/actions/tasks (the claimed-only view — reading runs here false-negatives because a waiting run "exists"; see idss #880 / GOTCHAS #95). Skip repos with no ci.yml.

Alert: one Mattermost post via the same MATTERMOST_URL/MATTERMOST_BOT_TOKEN/MATTERMOST_CHANNEL_ID ask-human.sh already uses, prefixed scheduler-canary:, naming repo, mode (saturated / ungated), the number, the oldest run's html_url, and the recovery pointer (GOTCHAS #95). De-bounce: a state file under the host's backstop state dir; re-post at most every CANARY_REPOST_MIN (default 120) while the condition holds, and post one recovered line when it clears. Exit 0 always (a canary that reds the crontab is noise, not signal); exit 2 only when the API itself is unreachable for all repos — that is its own alarm line.

Test: scripts/tests/scheduler-canary-test.sh (offline, pure bash, fakes curl on PATH like broker-install-test.sh does): (a) fresh queue → silent; (b) 165 waiting, oldest 23 h → saturated post, once, then de-bounced, then recovered; (c) head sha 2 h old, present in runs as waiting but absent from tasks → ungated post (the #880 false-negative trap); (d) head sha 2 h old and present in tasks → silent; (e) API down → exit 2, one post. The test runs in ci via the scripts/tests/*.sh sweep.

Docs: a GOTCHAS entry here (the "two modes, two views" table from idss #269) + .sandcastle/README.md line; FACTORY_REF bump + vendor into idss closes idss #269.

Recovery note that must NOT be encoded wrong

For the saturation mode the cure is to cancel the no-op runs and stop what mints them (dev-factory #103 fixed the minting; Ben bulk-cancelled). Re-pushing workflow files is the cure for the creation-drop mode only — the 2026-08-26 "re-register push revived claiming" reading was wrong: both runners' journals show them claiming continuously all day; the queue cleared when the backlog was cancelled.

Acceptance

  • AC1 scheduler-canary.sh lands with both assertions, Mattermost post, de-bounce, exit-code contract above
  • AC2 offline test with cases (a)–(e) green, running in ci
  • AC3 backstop-tick.sh (or its documented crontab line) calls it every 15 min as a sibling of the backstop
  • AC4 GOTCHAS entry + README line; FACTORY_REF bump ticket/handoff for idss (closes idss #269)
Detection half of the scheduler-silence failure mode. Ruled by Ben on idss #269 (2026-08-27) after two live incidents — idss lore 2026-07-28 (schedule rows dropped, runs never *created*) and idss #878 / dev-factory #103 (2026-08-26, ~2,700 no-op `swarm.yml` runs buried every other workflow for ~24 h; `ci` ungated on `main` for ~16 h while the swarm kept committing). The response half is idss GOTCHAS #95; this ticket is the alarm. ## Ruling (the design — accept as-is) **Home:** `.sandcastle/scheduler-canary.sh` here (canonical, ADR 0180), vendored into product repos like `schedule-backstop.sh`. Run from the host crontab's `backstop-tick.sh` as a **sibling** of the backstop — never folded into the backstop's dispatch guard (that guard reads `waiting` as "covered", the exact inverse of this alarm). It must live **outside** Forgejo's scheduler: a scheduled canary dies in the outage it watches. **No heartbeat is emitted — the queue is the heartbeat.** Two orthogonal assertions, per repo the host serves (list from the same config the backstop reads): 1. **Oldest-`waiting`-age** — catches saturation / claiming (the #878 mode). For each `event` in `push, schedule, workflow_dispatch, issues`: `GET /repos/{owner}/{repo}/actions/runs?event=<e>&status=waiting&limit=1` (page is newest-first, so read `total_count` and walk to the last page for the oldest, OR sort client-side over `limit=50` when `total_count ≤ 50`; when `total_count > 50` the count itself is already the alarm). Alarm when the oldest `created` is older than `CANARY_MAX_WAIT_MIN` (default 30) **or** `total_count > CANARY_MAX_WAITING` (default 40). NEVER call the unfiltered runs list — it is tens of MB and times out. 2. **Head-sha liveness** — catches creation-drop (the 2026-07-28 mode). For each repo's default branch: head sha via `GET /repos/{r}/branches/{default}`; if the head commit is older than `CANARY_MAX_UNGATED_MIN` (default 45) there must be a **claimed** `ci` task for it in `GET /repos/{r}/actions/tasks` (the claimed-only view — reading `runs` here false-negatives because a `waiting` run "exists"; see idss #880 / GOTCHAS #95). Skip repos with no `ci.yml`. **Alert:** one Mattermost post via the same `MATTERMOST_URL`/`MATTERMOST_BOT_TOKEN`/`MATTERMOST_CHANNEL_ID` `ask-human.sh` already uses, prefixed `scheduler-canary:`, naming repo, mode (`saturated` / `ungated`), the number, the oldest run's `html_url`, and the recovery pointer (GOTCHAS #95). **De-bounce:** a state file under the host's backstop state dir; re-post at most every `CANARY_REPOST_MIN` (default 120) while the condition holds, and post one `recovered` line when it clears. Exit 0 always (a canary that reds the crontab is noise, not signal); exit 2 only when the API itself is unreachable for all repos — that is its own alarm line. **Test:** `scripts/tests/scheduler-canary-test.sh` (offline, pure bash, fakes `curl` on PATH like `broker-install-test.sh` does): (a) fresh queue → silent; (b) 165 waiting, oldest 23 h → `saturated` post, once, then de-bounced, then `recovered`; (c) head sha 2 h old, present in `runs` as `waiting` but absent from `tasks` → `ungated` post (the #880 false-negative trap); (d) head sha 2 h old and present in `tasks` → silent; (e) API down → exit 2, one post. The test runs in `ci` via the `scripts/tests/*.sh` sweep. **Docs:** a GOTCHAS entry here (the "two modes, two views" table from idss #269) + `.sandcastle/README.md` line; FACTORY_REF bump + vendor into idss closes idss #269. ## Recovery note that must NOT be encoded wrong For the saturation mode the cure is to **cancel the no-op runs and stop what mints them** (dev-factory #103 fixed the minting; Ben bulk-cancelled). Re-pushing workflow files is the cure for the *creation-drop* mode only — the 2026-08-26 "re-register push revived claiming" reading was wrong: both runners' journals show them claiming continuously all day; the queue cleared when the backlog was cancelled. ## Acceptance - [ ] AC1 `scheduler-canary.sh` lands with both assertions, Mattermost post, de-bounce, exit-code contract above - [ ] AC2 offline test with cases (a)–(e) green, running in `ci` - [ ] AC3 `backstop-tick.sh` (or its documented crontab line) calls it every 15 min as a sibling of the backstop - [ ] AC4 GOTCHAS entry + README line; FACTORY_REF bump ticket/handoff for idss (closes idss #269)

swarm-claim host=elitebook-distributed-server-03 run=2730
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=2730 (automated multi-host claim — lowest live claim id works this ticket)

Ruled by agent under ADR 0174 — veto anytime.

Implementing this ticket required widening tests/actions-endpoint-test.sh, the ratchet that forbids ALL actions/runs reads (GOTCHAS 16). The ruling: the canary's saturation assertion may read actions/runs, but only in its status=waiting-filtered, paged, curl-timed form — a waiting run is not in the tasks (claimed-only) view, so the queue-depth alarm has no other source (this ticket says so explicitly). The exemption is bounded on both axes GOTCHAS 16 cared about: the status=waiting filter caps the result at the tiny live queue, and the ratchet still forces page= and a curl timeout. Any runs read WITHOUT status=waiting is still the forbidden unbounded read.

Why a two-way door: revertible by a one-line re-tightening of the ratchet, and proven by the ratchet test itself (which fails any broader runs read) plus tests/scheduler-canary-test.sh cases (a)–(e). Not on the one-way-door list. The design it serves (reading runs?status=waiting for saturation) was already ruled here on idss #269.

Landed in dev-factory #105 / commit 8ea613a.

**Ruled by agent under ADR 0174 — veto anytime.** Implementing this ticket required widening `tests/actions-endpoint-test.sh`, the ratchet that forbids ALL `actions/runs` reads (GOTCHAS 16). The ruling: the canary's saturation assertion may read `actions/runs`, but **only** in its `status=waiting`-filtered, paged, curl-timed form — a `waiting` run is not in the `tasks` (claimed-only) view, so the queue-depth alarm has no other source (this ticket says so explicitly). The exemption is bounded on both axes GOTCHAS 16 cared about: the `status=waiting` filter caps the result at the tiny live queue, and the ratchet still forces `page=` and a curl timeout. Any `runs` read WITHOUT `status=waiting` is still the forbidden unbounded read. **Why a two-way door:** revertible by a one-line re-tightening of the ratchet, and proven by the ratchet test itself (which fails any broader runs read) plus `tests/scheduler-canary-test.sh` cases (a)–(e). Not on the one-way-door list. The design it serves (reading `runs?status=waiting` for saturation) was already ruled here on idss #269. Landed in dev-factory #105 / commit 8ea613a.

close-report for #105 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 105,
  "status": "success",
  "commits": [
    "8ea613a83809f15a59f191021a2a3061be16e4b4"
  ],
  "changed_files": [
    "scheduler-canary.sh",
    "tests/scheduler-canary-test.sh",
    "tests/actions-endpoint-test.sh",
    "onboarding/host-state-lib.sh",
    "onboarding/tests/host-state-lib-test.sh",
    "onboarding/vendor-manifest",
    "docs/GOTCHAS.md",
    "README.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/scheduler-canary-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/actions-endpoint-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/host-state-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "AC1 scheduler-canary.sh lands with both assertions, Mattermost post, de-bounce, exit-code contract": "scheduler-canary.sh: assertion 1 (oldest-waiting-age over runs?event=<e>&status=waiting, CANARY_MAX_WAIT_MIN/CANARY_MAX_WAITING), assertion 2 (head-sha liveness over the claimed-only tasks view, CANARY_MAX_UNGATED_MIN, ci.yml skip), notify via notify-mattermost.sh prefixed 'scheduler-canary:' with per-mode recovery, de-bounce state file under CANARY_STATE_DIR (repost <= CANARY_REPOST_MIN, one recovered line on clear), exit 0 always while the API answers and exit 2 only on a full outage",
    "AC2 offline test with cases (a)-(e) green, running in ci": "tests/scheduler-canary-test.sh shims curl on PATH, cases (a) fresh->silent, (b) 165 waiting/23h->saturated once then de-bounced then recovered, (c) waiting-but-not-claimed->ungated (#880 trap), (d) claimed ci->silent, (e) API down->exit 2 one post, plus the pure-age branch; runs green in the tests/*.sh sweep that ci executes",
    "AC3 backstop-tick.sh calls it every 15 min as a sibling of the backstop": "onboarding/host-state-lib.sh host_state_render_backstop now defines canary() and calls it once per repo (before that repo's dispatches) inside run_repo; backstop-tick.sh runs at */15 (HOST_STATE_DEFAULT_BACKSTOP_SCHEDULE); onboarding/tests/host-state-lib-test.sh asserts one canary per repo driving each repo's own vendored copy and fires once per repo in the offline run",
    "AC4 GOTCHAS entry + README line; FACTORY_REF bump ticket/handoff for idss (closes idss #269)": "docs/GOTCHAS.md 34 ('two modes, two views'); README.md 'What lives here' documents the scheduler pair; the .sandcastle/README.md line + FACTORY_REF bump + vendor into idss are the human pin-bump follow-up (GOTCHAS 4, protected path here) noted in the commit and STATUS.md milestone log"
  },
  "summary": "Landed scheduler-canary.sh, the detection sibling of the backstop, with its offline test, the ratchet exemption for its status=waiting runs read, the generated-backstop-tick wiring, and GOTCHAS 34.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #105 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 105, "status": "success", "commits": [ "8ea613a83809f15a59f191021a2a3061be16e4b4" ], "changed_files": [ "scheduler-canary.sh", "tests/scheduler-canary-test.sh", "tests/actions-endpoint-test.sh", "onboarding/host-state-lib.sh", "onboarding/tests/host-state-lib-test.sh", "onboarding/vendor-manifest", "docs/GOTCHAS.md", "README.md", "STATUS.md" ], "tests": [ { "command": "bash tests/scheduler-canary-test.sh", "exit_code": 0 }, { "command": "bash tests/actions-endpoint-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/host-state-lib-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "AC1 scheduler-canary.sh lands with both assertions, Mattermost post, de-bounce, exit-code contract": "scheduler-canary.sh: assertion 1 (oldest-waiting-age over runs?event=<e>&status=waiting, CANARY_MAX_WAIT_MIN/CANARY_MAX_WAITING), assertion 2 (head-sha liveness over the claimed-only tasks view, CANARY_MAX_UNGATED_MIN, ci.yml skip), notify via notify-mattermost.sh prefixed 'scheduler-canary:' with per-mode recovery, de-bounce state file under CANARY_STATE_DIR (repost <= CANARY_REPOST_MIN, one recovered line on clear), exit 0 always while the API answers and exit 2 only on a full outage", "AC2 offline test with cases (a)-(e) green, running in ci": "tests/scheduler-canary-test.sh shims curl on PATH, cases (a) fresh->silent, (b) 165 waiting/23h->saturated once then de-bounced then recovered, (c) waiting-but-not-claimed->ungated (#880 trap), (d) claimed ci->silent, (e) API down->exit 2 one post, plus the pure-age branch; runs green in the tests/*.sh sweep that ci executes", "AC3 backstop-tick.sh calls it every 15 min as a sibling of the backstop": "onboarding/host-state-lib.sh host_state_render_backstop now defines canary() and calls it once per repo (before that repo's dispatches) inside run_repo; backstop-tick.sh runs at */15 (HOST_STATE_DEFAULT_BACKSTOP_SCHEDULE); onboarding/tests/host-state-lib-test.sh asserts one canary per repo driving each repo's own vendored copy and fires once per repo in the offline run", "AC4 GOTCHAS entry + README line; FACTORY_REF bump ticket/handoff for idss (closes idss #269)": "docs/GOTCHAS.md 34 ('two modes, two views'); README.md 'What lives here' documents the scheduler pair; the .sandcastle/README.md line + FACTORY_REF bump + vendor into idss are the human pin-bump follow-up (GOTCHAS 4, protected path here) noted in the commit and STATUS.md milestone log" }, "summary": "Landed scheduler-canary.sh, the detection sibling of the backstop, with its offline test, the ratchet exemption for its status=waiting runs read, the generated-backstop-tick wiring, and GOTCHAS 34.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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
Matou/dev-factory#105
No description provided.