swarm: head-of-line blocking — one long ticket holds the repo's workflow-level concurrency group, so a newly readied ticket waits hours while idle swarm hosts get no job #1732

Closed
opened 2026-09-22 15:22:01 +00:00 by ben · 1 comment
Owner

What Ben saw (2026-09-22 ~15:10Z)

Factory machines idle while an unblocked ready-for-agent ticket (#1729) sat unclaimed.

Evidence (read on the three hosts)

  • Run 30128 started 13:45:55Z. Its ready set was computed then. Worker 1 (matou-dev-server-01) claimed #1725 at 14:10 and is still in it (sandbox sandcastle-25615e1e…, up ~1.5 h).
  • Worker 2 of the same run landed on elitebook-03, where schedule_drive_yield found /tmp/matou-drive-wanted (an IDIP drive is running there; yield counter at 5) and exited 0 before the trace — so it leaves no verdict line at all.
  • #1729 was created at 13:48:41Z — 3 minutes after run 30128 listed its ready set.
  • The :15/:45 crons at 14:15, 14:45 and 15:15 all fired, but swarm.yml holds a workflow-level concurrency: group: swarm-${{ github.repository }} (cancel-in-progress false). Forgejo keeps ONE run running + ONE pending per group, cancelling the older pending run each time a newer one queues — the workstation runner log shows exactly that: task 119960 picked up 15:14:16Z, RESULT_CANCELLED 15:18:42Z. No new swarm run for idss can start until run 30128 ends (timeout 180 min).
  • bens-mac-04 is registered with the swarm label, runner up, load 0.15, zero idss tasks since 13:00. matou-dev-server-01's second slot is held by a CI session; elitebook-03 is in a drive. So the one host with capacity is the one that can never receive a job while the group is held.
  • #1729 is not lost: run 30128's worker drains up to maxIterations: 3 and re-lists after each task, so it will claim #1729 when #1725 finishes — but only on the busy host, only after #1725, and only because it happens to have iterations left.

Why it is shaped this way

The workflow-level group (#705 / dev-factory#26) was the fix for the 2026-08-26 storm (hundreds of queued no-op runs). It collapses bursts correctly — and, as a side effect, serialises whole RUNS per repo, so the matrix width (2) and the host pool size (3) buy nothing once one worker is inside a long ticket.

Proposed fix (ADR 0174 two-way door — factory config; protected path, hence session)

Keep storm protection, remove the head-of-line block:

  1. Move the concurrency guard off the whole run. Storms are already prevented by the ready-set-hash debounce (schedule_debounce_decide), per-ticket claiming, and the host-capacity slots. Replace the workflow-level group with a group keyed on the ready-set hash (a cheap pre-step computes it), or drop it and add a per-host guard: a run that finds no claimable ticket exits in <10 s, which is the cost the group was protecting against.
  2. A yielding worker must not keep the run alive for nothing — fine today (it exits), but make it RECORD the yield (reason=yielded-to-drive) in the verdict log; today it is invisible, which made this hard to diagnose.
  3. Rearm on ready-without-worker: when a worker finishes a ticket and the listing shows ready tickets it will not take (iterations exhausted), dispatch a fresh run (the D5 self-rearm) so another host can.
  4. Guard with scripts/tests/workflow-concurrency-test.sh (it currently pins the workflow-level group — update it to pin the new shape) and a storm regression test (N identical closed events ⇒ ≤ 1 worker per ready ticket).

Upstream: the same swarm.yml shape lives in Matou/dev-factory (FACTORY_REF) — fix there and bump, or fix here and upstream.

Why session, not agent

.forgejo/workflows/ and .sandcastle/ are protected paths workers never edit (#445).

## What Ben saw (2026-09-22 ~15:10Z) Factory machines idle while an unblocked `ready-for-agent` ticket (#1729) sat unclaimed. ## Evidence (read on the three hosts) - **Run 30128** started 13:45:55Z. Its ready set was computed then. Worker 1 (matou-dev-server-01) claimed **#1725** at 14:10 and is still in it (sandbox `sandcastle-25615e1e…`, up ~1.5 h). - Worker 2 of the same run landed on **elitebook-03**, where `schedule_drive_yield` found `/tmp/matou-drive-wanted` (an IDIP drive is running there; yield counter at 5) and exited 0 *before* the trace — so it leaves no verdict line at all. - **#1729** was created at 13:48:41Z — **3 minutes after** run 30128 listed its ready set. - The :15/:45 crons at 14:15, 14:45 and 15:15 all fired, but `swarm.yml` holds a **workflow-level** `concurrency: group: swarm-${{ github.repository }}` (cancel-in-progress false). Forgejo keeps ONE run running + ONE pending per group, cancelling the older pending run each time a newer one queues — the workstation runner log shows exactly that: task 119960 picked up 15:14:16Z, `RESULT_CANCELLED` 15:18:42Z. **No new swarm run for idss can start until run 30128 ends** (timeout 180 min). - **bens-mac-04** is registered with the `swarm` label, runner up, load 0.15, **zero idss tasks since 13:00**. matou-dev-server-01's second slot is held by a CI session; elitebook-03 is in a drive. So the one host with capacity is the one that can never receive a job while the group is held. - #1729 is not lost: run 30128's worker drains up to `maxIterations: 3` and re-lists after each task, so it will claim #1729 when #1725 finishes — but only on the busy host, only after #1725, and only because it happens to have iterations left. ## Why it is shaped this way The workflow-level group (#705 / dev-factory#26) was the fix for the 2026-08-26 storm (hundreds of queued no-op runs). It collapses bursts correctly — and, as a side effect, serialises whole RUNS per repo, so the matrix width (2) and the host pool size (3) buy nothing once one worker is inside a long ticket. ## Proposed fix (ADR 0174 two-way door — factory config; protected path, hence session) Keep storm protection, remove the head-of-line block: 1. **Move the concurrency guard off the whole run.** Storms are already prevented by the ready-set-hash debounce (`schedule_debounce_decide`), per-ticket claiming, and the host-capacity slots. Replace the workflow-level group with a group keyed on the **ready-set hash** (a cheap pre-step computes it), or drop it and add a per-host guard: a run that finds no claimable ticket exits in <10 s, which is the cost the group was protecting against. 2. **A yielding worker must not keep the run alive for nothing** — fine today (it exits), but make it RECORD the yield (`reason=yielded-to-drive`) in the verdict log; today it is invisible, which made this hard to diagnose. 3. **Rearm on ready-without-worker:** when a worker finishes a ticket and the listing shows ready tickets it will not take (iterations exhausted), dispatch a fresh run (the D5 self-rearm) so another host can. 4. Guard with `scripts/tests/workflow-concurrency-test.sh` (it currently pins the workflow-level group — update it to pin the new shape) and a storm regression test (N identical `closed` events ⇒ ≤ 1 worker per ready ticket). Upstream: the same `swarm.yml` shape lives in Matou/dev-factory (FACTORY_REF) — fix there and bump, or fix here and upstream. ## Why session, not agent `.forgejo/workflows/` and `.sandcastle/` are protected paths workers never edit (#445).

Ruled by agent under ADR 0174 — veto anytime.

Ruling

The workflow-level per-repo concurrency group (swarm-${{ github.repository }}, #705) was the head-of-line block: keyed on the repo alone, it serialised every swarm run for the repo, so a worker inside a long ticket held the group and every later run — the :15/:45 cron and the D5 self-rearm dispatch, the two paths that reach an idle host with a newly readied ticket — queued behind it and was cancelled one-by-one.

Of the proposal's four parts:

  • #1 (move the guard off the whole run) — LANDED. Keying on the ready-set hash is impossible at workflow level (concurrency is evaluated before any step runs, so a pre-step's output can't feed it). Keying on the trigger doesn't fix it either — the blocking run can itself be a cron, leaving the cron lane blocked. Only de-serialising the runs fixes it universally, which is the proposal's sanctioned "drop the run-serialisation; the per-host guard is the protection" path. swarm.yml now keys concurrency per run (swarm-${{ github.repository }}-${{ github.run_number }}), so runs never serialise and a newly readied ticket reaches an idle host at once.
  • #3 (rearm on ready-without-worker) — already exists (report_self_rearm → rearm_dispatch); its effectiveness is restored by #1, since the dispatch (workflow_dispatch) no longer queues behind a long run.
  • #4 (guards) — LANDED.
  • #2 (record the pre-work drive-yield) — split to #1733 (it touches the factory-vendored run-swarm.sh/schedule-lib.sh, so it needs the dev-factory upstream + re-vendor door), along with propagating the shape to the dev-factory template.

Why it is a two-way door

Revertible config (one workflow-file line + two test files, all non-vendored — not in FACTORY_MANIFEST, so no drift-gate impact). Proven at the same offline-test bar #705 itself was. Storm protection is preserved by guards that were absent in the 2026-08-26 storm and are now load-bearing: the labeled trigger (the storm's real multiplier) is gone (closed only); the host-capacity slot flocks yield a slot-less run in seconds before any sandbox; the ready-set-hash debounce + per-ticket claim collapse duplicate work. Worst-case degradation (an empty run_number) is re-serialisation — the status quo, never a storm.

Close-report

  • Commit: a075fb26 (on main).
  • Landed: .forgejo/workflows/swarm.yml concurrency group → per-run; scripts/tests/workflow-concurrency-test.sh rewritten to reject the serialising per-repo shape and require a per-run key + the host-capacity yield guard's presence; new scripts/tests/swarm-storm-regression-test.sh (N identical closed events ⇒ ≤1 run; a changed ready set runs; the debounce window expires); STATUS.md.
  • Proof (offline): workflow-concurrency-test.sh 8 checks green (and verified it FAILS on the old swarm-${{ github.repository }} shape); swarm-storm-regression-test.sh 4 checks green; swarm.yml parses; the swarm.yml-line-extracting drive-reservation-guard-test.sh still green; drift gate green (no vendored file touched). The runtime effect (Forgejo no longer serialising runs) is inherent to the documented per-group semantics — same bar #705 was accepted at.
  • Follow-ups: #1733 (pre-work drive-yield observability + dev-factory template propagation).

Closing as done.

**Ruled by agent under ADR 0174 — veto anytime.** ## Ruling The workflow-level per-repo concurrency group (`swarm-${{ github.repository }}`, #705) was the head-of-line block: keyed on the repo alone, it serialised **every** swarm run for the repo, so a worker inside a long ticket held the group and every later run — the :15/:45 cron and the D5 self-rearm dispatch, the two paths that reach an idle host with a newly readied ticket — queued behind it and was cancelled one-by-one. Of the proposal's four parts: - **#1 (move the guard off the whole run) — LANDED.** Keying on the ready-set hash is impossible at workflow level (concurrency is evaluated *before* any step runs, so a pre-step's output can't feed it). Keying on the *trigger* doesn't fix it either — the blocking run can itself be a cron, leaving the cron lane blocked. Only **de-serialising** the runs fixes it universally, which is the proposal's sanctioned "drop the run-serialisation; the per-host guard is the protection" path. `swarm.yml` now keys concurrency **per run** (`swarm-${{ github.repository }}-${{ github.run_number }}`), so runs never serialise and a newly readied ticket reaches an idle host at once. - **#3 (rearm on ready-without-worker) — already exists** (`report_self_rearm` → `rearm_dispatch`); its effectiveness is *restored* by #1, since the dispatch (`workflow_dispatch`) no longer queues behind a long run. - **#4 (guards) — LANDED.** - **#2 (record the pre-work drive-yield) — split to #1733** (it touches the factory-vendored `run-swarm.sh`/`schedule-lib.sh`, so it needs the dev-factory upstream + re-vendor door), along with propagating the shape to the dev-factory template. ## Why it is a two-way door Revertible config (one workflow-file line + two test files, all non-vendored — not in `FACTORY_MANIFEST`, so no drift-gate impact). Proven at the same offline-test bar #705 itself was. Storm protection is preserved by guards that were absent in the 2026-08-26 storm and are now load-bearing: the `labeled` trigger (the storm's real multiplier) is gone (`closed` only); the host-capacity slot flocks yield a slot-less run in seconds *before* any sandbox; the ready-set-hash debounce + per-ticket claim collapse duplicate work. Worst-case degradation (an empty `run_number`) is re-serialisation — the status quo, **never a storm**. ## Close-report - **Commit:** `a075fb26` (on `main`). - **Landed:** `.forgejo/workflows/swarm.yml` concurrency group → per-run; `scripts/tests/workflow-concurrency-test.sh` rewritten to reject the serialising per-repo shape and require a per-run key + the host-capacity yield guard's presence; new `scripts/tests/swarm-storm-regression-test.sh` (N identical `closed` events ⇒ ≤1 run; a changed ready set runs; the debounce window expires); `STATUS.md`. - **Proof (offline):** `workflow-concurrency-test.sh` 8 checks green (and verified it FAILS on the old `swarm-${{ github.repository }}` shape); `swarm-storm-regression-test.sh` 4 checks green; `swarm.yml` parses; the swarm.yml-line-extracting `drive-reservation-guard-test.sh` still green; drift gate green (no vendored file touched). The runtime effect (Forgejo no longer serialising runs) is inherent to the documented per-group semantics — same bar #705 was accepted at. - **Follow-ups:** #1733 (pre-work drive-yield observability + dev-factory template propagation). Closing as done.
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/idss#1732
No description provided.