Swarm: concurrent fleet workers collide on STATUS.md — Sandcastle's merge-to-main dies with SyncError #1899

Closed
opened 2026-09-25 20:12:43 +00:00 by matou-build-agent · 2 comments

Filed by the swarm healer for run https://git.matou.nz/Matou/idss/actions/runs/32926 (signature 3d11ef9a924f, host elitebook-distributed-server-03).

Symptom

sandcastle run (workers) exits 1 at the post-iteration merge:

SyncError: Merge of 'sandcastle/worker/20260925-190818-d08c0b' onto 'main' failed.
The temporary branch 'sandcastle/worker/20260925-190818-d08c0b' has been preserved.

The workdir is left mid-merge (UU STATUS.md, MERGE_HEAD=c0583996), and a sandcastle/worker/* branch is preserved forever. Two older orphans from the same shape are still sitting in the workdir: sandcastle/worker/20260826-041808-6b0e8f, sandcastle/worker/20260908-021709-1678bd.

Root cause

Since 7e7282e8 (2026-09-25 18:48, FACTORY_REF bump to 87e1b55) swarm.yml deliberately carries no concurrency group — swarm runs no longer serialise, which was the right fix for the #1732 head-of-line stall. The fleet now works several tickets at once (runs.json: bens-mac-04, elitebook-03, matou-workstation all running swarm within the same minutes).

Per-ticket claiming stops two workers taking the same ticket, but nothing keeps two workers on different tickets off the same file — and CLAUDE.md requires every state-changing commit to update STATUS.md, each one inserting a new entry at the head of the milestone log. Two concurrent workers therefore write adjacent, conflicting lines by construction:

  • elitebook-03 run 32926 started 19:07:50 from a2f2e99a, worked #1892, committed c0583996 at 20:02.
  • Meanwhile bens-mac-04 pushed 0a5b4619 (#1893, 19:19) and f911cc9f (#1887, 19:25) to main.
  • Merging c0583996 onto the advanced main conflicts on STATUS.md line 1 — <<<<<<< HEAD #1887's entry vs >>>>>>> #1892's entry. Nothing else in either change overlaps.

So this is not a one-off: with the fleet de-serialised, any two swarm runs whose workers both finish a state-changing ticket will collide on STATUS.md. Expect it roughly every time two tickets land close together.

What the healer did

  • Cleaned the stuck state only: git merge --abort in ~/swarm/Matou/idss (swarm lock free, no swarm process running). Workdir is clean at f911cc9f = origin/main.
  • No work was lost: c0583996 is on origin/agent/issue-1892 as open PR #1898 (landing-pr, awaiting human merge). The sibling #1891 is likewise safe on PR #1897.
  • Did not touch .forgejo/workflows/swarm.yml — dropping the concurrency group is a deliberate human decision and reverting it is outside the healer's remit.
  • Did not delete the preserved worker branches (healer charter forbids branch deletion).

What needs deciding

The fleet wants to run concurrently and the repo rule wants every commit to touch STATUS.md. Something has to give. Options, roughly in increasing order of blast radius:

  1. Make the milestone log append-safe. Give STATUS.md a merge=union entry in a root .gitattributes. Cheap; auto-keeps both entries. Risk: if two workers both edit the header line, union silently emits two header lines rather than conflicting — a corrupt status ledger that no one is told about. Would want a CI check that the header appears exactly once.
  2. Split the milestone log out of STATUS.md into per-entry files (docs/status/milestones/NNNN-*.md) with STATUS.md holding only the header + gate rows, so concurrent workers write disjoint files and only a genuine same-gate edit conflicts.
  3. Retry the merge on conflict in the harness: on SyncError, re-fetch, rebase the worker branch onto the new main and re-attempt once, escalating only if a non-STATUS.md path conflicts. (Lives in vendored @ai-hero/sandcastle, so likely an upstream dev-factory change.)
  4. Re-serialise only the merge, not the whole run — a host-side flock around the merge-to-main plus a fetch, keeping the #1732 fix intact.

Options 1 and 2 are repo-local; 3 and 4 are factory changes. Whichever is chosen should also sweep the orphaned sandcastle/worker/* branches the failed merges leave behind.

Acceptance criteria

  • Two swarm runs on different hosts can each land a state-changing ticket within the same window without the second run reddening on a STATUS.md merge conflict.
  • No STATUS.md content is silently lost or duplicated by whatever merge strategy is chosen (guarded by a test).
  • A failed worker merge no longer leaves the workdir mid-merge; orphaned sandcastle/worker/* branches are cleaned or reported.
Filed by the swarm healer for run https://git.matou.nz/Matou/idss/actions/runs/32926 (signature `3d11ef9a924f`, host `elitebook-distributed-server-03`). ## Symptom `sandcastle run (workers)` exits 1 at the post-iteration merge: ``` SyncError: Merge of 'sandcastle/worker/20260925-190818-d08c0b' onto 'main' failed. The temporary branch 'sandcastle/worker/20260925-190818-d08c0b' has been preserved. ``` The workdir is left mid-merge (`UU STATUS.md`, `MERGE_HEAD=c0583996`), and a `sandcastle/worker/*` branch is preserved forever. Two older orphans from the same shape are still sitting in the workdir: `sandcastle/worker/20260826-041808-6b0e8f`, `sandcastle/worker/20260908-021709-1678bd`. ## Root cause Since `7e7282e8` (2026-09-25 18:48, FACTORY_REF bump to 87e1b55) `swarm.yml` deliberately carries **no concurrency group** — swarm runs no longer serialise, which was the right fix for the #1732 head-of-line stall. The fleet now works several tickets at once (`runs.json`: `bens-mac-04`, `elitebook-03`, `matou-workstation` all running swarm within the same minutes). Per-ticket claiming stops two workers taking the *same* ticket, but nothing keeps two workers on *different* tickets off the same file — and CLAUDE.md requires **every** state-changing commit to update `STATUS.md`, each one inserting a new entry at the head of the milestone log. Two concurrent workers therefore write adjacent, conflicting lines by construction: - `elitebook-03` run 32926 started 19:07:50 from `a2f2e99a`, worked #1892, committed `c0583996` at 20:02. - Meanwhile `bens-mac-04` pushed `0a5b4619` (#1893, 19:19) and `f911cc9f` (#1887, 19:25) to `main`. - Merging `c0583996` onto the advanced `main` conflicts on STATUS.md line 1 — `<<<<<<< HEAD` #1887's entry vs `>>>>>>>` #1892's entry. Nothing else in either change overlaps. So this is not a one-off: with the fleet de-serialised, any two swarm runs whose workers both finish a state-changing ticket will collide on STATUS.md. Expect it roughly every time two tickets land close together. ## What the healer did - Cleaned the stuck state only: `git merge --abort` in `~/swarm/Matou/idss` (swarm lock free, no swarm process running). Workdir is clean at `f911cc9f` = `origin/main`. - **No work was lost**: `c0583996` is on `origin/agent/issue-1892` as open PR #1898 (`landing-pr`, awaiting human merge). The sibling #1891 is likewise safe on PR #1897. - Did **not** touch `.forgejo/workflows/swarm.yml` — dropping the concurrency group is a deliberate human decision and reverting it is outside the healer's remit. - Did **not** delete the preserved worker branches (healer charter forbids branch deletion). ## What needs deciding The fleet wants to run concurrently *and* the repo rule wants every commit to touch STATUS.md. Something has to give. Options, roughly in increasing order of blast radius: 1. **Make the milestone log append-safe.** Give `STATUS.md` a `merge=union` entry in a root `.gitattributes`. Cheap; auto-keeps both entries. Risk: if two workers both edit the **header line**, union silently emits two header lines rather than conflicting — a corrupt status ledger that no one is told about. Would want a CI check that the header appears exactly once. 2. **Split the milestone log out of STATUS.md** into per-entry files (`docs/status/milestones/NNNN-*.md`) with STATUS.md holding only the header + gate rows, so concurrent workers write disjoint files and only a genuine same-gate edit conflicts. 3. **Retry the merge on conflict** in the harness: on `SyncError`, re-fetch, rebase the worker branch onto the new `main` and re-attempt once, escalating only if a non-STATUS.md path conflicts. (Lives in vendored `@ai-hero/sandcastle`, so likely an upstream dev-factory change.) 4. **Re-serialise only the merge**, not the whole run — a host-side flock around the merge-to-main plus a fetch, keeping the #1732 fix intact. Options 1 and 2 are repo-local; 3 and 4 are factory changes. Whichever is chosen should also sweep the orphaned `sandcastle/worker/*` branches the failed merges leave behind. ## Acceptance criteria - Two swarm runs on different hosts can each land a state-changing ticket within the same window without the second run reddening on a STATUS.md merge conflict. - No STATUS.md content is silently lost or duplicated by whatever merge strategy is chosen (guarded by a test). - A failed worker merge no longer leaves the workdir mid-merge; orphaned `sandcastle/worker/*` branches are cleaned or reported.
Author
Member

This was generated by AI during triage.

Triage: bug + ready-for-session. Ruled by agent under ADR 0174 — veto anytime.

The ruling

Adopt Option 1 (root .gitattributes with STATUS.md merge=union) as the STATUS.md-collision fix, guarded by a test/CI check for residual conflict markers, and pair it with the host-side orphan-branch sweep. Options 3 and 4 (harness merge-retry, re-serialised merge) are not needed if union holds, and Option 2 (splitting the log into per-file entries) is a larger, unnecessary blast radius.

Why Option 1 is safe for this file specifically: the report flags one real hazard for merge=union — if two workers both edit a rewritten header line, union silently emits two header lines. I checked: STATUS.md has no rewritten header line. It carries no # title and no table/gate rows — it is a prepend-only log of one-line dated entries (each state-changing commit inserts one long single-line **date (#NNNN …)** entry at line 1). Union merge on a set of distinct single-line entries keeps both and never conflicts; the only cost is that two same-window entries land in arbitrary relative order, which is harmless for a log. A CI/test assertion that a merged STATUS.md contains no <<<<<<</=======/>>>>>>> markers covers the residual.

Why this is a two-way door (ADR 0174)

  • Revertible with a commit: the whole fix is a .gitattributes line (delete it to revert), a check script, and a test. No irreversible state.
  • Provable by a test/probe: construct two divergent single-line prepends onto STATUS.md, merge, assert both entries survive with no conflict markers; the live proof is two swarm runs on different hosts each landing a state-changing ticket in the same window without the second reddening.
  • Not on the one-way-door list: no personal credentials, no security-posture widening, no member-facing trust accept, no data destruction, no non-routine spend, no physical hardware.

Why ready-for-session, not ready-for-agent

Two reasons a swarm worker must not take this:

  1. The acceptance criteria include host/factory residue. "A failed worker merge no longer leaves the workdir mid-merge" and "orphaned sandcastle/worker/* branches are cleaned or reported" live in the vendored @ai-hero/sandcastle harness and host-side scripts — protected/live-infrastructure territory (ADR 0174 rule 5, .sandcastle//host standing), which the swarm queue (ready-for-agent-only) is built to keep workers out of.
  2. A swarm worker cannot safely repair its own merge mechanism from inside it. A worker fixing this ticket would itself land a state-changing STATUS.md commit and collide exactly as described. The fix has to be applied from outside the broken mechanism — an interactive session.

Why not ready-for-human

No one-way door and the whole call is revertible + provable, so under ADR 0174 this is a session ruling, not Ben's. Ben's veto stays asynchronous.

Note on the concurrency-group decision

The healer correctly left swarm.yml's dropped concurrency group alone (the deliberate #1732 fix). This ruling does not touch it — union merge lets the fleet keep running concurrently and satisfies the every-commit-touches-STATUS.md rule, which was the whole tension.

Cross-reference #1739 (swarm harness: merge-to-head can fast-forward local main onto an unpushed orphan) — the same merge-to-main harness surface, but a distinct failure; not a duplicate. The orphan-branch sweep here should be reconciled with that work.

> *This was generated by AI during triage.* **Triage: `bug` + `ready-for-session`.** Ruled by agent under ADR 0174 — veto anytime. ## The ruling **Adopt Option 1 (root `.gitattributes` with `STATUS.md merge=union`) as the STATUS.md-collision fix**, guarded by a test/CI check for residual conflict markers, and pair it with the host-side orphan-branch sweep. Options 3 and 4 (harness merge-retry, re-serialised merge) are not needed if union holds, and Option 2 (splitting the log into per-file entries) is a larger, unnecessary blast radius. Why Option 1 is safe *for this file specifically*: the report flags one real hazard for `merge=union` — if two workers both edit a rewritten **header line**, union silently emits two header lines. I checked: **STATUS.md has no rewritten header line.** It carries no `#` title and no table/gate rows — it is a prepend-only log of one-line dated entries (each state-changing commit inserts one long single-line `**date (#NNNN …)**` entry at line 1). Union merge on a set of distinct single-line entries keeps both and never conflicts; the only cost is that two same-window entries land in arbitrary relative order, which is harmless for a log. A CI/test assertion that a merged STATUS.md contains no `<<<<<<<`/`=======`/`>>>>>>>` markers covers the residual. ## Why this is a two-way door (ADR 0174) - **Revertible with a commit:** the whole fix is a `.gitattributes` line (delete it to revert), a check script, and a test. No irreversible state. - **Provable by a test/probe:** construct two divergent single-line prepends onto STATUS.md, merge, assert both entries survive with no conflict markers; the live proof is two swarm runs on different hosts each landing a state-changing ticket in the same window without the second reddening. - **Not on the one-way-door list:** no personal credentials, no security-posture widening, no member-facing trust accept, no data destruction, no non-routine spend, no physical hardware. ## Why `ready-for-session`, not `ready-for-agent` Two reasons a swarm worker must not take this: 1. **The acceptance criteria include host/factory residue.** "A failed worker merge no longer leaves the workdir mid-merge" and "orphaned `sandcastle/worker/*` branches are cleaned or reported" live in the vendored `@ai-hero/sandcastle` harness and host-side scripts — protected/live-infrastructure territory (ADR 0174 rule 5, `.sandcastle/`/host standing), which the swarm queue (`ready-for-agent`-only) is built to keep workers out of. 2. **A swarm worker cannot safely repair its own merge mechanism from inside it.** A worker fixing this ticket would itself land a state-changing STATUS.md commit and collide exactly as described. The fix has to be applied from outside the broken mechanism — an interactive session. ## Why not `ready-for-human` No one-way door and the whole call is revertible + provable, so under ADR 0174 this is a session ruling, not Ben's. Ben's veto stays asynchronous. ## Note on the concurrency-group decision The healer correctly left `swarm.yml`'s dropped concurrency group alone (the deliberate #1732 fix). This ruling does **not** touch it — union merge lets the fleet keep running concurrently *and* satisfies the every-commit-touches-STATUS.md rule, which was the whole tension. ## Related Cross-reference **#1739** (swarm harness: merge-to-head can fast-forward local main onto an unpushed orphan) — the same merge-to-main harness surface, but a distinct failure; not a duplicate. The orphan-branch sweep here should be reconciled with that work.
Author
Member

Ruled by agent under ADR 0174 — veto anytime

Ruling: took option 1 (the ticket's own lowest-blast-radius option) — a root .gitattributes declaring STATUS.md merge=union. It is a two-way door (revert = delete one line) and fully provable offline, so it needed no human gate.

Why it works with the harness unchanged: Sandcastle's merge-to-main shells out to a plain git merge "<worker-branch>" (execAsync in @ai-hero/sandcastle, dist/chunk-VOG34SRF.js), so the CLI honours the merge=union driver from .gitattributes with no factory change. Since STATUS.md is a prepend-only milestone log, union keeps both workers' line-1 entries instead of conflicting.

Proof:

  • Empirically reproduced the run-32926 collision in a scratch repo: without the attribute → the exact CONFLICT (content): Merge conflict in STATUS.md / non-zero git merge (the SyncError source); with it → Auto-merging STATUS.md, merge succeeds, both entries present, zero conflict markers.
  • Guarded by scripts/tests/status-md-union-merge-test.sh (run in ci's seam via scripts/seam-smoke.sh): pins the attribute via git check-attr, drives the collision, asserts no entry lost and none duplicated (union's one hazard) and the workdir ends clean, and asserts the no-attribute control still conflicts. Red before the fix, green after.

Close report

Landed: ead4f1a5 on main.

  • .gitattributes (new) — STATUS.md merge=union.
  • scripts/tests/status-md-union-merge-test.sh (new) — the guard test, auto-discovered by the seam's scripts/tests/*.sh loop.
  • docs/GOTCHAS.md — entry #348 (symptom → cause → rule).
  • STATUS.md — milestone entry prepended.

Acceptance:

  • ✅ Two runs on different hosts each land a state-changing ticket in the same window without the second reddening on a STATUS.md conflict — union auto-resolves the line-1 prepend.
  • ✅ No STATUS.md content silently lost or duplicated — asserted by the test in ci.
  • ✅ (for this defect) a failed worker merge no longer strands the workdir: the STATUS.md merge now succeeds, so no MERGE_HEAD, no preserved sandcastle/worker/* branch.

Split to #1901 (dev-factory follow-up), the honest residual: a genuine conflict on a non-STATUS.md path still strands the workdir + leaves an orphan branch — that is @ai-hero/sandcastle library behaviour with no host hook (the same out-of-reach residual #1717 recorded), and covers options 3/4 (retry-merge / flock-the-merge) plus the orphan sweep.

Orphans reported (not deleted — could hold un-pushed work; not reachable from this host): run 32926's sandcastle/worker/20260826-041808-6b0e8f, 20260908-021709-1678bd, 20260925-190818-d08c0b on elitebook-distributed-server-03 (~/swarm/Matou/idss); their work is already safe on PRs #1898/#1897. matou-workstation's swarm workdir carries no such orphans.

## Ruled by agent under ADR 0174 — veto anytime **Ruling:** took **option 1** (the ticket's own lowest-blast-radius option) — a root `.gitattributes` declaring `STATUS.md merge=union`. It is a two-way door (revert = delete one line) and fully provable offline, so it needed no human gate. **Why it works with the harness unchanged:** Sandcastle's merge-to-main shells out to a plain `git merge "<worker-branch>"` (`execAsync` in `@ai-hero/sandcastle`, `dist/chunk-VOG34SRF.js`), so the CLI honours the `merge=union` driver from `.gitattributes` with no factory change. Since STATUS.md is a prepend-only milestone log, union keeps **both** workers' line-1 entries instead of conflicting. **Proof:** - Empirically reproduced the run-32926 collision in a scratch repo: **without** the attribute → the exact `CONFLICT (content): Merge conflict in STATUS.md` / non-zero `git merge` (the SyncError source); **with** it → `Auto-merging STATUS.md`, merge succeeds, both entries present, zero conflict markers. - Guarded by `scripts/tests/status-md-union-merge-test.sh` (run in ci's seam via `scripts/seam-smoke.sh`): pins the attribute via `git check-attr`, drives the collision, asserts **no entry lost and none duplicated** (union's one hazard) and the workdir ends clean, and asserts the no-attribute control still conflicts. Red before the fix, green after. ## Close report **Landed:** `ead4f1a5` on `main`. - `.gitattributes` (new) — `STATUS.md merge=union`. - `scripts/tests/status-md-union-merge-test.sh` (new) — the guard test, auto-discovered by the seam's `scripts/tests/*.sh` loop. - `docs/GOTCHAS.md` — entry **#348** (symptom → cause → rule). - `STATUS.md` — milestone entry prepended. **Acceptance:** - ✅ Two runs on different hosts each land a state-changing ticket in the same window without the second reddening on a STATUS.md conflict — union auto-resolves the line-1 prepend. - ✅ No STATUS.md content silently lost or duplicated — asserted by the test in ci. - ✅ (for this defect) a failed worker merge no longer strands the workdir: the STATUS.md merge now **succeeds**, so no `MERGE_HEAD`, no preserved `sandcastle/worker/*` branch. **Split to #1901 (dev-factory follow-up), the honest residual:** a genuine conflict on a **non-STATUS.md** path still strands the workdir + leaves an orphan branch — that is `@ai-hero/sandcastle` library behaviour with no host hook (the same out-of-reach residual #1717 recorded), and covers options 3/4 (retry-merge / flock-the-merge) plus the orphan sweep. **Orphans reported (not deleted — could hold un-pushed work; not reachable from this host):** run 32926's `sandcastle/worker/20260826-041808-6b0e8f`, `20260908-021709-1678bd`, `20260925-190818-d08c0b` on `elitebook-distributed-server-03` (`~/swarm/Matou/idss`); their work is already safe on PRs #1898/#1897. matou-workstation's swarm workdir carries no such orphans.
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#1899
No description provided.