swarm reds on SyncError: STATUS.md is a guaranteed concurrent-write conflict, and merge-to-head runs even under LANDING=pr #230

Closed
opened 2026-10-15 10:04:00 +00:00 by matou-build-agent · 4 comments

Filed by the swarm healer from run
https://git.matou.nz/Matou/dev-factory/actions/runs/21996 (signature
0bf1a290dc09, evidence /tmp/matou-heal-Matou-dev-factory.K4aj3j).

Symptom

The swarm leg reds at stage sandcastle run (workers) with exit 1 after
the worker has already finished successfully:

Agent stopped
Merging to main
Git sync failed: Merge of 'sandcastle/worker/20261015-085822-727bff' onto 'main'
failed. The temporary branch ... has been preserved.
SyncError  (_tag: 'Fail')  [ELIFECYCLE] Command failed with exit code 1.

(run-verdict.txt; worker-logs.txt:256-260)

The worker's own work was fine: it completed #193, the close-report gate
passed, and it landed via the LANDING=pr rail as PR #229
(worker-logs.txt:225-256). Only Sandcastle's post-run host-side merge failed.

Evidence — it is a STATUS.md concurrent-write conflict

$ git -C ~/swarm/Matou/dev-factory status --short
UU STATUS.md            <- only conflicted path; MERGE_HEAD=979d55f present
$ git merge-base origin/main 979d55f   ->  468ab80   (#220, 08:55)
  • worker branch tip 979d55f (#193, committed 09:55) — forked at 468ab80
  • origin/main tip c436d49 (#221, landed 09:34 by the session-runner)

Both commits touch STATUS.md (and both touch .sandcastle/prompt.md, which
merged cleanly). STATUS.md is the only conflict because every state-changing
commit rewrites the same region of it — the header line plus a new
**Last updated** paragraph prepended at a fixed anchor — and
tests/docs-budget-test.sh additionally forces each writer to delete some
of the oldest paragraphs to fit the byte budget. Divergent inserts at one
anchor plus divergent deletions is a textual conflict git cannot resolve. Any
two concurrent state-changing writers (swarm worker vs. session-runner vs. live
session — all three share origin/main) collide.

Two causes, both in factory source

  1. STATUS.md is a guaranteed concurrent-write conflict surface. The
    CLAUDE.md rule ("any commit that changes project state must update the
    affected STATUS.md surface row + header line") plus the docs budget make
    every ticket rewrite the same lines. This will recur on every overlapping
    pair of writers, not just this one.
  2. branchStrategy: { type: "merge-to-head" } in main.mts is
    unconditional
    (main.mts, .sandcastle/main.mts:279) — it knows nothing
    about LANDING. Under LANDING=pr the PR is the landing path, so merging
    the worker's temp branch onto local main after the run is (a) redundant,
    (b) would put worker commits on local main ahead of the human PR merge,
    and (c) is what converts a merely-stale worker branch into a red run plus a
    workdir left mid-merge.

Proposed change

  • Make the post-run branch sync LANDING-aware: under LANDING=pr, do not
    merge the worker temp branch onto main (the landing already happened via
    the PR), and do not red the run for it.
  • Reduce STATUS.md's conflict surface so concurrent writers compose — e.g.
    append-only ordering, one line per writer, or move the per-change paragraph
    entirely into docs/journal/ (the journal is already append-only and
    per-ticket-filed, so it does not conflict) and leave STATUS.md as the
    surface rows + header only.
  • Whatever shape wins, add the hazard to docs/GOTCHAS.md (related: 66).

Notes for whoever picks this up

  • A root fix does not reach the running copy until a human re-vendors.
    .sandcastle/FACTORY_REF is 2445159 and already far behind main
    (see #131/#132) — this fix lands in the running swarm only at the next
    bash onboarding/onboard.sh vendor .sandcastle <sha> + pin bump (GOTCHAS 4).
  • Immediate residue that does not self-heal: PR #229 is
    mergeable: false
    — #193's work is stuck behind the same STATUS.md
    conflict and needs a rebase/resolve. #193 is still open and
    agent-working/ready-for-agent, so it owns that.
  • The dirty swarm workdir does self-heal: .forgejo/workflows/swarm.yml:222-224
    / .sandcastle/git-setup.sh:49 do git fetch origin main && git reset --hard origin/main before every run, which clears MERGE_HEAD. The preserved local
    branch sandcastle/worker/20261015-085822-727bff lingers harmlessly.
  • The healer did not touch the workdir: swarm-lock.txt said held, and
    fuser /tmp/matou-swarm.lock confirmed a live holder (the session-runner
    working #223).
Filed by the swarm healer from run https://git.matou.nz/Matou/dev-factory/actions/runs/21996 (signature `0bf1a290dc09`, evidence `/tmp/matou-heal-Matou-dev-factory.K4aj3j`). ## Symptom The `swarm` leg reds at stage `sandcastle run (workers)` with exit 1 *after* the worker has already finished successfully: ``` Agent stopped Merging to main Git sync failed: Merge of 'sandcastle/worker/20261015-085822-727bff' onto 'main' failed. The temporary branch ... has been preserved. SyncError (_tag: 'Fail') [ELIFECYCLE] Command failed with exit code 1. ``` (`run-verdict.txt`; `worker-logs.txt:256-260`) The worker's own work was fine: it completed #193, the close-report gate passed, and it landed via the `LANDING=pr` rail as **PR #229** (`worker-logs.txt:225-256`). Only Sandcastle's post-run host-side merge failed. ## Evidence — it is a STATUS.md concurrent-write conflict ``` $ git -C ~/swarm/Matou/dev-factory status --short UU STATUS.md <- only conflicted path; MERGE_HEAD=979d55f present $ git merge-base origin/main 979d55f -> 468ab80 (#220, 08:55) ``` - worker branch tip `979d55f` (#193, committed **09:55**) — forked at `468ab80` - `origin/main` tip `c436d49` (#221, landed **09:34** by the *session-runner*) Both commits touch `STATUS.md` (and both touch `.sandcastle/prompt.md`, which merged cleanly). `STATUS.md` is the only conflict because every state-changing commit rewrites the *same* region of it — the header line plus a new `**Last updated**` paragraph prepended at a fixed anchor — and `tests/docs-budget-test.sh` additionally forces each writer to **delete** some of the oldest paragraphs to fit the byte budget. Divergent inserts at one anchor plus divergent deletions is a textual conflict git cannot resolve. Any two concurrent state-changing writers (swarm worker vs. session-runner vs. live session — all three share `origin/main`) collide. ## Two causes, both in factory source 1. **`STATUS.md` is a guaranteed concurrent-write conflict surface.** The CLAUDE.md rule ("any commit that changes project state must update the affected `STATUS.md` surface row + header line") plus the docs budget make every ticket rewrite the same lines. This will recur on every overlapping pair of writers, not just this one. 2. **`branchStrategy: { type: "merge-to-head" }` in `main.mts` is unconditional** (`main.mts`, `.sandcastle/main.mts:279`) — it knows nothing about `LANDING`. Under `LANDING=pr` the PR *is* the landing path, so merging the worker's temp branch onto local `main` after the run is (a) redundant, (b) would put worker commits on local `main` ahead of the human PR merge, and (c) is what converts a merely-stale worker branch into a red run plus a workdir left mid-merge. ## Proposed change - Make the post-run branch sync `LANDING`-aware: under `LANDING=pr`, do not merge the worker temp branch onto `main` (the landing already happened via the PR), and do not red the run for it. - Reduce `STATUS.md`'s conflict surface so concurrent writers compose — e.g. append-only ordering, one line per writer, or move the per-change paragraph entirely into `docs/journal/` (the journal is already append-only and per-ticket-filed, so it does not conflict) and leave `STATUS.md` as the surface rows + header only. - Whatever shape wins, add the hazard to `docs/GOTCHAS.md` (related: 66). ## Notes for whoever picks this up - **A root fix does not reach the running copy until a human re-vendors.** `.sandcastle/FACTORY_REF` is `2445159` and already far behind `main` (see #131/#132) — this fix lands in the running swarm only at the next `bash onboarding/onboard.sh vendor .sandcastle <sha>` + pin bump (GOTCHAS 4). - **Immediate residue that does not self-heal: PR #229 is `mergeable: false`** — #193's work is stuck behind the same `STATUS.md` conflict and needs a rebase/resolve. #193 is still open and `agent-working`/`ready-for-agent`, so it owns that. - The dirty swarm workdir *does* self-heal: `.forgejo/workflows/swarm.yml:222-224` / `.sandcastle/git-setup.sh:49` do `git fetch origin main && git reset --hard origin/main` before every run, which clears `MERGE_HEAD`. The preserved local branch `sandcastle/worker/20261015-085822-727bff` lingers harmlessly. - The healer did not touch the workdir: `swarm-lock.txt` said `held`, and `fuser /tmp/matou-swarm.lock` confirmed a live holder (the session-runner working #223).
Author
Member

close-report for #230 — status success

✅ close-report gates passed — every claim verified against the PR head. PR #232 (#232) is open and green; a human merges it and the merge closes this issue via closes #230 (MERGE_AUTHORITY=human).

envelope
{
  "issue": 230,
  "status": "success",
  "commits": [
    "836d5b1f1bb204f6535bda12e9d8423a8740aace"
  ],
  "changed_files": [
    "STATUS.md",
    "branch-strategy.mts",
    "docs/GOTCHAS.md",
    "docs/gotchas/72-merge-to-head-reds-a-landing-pr-run-on-a-status-conflict.md",
    "docs/journal/2026-10-15-230.md",
    "main.mts",
    "onboarding/vendor-manifest",
    "tests/branch-strategy-test.sh",
    "tests/docs-budget-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/branch-strategy-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/onboard-lib-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Make the post-run branch sync LANDING-aware: under LANDING=pr do not merge the worker temp branch onto main, and do not red the run for it": "main.mts now calls resolveBranchStrategy(process.env.SWARM_POLICY_LANDING, <per-run branch>) (branch-strategy.mts) instead of a hardcoded { type: \"merge-to-head\" }; pr returns { type: \"branch\" } which Sandcastle collects commits from but never merges onto main (withSandboxLifecycle's hostCurrentBranch===null path), so no SyncError. push keeps merge-to-head. Proven by tests/branch-strategy-test.sh (11/11).",
    "Reduce STATUS.md's conflict surface so concurrent writers compose (move per-change paragraph into docs/journal, leave STATUS.md surface rows + header only)": "STATUS.md collapsed from 7 accreted **Last updated paragraphs (all already byte-for-byte in docs/journal/) to a single header line + tables/blockers/journal pointer; tests/docs-budget-test.sh gains a ratchet asserting at most one **Last updated line so it cannot re-accrete. docs-budget-test 4/4.",
    "Add the hazard to docs/GOTCHAS.md (related: 66)": "New body docs/gotchas/72-merge-to-head-reds-a-landing-pr-run-on-a-status-conflict.md + index row 72 in docs/GOTCHAS.md, cross-linking 66/4/ADR 0002.",
    "Factory-source change respects blast radius / vendoring": "branch-strategy.mts added to onboarding/vendor-manifest so it vendors beside main.mts (coverage test green); root main.mts/branch-strategy.mts are inert until the next re-vendor + FACTORY_REF bump (noted in the journal + GOTCHAS 72)."
  },
  "summary": "Made the worker's post-run host branch strategy LANDING-aware (pr pins a named branch, no merge-to-head) and collapsed STATUS.md to a single header line with a re-accretion ratchet, so a LANDING=pr run no longer reds on a STATUS.md SyncError.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #230 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against the PR head. PR #232 (https://git.matou.nz/Matou/dev-factory/pulls/232) is open and green; a human merges it and the merge closes this issue via `closes #230` (MERGE_AUTHORITY=human). <details><summary>envelope</summary> ```json { "issue": 230, "status": "success", "commits": [ "836d5b1f1bb204f6535bda12e9d8423a8740aace" ], "changed_files": [ "STATUS.md", "branch-strategy.mts", "docs/GOTCHAS.md", "docs/gotchas/72-merge-to-head-reds-a-landing-pr-run-on-a-status-conflict.md", "docs/journal/2026-10-15-230.md", "main.mts", "onboarding/vendor-manifest", "tests/branch-strategy-test.sh", "tests/docs-budget-test.sh" ], "tests": [ { "command": "bash tests/branch-strategy-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/onboard-lib-test.sh", "exit_code": 0 } ], "criteria": { "Make the post-run branch sync LANDING-aware: under LANDING=pr do not merge the worker temp branch onto main, and do not red the run for it": "main.mts now calls resolveBranchStrategy(process.env.SWARM_POLICY_LANDING, <per-run branch>) (branch-strategy.mts) instead of a hardcoded { type: \"merge-to-head\" }; pr returns { type: \"branch\" } which Sandcastle collects commits from but never merges onto main (withSandboxLifecycle's hostCurrentBranch===null path), so no SyncError. push keeps merge-to-head. Proven by tests/branch-strategy-test.sh (11/11).", "Reduce STATUS.md's conflict surface so concurrent writers compose (move per-change paragraph into docs/journal, leave STATUS.md surface rows + header only)": "STATUS.md collapsed from 7 accreted **Last updated paragraphs (all already byte-for-byte in docs/journal/) to a single header line + tables/blockers/journal pointer; tests/docs-budget-test.sh gains a ratchet asserting at most one **Last updated line so it cannot re-accrete. docs-budget-test 4/4.", "Add the hazard to docs/GOTCHAS.md (related: 66)": "New body docs/gotchas/72-merge-to-head-reds-a-landing-pr-run-on-a-status-conflict.md + index row 72 in docs/GOTCHAS.md, cross-linking 66/4/ADR 0002.", "Factory-source change respects blast radius / vendoring": "branch-strategy.mts added to onboarding/vendor-manifest so it vendors beside main.mts (coverage test green); root main.mts/branch-strategy.mts are inert until the next re-vendor + FACTORY_REF bump (noted in the journal + GOTCHAS 72)." }, "summary": "Made the worker's post-run host branch strategy LANDING-aware (pr pins a named branch, no merge-to-head) and collapsed STATUS.md to a single header line with a re-accretion ratchet, so a LANDING=pr run no longer reds on a STATUS.md SyncError.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Author
Member

Healer note — this fault fired again on run 22036 (signature 33cba5d1742d)

The swarm leg on matou-workstation reded at sandcastle run (workers) with
exactly the post-run SyncError this ticket describes, after the worker had
finished #230 and opened PR #232:

Merging to main
Git sync failed: Merge of 'sandcastle/worker/20261015-050435-eb962d' onto 'main' failed.

Evidence confirming the diagnosis in this ticket is right:

  • The swarm workdir is left mid-merge: .git/MERGE_HEAD present, UU STATUS.md,
    temp branch sandcastle/worker/20261015-050435-eb962d preserved at
    HEAD=11d4a4a (the merge never completed, so local main is not ahead).
  • The conflict hunk is precisely the predicted one: HEAD accreted the #231,
    #223 and #222 **Last updated paragraphs while the run was in flight; the
    worker branch collapses them. Textual, unresolvable by git.
  • .sandcastle/main.mts (the copy actually executed, pnpm sandcastle →
    tsx .sandcastle/main.mts) is at FACTORY_REF=2445159 and still carries the
    unconditional branchStrategy: { type: "merge-to-head" }.

No repair made, and none possible from the healer:

  • .sandcastle/main.mts is a FACTORY_MANIFEST path, so a vendored hotfix is
    blocked by the pre-push drift gate (and would red the seam drift stage).
  • The stuck workdir is self-healing — git-setup.sh's git checkout -f main && git reset --hard origin/main clears MERGE_HEAD on the next non-yielding
    tick. No cleanup was attempted: the global swarm lock is held (by the
    session-runner draining #225), so the workdir was treated read-only.
  • Recent swarm legs on this host read green only because they yielded on host
    capacity before reaching git-setup.sh — which is also why the dirty workdir
    has persisted.

Residual for the merge authority: PR #232 is mergeable: false against
current main (same STATUS.md conflict) and needs a rebase. Note that merging
#232 removes most of the recurrence on its own — STATUS.md collapses to one
header line plus the docs-budget-test.sh ratchet, so the old vendored
merge-to-head stops finding a conflict to fail on; the branch-strategy.mts
half only becomes live at the next re-vendor + FACTORY_REF bump.

agent-working is left in place deliberately: the work exists in PR #232, so
releasing the claim would only invite a duplicate worker.

## Healer note — this fault fired again on run 22036 (signature `33cba5d1742d`) The swarm leg on `matou-workstation` reded at `sandcastle run (workers)` with exactly the post-run `SyncError` this ticket describes, **after** the worker had finished #230 and opened PR #232: ``` Merging to main Git sync failed: Merge of 'sandcastle/worker/20261015-050435-eb962d' onto 'main' failed. ``` Evidence confirming the diagnosis in this ticket is right: - The swarm workdir is left mid-merge: `.git/MERGE_HEAD` present, `UU STATUS.md`, temp branch `sandcastle/worker/20261015-050435-eb962d` preserved at `HEAD=11d4a4a` (the merge never completed, so local `main` is not ahead). - The conflict hunk is precisely the predicted one: `HEAD` accreted the `#231`, `#223` and `#222` `**Last updated` paragraphs while the run was in flight; the worker branch collapses them. Textual, unresolvable by git. - `.sandcastle/main.mts` (the copy actually executed, `pnpm sandcastle` → `tsx .sandcastle/main.mts`) is at `FACTORY_REF=2445159` and still carries the unconditional `branchStrategy: { type: "merge-to-head" }`. **No repair made, and none possible from the healer:** - `.sandcastle/main.mts` is a `FACTORY_MANIFEST` path, so a vendored hotfix is blocked by the pre-push drift gate (and would red the `seam` drift stage). - The stuck workdir is self-healing — `git-setup.sh`'s `git checkout -f main && git reset --hard origin/main` clears `MERGE_HEAD` on the next non-yielding tick. No cleanup was attempted: the global swarm lock is **held** (by the session-runner draining #225), so the workdir was treated read-only. - Recent `swarm` legs on this host read green only because they yielded on host capacity before reaching `git-setup.sh` — which is also why the dirty workdir has persisted. **Residual for the merge authority:** PR #232 is `mergeable: false` against current `main` (same STATUS.md conflict) and needs a rebase. Note that merging #232 removes most of the recurrence on its own — STATUS.md collapses to one header line plus the `docs-budget-test.sh` ratchet, so the old vendored `merge-to-head` stops finding a conflict to fail on; the `branch-strategy.mts` half only becomes live at the next re-vendor + `FACTORY_REF` bump. `agent-working` is left in place deliberately: the work exists in PR #232, so releasing the claim would only invite a duplicate worker.
Owner

Interactive claim (Ben's Claude Code session, 2026-10-16T15:37:14Z): rebasing the PR onto current main, re-running the offline suite, then merging as MERGE_AUTHORITY=human. agent-working set so the swarm skips this ticket meanwhile.

Interactive claim (Ben's Claude Code session, 2026-10-16T15:37:14Z): rebasing the PR onto current `main`, re-running the offline suite, then merging as MERGE_AUTHORITY=human. `agent-working` set so the swarm skips this ticket meanwhile.
Owner

Rebased onto current main (53793ce, #237) by Ben's Claude Code session, 2026-10-16. The only conflict was the predicted STATUS.md hunk: resolved to the single **Last updated header line this ticket introduces (the 7 paragraphs main had accreted since — #237/#235/#234/#227×2/#225/#231 — each already have their docs/journal/ file). main.mts auto-merged cleanly (resolveBranchStrategy wired). Full offline suite on the rebased tree: 0 failures. PR #232's head is now cf02cae, a fast-forward child of main. Awaiting the human merge (MERGE_AUTHORITY=human); agent-working stays on until then.

Rebased onto current `main` (`53793ce`, #237) by Ben's Claude Code session, 2026-10-16. The only conflict was the predicted `STATUS.md` hunk: resolved to the single `**Last updated` header line this ticket introduces (the 7 paragraphs main had accreted since — #237/#235/#234/#227×2/#225/#231 — each already have their `docs/journal/` file). `main.mts` auto-merged cleanly (`resolveBranchStrategy` wired). Full offline suite on the rebased tree: 0 failures. PR #232's head is now `cf02cae`, a fast-forward child of `main`. Awaiting the human merge (MERGE_AUTHORITY=human); `agent-working` stays on until then.
ben closed this issue 2026-10-16 15:57:27 +00:00
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#230
No description provided.