Fleet dispatcher live mode re-dispatches the same pick on every pass and ignores the #351 marker — duplicate runs until the leg claims #365

Closed
opened 2026-11-19 16:16:11 +00:00 by ben · 2 comments
Owner

Found on 2026-11-19 by reading the live path before flipping matou-workstation live for #357 (interactive session). The flip was not made; the dispatcher stays in shadow until this is fixed.

The defect

fleet_dispatch_once (fleet-dispatch.sh) calls fleet_dispatch_start_run for every placed pick on every pass, and a pass runs about every 17 s. In live mode that is a workflow_dispatch per pass. Nothing remembers that a pick was already dispatched:

  • the ticket stays in the ready list until the leg claims it, and
  • the slot stays free in the host's report until the leg takes the flock and run-swarm.sh sends its take report.

That gap is the runner picking the job up plus the sandbox starting — routinely one to four minutes (the host tick waits up to ~240 s on its dispatch stamp for exactly this reason). So one ready ticket and one free slot produce a fresh swarm run every pass until the first one claims: on the order of 5–15 duplicate runs per ticket.

The second half: it ignores the #351 marker

In stage 6b the other hosts keep ticking. Their ticks post a fleet-dispatch host=<h> marker and dispatch the fleet head to themselves. The dispatcher neither reads those markers nor posts its own (grep -n marker fleet-dispatch-lib.sh is empty), so it sends the same head to the live host while a peer is already dispatching it — the #351 duplicate, between the dispatcher and a ticking host.

Direction (for the builder to confirm)

