swarm loop stalls green: runs conclude 'success' with a ready ticket unworked and no worker spawned — log every run-swarm exit reason host-side, then fix the wedge #435

Closed
opened 2026-08-11 14:50:20 +00:00 by ben · 1 comment
Owner

Symptom — two stall windows in 24h, ~10 hours of loop time lost

Twice now the ourcloud swarm has gone hours with a ready ticket sitting untouched while swarm.yml runs completed "success" on cadence:

  • 2026-08-11 00:19–03:16Z (~3h): #426 ready and unworked; runner journal shows ourcloud tasks starting and finishing within seconds-to-a-minute; no sandcastle container ever spawned. (Ended when a run finally picked up work at 03:16 — cause of the transition unknown.)
  • 2026-08-11 07:33–14:35Z (~7h): #432 ready and unworked; backstop dispatched swarm.yml at 13:30 and 14:15 (plus the cron's own 15,45 firings all day), every run concluded "success", docker events during a live-watched dispatch showed no container created, zero comments/claims on #432. A manual workflow_dispatch at 14:35 broke the spell — that run spawned a worker within a minute and is working #432 normally.

Eliminated (checked live during the second window)

  • Global flock: no holder (fuser /tmp/matou-swarm.lock empty between runs; last night's holder was a legitimate 2h #424 worker).
  • Forgejo token: list-ready-tasks.sh with the real token returns [#432] in <1s; with a bogus token it fails loud (rc=22), which under set -euo pipefail + the verdict trap would red the job — daytime runs were green.
  • Ready-set debounce: SWARM_DEBOUNCE=600 — the 30–45min dispatch cadence sails past it.
  • Claude limit park: /tmp/matou-swarm-claude-limit mtime is 2026-08-02, far beyond CLAUDE_LIMIT_TTL=3600 → claude_limit_parked returns false.

What plugging it needs

  1. Instrument first (the durable deliverable): every exit path in .sandcastle/run-swarm.sh — "no ready tasks", coalesce, limit-pause, each verdict_stage failure, normal completion — appends ONE line to a host-side log (e.g. ~/swarm/logs/run-swarm-verdicts.log): timestamp, repo, ready-set numbers, exit reason, duration. The two stall windows were archaeology precisely because a green no-op run leaves no host-side trace. (The job log has it, but the actions REST API hangs intermittently — from the laptop constantly, from the workstation sporadically — so job logs are not a dependable forensic path.)
  2. Root-cause from the 13:30Z and 14:15Z 2026-08-11 run logs (readable in the Forgejo web UI even when the API hangs): which exit path did they take? Discriminator already in hand: if Mattermost got "Swarm picking up 1 task(s)" posts during the stall windows, the runs died AFTER the debounce (between pickup-post and container spawn — pnpm install / build-image / nix-seed territory); if not, they exited at or before the ready/debounce checks despite a non-empty ready set.
  3. Fix the wedge so a dispatched run with a non-empty ready set either spawns a worker or exits loudly (red job + verdict), never green-and-empty. If the cause turns out to be the coalescing stamp being written before an attempt that then dies quietly, invalidate the stamp on any non-worker exit.

Context: both stalls gated the #183 rehearsal ratchet (the drive issue's blockers sat ready for hours), but the defect is loop infrastructure, not rehearsal-specific.

## Symptom — two stall windows in 24h, ~10 hours of loop time lost Twice now the ourcloud swarm has gone hours with a ready ticket sitting untouched while `swarm.yml` runs completed **"success"** on cadence: - **2026-08-11 00:19–03:16Z** (~3h): #426 ready and unworked; runner journal shows ourcloud tasks starting and finishing within seconds-to-a-minute; no sandcastle container ever spawned. (Ended when a run finally picked up work at 03:16 — cause of the transition unknown.) - **2026-08-11 07:33–14:35Z** (~7h): #432 ready and unworked; backstop dispatched `swarm.yml` at 13:30 and 14:15 (plus the cron's own 15,45 firings all day), every run concluded "success", `docker events` during a live-watched dispatch showed **no container created**, zero comments/claims on #432. A manual `workflow_dispatch` at 14:35 broke the spell — that run spawned a worker within a minute and is working #432 normally. ## Eliminated (checked live during the second window) - **Global flock**: no holder (`fuser /tmp/matou-swarm.lock` empty between runs; last night's holder was a legitimate 2h #424 worker). - **Forgejo token**: `list-ready-tasks.sh` with the real token returns `[#432]` in <1s; with a bogus token it fails **loud** (rc=22), which under `set -euo pipefail` + the verdict trap would red the job — daytime runs were green. - **Ready-set debounce**: `SWARM_DEBOUNCE=600` — the 30–45min dispatch cadence sails past it. - **Claude limit park**: `/tmp/matou-swarm-claude-limit` mtime is 2026-08-02, far beyond `CLAUDE_LIMIT_TTL=3600` → `claude_limit_parked` returns false. ## What plugging it needs 1. **Instrument first (the durable deliverable):** every exit path in `.sandcastle/run-swarm.sh` — "no ready tasks", coalesce, limit-pause, each verdict_stage failure, normal completion — appends ONE line to a host-side log (e.g. `~/swarm/logs/run-swarm-verdicts.log`): timestamp, repo, ready-set numbers, exit reason, duration. The two stall windows were archaeology precisely because a green no-op run leaves no host-side trace. (The job log has it, but the actions REST API hangs intermittently — from the laptop constantly, from the workstation sporadically — so job logs are not a dependable forensic path.) 2. **Root-cause from the 13:30Z and 14:15Z 2026-08-11 run logs** (readable in the Forgejo web UI even when the API hangs): which exit path did they take? Discriminator already in hand: if Mattermost got "Swarm picking up 1 task(s)" posts during the stall windows, the runs died AFTER the debounce (between pickup-post and container spawn — pnpm install / build-image / nix-seed territory); if not, they exited at or before the ready/debounce checks despite a non-empty ready set. 3. **Fix the wedge** so a dispatched run with a non-empty ready set either spawns a worker or exits loudly (red job + verdict), never green-and-empty. If the cause turns out to be the coalescing stamp being written before an attempt that then dies quietly, invalidate the stamp on any non-worker exit. Context: both stalls gated the #183 rehearsal ratchet (the drive issue's blockers sat ready for hours), but the defect is loop infrastructure, not rehearsal-specific.
Author
Owner

Landed in 9a123a3 on main. Two durable halves — instrument first, then plug the wedge.

1. Host-side exit log (the durable deliverable). New .sandcastle/runlog-lib.sh; run-swarm.sh sources it and, via its existing EXIT trap, appends ONE line at EVERY exit path — no-ready-tasks, coalesced, claude-limit-parked, each set -e stage death (died-in:<stage>), the green wedge (no-worker-spawned), and normal completed — to ~/swarm/logs/run-swarm-verdicts.log (override with SWARM_RUNLOG): UTC-timestamp repo=… ready=[nums] reason=… exit=… duration=…s. A green no-op now leaves a trace on disk, so the next stall is readable without the Actions REST API.

2. Fix the wedge (never green-and-empty again). A live docker events --since <run-start> --filter event=create stream watches for worker births for the whole run. Sandcastle starts each iteration's worker as docker run -d --name sandcastle-<uuid> (verified against @ai-hero/sandcastle's docker sandbox), so a create event named sandcastle-* is proof a worker spawned. If a non-empty ready set concludes success (exit 0) with ZERO worker births — never legitimate, even a blocked task spawns a container — the run fails LOUD: red job + a no-worker-spawned verdict the healer keys a fresh signature on + a :rotating_light: Mattermost post. And per the issue's own hint: any run that wrote a fresh debounce stamp but never confirmed a worker (quiet death, green wedge, limit park, sandcastle failure) clears the stamp on exit, so a stale stamp can't coalesce away the very next genuine retry; the coalesce path keeps its stamp, so burst-debouncing still works.

Guards: docker-unavailable skips the wedge check (never false-fails — and a run that got this far already needed docker for build/run); the --since replay closes the stream-attach startup race; the sandcastle- name filter keeps the unnamed nix-seed containers out.

Tests: new .sandcastle/tests/runlog-lib-test.sh (line format incl. ready-set numbers/duration, append-never-fails-the-caller, and the worker_wedge predicate across all four cases). bash -n + debounce-test.sh still green.

Root-cause (issue step 2) left open, honestly. Reading the specific 13:30Z/14:15Z 2026-08-11 run logs to name which exit path they took needs the Actions job logs — not reachable from the worker sandbox (and the REST API hangs, which is exactly why this ticket exists). The fix above is robust regardless of which path those runs took: any green-and-empty run is now loud, and the stamp can't wedge a retry. The instrumentation is precisely what will capture the discriminator (exit reason + worker-birth count) on disk the next time it happens. If a human can pull those two run logs from the Forgejo web UI, the reason= this code now emits is the same discriminator, retrofit-readable.

STATUS.md header + milestone log updated in the same commit.

Landed in `9a123a3` on `main`. Two durable halves — instrument first, then plug the wedge. **1. Host-side exit log (the durable deliverable).** New `.sandcastle/runlog-lib.sh`; `run-swarm.sh` sources it and, via its existing EXIT trap, appends ONE line at EVERY exit path — `no-ready-tasks`, `coalesced`, `claude-limit-parked`, each `set -e` stage death (`died-in:<stage>`), the green wedge (`no-worker-spawned`), and normal `completed` — to `~/swarm/logs/run-swarm-verdicts.log` (override with `SWARM_RUNLOG`): `UTC-timestamp repo=… ready=[nums] reason=… exit=… duration=…s`. A green no-op now leaves a trace on disk, so the next stall is readable without the Actions REST API. **2. Fix the wedge (never green-and-empty again).** A live `docker events --since <run-start> --filter event=create` stream watches for worker births for the whole run. Sandcastle starts each iteration's worker as `docker run -d --name sandcastle-<uuid>` (verified against `@ai-hero/sandcastle`'s docker sandbox), so a create event named `sandcastle-*` is proof a worker spawned. If a **non-empty ready set concludes success (exit 0) with ZERO worker births** — never legitimate, even a blocked task spawns a container — the run **fails LOUD**: red job + a `no-worker-spawned` verdict the healer keys a fresh signature on + a `:rotating_light:` Mattermost post. And per the issue's own hint: any run that wrote a fresh debounce stamp but never confirmed a worker (quiet death, green wedge, limit park, sandcastle failure) **clears the stamp on exit**, so a stale stamp can't coalesce away the very next genuine retry; the coalesce path keeps its stamp, so burst-debouncing still works. Guards: docker-unavailable **skips** the wedge check (never false-fails — and a run that got this far already needed docker for build/run); the `--since` replay closes the stream-attach startup race; the `sandcastle-` name filter keeps the unnamed nix-seed containers out. Tests: new `.sandcastle/tests/runlog-lib-test.sh` (line format incl. ready-set numbers/duration, append-never-fails-the-caller, and the `worker_wedge` predicate across all four cases). `bash -n` + `debounce-test.sh` still green. **Root-cause (issue step 2) left open, honestly.** Reading the specific 13:30Z/14:15Z 2026-08-11 run logs to name which exit path they took needs the Actions job logs — not reachable from the worker sandbox (and the REST API hangs, which is exactly why this ticket exists). The fix above is robust regardless of which path those runs took: any green-and-empty run is now loud, and the stamp can't wedge a retry. The instrumentation is precisely what will capture the discriminator (exit reason + worker-birth count) on disk the next time it happens. If a human can pull those two run logs from the Forgejo web UI, the `reason=` this code now emits is the same discriminator, retrofit-readable. STATUS.md header + milestone log updated in the same commit.
ben 2026-08-11 15:20:30 +00:00
  • closed this issue
  • added the
    priority
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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#435
No description provided.