Fleet dispatcher landing detection: false stranded-closes on every rebase-landed ticket, and each pass blocks allocation ~3 min (found in shadow, #358) #363

Closed
opened 2026-11-19 15:17:35 +00:00 by ben · 1 comment
Owner

Found on 2026-11-19 while deploying the dispatcher in shadow on matou-workstation for #357 (interactive session, at Ben's instruction). The first shadow detection pass logged 25 anomalies; had the dispatcher been live it would have filed 25 priority tickets at the front of the fleet queue. Landing detection is now switched off on that deployment (FLEET_DISPATCH_DETECT=off in the unit) and must stay off for the stage-1 live flip until these are fixed.

1. stranded-close flags every rebase-landed close (false positive)

18 of the 25. Example: Matou/dev-factory#360 — the close report claims b845c29; the host landed it on main as 4cc991f (rebased, so a new sha). git merge-base --is-ancestor b845c29 origin/main is false, so the check reports "ticket closed but commit(s) absent from main". Same shape for dev-factory#193 (979d55f), 9 Tupu/ai-company-os tickets and 6 Matou/policy-generators tickets (PR-mode repos, where a merge or squash also changes the sha). Ancestry of the close-report sha is not evidence of a stranded close when the landing path rewrites commits. It needs the same test the stranded-close reopen (#283/#328) uses, or a patch-id / landed-marker comparison.

Also Matou/idss#2202: closed at about 14:54Z with its commit still on a sandcastle/worker/* branch — the run had not finished landing. A close needs a grace window before it is called stranded, as working-no-run already has.

2. A detection pass blocks allocation for about three minutes

Detection runs inline in fleet_dispatch_once. Observed pass start times: 15:09:53, then nothing until 15:12:53 (detection running), then one pass every ~17 s, then silent again from 15:14:49 when the next detection began. With the default FLEET_DISPATCH_DETECT_INTERVAL=120 the allocator is blocked for roughly three minutes in every five, so a freed slot is not refilled "in seconds" (ADR 0009 ruling A). Detection wants to run off the allocation path (its own process or loop), and the per-ticket reads want bounding.

It also made systemctl restart hang until the stop timeout: the loop does not exit on SIGTERM while a detection read is in flight.

3. working-no-run on a cold start

2 of the 25 (dev-factory#359, policy-generators#92) were flagged because the dispatcher had just started and held no reports yet; both were held by live runs on bens-mac-04. With no fresh report from any host, or from the host that claimed the ticket, the check should surface nothing. Separately: a ticket claimed by an interactive session, or by the session-runner outside a heavy slot, carries agent-working and is in no slot report — confirm whether those are suppressed, with a test.

4. unmerged-pr on Matou/coa

5 of the 25 (coa PRs #157, #180–#183). Check that coa really is MERGE_AUTHORITY=agent-after-green; if a human merges there, these are not anomalies.

5. The forge token is on curl's argv

_fleet_landing_api passes -H "Authorization: token $FORGEJO_TOKEN" as an argument, so the token is readable in ps by any user on the host for the length of each call. fleet-dispatch.sh says "Never on argv or a URL". Pass it by --config - / -H @file as the other libs do.

Acceptance

  • A rebase-landed and a PR-merged close are not reported; a genuinely stranded close still is (offline tests for each).
  • Allocation passes keep their cadence while detection runs.
  • A cold-started dispatcher reports no working-no-run.
  • No token in ps output.

Related: #358 (the slice), #357 (stage 1 runs with detection off), ADR 0009 decision 5.

Found on 2026-11-19 while deploying the dispatcher in shadow on `matou-workstation` for #357 (interactive session, at Ben's instruction). The first shadow detection pass logged **25 anomalies**; had the dispatcher been live it would have filed 25 `priority` tickets at the front of the fleet queue. Landing detection is now switched off on that deployment (`FLEET_DISPATCH_DETECT=off` in the unit) and must stay off for the stage-1 live flip until these are fixed. ## 1. `stranded-close` flags every rebase-landed close (false positive) 18 of the 25. Example: `Matou/dev-factory#360` — the close report claims `b845c29`; the host landed it on `main` as `4cc991f` (rebased, so a new sha). `git merge-base --is-ancestor b845c29 origin/main` is false, so the check reports "ticket closed but commit(s) absent from main". Same shape for `dev-factory#193` (`979d55f`), 9 `Tupu/ai-company-os` tickets and 6 `Matou/policy-generators` tickets (PR-mode repos, where a merge or squash also changes the sha). Ancestry of the close-report sha is not evidence of a stranded close when the landing path rewrites commits. It needs the same test the stranded-close reopen (#283/#328) uses, or a patch-id / landed-marker comparison. Also `Matou/idss#2202`: closed at about 14:54Z with its commit still on a `sandcastle/worker/*` branch — the run had not finished landing. A close needs a grace window before it is called stranded, as `working-no-run` already has. ## 2. A detection pass blocks allocation for about three minutes Detection runs inline in `fleet_dispatch_once`. Observed pass start times: `15:09:53`, then nothing until `15:12:53` (detection running), then one pass every ~17 s, then silent again from `15:14:49` when the next detection began. With the default `FLEET_DISPATCH_DETECT_INTERVAL=120` the allocator is blocked for roughly three minutes in every five, so a freed slot is not refilled "in seconds" (ADR 0009 ruling A). Detection wants to run off the allocation path (its own process or loop), and the per-ticket reads want bounding. It also made `systemctl restart` hang until the stop timeout: the loop does not exit on SIGTERM while a detection read is in flight. ## 3. `working-no-run` on a cold start 2 of the 25 (`dev-factory#359`, `policy-generators#92`) were flagged because the dispatcher had just started and held no reports yet; both were held by live runs on `bens-mac-04`. With no fresh report from **any** host, or from the host that claimed the ticket, the check should surface nothing. Separately: a ticket claimed by an interactive session, or by the session-runner outside a heavy slot, carries `agent-working` and is in no slot report — confirm whether those are suppressed, with a test. ## 4. `unmerged-pr` on `Matou/coa` 5 of the 25 (coa PRs #157, #180–#183). Check that coa really is `MERGE_AUTHORITY=agent-after-green`; if a human merges there, these are not anomalies. ## 5. The forge token is on `curl`'s argv `_fleet_landing_api` passes `-H "Authorization: token $FORGEJO_TOKEN"` as an argument, so the token is readable in `ps` by any user on the host for the length of each call. `fleet-dispatch.sh` says "Never on argv or a URL". Pass it by `--config -` / `-H @file` as the other libs do. ## Acceptance - A rebase-landed and a PR-merged close are not reported; a genuinely stranded close still is (offline tests for each). - Allocation passes keep their cadence while detection runs. - A cold-started dispatcher reports no `working-no-run`. - No token in `ps` output. Related: #358 (the slice), #357 (stage 1 runs with detection off), ADR 0009 decision 5.

close-report for #363 — all five shadow-found faults fixed on main (push mode), landed as fc4c1c2.

What landed (fleet-landing-detect-lib.sh, fleet-dispatch.sh, their offline tests, + a journal/GOTCHAS/STATUS update):

  1. False stranded-close on a rewritten landing sha (18/25). fleet_landing_unlanded now treats a commit as landed under ANY of three witnesses — sha ancestry (clean push / merge-commit), its patch-id on main (rebase / cherry-pick / single-commit squash), or an #N reference by a main commit (multi-commit squash / merge, sha-free). A close grace (FLEET_LANDING_CLOSE_GRACE, 900s) defers a close a run may still be landing (the idss#2202 mid-land case), and the gather git fetch origins first so the witnesses read current refs.
  2. Detection off the allocation path. The loop now forks one detection pass on its own cadence (fleet_dispatch_detect_maybe_fork, one at a time, stamped at launch) + a TERM/INT trap with an interruptible sleep & wait; the once CLI stays synchronous. The fork is disowned so the next pass's fleet_queue_collect bare-wait does not inherit and busy-spin on it (GOTCHAS #363). Measured: allocation keeps its 1s cadence while a slow detection runs, and SIGTERM stops the loop in 9ms (was deferred behind a read in flight).
  3. working-no-run on a cold start. The pure core gates it on reports_seen (no fresh report from any host → flag nothing); fleet_landing_working also drops a ticket held by a live session claim (swarm-claim … session-ttl=<N> within ttl) — the session-runner / interactive case.
  4. unmerged-pr on Matou/coa (5/25) — confirmed REAL, not a false positive: coa's .sandcastle/swarm-policy.sh reads MERGE_AUTHORITY=agent-after-green, so a green unmerged agent PR is exactly the anomaly the check should surface. No code change.
  5. The forge token off curl's argv — --config - on stdin for reads, a mode-600 config file for the create POST (its stdin carries the body). Verified authenticating against the live forge with no token in the argv trace.

Proof. tests/fleet-landing-detect-lib-test.sh 55/55, tests/fleet-dispatch-test.sh 33/33 (incl. new rebase-landed/PR-merged/genuine-strand, cold-start, session-claim, token-off-argv, cadence + SIGTERM checks); full offline suite 105 ok (the lone fleet-queue-test.sh red is pre-existing + unrelated — fails on clean main, filed as #369). shellcheck -S warning -x (v0.11.0) clean on all four files; bash -n clean. Journal docs/journal/2026-11-19-363.md; GOTCHAS #363; STATUS #353 row updated.

Acceptance. A rebase-landed and a PR-merged close are not reported; a genuine strand still is ✓. Allocation keeps its cadence while detection runs ✓. A cold-started dispatcher reports no working-no-run ✓. No token in ps ✓.

Owed (not this ticket): the fixes are not vendored, so they reach the running factory-dispatcher.service on matou-workstation only at the next self-pin re-vendor (GOTCHAS 4); detection stays FLEET_DISPATCH_DETECT=off there until then, and the live-flip go stays Ben's (#353 / #357).

Ruled by agent under ADR 0174 — veto anytime.

**close-report for #363** — all five shadow-found faults fixed on `main` (push mode), landed as `fc4c1c2`. **What landed** (`fleet-landing-detect-lib.sh`, `fleet-dispatch.sh`, their offline tests, + a journal/GOTCHAS/STATUS update): 1. **False `stranded-close` on a rewritten landing sha** (18/25). `fleet_landing_unlanded` now treats a commit as landed under ANY of three witnesses — sha ancestry (clean push / merge-commit), its **patch-id** on `main` (rebase / cherry-pick / single-commit squash), or an **`#N` reference** by a `main` commit (multi-commit squash / merge, sha-free). A **close grace** (`FLEET_LANDING_CLOSE_GRACE`, 900s) defers a close a run may still be landing (the `idss#2202` mid-land case), and the gather `git fetch origin`s first so the witnesses read current refs. 2. **Detection off the allocation path.** The loop now **forks** one detection pass on its own cadence (`fleet_dispatch_detect_maybe_fork`, one at a time, stamped at launch) + a TERM/INT trap with an interruptible `sleep & wait`; the `once` CLI stays synchronous. The fork is **`disown`ed** so the next pass's `fleet_queue_collect` bare-`wait` does not inherit and busy-spin on it (GOTCHAS #363). Measured: allocation keeps its 1s cadence while a slow detection runs, and SIGTERM stops the loop in **9ms** (was deferred behind a read in flight). 3. **`working-no-run` on a cold start.** The pure core gates it on `reports_seen` (no fresh report from any host → flag nothing); `fleet_landing_working` also drops a ticket held by a **live session claim** (`swarm-claim … session-ttl=<N>` within ttl) — the session-runner / interactive case. 4. **`unmerged-pr` on `Matou/coa`** (5/25) — confirmed **REAL, not a false positive**: coa's `.sandcastle/swarm-policy.sh` reads `MERGE_AUTHORITY=agent-after-green`, so a green unmerged agent PR is exactly the anomaly the check should surface. No code change. 5. **The forge token off `curl`'s argv** — `--config -` on stdin for reads, a mode-600 config file for the create POST (its stdin carries the body). Verified authenticating against the live forge with **no token in the argv trace**. **Proof.** `tests/fleet-landing-detect-lib-test.sh` 55/55, `tests/fleet-dispatch-test.sh` 33/33 (incl. new rebase-landed/PR-merged/genuine-strand, cold-start, session-claim, token-off-argv, cadence + SIGTERM checks); full offline suite 105 ok (the lone `fleet-queue-test.sh` red is pre-existing + unrelated — fails on clean `main`, filed as **#369**). `shellcheck -S warning -x` (v0.11.0) clean on all four files; `bash -n` clean. Journal `docs/journal/2026-11-19-363.md`; GOTCHAS #363; STATUS `#353` row updated. **Acceptance.** A rebase-landed and a PR-merged close are not reported; a genuine strand still is ✓. Allocation keeps its cadence while detection runs ✓. A cold-started dispatcher reports no `working-no-run` ✓. No token in `ps` ✓. **Owed (not this ticket):** the fixes are not vendored, so they reach the running `factory-dispatcher.service` on `matou-workstation` only at the next self-pin re-vendor (GOTCHAS 4); detection stays `FLEET_DISPATCH_DETECT=off` there until then, and the live-flip go stays Ben's (#353 / #357). Ruled by agent under ADR 0174 — veto anytime.
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#363
No description provided.