LANDING-aware worker branch strategy + STATUS.md conflict-surface fix (#230) #232
No reviewers
Labels
No labels
agent-blocked
agent-working
bug
deferred
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-info
needs-triage
no-triage
priority
ready-for-agent
ready-for-human
ready-for-session
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Matou/dev-factory!232
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "agent/issue-230"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
closes #230
What
Fixes the post-run
SyncErrorthat reds aswarmleg after the worker hasalready finished and landed via its
LANDING=prpull request, and removes theSTATUS.md concurrent-write conflict that triggers it.
Two causes, both in factory source:
main.mtshanded Sandcastle an unconditionalbranchStrategy: { type: "merge-to-head" }. That merges the worker'sthrowaway worktree branch onto local
mainwhen the run ends — correctunder
LANDING=push(wheremainis the landing surface), but underLANDING=prthe landing already happened via the PR, so the merge isredundant, puts worker commits on local
mainahead of the human merge, andturns a merely-stale branch into a hard red + a mid-merge workdir.
state-changing commit prepended a
**Last updatedparagraph at a fixedanchor 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 helperresolveBranchStrategy(landing, branchName), imported bymain.mtsand fedprocess.env.SWARM_POLICY_LANDING.prpins the worktree to a per-run-unique named branch (Sandcastlecollects the worker's commits but performs no merge onto
main— it takeswithSandboxLifecycle'shostCurrentBranch === nullpath); anything else(push, or a bare
npm run sandcastle) keepsmerge-to-headunchanged. Addedto
onboarding/vendor-manifestso it vendors besidemain.mts.**Last updatedparagraphs (all alreadypresent byte-for-byte as
docs/journal/entries) collapse into the singleheader line; the surface tables, blockers, and journal pointer are kept.
tests/docs-budget-test.sh— gains a ratchet: STATUS.md may carry at mostone
**Last updatedheader line, so history cannot re-accrete here andre-open the conflict.
tests/branch-strategy-test.sh— new, 11 checks: runs the pure resolvervia
tsxoffline (the same runnerpnpm run sandcastleuses) acrosspr/push/unset/unknown, and assertsmain.mtswires it rather than ahardcoded strategy.
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.mtsline + a pure helper proven bytests/branch-strategy-test.sh; the STATUS.md ratchet merely enforces therule
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.mtsare inert in the running.sandcastle/self-copy and every consumer until the next coordinatedre-vendor +
FACTORY_REFbump (GOTCHAS 4) — and they vendor together (both inthe manifest). The STATUS.md/journal/GOTCHAS/test changes are live at merge.
Tests
Offline suite loop green except the pre-existing
rehearsal-heal-lib-test8bred (the #223/#225date/interpret-trailersenvironment — red on thepristine tree too, confirmed by stashing this change; untouched here).
Residual
A worker PR that already went
mergeable: falseon a STATUS.md conflict stillneeds a human/
landing-prrebase — the merge authority owns that. This changestops new runs from reding.
Screenshots: none — harness TypeScript, docs, and offline shell tests; no
rendered/visible surface to capture. Evidence is the
tsx-backedtests/branch-strategy-test.sh(11/11) andtests/docs-budget-test.sh(4/4).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>836d5b1f1bcf02cae100