Dispatcher: do not offer a pick to a host whose runner queue is backed up #373

Closed
opened 2026-11-19 19:54:45 +00:00 by ben · 4 comments
Owner

Problem

The dispatcher offers a pick to any host with a free heavy slot. A free slot does not mean the host's runner will pick the dispatched leg up soon: on 2026-11-19 the dispatcher offered Matou/policy-generators#113 to matou-workstation, whose runner queue was about an hour deep, and the leg was never picked before the 600 s marker expired (#370). In live mode the host's own tick stands down, so nothing retries and the slot idles for the whole marker TTL.

What to build

Before the live path offers a pick to a host, estimate that host's runner queue lag and treat a host over a threshold as not free for this pass (log the reason, like any other unplaced pick).

  • The signal is on the tracker: actions/runs?status=waiting per repo gives the queued runs with created; a run whose other hosts' legs have finished but which is still waiting is waiting on the remaining host. GOTCHAS 78 already names this read as the place a queued run lives (actions/tasks shows only picked jobs).
  • Keep it rebuildable (ADR 0009 decision 2): compute it each pass or cache it briefly; no state the dispatcher cannot rebuild.
  • Bound the cost: eight repos, one bounded page each, curl-timed, and fail open (a failed read must not stall allocation).
  • Threshold and its env name are the builder's call; the host tick waits ~240 s for a claim, which is a sensible ceiling.

Also weigh (not required)

  • Release the dispatcher's marker early when its dispatched run's target leg is still unpicked after N seconds, so another host can take the ticket before the 600 s TTL.
  • Whether the host tick should use the same check.

Acceptance

  • Offline tests: a host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host or queues with the reason named; a failed queue read fails open; shadow mode makes no extra tracker writes.
  • docs/deploy/fleet-dispatcher.md documents the knob.

Context: #370 (measurement), #357 (stage 1), #365 (arbitration), ADR 0009.

## Problem The dispatcher offers a pick to any host with a free heavy slot. A free slot does not mean the host's runner will pick the dispatched leg up soon: on 2026-11-19 the dispatcher offered `Matou/policy-generators#113` to `matou-workstation`, whose runner queue was about an hour deep, and the leg was never picked before the 600 s marker expired (#370). In live mode the host's own tick stands down, so nothing retries and the slot idles for the whole marker TTL. ## What to build Before the live path offers a pick to a host, estimate that host's runner queue lag and treat a host over a threshold as not free for this pass (log the reason, like any other unplaced pick). - The signal is on the tracker: `actions/runs?status=waiting` per repo gives the queued runs with `created`; a run whose other hosts' legs have finished but which is still `waiting` is waiting on the remaining host. GOTCHAS 78 already names this read as the place a queued run lives (`actions/tasks` shows only picked jobs). - Keep it rebuildable (ADR 0009 decision 2): compute it each pass or cache it briefly; no state the dispatcher cannot rebuild. - Bound the cost: eight repos, one bounded page each, curl-timed, and fail open (a failed read must not stall allocation). - Threshold and its env name are the builder's call; the host tick waits ~240 s for a claim, which is a sensible ceiling. ## Also weigh (not required) - Release the dispatcher's marker early when its dispatched run's target leg is still unpicked after N seconds, so another host can take the ticket before the 600 s TTL. - Whether the host tick should use the same check. ## Acceptance - Offline tests: a host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host or queues with the reason named; a failed queue read fails open; shadow mode makes no extra tracker writes. - `docs/deploy/fleet-dispatcher.md` documents the knob. Context: #370 (measurement), #357 (stage 1), #365 (arbitration), ADR 0009.

⏩ independent reviewer for #373 — verdict unauthenticated

review JSON
{
  "verdict": "unauthenticated",
  "findings": []
}
:fast_forward: **independent reviewer** for #373 — verdict `unauthenticated` <details><summary>review JSON</summary> ```json { "verdict": "unauthenticated", "findings": [] } ``` </details>

close-report for #373 — status success

