LANDING-aware worker branch strategy + STATUS.md conflict-surface fix (#230) #232

Merged
ben merged 1 commit from agent/issue-230 into main 2026-10-16 15:57:25 +00:00

closes #230

What

Fixes the post-run SyncError that reds a swarm leg after the worker has
already finished and landed via its LANDING=pr pull request, and removes the
STATUS.md concurrent-write conflict that triggers it.

Two causes, both in factory source:

  1. main.mts handed Sandcastle an unconditional
    branchStrategy: { type: "merge-to-head" }.
    That merges the worker's
    throwaway worktree branch onto local main when the run ends — correct
    under LANDING=push (where main is the landing surface), but under
    LANDING=pr the landing already happened via the PR, so the merge is
    redundant, puts worker commits on local main ahead of the human merge, and
    turns a merely-stale branch into a hard red + a mid-merge workdir.
  2. STATUS.md was a guaranteed concurrent-write conflict surface. Every
    state-changing commit prepended a **Last updated paragraph at a fixed
    anchor and the docs budget forced each writer to delete some of the oldest
    — divergent inserts at one anchor plus divergent deletions is a conflict git
    cannot auto-resolve, so any two overlapping writers collided.

How

  • branch-strategy.mts — new pure helper resolveBranchStrategy(landing, branchName), imported by main.mts and fed process.env.SWARM_POLICY_LANDING.
    pr pins the worktree to a per-run-unique named branch (Sandcastle
    collects the worker's commits but performs no merge onto main — it takes
    withSandboxLifecycle's hostCurrentBranch === null path); anything else
    (push, or a bare npm run sandcastle) keeps merge-to-head unchanged. Added
    to onboarding/vendor-manifest so it vendors beside main.mts.
  • STATUS.md — the 7 accreted **Last updated paragraphs (all already
    present byte-for-byte as docs/journal/ entries) collapse into the single
    header line; the surface tables, blockers, and journal pointer are kept.
  • tests/docs-budget-test.sh — gains a ratchet: STATUS.md may carry at most
    one **Last updated header line, so history cannot re-accrete here and
    re-open the conflict.
  • tests/branch-strategy-test.sh — new, 11 checks: runs the pure resolver
    via tsx offline (the same runner pnpm run sandcastle uses) across
    pr/push/unset/unknown, and asserts main.mts wires it rather than a
    hardcoded strategy.
  • GOTCHAS 72 (body + index row) and journal docs/journal/2026-10-15-230.md.

Rulings (ADR 0174 — veto anytime)

Both changes are two-way doors, revertible and proven by offline tests: the
branch-strategy switch is one main.mts line + a pure helper proven by
tests/branch-strategy-test.sh; the STATUS.md ratchet merely enforces the
rule CLAUDE.md/#196 already carry ("never let STATUS.md re-accrete history").
No one-way door (no credentials, no security-posture change; the collapsed
paragraphs survive in docs/journal/).

Blast radius

Root main.mts + branch-strategy.mts are inert in the running
.sandcastle/ self-copy and every consumer until the next coordinated
re-vendor + FACTORY_REF bump (GOTCHAS 4) — and they vendor together (both in
the manifest). The STATUS.md/journal/GOTCHAS/test changes are live at merge.

Tests

Offline suite loop green except the pre-existing rehearsal-heal-lib-test
8b red (the #223/#225 date/interpret-trailers environment — red on the
pristine tree too, confirmed by stashing this change; untouched here).

Residual

A worker PR that already went mergeable: false on a STATUS.md conflict still
needs a human/landing-pr rebase — the merge authority owns that. This change
stops new runs from reding.

Screenshots: none — harness TypeScript, docs, and offline shell tests; no
rendered/visible surface to capture. Evidence is the tsx-backed
tests/branch-strategy-test.sh (11/11) and tests/docs-budget-test.sh (4/4).

closes #230 ## What Fixes the post-run `SyncError` that reds a `swarm` leg *after* the worker has already finished and landed via its `LANDING=pr` pull request, and removes the STATUS.md concurrent-write conflict that triggers it. Two causes, both in factory source: 1. **`main.mts` handed Sandcastle an unconditional `branchStrategy: { type: "merge-to-head" }`.** That merges the worker's throwaway worktree branch onto local `main` when the run ends — correct under `LANDING=push` (where `main` is the landing surface), but under `LANDING=pr` the landing already happened via the PR, so the merge is redundant, puts worker commits on local `main` ahead of the human merge, and turns a merely-stale branch into a hard red + a mid-merge workdir. 2. **STATUS.md was a guaranteed concurrent-write conflict surface.** Every state-changing commit prepended a `**Last updated` paragraph at a fixed anchor *and* the docs budget forced each writer to delete some of the oldest — divergent inserts at one anchor plus divergent deletions is a conflict git cannot auto-resolve, so any two overlapping writers collided. ## How - **`branch-strategy.mts`** — new pure helper `resolveBranchStrategy(landing, branchName)`, imported by `main.mts` and fed `process.env.SWARM_POLICY_LANDING`. `pr` pins the worktree to a per-run-unique **named** branch (Sandcastle collects the worker's commits but performs **no** merge onto `main` — it takes `withSandboxLifecycle`'s `hostCurrentBranch === null` path); anything else (push, or a bare `npm run sandcastle`) keeps `merge-to-head` unchanged. Added to `onboarding/vendor-manifest` so it vendors beside `main.mts`. - **STATUS.md** — the 7 accreted `**Last updated` paragraphs (all already present byte-for-byte as `docs/journal/` entries) collapse into the single header line; the surface tables, blockers, and journal pointer are kept. - **`tests/docs-budget-test.sh`** — gains a ratchet: STATUS.md may carry at most one `**Last updated` header line, so history cannot re-accrete here and re-open the conflict. - **`tests/branch-strategy-test.sh`** — new, 11 checks: runs the pure resolver via `tsx` offline (the same runner `pnpm run sandcastle` uses) across `pr`/`push`/unset/unknown, and asserts `main.mts` wires it rather than a hardcoded strategy. - **GOTCHAS 72** (body + index row) and journal `docs/journal/2026-10-15-230.md`. ## Rulings (ADR 0174 — veto anytime) Both changes are two-way doors, revertible and proven by offline tests: the branch-strategy switch is one `main.mts` line + a pure helper proven by `tests/branch-strategy-test.sh`; the STATUS.md ratchet merely **enforces** the rule `CLAUDE.md`/#196 already carry ("never let STATUS.md re-accrete history"). No one-way door (no credentials, no security-posture change; the collapsed paragraphs survive in `docs/journal/`). ## Blast radius Root `main.mts` + `branch-strategy.mts` are **inert** in the running `.sandcastle/` self-copy and every consumer until the next coordinated re-vendor + `FACTORY_REF` bump (GOTCHAS 4) — and they vendor together (both in the manifest). The STATUS.md/journal/GOTCHAS/test changes are live at merge. ## Tests Offline suite loop green except the **pre-existing** `rehearsal-heal-lib-test` `8b` red (the #223/#225 `date`/`interpret-trailers` environment — red on the pristine tree too, confirmed by stashing this change; untouched here). ## Residual A worker PR that already went `mergeable: false` on a STATUS.md conflict still needs a human/`landing-pr` rebase — the merge authority owns that. This change stops **new** runs from reding. **Screenshots:** none — harness TypeScript, docs, and offline shell tests; no rendered/visible surface to capture. Evidence is the `tsx`-backed `tests/branch-strategy-test.sh` (11/11) and `tests/docs-budget-test.sh` (4/4).
sandcastle: #230 — LANDING-aware worker branch strategy; STATUS.md stops being a concurrent-write conflict
Some checks failed
ci / static (pull_request) Successful in 2m20s
ci / test (pull_request) Failing after 5m8s
836d5b1f1b
A swarm leg reded at `sandcastle run (workers)` with a post-run SyncError
*after* the worker had finished and landed via its LANDING=pr PR: Sandcastle's
host-side `merge-to-head` merged the worker's temp branch onto local `main`
and hit a STATUS.md `UU` conflict. Two causes, both factory source:

1. `main.mts` handed Sandcastle an UNCONDITIONAL
   `branchStrategy: { type: "merge-to-head" }` — right under LANDING=push (main
   is the landing surface) but redundant + harmful under LANDING=pr (the PR
   already landed; the merge puts worker commits on local main ahead of the
   human merge and converts a stale branch into a red + a mid-merge workdir).
2. STATUS.md was a guaranteed concurrent-write conflict surface: every
   state-changing commit prepended a `**Last updated` paragraph at a fixed
   anchor AND the docs budget forced each writer to delete the oldest — a
   textual conflict git cannot resolve, so any two overlapping writers collide.

Changes:
- NEW `branch-strategy.mts` (pure `resolveBranchStrategy(landing, branchName)`),
  imported by `main.mts` and fed `process.env.SWARM_POLICY_LANDING`. `pr` pins
  the worktree to a per-run NAMED branch (Sandcastle collects commits, NO merge
  onto main — the `hostCurrentBranch === null` path); anything else (push, or a
  bare `npm run sandcastle`) keeps `merge-to-head` unchanged. In the manifest so
  it vendors beside `main.mts`.
- STATUS.md: the 7 accreted `**Last updated` paragraphs (all already byte-for-
  byte in docs/journal/) collapse into the single header line; tables/blockers/
  journal pointer kept. `tests/docs-budget-test.sh` gains a ratchet (≤1
  `**Last updated` line) so history cannot re-accrete and re-open the conflict.
- NEW `tests/branch-strategy-test.sh` (11 checks; runs the resolver via tsx
  offline and asserts main.mts wires it, not a hardcoded strategy).
- GOTCHAS 72 (body + index row); journal docs/journal/2026-10-15-230.md.

Both calls ruled two-way (ADR 0174, veto anytime): revertible and proven by
offline tests; the ratchet only enforces the rule CLAUDE.md/#196 already carry.

Root `main.mts`/`branch-strategy.mts` are INERT until the next re-vendor +
FACTORY_REF bump (GOTCHAS 4); the STATUS/journal/GOTCHAS/test changes are live
at merge. Residual (not self-healing): a worker PR already `mergeable: false`
on a STATUS.md conflict needs a human/landing-pr rebase — the merge authority
owns that; this stops NEW runs from reding.

Suite: offline loop green except the pre-existing `rehearsal-heal-lib-test`
`8b` red (the #223/#225 `date`/`interpret-trailers` environment, red on the
pristine tree too — untouched by this change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ben force-pushed agent/issue-230 from 836d5b1f1b
Some checks failed
ci / static (pull_request) Successful in 2m20s
ci / test (pull_request) Failing after 5m8s
to cf02cae100
All checks were successful
ci / static (pull_request) Successful in 2m33s
ci / test (pull_request) Successful in 5m13s
ci / test (push) Successful in 9m55s
ci / static (push) Successful in 2m42s
2026-10-16 15:45:22 +00:00
Compare
ben merged commit cf02cae100 into main 2026-10-16 15:57:25 +00:00
Sign in to join this conversation.
No reviewers
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!232
No description provided.