Decision 2 says the dispatcher stores nothing it cannot rebuild, so the memory wants to live on the tracker, where #351 already put it:

  • before dispatching, arbitrate with the same marker (fleet_queue_arbitrate), posting fleet-dispatch host=<target>;
  • skip any ticket that carries a live marker (its own or a peer's);
  • treat a host's live markers as slots already offered, so a second pick is not sent to a slot the first has not yet taken;
  • a marker expires on FLEET_QUEUE_MARK_TTL, so an offer never taken frees itself.

Acceptance

  • Two consecutive live passes with one ready ticket and one free slot, no claim in between: exactly one workflow_dispatch (offline test).
  • A ticket carrying a peer host's live marker is not dispatched by the dispatcher.
  • Two ready tickets, one free slot on the live host: one dispatch, the second queued with the reason named in the log.

Blocks #357 (stage 1). Related: #351, #355, ADR 0009 decisions 2 and 3.

Found on 2026-11-19 by reading the live path before flipping `matou-workstation` live for #357 (interactive session). **The flip was not made**; the dispatcher stays in shadow until this is fixed. ## The defect `fleet_dispatch_once` (`fleet-dispatch.sh`) calls `fleet_dispatch_start_run` for every placed pick on **every pass**, and a pass runs about every 17 s. In live mode that is a `workflow_dispatch` per pass. Nothing remembers that a pick was already dispatched: - the ticket stays in the ready list until the leg claims it, and - the slot stays `free` in the host's report until the leg takes the flock and `run-swarm.sh` sends its `take` report. That gap is the runner picking the job up plus the sandbox starting — routinely one to four minutes (the host tick waits up to ~240 s on its dispatch stamp for exactly this reason). So one ready ticket and one free slot produce a fresh swarm run every pass until the first one claims: on the order of 5–15 duplicate runs per ticket. ## The second half: it ignores the #351 marker In stage 6b the other hosts keep ticking. Their ticks post a `fleet-dispatch host=<h>` marker and dispatch the fleet head to themselves. The dispatcher neither reads those markers nor posts its own (`grep -n marker fleet-dispatch-lib.sh` is empty), so it sends the same head to the live host while a peer is already dispatching it — the #351 duplicate, between the dispatcher and a ticking host. ## Direction (for the builder to confirm) Decision 2 says the dispatcher stores nothing it cannot rebuild, so the memory wants to live on the tracker, where #351 already put it: - before dispatching, arbitrate with the same marker (`fleet_queue_arbitrate`), posting `fleet-dispatch host=<target>`; - skip any ticket that carries a live marker (its own or a peer's); - treat a host's live markers as slots already offered, so a second pick is not sent to a slot the first has not yet taken; - a marker expires on `FLEET_QUEUE_MARK_TTL`, so an offer never taken frees itself. ## Acceptance - Two consecutive live passes with one ready ticket and one free slot, no claim in between: exactly one `workflow_dispatch` (offline test). - A ticket carrying a peer host's live marker is not dispatched by the dispatcher. - Two ready tickets, one free slot on the live host: one dispatch, the second queued with the reason named in the log. Blocks #357 (stage 1). Related: #351, #355, ADR 0009 decisions 2 and 3.

close-report — #365 landed on main (push mode).

What landed. The live fleet dispatcher now arbitrates each placed pick on the tracker before it dispatches, reusing the #351 marker as its only cross-pass memory (ADR 0009 decision 2 — the dispatcher stores nothing it cannot rebuild).

  • fleet_dispatch_arbitrate (fleet-dispatch-lib.sh): reads the ticket’s live markers; ANY live marker — the dispatcher’s own from a prior pass (the leg has not claimed, so the slot still reads free) or a ticking peer host’s — returns skip (rc 2); otherwise it posts fleet-dispatch host=<target>, wins the #351 race, and returns dispatch (rc 0). Fails OPEN exactly like the host tick (a tracker blip dispatches unarbitrated, guarded by the claim).
  • fleet_dispatch_once (fleet-dispatch.sh): calls it per placed pick in LIVE mode only (shadow leaves the tracker untouched — no marker), skips on rc 1/2 with a named log line, releases its marker on a failed dispatch, and sweeps its own expired markers each pass. Markers scoped to the dispatcher’s own spool (FLEET_QUEUE_MARKS, default $FLEET_DISPATCH_HOME/fleet-queue-marks).

Acceptance (all proven, offline).

  1. Two consecutive live passes, one ready ticket + one free slot, no claim between → exactly one workflow_dispatch (pass 2 logs the SKIP). ✓
  2. A ticket carrying a peer host’s live marker is not dispatched by the dispatcher (skip names the peer, #351). ✓
  3. Two ready tickets, one free slot on the live host → one dispatch, the second queued with the reason named. ✓

Residual (named on the ticket, not fixed). The marker closes the steady-state window (pick still in the ready order). The one window it cannot close is after a pick is CLAIMED (dropped from the ready order) but before its take report flips the slot busy — the marker is on a ticket the dispatcher no longer scans; the claim/flock guard yields the loser gracefully (a wasted run, not corruption). Closing it would need the dispatcher to remember dispatched tickets, which decision 2 forbids as un-rebuildable state.

Commits. 9fd804b on main (harness: #365 — arbitrate each live fleet dispatch on the tracker (no duplicate re-dispatch)).

Proof. tests/fleet-dispatch-lib-test.sh 49/49, tests/fleet-dispatch-test.sh 30/30, tests/fleet-queue-lib-test.sh 78/78, tests/docs-budget-test.sh 4/4, receiver + ack-contract green; bash -n clean. Full offline suite run: the only red is the pre-existing tests/fleet-queue-test.sh (one #356/#357 dispatcher-ack case — present on a clean tree with this change stashed; the same red #359 recorded). Filed as a follow-up below.

Pull-only (GOTCHAS 4). The fix reaches the running factory-dispatcher.service self-copy and the live flip (#357) only at the next self-pin bump; it is harmless in the deployed SHADOW until then. STATUS.md #353 row + docs/journal/2026-11-19-365.md + docs/deploy/fleet-dispatcher.md updated in the same commit.

Ruled by agent under ADR 0174 — two-way door (every change a revertible commit, every claim proven by an offline test; the live flip itself stays Ben’s go, #357). Veto anytime.

**close-report — #365 landed on `main` (push mode).** **What landed.** The live fleet dispatcher now arbitrates each placed pick on the tracker before it dispatches, reusing the #351 marker as its only cross-pass memory (ADR 0009 decision 2 — the dispatcher stores nothing it cannot rebuild). - `fleet_dispatch_arbitrate` (`fleet-dispatch-lib.sh`): reads the ticket’s live markers; ANY live marker — the dispatcher’s own from a prior pass (the leg has not claimed, so the slot still reads `free`) or a ticking peer host’s — returns **skip (rc 2)**; otherwise it posts `fleet-dispatch host=<target>`, wins the #351 race, and returns **dispatch (rc 0)**. Fails OPEN exactly like the host tick (a tracker blip dispatches unarbitrated, guarded by the claim). - `fleet_dispatch_once` (`fleet-dispatch.sh`): calls it per placed pick in **LIVE mode only** (shadow leaves the tracker untouched — no marker), skips on rc 1/2 with a named log line, releases its marker on a failed dispatch, and sweeps its own expired markers each pass. Markers scoped to the dispatcher’s own spool (`FLEET_QUEUE_MARKS`, default `$FLEET_DISPATCH_HOME/fleet-queue-marks`). **Acceptance (all proven, offline).** 1. Two consecutive live passes, one ready ticket + one free slot, no claim between → **exactly one `workflow_dispatch`** (pass 2 logs the SKIP). ✓ 2. A ticket carrying a peer host’s live marker is **not dispatched** by the dispatcher (skip names the peer, #351). ✓ 3. Two ready tickets, one free slot on the live host → **one dispatch, the second queued** with the reason named. ✓ **Residual (named on the ticket, not fixed).** The marker closes the steady-state window (pick still in the ready order). The one window it cannot close is after a pick is CLAIMED (dropped from the ready order) but before its `take` report flips the slot `busy` — the marker is on a ticket the dispatcher no longer scans; the claim/flock guard yields the loser gracefully (a wasted run, not corruption). Closing it would need the dispatcher to remember dispatched tickets, which decision 2 forbids as un-rebuildable state. **Commits.** `9fd804b` on `main` (`harness: #365 — arbitrate each live fleet dispatch on the tracker (no duplicate re-dispatch)`). **Proof.** `tests/fleet-dispatch-lib-test.sh` 49/49, `tests/fleet-dispatch-test.sh` 30/30, `tests/fleet-queue-lib-test.sh` 78/78, `tests/docs-budget-test.sh` 4/4, receiver + ack-contract green; `bash -n` clean. Full offline suite run: the only red is the **pre-existing** `tests/fleet-queue-test.sh` (one #356/#357 dispatcher-ack case — present on a clean tree with this change stashed; the same red #359 recorded). Filed as a follow-up below. **Pull-only (GOTCHAS 4).** The fix reaches the running `factory-dispatcher.service` self-copy and the live flip (#357) only at the next self-pin bump; it is harmless in the deployed SHADOW until then. STATUS.md #353 row + `docs/journal/2026-11-19-365.md` + `docs/deploy/fleet-dispatcher.md` updated in the same commit. Ruled by agent under ADR 0174 — two-way door (every change a revertible commit, every claim proven by an offline test; the live flip itself stays Ben’s go, #357). Veto anytime.

Correction to the close-report: the pre-existing tests/fleet-queue-test.sh red is already tracked as #368 (test-hermeticity — the ack-stand-down case reds only on a host with FLEET_DISPATCHER_URL set, i.e. this dispatcher host; FLEET_DISPATCH_ACK_STATE/env leaks into the test). No new follow-up filed — it is not a regression from #365 (confirmed by stashing this change and re-running).

Correction to the close-report: the pre-existing `tests/fleet-queue-test.sh` red is **already tracked as #368** (test-hermeticity — the ack-stand-down case reds only on a host with `FLEET_DISPATCHER_URL` set, i.e. this dispatcher host; `FLEET_DISPATCH_ACK_STATE`/env leaks into the test). No new follow-up filed — it is not a regression from #365 (confirmed by stashing this change and re-running).
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.

Reference
Matou/dev-factory#365
No description provided.