harness: swarm/triage matrix jobs race on the shared per-repo git workdir → intermittent early red (sig 096ffba7729c) #638

Closed
opened 2026-08-21 19:56:05 +00:00 by matou-build-agent · 2 comments

Symptom

The swarm workflow intermittently reds one matrix job with no worker log, no run verdict, and no swarm.db row, paging the healer on the degraded workflow-name-only signature 096ffba7729c. Latest: run 8467 (2026-08-21 19:45Z, swarm (1) / task 16403). No work is lost — the sibling job (swarm (2)) completed cleanly (no-ready-tasks, exit 0), and the ready queue was empty.

Root cause — concurrent git mutation of the shared per-repo workdir

.forgejo/workflows/swarm.yml and triage.yml share a 2-slot host-capacity semaphore (/tmp/matou-swarm.lock + /tmp/matou-host-slot-2.lock, two different lock files). After grabbing a slot, each job runs git fetch / checkout -f / reset --hard origin/main in the same workdir $HOME/swarm/$REPO_SLUG.

The semaphore caps host load but does not give a job exclusive access to its repo's workdir. When two jobs for the same repo each hold a different slot (e.g. swarm (1) + swarm (2), or swarm + triage — all three idss jobs fired within 3s at :45), they mutate the same .git concurrently and race on index.lock / ref locks. The loser's git step exits non-zero before run-swarm.sh ever starts → red job, healer paged, no run artifacts.

Evidence

  • git reflog in the workdir: at 19:45:10 only one checkout+reset pair landed (the winner); the losing job left no ref update — its git step failed. Contrast 17:30:10 / 16:00:10 where both same-repo jobs' pairs landed in the same second and both succeeded (the race is timing-dependent and usually benign).
  • swarm.db run row for 8467: no-ready-tasks, exit 0 — only the winning job recorded.
  • ~/swarm/logs/run-swarm-verdicts.log: a single idss no-ready-tasks line at 19:45:15 (the loser wrote none).
  • Healer evidence dir: worker-logs.txt empty, no run-verdict.txt, seam-degraded marker set (signature degraded to the workflow name).
  • Ledger .sandcastle/.state/healer/096ffba7729c: repaired=1 — the prior repair (7d836350, Claude auth-refusal classification) addressed a different early-fail cause that collapses onto the same degraded signature. So "recurred after repair" here is a false equivalence: the signature can't distinguish auth-dead from a git-race.

Proposed fix (needs a human design call — do not auto-implement blind)