✅ close-report gates passed — every claim verified against the pushed worker branch sandcastle/worker/20261119195637-2051281 (pre-land — the host promotes it to main only after its post-run verify, #193/#283); issue closed.

envelope
{
  "issue": 373,
  "status": "success",
  "commits": [
    "108baac1c7c58515cc12849f768a7673a6285e92"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/deploy/fleet-dispatcher.md",
    "docs/journal/2026-11-19-373.md",
    "fleet-dispatch-lib.sh",
    "fleet-dispatch.sh",
    "tests/fleet-dispatch-lib-test.sh",
    "tests/fleet-dispatch-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/fleet-dispatch-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/fleet-dispatch-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/actions-endpoint-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host or queues with the reason named": "tests/fleet-dispatch-test.sh — the backed-up host (boxA, ~1000s waiting leg) is HELD, alpha#10 is allocated to boxB (the next free host), beta#5 queues; the pure path in tests/fleet-dispatch-lib-test.sh (fleet_dispatch_backed_up_hosts / fleet_dispatch_drop_slots). Loop gate in fleet-dispatch.sh fleet_dispatch_once (live-only, before fleet_dispatch_allocate)",
    "A failed queue read fails open": "fleet_dispatch_waiting_runs returns [] with a stderr line on a failed read (fleet-dispatch-lib.sh); tests/fleet-dispatch-lib-test.sh 'waiting_runs fails OPEN' and tests/fleet-dispatch-test.sh 'a failed queue read fails OPEN — no host held, both picks dispatch'",
    "Shadow mode makes no extra tracker writes": "the gate is guarded by [mode=live]; tests/fleet-dispatch-test.sh 'a shadow pass reads no waiting-run queue (no actions/runs read, gate is live-only)' — shadow does zero reads and zero writes",
    "docs/deploy/fleet-dispatcher.md documents the knob": "fleet-dispatcher.md gains a FLEET_DISPATCH_QUEUE_LAG_MAX bullet (default 240s, 0 disables, signal, attribution, fail-open, live-only)"
  },
  "summary": "The live dispatcher estimates each host's runner-queue lag from actions/runs?status=waiting and holds a host backed up past FLEET_DISPATCH_QUEUE_LAG_MAX, so the pick falls to the next free host or queues.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #373 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against the pushed worker branch `sandcastle/worker/20261119195637-2051281` (pre-land — the host promotes it to `main` only after its post-run verify, #193/#283); issue closed. <details><summary>envelope</summary> ```json { "issue": 373, "status": "success", "commits": [ "108baac1c7c58515cc12849f768a7673a6285e92" ], "changed_files": [ "STATUS.md", "docs/deploy/fleet-dispatcher.md", "docs/journal/2026-11-19-373.md", "fleet-dispatch-lib.sh", "fleet-dispatch.sh", "tests/fleet-dispatch-lib-test.sh", "tests/fleet-dispatch-test.sh" ], "tests": [ { "command": "bash tests/fleet-dispatch-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/fleet-dispatch-test.sh", "exit_code": 0 }, { "command": "bash tests/actions-endpoint-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 } ], "criteria": { "A host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host or queues with the reason named": "tests/fleet-dispatch-test.sh — the backed-up host (boxA, ~1000s waiting leg) is HELD, alpha#10 is allocated to boxB (the next free host), beta#5 queues; the pure path in tests/fleet-dispatch-lib-test.sh (fleet_dispatch_backed_up_hosts / fleet_dispatch_drop_slots). Loop gate in fleet-dispatch.sh fleet_dispatch_once (live-only, before fleet_dispatch_allocate)", "A failed queue read fails open": "fleet_dispatch_waiting_runs returns [] with a stderr line on a failed read (fleet-dispatch-lib.sh); tests/fleet-dispatch-lib-test.sh 'waiting_runs fails OPEN' and tests/fleet-dispatch-test.sh 'a failed queue read fails OPEN — no host held, both picks dispatch'", "Shadow mode makes no extra tracker writes": "the gate is guarded by [mode=live]; tests/fleet-dispatch-test.sh 'a shadow pass reads no waiting-run queue (no actions/runs read, gate is live-only)' — shadow does zero reads and zero writes", "docs/deploy/fleet-dispatcher.md documents the knob": "fleet-dispatcher.md gains a FLEET_DISPATCH_QUEUE_LAG_MAX bullet (default 240s, 0 disables, signal, attribution, fail-open, live-only)" }, "summary": "The live dispatcher estimates each host's runner-queue lag from actions/runs?status=waiting and holds a host backed up past FLEET_DISPATCH_QUEUE_LAG_MAX, so the pick falls to the next free host or queues.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>

