swarm: multi-project queue hygiene — flock -n fast-exit, per-repo /tmp namespacing, waiting-aware backstop #238

Closed
opened 2026-07-31 21:57:10 +00:00 by ben · 5 comments
Owner

Why (evidence from 2026-07-31 ~21:55 UTC)

Sandcastle now serves TWO repos (Matou/ourcloud + Matou/matou-app) from one capacity-1 runner on matou-workstation, and the seams showed tonight:

  • 25 runs waiting on ourcloud (18 of them swarm.yml) + 10 on matou-app, all serialized behind one hour-class worker. Every issue event stacks another swarm.yml run, and each started run blocks up to 2h on flock -w 7200 /tmp/matou-swarm.lock (swarm.yml:37) instead of yielding. matou-app — whose queue positions are newest — is starved for hours even though its jobs would mostly no-op.
  • /tmp state is shared across repos with repo-agnostic names: /tmp/matou-swarm-lastready (each repo overwrites the other's debounce stamp → the anti-storm coalescing from 2026-07-29 is defeated), /tmp/matou-healer.lock (one repo's healer makes the other's skip its incident), /tmp/matou-heal.* evidence dirs (no repo tag), /tmp/matou-swarm-claude-limit (notice dedupe suppresses the other repo's first notice).
  • schedule-backstop.sh (now cron-driven every 15m via ~/swarm/backstop-tick.sh, installed tonight after BOTH repos' Forgejo schedule rows died again) only counts started runs, so while the runner is busy it re-dispatches workflows whose earlier dispatch is still waiting — duplicates piled up 2× per workflow on matou-app within 20 minutes. The cron wrapper now carries a stopgap waiting-run guard; that logic belongs upstream in the script.
  • Housekeeping: 3 stale sandcastle-* containers (44h and 2×2d old) are still up on an 8GB host — worker cleanup is leaking containers.

Acceptance criteria

  1. swarm.yml yields instead of camping: replace flock -w 7200 with flock -n + clean exit 0 ("another swarm run holds the host — yielding; the backstop/cron re-fires"). Queued swarm runs then drain in seconds instead of serializing hour-class waits. Same change in both repos (or via the shared-harness home, see #-note below).
  2. Per-repo /tmp namespacing: suffix matou-swarm-lastready, matou-healer.lock, and matou-heal.* evidence dirs with the repo slug. /tmp/matou-swarm.lock STAYS global by design (one heavy worker per host — that is the cross-repo serialization we want, made survivable by AC1) — document that intent where it's defined. /tmp/matou-swarm-claude-limit stays global (one subscription) — document likewise.
  3. Waiting-aware backstop: schedule-backstop.sh counts status=waiting runs for the workflow (see the guard in ~/swarm/backstop-tick.sh on matou-workstation) before dispatching; remove the wrapper stopgap once upstreamed.
  4. Container reaping: worker teardown (or a backstop-adjacent sweep) removes sandcastle-* containers older than a run-lifetime; the 3 stale ones get cleaned as part of landing this.
  5. Offline tests pin AC1 (second flock holder exits 0 fast) and AC3 (waiting run suppresses dispatch).

Open question for Ben (not blocking the ACs)

The harness is now two diverging vendored copies (matou-app has verify.yml/check-verifications.sh/schedule-backstop.sh; ourcloud has gate.sh/git-hooks, and #235's healer fixes will land only here). Extracting .sandcastle/ + workflows into a shared repo consumed by both is the durable shape — needs a ruling on repo layout before anyone builds it.

Pointers

  • .forgejo/workflows/swarm.yml (both repos), .sandcastle/run-swarm.sh, .sandcastle/heal.sh, .sandcastle/schedule-backstop.sh (matou-app copy is canonical), ~/swarm/backstop-tick.sh + crontab on matou-workstation (installed 2026-07-31)
  • Sibling ticket: #235 (healer signature fidelity)

Blocks

depends_on: [#250] — the remaining half (matou-app mirror of AC1/AC2/AC4 + the AC3 backstop) rides #250's manifest+sync per the 2026-08-01 layout ruling (comment 3687). Native dependency API 404s on this instance; this block is the durable edge.

## Why (evidence from 2026-07-31 ~21:55 UTC) Sandcastle now serves TWO repos (`Matou/ourcloud` + `Matou/matou-app`) from one capacity-1 runner on matou-workstation, and the seams showed tonight: - **25 runs waiting on ourcloud** (18 of them `swarm.yml`) + **10 on matou-app**, all serialized behind one hour-class worker. Every issue event stacks another `swarm.yml` run, and each started run **blocks up to 2h** on `flock -w 7200 /tmp/matou-swarm.lock` (`swarm.yml:37`) instead of yielding. matou-app — whose queue positions are newest — is starved for hours even though its jobs would mostly no-op. - `/tmp` state is shared across repos with repo-agnostic names: `/tmp/matou-swarm-lastready` (each repo overwrites the other's debounce stamp → the anti-storm coalescing from 2026-07-29 is defeated), `/tmp/matou-healer.lock` (one repo's healer makes the other's skip its incident), `/tmp/matou-heal.*` evidence dirs (no repo tag), `/tmp/matou-swarm-claude-limit` (notice dedupe suppresses the other repo's first notice). - `schedule-backstop.sh` (now cron-driven every 15m via `~/swarm/backstop-tick.sh`, installed tonight after BOTH repos' Forgejo schedule rows died again) only counts **started** runs, so while the runner is busy it re-dispatches workflows whose earlier dispatch is still `waiting` — duplicates piled up 2× per workflow on matou-app within 20 minutes. The cron wrapper now carries a stopgap waiting-run guard; that logic belongs upstream in the script. - Housekeeping: 3 stale `sandcastle-*` containers (44h and 2×2d old) are still up on an 8GB host — worker cleanup is leaking containers. ## Acceptance criteria 1. **`swarm.yml` yields instead of camping**: replace `flock -w 7200` with `flock -n` + clean exit 0 ("another swarm run holds the host — yielding; the backstop/cron re-fires"). Queued swarm runs then drain in seconds instead of serializing hour-class waits. Same change in both repos (or via the shared-harness home, see #-note below). 2. **Per-repo `/tmp` namespacing**: suffix `matou-swarm-lastready`, `matou-healer.lock`, and `matou-heal.*` evidence dirs with the repo slug. `/tmp/matou-swarm.lock` STAYS global by design (one heavy worker per host — that is the cross-repo serialization we want, made survivable by AC1) — document that intent where it's defined. `/tmp/matou-swarm-claude-limit` stays global (one subscription) — document likewise. 3. **Waiting-aware backstop**: `schedule-backstop.sh` counts `status=waiting` runs for the workflow (see the guard in `~/swarm/backstop-tick.sh` on matou-workstation) before dispatching; remove the wrapper stopgap once upstreamed. 4. **Container reaping**: worker teardown (or a backstop-adjacent sweep) removes `sandcastle-*` containers older than a run-lifetime; the 3 stale ones get cleaned as part of landing this. 5. Offline tests pin AC1 (second flock holder exits 0 fast) and AC3 (waiting run suppresses dispatch). ## Open question for Ben (not blocking the ACs) The harness is now two diverging vendored copies (matou-app has `verify.yml`/`check-verifications.sh`/`schedule-backstop.sh`; ourcloud has `gate.sh`/`git-hooks`, and #235's healer fixes will land only here). Extracting `.sandcastle/` + workflows into a shared repo consumed by both is the durable shape — needs a ruling on repo layout before anyone builds it. ## Pointers - `.forgejo/workflows/swarm.yml` (both repos), `.sandcastle/run-swarm.sh`, `.sandcastle/heal.sh`, `.sandcastle/schedule-backstop.sh` (matou-app copy is canonical), `~/swarm/backstop-tick.sh` + crontab on matou-workstation (installed 2026-07-31) - Sibling ticket: #235 (healer signature fidelity) ## Blocks depends_on: [#250] — the remaining half (matou-app mirror of AC1/AC2/AC4 + the AC3 backstop) rides #250's manifest+sync per the 2026-08-01 layout ruling (comment 3687). Native dependency API 404s on this instance; this block is the durable edge.
Author
Owner

Landed the ourcloud-tree portion (commit a47b900 on main): AC1, AC2, AC4, and the AC1+AC4 offline tests.

  • AC1 — yield instead of camping: swarm.yml (and triage.yml, which spins Sandcastle the same way) now flock -n + exit 0 instead of flock -w 7200 on /tmp/matou-swarm.lock. A run that can't take the host lock yields and the cron re-fires, so queued runs drain in seconds. The lock stays global by design (one heavy worker per host — the cross-repo serialization we want, now survivable) — documented in place.
  • AC2 — per-repo /tmp: matou-swarm-lastready, the healer lock, and the matou-heal.* evidence dir now carry the repo slug (run-swarm.sh, heal.sh). matou-swarm.lock and matou-swarm-claude-limit stay global (one host / one subscription) — intent documented where each is defined.
  • AC4 — container reaping: sweep-lib.sh grew reap_containers, run from run-swarm.sh's exit trap under the held lock; force-removes any sandcastle-* container older than a run-lifetime (3h > the 180-min job timeout). No-op where docker is absent.
  • AC5: tests/swarm-lock-yield-test.sh pins AC1 (held lock → second run yields 0 fast, never camps); tests/sweep-lib-test.sh gains reap groups pinning AC4. All existing .sandcastle/tests/* still pass.

Remaining — relabelled ready-for-human (needs a human + the repo-layout ruling):

  1. AC3 (waiting-aware backstop) lives entirely outside this repo: schedule-backstop.sh is matou-app's canonical copy and backstop-tick.sh is on matou-workstation. Neither is in Matou/ourcloud, so the ourcloud swarm cannot edit them. The AC3 offline test rides with that script.
  2. The matou-app mirror of AC1/AC2/AC4 — same change, other repo.
  3. Both of the above are tangled with the open question in this issue: the harness is two diverging vendored copies, and extracting .sandcastle/ + workflows into a shared home consumed by both "needs a ruling on repo layout before anyone builds it." That ruling is the natural gate for finishing this ticket's cross-repo half — hence ready-for-human rather than closed.
**Landed the ourcloud-tree portion (commit a47b900 on main): AC1, AC2, AC4, and the AC1+AC4 offline tests.** - **AC1 — yield instead of camping**: `swarm.yml` (and `triage.yml`, which spins Sandcastle the same way) now `flock -n` + `exit 0` instead of `flock -w 7200` on `/tmp/matou-swarm.lock`. A run that can't take the host lock yields and the cron re-fires, so queued runs drain in seconds. The lock stays **global** by design (one heavy worker per host — the cross-repo serialization we want, now survivable) — documented in place. - **AC2 — per-repo `/tmp`**: `matou-swarm-lastready`, the healer lock, and the `matou-heal.*` evidence dir now carry the repo slug (`run-swarm.sh`, `heal.sh`). `matou-swarm.lock` and `matou-swarm-claude-limit` stay **global** (one host / one subscription) — intent documented where each is defined. - **AC4 — container reaping**: `sweep-lib.sh` grew `reap_containers`, run from `run-swarm.sh`'s exit trap under the held lock; force-removes any `sandcastle-*` container older than a run-lifetime (3h > the 180-min job timeout). No-op where docker is absent. - **AC5**: `tests/swarm-lock-yield-test.sh` pins AC1 (held lock → second run yields 0 fast, never camps); `tests/sweep-lib-test.sh` gains reap groups pinning AC4. All existing `.sandcastle/tests/*` still pass. **Remaining — relabelled `ready-for-human` (needs a human + the repo-layout ruling):** 1. **AC3 (waiting-aware backstop)** lives entirely outside this repo: `schedule-backstop.sh` is matou-app's canonical copy and `backstop-tick.sh` is on matou-workstation. Neither is in `Matou/ourcloud`, so the ourcloud swarm cannot edit them. The AC3 offline test rides with that script. 2. **The matou-app mirror** of AC1/AC2/AC4 — same change, other repo. 3. Both of the above are tangled with **the open question in this issue**: the harness is two diverging vendored copies, and extracting `.sandcastle/` + workflows into a shared home consumed by both "needs a ruling on repo layout before anyone builds it." That ruling is the natural gate for finishing this ticket's cross-repo half — hence `ready-for-human` rather than closed.
Author
Owner

Cross-reference for whoever picks up the matou-app mirror half: matou-app commit 4342c01 (2026-07-31 late, first manual harness sync — see #250) already carried the healer portion of AC2 to matou-app: its heal.sh/heal-lib.sh/heal-prompt.md now match ourcloud canonical (per-repo healer lock matou-healer-<slug>.lock, per-repo matou-heal-<slug>.* evidence prefix, #197 seam signatures, #235 run-window scoping; only transform = the repo slug). Still OUTSTANDING on the matou-app side: AC1 (swarm.yml/triage.yml flock -n yield), AC2's run-swarm.sh lastready namespacing, AC4 (sweep-lib.sh reap_containers) — those files were not in the synced set. Also note new sibling ticket #253: the triage + healer claude calls need the limit guard (global matou-swarm-claude-limit semantics from this ticket's landed half). The repo-layout ruling this ticket is parked on is being decided against #250's canonical-copy proposal — one ruling will reconcile both.

Cross-reference for whoever picks up the matou-app mirror half: matou-app commit `4342c01` (2026-07-31 late, first manual harness sync — see #250) already carried the **healer** portion of AC2 to matou-app: its `heal.sh`/`heal-lib.sh`/`heal-prompt.md` now match ourcloud canonical (per-repo healer lock `matou-healer-<slug>.lock`, per-repo `matou-heal-<slug>.*` evidence prefix, #197 seam signatures, #235 run-window scoping; only transform = the repo slug). Still OUTSTANDING on the matou-app side: AC1 (`swarm.yml`/`triage.yml` flock -n yield), AC2's `run-swarm.sh` lastready namespacing, AC4 (`sweep-lib.sh` reap_containers) — those files were not in the synced set. Also note new sibling ticket #253: the triage + healer claude calls need the limit guard (global `matou-swarm-claude-limit` semantics from this ticket's landed half). The repo-layout ruling this ticket is parked on is being decided against #250's canonical-copy proposal — one ruling will reconcile both.
Author
Owner

Layout ruling (the gate this ticket parked on): no shared home at n=2.

Sandcastle stays per-repo vendored harnesses, converged mechanically — the #250 model (ourcloud .sandcastle canonical for the manifest set; renderer pushes to matou-app; far-side drift-check red). Rationale, recorded so it isn't relitigated per-file:

  1. The self-healing loop is the design's crown jewel — an agent fixes the harness it runs, in the repo it's working, with that repo's CI testing exactly what executes (#197, #235, this ticket's landed half all shipped that way). Extraction breaks that loop for a third repo's worth of plumbing.
  2. Every consumption mechanism (submodule / subtree / runtime clone) collapses back into a sync with worse ergonomics or new failure modes. At two repos, a shared home is #250's renderer plus indirection.
  3. The repos differ in policy, not just slug (matou-app's human-verification triage gate). The manifest forces the shared-infrastructure vs repo-policy split to be ruled explicitly, file by file — that is the real question, and it stays visible.
  4. Runtime intent is unchanged: host deliberately shared (one global lock, one matou-swarm-claude-limit marker, one subscription — per the landed half), code per-repo.

Promotion path, not a dead end: the manifest boundary IS the extraction seam. If a third repo joins the swarm, or the harness wants its own release/test cadence, promote the manifest set into a dedicated harness repo then.

Consequences for this ticket's remaining half: the matou-app mirror of AC1/AC2/AC4 and the AC3 backstop ride #250's mechanism (heal.sh portion already delivered by matou-app 4342c01; see the cross-reference above). Dependency on #250 added accordingly; re-arming ready-for-agent.

**Layout ruling (the gate this ticket parked on): no shared home at n=2.** Sandcastle stays **per-repo vendored harnesses, converged mechanically** — the #250 model (ourcloud `.sandcastle` canonical for the manifest set; renderer pushes to matou-app; far-side drift-check red). Rationale, recorded so it isn't relitigated per-file: 1. The self-healing loop is the design's crown jewel — an agent fixes the harness it runs, in the repo it's working, with that repo's CI testing exactly what executes (#197, #235, this ticket's landed half all shipped that way). Extraction breaks that loop for a third repo's worth of plumbing. 2. Every consumption mechanism (submodule / subtree / runtime clone) collapses back into a sync with worse ergonomics or new failure modes. At two repos, a shared home is #250's renderer plus indirection. 3. The repos differ in **policy**, not just slug (matou-app's human-verification triage gate). The manifest forces the shared-infrastructure vs repo-policy split to be ruled explicitly, file by file — that is the real question, and it stays visible. 4. Runtime intent is unchanged: host deliberately shared (one global lock, one `matou-swarm-claude-limit` marker, one subscription — per the landed half), code per-repo. **Promotion path, not a dead end:** the manifest boundary IS the extraction seam. If a third repo joins the swarm, or the harness wants its own release/test cadence, promote the manifest set into a dedicated harness repo then. **Consequences for this ticket's remaining half:** the matou-app mirror of AC1/AC2/AC4 and the AC3 backstop ride #250's mechanism (heal.sh portion already delivered by matou-app `4342c01`; see the cross-reference above). Dependency on #250 added accordingly; re-arming `ready-for-agent`.
Author
Owner

Landed the manifest-riding slice of the remaining half (commit a8e3e60 on main).

Per the 2026-08-01 layout ruling (comment above) — the mirror rides #250's manifest+sync — the swarm took the part it can reach from the ourcloud tree:

  • AC3 — waiting-aware backstop: schedule-backstop.sh is promoted from matou-app-only into ourcloud canonical with the fix. It now treats an in-flight run (status=waiting, i.e. queued behind the busy capacity-1 host, or running) as "already covered" and skips — not just a run STARTED within the window. The pre-#238 started-only count re-dispatched, every tick, a workflow whose earlier dispatch was still queued (the 2× duplicates in 20m). This is its upstream home; the host backstop-tick.sh stopgap can be dropped once the fixed copy is installed.
  • AC4 mirror: sweep-lib.sh (the reap_containers reaper) added to harness-manifest — verified byte-identical to matou-app's copy modulo the reaper (no slug refs → generic).
  • Both files now sit on harness-manifest, so #250's harness-sync.yml propagates them to matou-app on push and the far-side drift check keeps them from rotting. The sync dry-run confirms both render and would sync to matou-app.
  • AC5-for-AC3: .sandcastle/tests/schedule-backstop-test.sh — 5 offline scenarios (waiting/running suppress dispatch; an idle scheduler still dispatches; a fresh started run suppresses; another workflow's waiting run does not). sync-harness-test.sh still green.

Still off-repo — needs Ben's hands, relabelling ready-for-human:

  1. Install the fixed backstop on matou-workstation's crontab and drop the backstop-tick.sh waiting-run stopgap (now upstreamed). ourcloud CI does not run the backstop, so this is a host action.
  2. matou-app mirror of AC1/AC2/AC4 in swarm.yml/triage.yml (flock -w 7200 → -n yield) and run-swarm.sh (matou-swarm-lastready → -$repo_tag, and the reap_containers exit-trap call). These are workflow + repo-specific files, off-manifest by the ruling (the sync only carries generic .sandcastle/ files) — so they can't ride the manifest and need either a matou-app-side ticket/commit or your hands. Confirmed still outstanding on matou-app tip today: flock -w 7200 in both workflows, un-namespaced stamp="/tmp/matou-swarm-lastready", no reap call.
**Landed the manifest-riding slice of the remaining half (commit `a8e3e60` on main).** Per the 2026-08-01 layout ruling (comment above) — the mirror rides #250's manifest+sync — the swarm took the part it can reach from the ourcloud tree: - **AC3 — waiting-aware backstop**: `schedule-backstop.sh` is promoted from matou-app-only into **ourcloud canonical** with the fix. It now treats an in-flight run (`status=waiting`, i.e. queued behind the busy capacity-1 host, **or** `running`) as "already covered" and skips — not just a run STARTED within the window. The pre-#238 started-only count re-dispatched, every tick, a workflow whose earlier dispatch was still queued (the 2× duplicates in 20m). This is its upstream home; the host `backstop-tick.sh` stopgap can be dropped once the fixed copy is installed. - **AC4 mirror**: `sweep-lib.sh` (the `reap_containers` reaper) added to `harness-manifest` — verified byte-identical to matou-app's copy modulo the reaper (no slug refs → generic). - Both files now sit on `harness-manifest`, so #250's `harness-sync.yml` propagates them to matou-app on push and the far-side drift check keeps them from rotting. The sync dry-run confirms both render and would sync to matou-app. - **AC5-for-AC3**: `.sandcastle/tests/schedule-backstop-test.sh` — 5 offline scenarios (waiting/running suppress dispatch; an idle scheduler still dispatches; a fresh started run suppresses; another workflow's waiting run does not). `sync-harness-test.sh` still green. **Still off-repo — needs Ben's hands, relabelling `ready-for-human`:** 1. **Install the fixed backstop on matou-workstation's crontab** and drop the `backstop-tick.sh` waiting-run stopgap (now upstreamed). ourcloud CI does not run the backstop, so this is a host action. 2. **matou-app mirror of AC1/AC2/AC4** in `swarm.yml`/`triage.yml` (flock `-w 7200` → `-n` yield) and `run-swarm.sh` (`matou-swarm-lastready` → `-$repo_tag`, and the `reap_containers` exit-trap call). These are **workflow + repo-specific files, off-manifest by the ruling** (the sync only carries generic `.sandcastle/` files) — so they can't ride the manifest and need either a matou-app-side ticket/commit or your hands. Confirmed still outstanding on matou-app tip today: `flock -w 7200` in both workflows, un-namespaced `stamp="/tmp/matou-swarm-lastready"`, no reap call.
Author
Owner

Both remaining chores executed (2026-08-06, Ben's sweep ruling: agent does both) — closing.

  1. Workstation backstop: ~/swarm/backstop-tick.sh rewritten (old copy at backstop-tick.sh.bak-0806) — it now delegates to ourcloud's canonical .sandcastle/schedule-backstop.sh (both checkouts pulled; both copies verified waiting-aware from a8e3e60) and the local waiting-run stopgap is dropped, as upstreamed. Live run verified: the upstream suppression fired (swarm already in flight (waiting/running) … skipping) and idle workflows dispatched normally. Crontab entry unchanged (same path).
  2. matou-app mirror: commit 054faae on matou-app main — AC1 (swarm.yml/triage.yml flock -n + exit-0 yield, global-lock intent documented), AC2 (run-swarm.sh debounce stamp → /tmp/matou-swarm-lastready-Matou-matou-app; claude-limit marker documented global), AC4 (sweep_and_report calls the synced reap_containers). Offline checks green: bash -n, workflow YAML parse, sweep-lib-test.sh, debounce-test.sh.

Every AC is now live in both repos + on the host. The stale containers named in the body were already reaped by the landed AC4 half.

**Both remaining chores executed (2026-08-06, Ben's sweep ruling: agent does both) — closing.** 1. **Workstation backstop**: `~/swarm/backstop-tick.sh` rewritten (old copy at `backstop-tick.sh.bak-0806`) — it now delegates to **ourcloud's canonical** `.sandcastle/schedule-backstop.sh` (both checkouts pulled; both copies verified waiting-aware from `a8e3e60`) and the local waiting-run stopgap is dropped, as upstreamed. Live run verified: the upstream suppression fired (`swarm already in flight (waiting/running) … skipping`) and idle workflows dispatched normally. Crontab entry unchanged (same path). 2. **matou-app mirror**: commit `054faae` on matou-app main — AC1 (`swarm.yml`/`triage.yml` `flock -n` + exit-0 yield, global-lock intent documented), AC2 (`run-swarm.sh` debounce stamp → `/tmp/matou-swarm-lastready-Matou-matou-app`; claude-limit marker documented global), AC4 (`sweep_and_report` calls the synced `reap_containers`). Offline checks green: `bash -n`, workflow YAML parse, `sweep-lib-test.sh`, `debounce-test.sh`. Every AC is now live in both repos + on the host. The stale containers named in the body were already reaped by the landed AC4 half.
ben closed this issue 2026-08-06 21:56:13 +00:00
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#238
No description provided.