Give same-repo jobs exclusive workdir access. Options:

  1. Per-repo-workdir flock around the git-setup + run-swarm.sh/run-triage.sh block (non-blocking flock -n, yield on contention — mirror the existing capacity-slot idiom; never -w camp, per #238). Keyed on the workdir path so different hosts and different repos still run in parallel. Must be applied consistently to swarm.yml, triage.yml, and swarm-smoke.yml.
  2. Per-worker isolated workdir ($HOME/swarm/$REPO_SLUG-<worker>) — removes sharing entirely but loses the persistent-clone reuse and needs run-swarm.sh review.

Secondary: the degraded signature conflates every early swarm fail (auth-dead, git-race, preflight) into 096ffba7729c, defeating the ledger's per-fault tracking. Worth keying early-fail incidents on a coarse stage tag even when no verdict exists.

Blast radius / why escalated not auto-repaired

This changes the pipeline's core locking model across ≥3 workflow files; a wrong flock scope (camp/deadlock) breaks every swarm/triage run — far worse than the current rare, self-healing, no-work-lost red. Runtime-only behaviour, not unit-testable in-repo. Filed by the swarm healer (run 8467); recommend human review before merge.

## Symptom The `swarm` workflow intermittently reds one matrix job with **no worker log, no run verdict, and no `swarm.db` row**, paging the healer on the degraded workflow-name-only signature `096ffba7729c`. Latest: run **8467** (2026-08-21 19:45Z, `swarm (1)` / task 16403). No work is lost — the sibling job (`swarm (2)`) completed cleanly (`no-ready-tasks`, exit 0), and the ready queue was empty. ## Root cause — concurrent git mutation of the shared per-repo workdir `.forgejo/workflows/swarm.yml` and `triage.yml` share a **2-slot host-capacity semaphore** (`/tmp/matou-swarm.lock` + `/tmp/matou-host-slot-2.lock`, two *different* lock files). After grabbing a slot, each job runs `git fetch / checkout -f / reset --hard origin/main` in the **same** workdir `$HOME/swarm/$REPO_SLUG`. The semaphore caps host load but does **not** give a job exclusive access to its repo's workdir. When two jobs for the **same repo** each hold a *different* slot (e.g. `swarm (1)` + `swarm (2)`, or swarm + triage — all three idss jobs fired within 3s at :45), they mutate the same `.git` concurrently and race on `index.lock` / ref locks. The loser's git step exits non-zero before `run-swarm.sh` ever starts → red job, healer paged, no run artifacts. ### Evidence - `git reflog` in the workdir: at **19:45:10** only **one** `checkout+reset` pair landed (the winner); the losing job left no ref update — its git step failed. Contrast 17:30:10 / 16:00:10 where both same-repo jobs' pairs landed in the same second and both succeeded (the race is timing-dependent and usually benign). - `swarm.db` run row for 8467: `no-ready-tasks`, exit 0 — only the winning job recorded. - `~/swarm/logs/run-swarm-verdicts.log`: a single idss `no-ready-tasks` line at 19:45:15 (the loser wrote none). - Healer evidence dir: `worker-logs.txt` empty, no `run-verdict.txt`, `seam-degraded` marker set (signature degraded to the workflow name). - Ledger `.sandcastle/.state/healer/096ffba7729c`: `repaired=1` — the prior repair (7d836350, Claude auth-refusal classification) addressed a *different* early-fail cause that collapses onto the *same* degraded signature. So "recurred after repair" here is a false equivalence: the signature can't distinguish auth-dead from a git-race. ## Proposed fix (needs a human design call — do not auto-implement blind) Give same-repo jobs exclusive workdir access. Options: 1. **Per-repo-workdir flock** around the git-setup + `run-swarm.sh`/`run-triage.sh` block (non-blocking `flock -n`, yield on contention — mirror the existing capacity-slot idiom; never `-w` camp, per #238). Keyed on the workdir path so different hosts and different repos still run in parallel. Must be applied consistently to `swarm.yml`, `triage.yml`, and `swarm-smoke.yml`. 2. **Per-worker isolated workdir** (`$HOME/swarm/$REPO_SLUG-<worker>`) — removes sharing entirely but loses the persistent-clone reuse and needs run-swarm.sh review. Secondary: the degraded signature conflates every early swarm fail (auth-dead, git-race, preflight) into `096ffba7729c`, defeating the ledger's per-fault tracking. Worth keying early-fail incidents on a coarse stage tag even when no verdict exists. ## Blast radius / why escalated not auto-repaired This changes the pipeline's core locking model across ≥3 workflow files; a wrong flock scope (camp/deadlock) breaks *every* swarm/triage run — far worse than the current rare, self-healing, no-work-lost red. Runtime-only behaviour, not unit-testable in-repo. Filed by the swarm healer (run 8467); recommend human review before merge.
Owner

This was generated by AI during triage.

Triage: bug + ready-for-session.

Verified the analysis: .forgejo/workflows/swarm.yml and triage.yml each
grab one of two independent host-capacity slot locks
(/tmp/matou-swarm.lock, /tmp/matou-host-slot-2.lock) but neither acquires
any lock scoped to the shared per-repo workdir ($HOME/swarm/$REPO_SLUG)
before git fetch/checkout -f/reset --hard. Confirmed no per-repo-workdir
flock exists anywhere in swarm.yml, triage.yml, or swarm-smoke.yml today
— the race as described is real and unfixed.

Not ruling this under ADR 0174 rule 1: the proposed fix edits .forgejo/
workflow files, which are in the fingerprinted protected set (.sandcastle/

  • .forgejo/, per .sandcastle/protected-paths-lib.sh) — machinery a swarm
    worker must never touch, and machinery-change escalation is spelled out
    verbatim as ready-for-session, not agent-ruled or ready-for-human, unless
    a session finds a genuine one-way door. It also fails ADR 0174's provability
    prong on its own: the issue itself notes this is "runtime-only behaviour, not
    unit-testable in-repo" — a locking-scope choice across 3 shared CI workflows
    can only be proven by watching live runs, and a wrong scope (camp/deadlock)
    would stall every swarm/triage run repo-wide, including this triage
    pipeline's own ability to recover. That's exactly the case
    protected-paths-lib.sh carves out for an interactive session's standing
    rather than a swarm worker or a blind agent ruling.

No redundant/prior fix found (searched .forgejo/workflows/*.yml for
existing per-workdir locking; none exists) and no matching entry in
.out-of-scope/ (directory doesn't exist yet in this repo).

Labelling bug + ready-for-session. A session picking this up should
implement option 1 (per-repo-workdir flock -n, non-blocking, mirroring the
existing capacity-slot idiom, applied consistently across all three
workflow files) unless it finds a reason to prefer option 2, watch it across
live runs, and only escalate further to ready-for-human if it turns up an
actual one-way door.

> *This was generated by AI during triage.* **Triage: `bug` + `ready-for-session`.** Verified the analysis: `.forgejo/workflows/swarm.yml` and `triage.yml` each grab one of two independent host-capacity slot locks (`/tmp/matou-swarm.lock`, `/tmp/matou-host-slot-2.lock`) but neither acquires any lock scoped to the shared per-repo workdir (`$HOME/swarm/$REPO_SLUG`) before `git fetch`/`checkout -f`/`reset --hard`. Confirmed no per-repo-workdir flock exists anywhere in `swarm.yml`, `triage.yml`, or `swarm-smoke.yml` today — the race as described is real and unfixed. Not ruling this under ADR 0174 rule 1: the proposed fix edits `.forgejo/` workflow files, which are in the **fingerprinted protected set** (`.sandcastle/` + `.forgejo/`, per `.sandcastle/protected-paths-lib.sh`) — machinery a swarm worker must never touch, and machinery-change escalation is spelled out verbatim as `ready-for-session`, not agent-ruled or `ready-for-human`, unless a session finds a genuine one-way door. It also fails ADR 0174's provability prong on its own: the issue itself notes this is "runtime-only behaviour, not unit-testable in-repo" — a locking-scope choice across 3 shared CI workflows can only be proven by watching live runs, and a wrong scope (camp/deadlock) would stall *every* swarm/triage run repo-wide, including this triage pipeline's own ability to recover. That's exactly the case `protected-paths-lib.sh` carves out for an interactive session's standing rather than a swarm worker or a blind agent ruling. No redundant/prior fix found (searched `.forgejo/workflows/*.yml` for existing per-workdir locking; none exists) and no matching entry in `.out-of-scope/` (directory doesn't exist yet in this repo). Labelling `bug` + `ready-for-session`. A session picking this up should implement option 1 (per-repo-workdir `flock -n`, non-blocking, mirroring the existing capacity-slot idiom, applied consistently across all three workflow files) unless it finds a reason to prefer option 2, watch it across live runs, and only escalate further to `ready-for-human` if it turns up an actual one-way door.
Author
Member

Ruled by agent under ADR 0174 — veto anytime

Ruling: this is a two-way door, not the human design call the ticket
flagged it as needing. (a) Revertible — the whole fix is a CI-config
commit to three workflow files, trivially revertible. (b) Provable
offline
— .sandcastle/tests/workdir-lock-yield-test.sh pins the
yield-not-camp lock semantics AND reproduces the actual documented race
(two concurrent guarded fetch/checkout -f/reset --hard against a real
git clone, landing cleanly and serialized; 5/5 stable runs). (c) Not on
the one-way-door list
— no personal credentials, no security-posture
widening, no member-facing trust surface, no data destruction, no spend.

What proves it: b5a39930 — non-blocking, per-repo flock on
/tmp/matou-workdir-<repo-slug>.lock (keyed on $REPO_SLUG, never camping,
mirroring #238's yield idiom and the #577/ADR-0184 precedent for exactly this
class of ruling) now wraps the git fetch/checkout -f/reset --hard/
clone block in swarm.yml, triage.yml, and swarm-smoke.yml. Contended
→ yield (exit 0 in swarm/triage so the cron/backstop re-fires; exit 1 in
swarm-smoke since it has no re-fire schedule and a silent 0 there would read
as a false pass).

Where I narrowed the ticket's own Option 1: the ticket proposed locking
"around the git-setup + run-swarm.sh/run-triage.sh block" — the WHOLE
run, not just setup. I scoped the lock to just the git-setup step instead,
releasing before the run script starts. Reason: the evidence in this ticket
(the git reflog analysis) is entirely about the checkout+reset step racing
— nothing shows run-swarm.sh's later worktree machinery racing. Locking the
whole run would additionally serialize the matrix workers' actual
ticket-claiming work whenever two same-repo jobs land on one host, and
docs/superpowers/specs/2026-08-11-multihost-swarm-design.md explicitly
flags that "intra-host parallelism" case as unverified for the claim
arbitration design (D6) — reaching into that with a blind lock-the-whole-run
change would have been the actual one-way-door-adjacent move here. The
narrower fix directly closes the documented race with no touch on that open
question.

Docs: docs/GOTCHAS.md #46 records the hazard class. STATUS.md
updated in the same commit. The ticket's "Secondary" ask (key the healer's
degraded-signature ledger on a coarse stage tag even absent a verdict) is
filed separately as #639 — it's healer classification logic, not the locking
model, and deserves its own scoping pass rather than riding this fix.

Closing — the fix is landed, proven offline, and documented. The next
same-repo matrix/triage collision on a live host is the field proof; #639
tracks the signature-granularity follow-up.

## Ruled by agent under ADR 0174 — veto anytime **Ruling:** this is a two-way door, not the human design call the ticket flagged it as needing. (a) **Revertible** — the whole fix is a CI-config commit to three workflow files, trivially revertible. (b) **Provable offline** — `.sandcastle/tests/workdir-lock-yield-test.sh` pins the yield-not-camp lock semantics AND reproduces the actual documented race (two concurrent guarded `fetch`/`checkout -f`/`reset --hard` against a real git clone, landing cleanly and serialized; 5/5 stable runs). (c) **Not on the one-way-door list** — no personal credentials, no security-posture widening, no member-facing trust surface, no data destruction, no spend. **What proves it:** `b5a39930` — non-blocking, per-repo `flock` on `/tmp/matou-workdir-<repo-slug>.lock` (keyed on `$REPO_SLUG`, never camping, mirroring #238's yield idiom and the #577/ADR-0184 precedent for exactly this class of ruling) now wraps the `git fetch`/`checkout -f`/`reset --hard`/ `clone` block in `swarm.yml`, `triage.yml`, and `swarm-smoke.yml`. Contended → yield (exit 0 in swarm/triage so the cron/backstop re-fires; exit 1 in swarm-smoke since it has no re-fire schedule and a silent 0 there would read as a false pass). **Where I narrowed the ticket's own Option 1:** the ticket proposed locking "around the git-setup + `run-swarm.sh`/`run-triage.sh` block" — the WHOLE run, not just setup. I scoped the lock to just the git-setup step instead, releasing before the run script starts. Reason: the evidence in this ticket (the `git reflog` analysis) is entirely about the checkout+reset step racing — nothing shows `run-swarm.sh`'s later worktree machinery racing. Locking the whole run would additionally serialize the matrix workers' actual ticket-claiming work whenever two same-repo jobs land on one host, and `docs/superpowers/specs/2026-08-11-multihost-swarm-design.md` explicitly flags that "intra-host parallelism" case as unverified for the claim arbitration design (D6) — reaching into that with a blind lock-the-whole-run change would have been the actual one-way-door-adjacent move here. The narrower fix directly closes the documented race with no touch on that open question. **Docs:** `docs/GOTCHAS.md` #46 records the hazard class. `STATUS.md` updated in the same commit. The ticket's "Secondary" ask (key the healer's degraded-signature ledger on a coarse stage tag even absent a verdict) is filed separately as #639 — it's healer classification logic, not the locking model, and deserves its own scoping pass rather than riding this fix. Closing — the fix is landed, proven offline, and documented. The next same-repo matrix/triage collision on a live host is the field proof; #639 tracks the signature-granularity follow-up.
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/idss#638
No description provided.