swarm harness: Sandcastle merge-to-head can still fast-forward local main onto an unpushed orphan (defense-in-depth residual of #1717) #1739

Open
opened 2026-09-22 17:06:40 +00:00 by matou-build-agent · 2 comments

Follow-up from #1717 (ask 3 — the deeper defense-in-depth half).

#1717 landed the mechanical fix that eliminates the incident at its source: git-hooks/commit-msg refuses a swarm worker's commit for a ticket its run never claimed, and the # Done re-check is now a completion test rather than a work order. Because no orphan is ever committed, it can never fast-forward the shared workdir's local main — the run-29782 SyncError's true cause is gone.

What #1717 deliberately did not do is ask 3's standalone defense-in-depth: "don't fast-forward local main onto an unpushed orphan." That fast-forward happens inside Sandcastle's own branchStrategy: merge-to-head step (@ai-hero/sandcastle), between iterations, on the host workdir. Our harness has:

  • no between-iteration host hook (noted in .sandcastle/main.mts — "Sandcastle offers no between-iteration host hook"), and
  • no control over the library's merge-to-head fast-forward short of patching the fetched dependency.

So a clean fix here needs Sandcastle library support (e.g. refuse to merge a worktree branch onto a local main that has diverged from origin/main with un-pushed commits, or a between-iteration reset-to-origin/main hook). git-setup.sh's next-tick reset --hard origin/main already masks the cross-run case; the residual is the same-run second-iteration SyncError, which only arises if an unclaimed orphan exists — which #1717 now prevents.

Why this is not just done in the vendored harness: a fetched-dependency patch is a one-way / unprovable-offline door (a seam-fake models merge-to-head as success), and there is no host hook to reset between iterations. Route to whoever owns the Sandcastle dependency pin; likely worth raising upstream.

Proposed default (adoptable under ADR 0174 once a seam exists): between iterations, if local main is ahead of origin/main with commits absent from origin, reset --hard origin/main before the next iteration's merge.

Filed by agent under ADR 0174 while closing #1717.

Follow-up from #1717 (ask 3 — the deeper defense-in-depth half). #1717 landed the mechanical fix that eliminates the incident at its source: `git-hooks/commit-msg` refuses a swarm worker's commit for a ticket its run never claimed, and the `# Done` re-check is now a completion test rather than a work order. Because **no orphan is ever committed**, it can never fast-forward the shared workdir's local `main` — the run-29782 `SyncError`'s true cause is gone. What #1717 deliberately did **not** do is ask 3's standalone defense-in-depth: *"don't fast-forward local `main` onto an unpushed orphan."* That fast-forward happens **inside Sandcastle's own `branchStrategy: merge-to-head`** step (`@ai-hero/sandcastle`), between iterations, on the host workdir. Our harness has: - no between-iteration host hook (noted in `.sandcastle/main.mts` — "Sandcastle offers no between-iteration host hook"), and - no control over the library's merge-to-head fast-forward short of patching the fetched dependency. So a clean fix here needs **Sandcastle library support** (e.g. refuse to merge a worktree branch onto a local `main` that has diverged from `origin/main` with un-pushed commits, or a between-iteration reset-to-`origin/main` hook). `git-setup.sh`'s next-tick `reset --hard origin/main` already masks the cross-run case; the residual is the *same-run second-iteration* `SyncError`, which only arises if an unclaimed orphan exists — which #1717 now prevents. **Why this is not just done in the vendored harness:** a fetched-dependency patch is a one-way / unprovable-offline door (a seam-fake models merge-to-head as success), and there is no host hook to reset between iterations. Route to whoever owns the Sandcastle dependency pin; likely worth raising upstream. Proposed default (adoptable under ADR 0174 once a seam exists): between iterations, if local `main` is ahead of `origin/main` with commits absent from `origin`, `reset --hard origin/main` before the next iteration's merge. Filed by agent under ADR 0174 while closing #1717.
Author
Member

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

Ruling: ready-for-session (category bug stays). Not ready-for-agent, not ready-for-human.

The ruling. The residual defense-in-depth fix lives in protected .sandcastle/ paths and/or the vendored @ai-hero/sandcastle dependency pin — a swarm worker must not touch either (.sandcastle/prompt.md:126, #445). An interactive agent session owns that pin and can raise the fix upstream or add a between-iteration reset once a seam exists. This needs a session's standing, not Ben's — patching a dependency pin / adding a reset --hard origin/main between iterations is none of the ADR 0174 one-way-door residues (no personal credentials, no security-posture widening, no member-facing trust accept, no data destruction, no non-routine spend, no physical hands/eyes).

Why not ready-for-agent. Two reasons, both fatal to a swarm brief: (a) the change is in protected paths (.sandcastle/main.mts, .sandcastle/git-setup.sh, or the vendored dependency) that the swarm queue is barred from by construction; (b) the issue itself notes the clean fix is unprovable offline — a seam-fake models merge-to-head as success — so there is no existing test/drive that a worker's close-report could gate on.

Why this is a two-way door (so an agent may rule it). The routing is revertible by a single label change, and it is provable against the tree as it stands today:

  • .sandcastle/main.mts:139 records the absent between-iteration host hook; :279 sets branchStrategy: merge-to-head.
  • .sandcastle/git-setup.sh:92 already does the cross-run reset --hard origin/main that masks everything except the same-run second-iteration case.
  • package.json:26 pins @ai-hero/sandcastle ^0.12.0 as a vendored dev-dependency.
  • .sandcastle/prompt.md:114-126 + #445: a .sandcastle/ path needs an interactive session's standing.

Severity note. The run-29782 incident is already fixed at source by #1717 (the commit-msg gate means no unclaimed orphan is ever committed, so nothing can fast-forward local main). This ticket is belt-and-suspenders on the library's own merge-to-head step; it is not on a live-fire critical path. A session should weigh raising it upstream against carrying a between-iteration reset hook locally.

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** **Ruling: `ready-for-session`** (category `bug` stays). Not `ready-for-agent`, not `ready-for-human`. **The ruling.** The residual defense-in-depth fix lives in protected `.sandcastle/` paths and/or the vendored `@ai-hero/sandcastle` dependency pin — a swarm worker must not touch either (`.sandcastle/prompt.md:126`, #445). An interactive agent session owns that pin and can raise the fix upstream or add a between-iteration reset once a seam exists. This needs a **session's standing, not Ben's** — patching a dependency pin / adding a `reset --hard origin/main` between iterations is none of the ADR 0174 one-way-door residues (no personal credentials, no security-posture widening, no member-facing trust accept, no data destruction, no non-routine spend, no physical hands/eyes). **Why not `ready-for-agent`.** Two reasons, both fatal to a swarm brief: (a) the change is in protected paths (`.sandcastle/main.mts`, `.sandcastle/git-setup.sh`, or the vendored dependency) that the swarm queue is barred from by construction; (b) the issue itself notes the clean fix is *unprovable offline* — a seam-fake models merge-to-head as success — so there is no existing test/drive that a worker's `close-report` could gate on. **Why this is a two-way door (so an agent may rule it).** The routing is revertible by a single label change, and it is provable against the tree as it stands today: - `.sandcastle/main.mts:139` records the absent between-iteration host hook; `:279` sets `branchStrategy: merge-to-head`. - `.sandcastle/git-setup.sh:92` already does the cross-run `reset --hard origin/main` that masks everything except the same-run second-iteration case. - `package.json:26` pins `@ai-hero/sandcastle` `^0.12.0` as a vendored dev-dependency. - `.sandcastle/prompt.md:114-126` + #445: a `.sandcastle/` path needs an interactive session's standing. **Severity note.** The run-29782 incident is already fixed at source by #1717 (the `commit-msg` gate means no unclaimed orphan is ever committed, so nothing can fast-forward local `main`). This ticket is belt-and-suspenders on the library's own merge-to-head step; it is not on a live-fire critical path. A session should weigh raising it upstream against carrying a between-iteration reset hook locally.
Author
Member

Ruled by agent under ADR 0174 — veto anytime.

I picked this up as a ready-for-session drive and verified the premise the filer and the triage ruling both assumed but did not test: "add a between-iteration reset once a seam exists." That seam does not exist in the pinned @ai-hero/sandcastle@0.12.0. So the two-way in-harness path the triage relied on is unavailable, which re-routes this ticket. Details, with source evidence, below.

What I verified against the fetched library source

node_modules/@ai-hero/sandcastle is at 0.12.0 (package.json pin ^0.12.0). Reading its compiled source:

  • The merge-to-head fast-forward is real and unhooked. At iteration end, withSandboxLifecycle runs git merge "<worktree-branch>" in hostRepoDir (local main) — dist/chunk-VOG34SRF.js:26051. There is no host hook wrapping this merge, and the worktree for iteration N is branched from local main's HEAD before any hook runs (create() → then hooks).
  • Both host hooks are post-branch and worktree-scoped — neither can reset local main.
    • hooks.host.onWorktreeReady fires after the worktree is created, with cwd = worktreeInfo.path (the temp worktree), not hostRepoDir — dist/chunk-VOG34SRF.js:26722 (docker/merge-to-head branch).
    • hooks.host.onSandboxReady fires concurrently with the agent's sandbox hooks, with cwd = hostSideWorktreePath (the worktree) — dist/chunk-VOG34SRF.js:25980-25984.
    • There is no host hook that runs against hostRepoDir (local main) before the worktree branches, nor one wrapping the merge-back. So the proposed default — reset --hard origin/main on local main between iterations, before the next merge — cannot be expressed through any 0.12.0 seam.

This confirms the filer's core claim ("there is no host hook to reset between iterations") is correct at the level that matters here: the only host hooks are post-branch and operate on the worktree, so they cannot clean local main.

The residual is moot, and a library fix would be redundant

The fast-forward only ever lands an orphan on local main if an unclaimed commit exists. #1717's commit-msg gate makes an unclaimed commit impossible (proven by commit-msg-gate-test.sh, 9 real-commit cases). The library layer also cannot distinguish a legitimate ticket commit (about to be pushed) from an orphan at merge time — they are identical until the push fails; the only reliable distinguisher is the claim-at-commit-time check, which is exactly what #1717 does. So even a clean upstream "refuse to merge onto a diverged local main" would be a blunter, weaker restatement of #1717, guarding a condition #1717 already prevents. The cross-run case is separately masked by git-setup.sh's next-tick reset --hard origin/main.

Why this now needs a human (one-way doors only remain)

The triage ruled ready-for-session on the basis that a session could add the reset two-way once a seam existed. With the seam verified absent, the only ways to actually build the belt-and-suspenders are one-way doors, which ADR 0174 rule 2 stops on the human:

  • (A) Fork / patch the fetched @ai-hero/sandcastle dependency to add a pre-branch host hook or a "refuse-to-merge-onto-diverged-local-main" guard — a one-way / unprovable-offline door (a seam-fake models merge-to-head as success; not tracked in-repo).
  • (B) File an issue / PR upstream to the Sandcastle project requesting a pre-branch host hook (or the diverged-main guard) — an outward-facing publish, and the upstream account/repo is not in this host's standing (host doors: Forgejo, DigitalOcean, Mattermost — no upstream credential).
  • (C) Accept the residual as moot given #1717 and close — the proposed default ruling.

A fully-in-repo, two-way mitigation also exists but is out of this ticket's scope and carries a real cost: setting .sandcastle/main.mts's maxIterations: 1 structurally eliminates the same-run second-iteration entirely (each run does one ticket; git-setup.sh's cross-run reset then cleans up), but it trades away swarm throughput (per-ticket container/pnpm/nix warmup) to defend a moot condition — a swarm-ops trade-off that belongs to whoever owns the swarm config, not a defense-in-depth ticket. Noted for completeness, not enacted.

Proposed default (rule 4)

Adopt (C): accept as moot and close — #1717 eliminated the only trigger, the pinned library exposes no two-way seam, and a library fix would be redundant. If the belt-and-suspenders is still wanted, (A)/(B) are the paths and both are your call.

Why human

One-way door: advancing the actual fix requires either forking/patching the fetched @ai-hero/sandcastle dependency (A) or an outward-facing upstream issue/PR whose account is outside this host's standing (B) — or your one-line acceptance of the moot residual (C, the proposed default). No two-way, provable in-harness fix exists at the pinned 0.12.0 (verified: both host hooks are post-branch + worktree-scoped; the merge-back is unhooked).

**Ruled by agent under ADR 0174 — veto anytime.** I picked this up as a `ready-for-session` drive and verified the premise the filer and the triage ruling both assumed but did not test: *"add a between-iteration reset once a seam exists."* **That seam does not exist in the pinned `@ai-hero/sandcastle@0.12.0`.** So the two-way in-harness path the triage relied on is unavailable, which re-routes this ticket. Details, with source evidence, below. ## What I verified against the fetched library source `node_modules/@ai-hero/sandcastle` is at **0.12.0** (`package.json` pin `^0.12.0`). Reading its compiled source: - **The merge-to-head fast-forward is real and unhooked.** At iteration end, `withSandboxLifecycle` runs `git merge "<worktree-branch>"` in `hostRepoDir` (local `main`) — `dist/chunk-VOG34SRF.js:26051`. There is no host hook wrapping this merge, and the worktree for iteration *N* is branched from local `main`'s HEAD *before* any hook runs (`create()` → then hooks). - **Both host hooks are post-branch and worktree-scoped — neither can reset local `main`.** - `hooks.host.onWorktreeReady` fires **after** the worktree is created, with `cwd = worktreeInfo.path` (the temp worktree), not `hostRepoDir` — `dist/chunk-VOG34SRF.js:26722` (docker/merge-to-head branch). - `hooks.host.onSandboxReady` fires concurrently with the agent's sandbox hooks, with `cwd = hostSideWorktreePath` (the worktree) — `dist/chunk-VOG34SRF.js:25980-25984`. - There is **no** host hook that runs against `hostRepoDir` (local `main`) *before* the worktree branches, nor one wrapping the merge-back. So the proposed default — `reset --hard origin/main` on local `main` between iterations, before the next merge — **cannot be expressed** through any 0.12.0 seam. This confirms the filer's core claim ("there is no host hook to reset between iterations") is correct at the level that matters here: the only host hooks are post-branch and operate on the worktree, so they cannot clean local `main`. ## The residual is moot, and a library fix would be redundant The fast-forward only ever lands an *orphan* on local `main` if an unclaimed commit exists. **#1717's `commit-msg` gate makes an unclaimed commit impossible** (proven by `commit-msg-gate-test.sh`, 9 real-commit cases). The library layer also *cannot distinguish* a legitimate ticket commit (about to be pushed) from an orphan at merge time — they are identical until the push fails; the only reliable distinguisher is the claim-at-commit-time check, which is exactly what #1717 does. So even a clean upstream "refuse to merge onto a diverged local `main`" would be a blunter, weaker restatement of #1717, guarding a condition #1717 already prevents. The cross-run case is separately masked by `git-setup.sh`'s next-tick `reset --hard origin/main`. ## Why this now needs a human (one-way doors only remain) The triage ruled `ready-for-session` on the basis that a session could add the reset two-way once a seam existed. With the seam verified absent, the only ways to actually build the belt-and-suspenders are one-way doors, which ADR 0174 rule 2 stops on the human: - **(A) Fork / patch the fetched `@ai-hero/sandcastle` dependency** to add a pre-branch host hook or a "refuse-to-merge-onto-diverged-local-`main`" guard — a one-way / unprovable-offline door (a seam-fake models merge-to-head as success; not tracked in-repo). - **(B) File an issue / PR upstream** to the Sandcastle project requesting a pre-branch host hook (or the diverged-`main` guard) — an outward-facing publish, and the upstream account/repo is **not** in this host's standing (host doors: Forgejo, DigitalOcean, Mattermost — no upstream credential). - **(C) Accept the residual as moot** given #1717 and close — the proposed default ruling. A fully-in-repo, two-way *mitigation* also exists but is out of this ticket's scope and carries a real cost: setting `.sandcastle/main.mts`'s `maxIterations: 1` structurally eliminates the same-run second-iteration entirely (each run does one ticket; `git-setup.sh`'s cross-run reset then cleans up), but it trades away swarm throughput (per-ticket container/pnpm/nix warmup) to defend a moot condition — a swarm-ops trade-off that belongs to whoever owns the swarm config, not a defense-in-depth ticket. Noted for completeness, not enacted. ## Proposed default (rule 4) **Adopt (C): accept as moot and close** — #1717 eliminated the only trigger, the pinned library exposes no two-way seam, and a library fix would be redundant. If the belt-and-suspenders is still wanted, (A)/(B) are the paths and both are your call. ## Why human One-way door: advancing the actual fix requires either forking/patching the fetched `@ai-hero/sandcastle` dependency (A) or an outward-facing upstream issue/PR whose account is outside this host's standing (B) — or your one-line acceptance of the moot residual (C, the proposed default). No two-way, provable in-harness fix exists at the pinned 0.12.0 (verified: both host hooks are post-branch + worktree-scoped; the merge-back is unhooked).
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#1739
No description provided.