🚨 Reopened — a push-mode close did NOT land on main (#283). close-report closed this issue against the pushed worker branch, but the host's post-run verify rolled the land back (push-parked-on-rescue), so origin/main never carried the commits (108baac1c7c58515cc12849f768a7673a6285e92). The gates-passed comment above is therefore NOT true of main. Reopening and relabelling ready-for-session so the work is redone where it can land; the commits are parked on a rescue branch for triage (see this run's alarm).

:rotating_light: **Reopened — a push-mode close did NOT land on `main` (#283).** close-report closed this issue against the pushed worker branch, but the host's post-run verify rolled the land back (`push-parked-on-rescue`), so `origin/main` never carried the commits (`108baac1c7c58515cc12849f768a7673a6285e92`). The gates-passed comment above is therefore NOT true of `main`. Reopening and relabelling `ready-for-session` so the work is redone where it can land; the commits are parked on a rescue branch for triage (see this run's alarm).

close-report for #373 — status success (landed on main, push mode)

What landed. A live-only runner-queue backpressure gate in the fleet dispatcher: before a live pass offers a pick to a host, the dispatcher estimates that host's runner-queue lag from the tracker and treats a host over the ceiling as not free this pass — the pick falls to the next free host, or queues, with the lag named like any other unplaced pick.

  • Signal: actions/runs?status=waiting per repo (GOTCHAS 78's queued-run view — actions/tasks shows only picked jobs), each waiting run attributed to the host whose per-host leg (runs-on: <host>, GOTCHAS 62) it names; the host's lag is the age of its oldest such run. Rebuilt every pass, no cached state (ADR 0009 decision 2).
  • Bounded + fail-open: one page per repo (FLEET_DISPATCH_QUEUE_PAGE, default 50), each curl-timed; a failed read contributes nothing (never withholds an offer). Passes the #28 actions-endpoint ratchet (status=waiting + page= + --max-time).
  • Knob: FLEET_DISPATCH_QUEUE_LAG_MAX (seconds, default 240 = two host ticks / the ack TTL); 0 disables. Read live-only and a GET, so a shadow pass makes no extra tracker call.

Acceptance — all proven offline.

  • a host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host or queues with the reason named → tests/fleet-dispatch-test.sh (next-free-host + queue-with-reason).
  • a failed queue read fails open → tests/fleet-dispatch-test.sh (WAITING_FAIL → host still offered + dispatched).
  • shadow mode makes no extra tracker writes → tests/fleet-dispatch-test.sh (shadow pass makes no actions/runs call at all).
  • docs/deploy/fleet-dispatcher.md documents the knob.

Where. fleet-dispatch-lib.sh (pure attribution fleet_dispatch_lag_from_runs, gating fleet_dispatch_backed_off_hosts/_fleet_dispatch_host_backed_off, the one bounded queued-run curl _fleet_dispatch_waiting_runs, fleet_dispatch_reporting_hosts; fleet_dispatch_free_slots/fleet_dispatch_host_lines take an optional lag map); fleet-dispatch.sh (_fleet_dispatch_queue_lagmap fans the read over the fleet repos and wires it into the live pass). Tests: tests/fleet-dispatch-lib-test.sh (+11 checks), tests/fleet-dispatch-test.sh (+5 checks). Full offline suite green (107/107).

Commit. c8d850d (landed on main).

Also weigh (deferred, not required by the ticket). The "release the marker early when the leg is still unpicked after N s" option and "whether the host tick should run the same check" are left as follow-ups to keep this a single two-way door. A firmer per-leg attribution witness (the jobs web-JSON, GOTCHAS 78) is also a follow-up — the current read fails open, so an unattributable signal never withholds an offer.

Owed. A re-vendor (GOTCHAS 4) to carry this into the running .sandcastle/ dispatcher copy — the dispatcher (live fleet-wide since 2026-11-19, #357) runs the vendored copy, so the gate reaches it at the next FACTORY_REF bump. Inert until then and live-only regardless.

Ruled by agent under ADR 0174 — veto anytime. Proof: the offline test suite above (red-before-green on each new assertion) and the landed commit.

**close-report** for #373 — status `success` (landed on `main`, push mode) **What landed.** A live-only runner-queue backpressure gate in the fleet dispatcher: before a live pass offers a pick to a host, the dispatcher estimates that host's runner-queue lag from the tracker and treats a host over the ceiling as **not free this pass** — the pick falls to the next free host, or queues, with the lag named like any other unplaced pick. - **Signal:** `actions/runs?status=waiting` per repo (GOTCHAS 78's queued-run view — `actions/tasks` shows only picked jobs), each waiting run attributed to the host whose per-host leg (`runs-on: <host>`, GOTCHAS 62) it names; the host's lag is the age of its oldest such run. Rebuilt every pass, no cached state (ADR 0009 decision 2). - **Bounded + fail-open:** one page per repo (`FLEET_DISPATCH_QUEUE_PAGE`, default 50), each curl-timed; a failed read contributes nothing (never withholds an offer). Passes the #28 actions-endpoint ratchet (`status=waiting` + `page=` + `--max-time`). - **Knob:** `FLEET_DISPATCH_QUEUE_LAG_MAX` (seconds, default **240** = two host ticks / the ack TTL); **0 disables**. Read **live-only** and a GET, so a shadow pass makes no extra tracker call. **Acceptance — all proven offline.** - a host whose legs are waiting past the threshold gets no live offer and the pick goes to the next free host **or** queues with the reason named → `tests/fleet-dispatch-test.sh` (next-free-host + queue-with-reason). - a failed queue read fails open → `tests/fleet-dispatch-test.sh` (`WAITING_FAIL` → host still offered + dispatched). - shadow mode makes no extra tracker writes → `tests/fleet-dispatch-test.sh` (shadow pass makes no `actions/runs` call at all). - `docs/deploy/fleet-dispatcher.md` documents the knob. **Where.** `fleet-dispatch-lib.sh` (pure attribution `fleet_dispatch_lag_from_runs`, gating `fleet_dispatch_backed_off_hosts`/`_fleet_dispatch_host_backed_off`, the one bounded queued-run curl `_fleet_dispatch_waiting_runs`, `fleet_dispatch_reporting_hosts`; `fleet_dispatch_free_slots`/`fleet_dispatch_host_lines` take an optional lag map); `fleet-dispatch.sh` (`_fleet_dispatch_queue_lagmap` fans the read over the fleet repos and wires it into the live pass). Tests: `tests/fleet-dispatch-lib-test.sh` (+11 checks), `tests/fleet-dispatch-test.sh` (+5 checks). Full offline suite green (107/107). **Commit.** `c8d850d` (landed on `main`). **Also weigh (deferred, not required by the ticket).** The "release the marker early when the leg is still unpicked after N s" option and "whether the host tick should run the same check" are left as follow-ups to keep this a single two-way door. A firmer per-leg attribution witness (the jobs web-JSON, GOTCHAS 78) is also a follow-up — the current read fails open, so an unattributable signal never withholds an offer. **Owed.** A re-vendor (GOTCHAS 4) to carry this into the running `.sandcastle/` dispatcher copy — the dispatcher (live fleet-wide since 2026-11-19, #357) runs the vendored copy, so the gate reaches it at the next `FACTORY_REF` bump. Inert until then and live-only regardless. Ruled by agent under ADR 0174 — veto anytime. Proof: the offline test suite above (red-before-green on each new assertion) and the landed commit.
matou-build-agent 2026-11-20 01:16:47 +00:00
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#373
No description provided.