sandcastle: the claim mechanism handed #536 to two hosts — both fully implemented it, one duplicate discarded #541

Closed
opened 2026-08-14 18:07:39 +00:00 by ben · 3 comments
Owner

Symptom

Issue #536 was handed to my Sandcastle run as its claimed ticket (top-of-prompt ready list, my SWARM_RUN_ID=6236 on host fd9d69e4d645), and I implemented the full three-part fix. On push, git rebase origin/main conflicted across all 8 files with commit 293097a — a near-identical independent #536 implementation landed by another host, which had already closed the issue. The claim comment on the issue reads swarm-claim host=elitebook-distributed-server-03 run=6236 with the note "(automated multi-host claim — lowest live claim id works this ticket)".

So two hosts fully implemented the same ticket (same ServiceHealth.Detail, same droplet-units.txt harvest, same co-host closure pin, same GOTCHAS #35) — one landed, one was discarded. I aborted the rebase and reset to origin/main; no duplicate was pushed.

Likely cause (for a human to confirm)

The claim resolution — "lowest live claim id works this ticket" — appears not to have fenced my host out before it started work. Either the tiebreak did not deduplicate across hosts, or both hosts started before either claim was visible to the other. The .sandcastle/ claim machinery is a protected path, so I did not touch it.

Suggested direction

Have the executor confirm a single live claim owner (and re-verify the issue is still open + ready-for-agent) immediately before the agent begins work, so a losing claimant exits early instead of implementing a full duplicate. At minimum, a pre-flight re-check of issue state right before the agent starts would have caught that #536 was already closed.

Found while working #536 (2026-08-14); the fix itself is fine and merged as 293097a.

## Symptom Issue #536 was handed to my Sandcastle run as its claimed ticket (top-of-prompt ready list, my `SWARM_RUN_ID=6236` on host `fd9d69e4d645`), and I implemented the full three-part fix. On push, `git rebase origin/main` conflicted across **all 8 files** with commit `293097a` — a **near-identical independent #536 implementation** landed by another host, which had already **closed** the issue. The claim comment on the issue reads `swarm-claim host=elitebook-distributed-server-03 run=6236` with the note *"(automated multi-host claim — lowest live claim id works this ticket)"*. So two hosts fully implemented the same ticket (same `ServiceHealth.Detail`, same `droplet-units.txt` harvest, same co-host closure pin, same GOTCHAS #35) — one landed, one was discarded. I aborted the rebase and reset to origin/main; no duplicate was pushed. ## Likely cause (for a human to confirm) The claim resolution — "lowest live claim id works this ticket" — appears not to have fenced my host out before it started work. Either the tiebreak did not deduplicate across hosts, or both hosts started before either claim was visible to the other. The `.sandcastle/` claim machinery is a protected path, so I did not touch it. ## Suggested direction Have the executor confirm a **single** live claim owner (and re-verify the issue is still open + `ready-for-agent`) immediately before the agent begins work, so a losing claimant exits early instead of implementing a full duplicate. At minimum, a pre-flight re-check of issue state right before the agent starts would have caught that #536 was already closed. Found while working #536 (2026-08-14); the fix itself is fine and merged as `293097a`.
Author
Owner

Relabelled ready-for-session under ADR 0174: the likely-cause confirmation is an investigation against the claim-lib code and the two runs' timestamps (provable, not a judgement call), and the fix touches .sandcastle/ protected paths — session work. The suggested pre-work re-check (single live claim owner + issue still open/ready right before the agent starts) is the obvious two-way-door shape.

Relabelled `ready-for-session` under ADR 0174: the likely-cause confirmation is an investigation against the claim-lib code and the two runs' timestamps (provable, not a judgement call), and the fix touches `.sandcastle/` protected paths — session work. The suggested pre-work re-check (single live claim owner + issue still open/ready right before the agent starts) is the obvious two-way-door shape.
Author
Owner

Ruled by agent under ADR 0174 — veto anytime

Ruling: root-caused and fixed in code, not a one-way door. claim-lib.sh's
claim_alive_runs() filtered /actions/tasks with an exact .name == "swarm"
match (39c5a23, 2026-08-11), predating swarm.yml's 2-wide worker matrix
(strategy.matrix.worker:[1,2], 44fe333, the "POOL CUTOVER"). Forgejo names
each matrix job swarm (1) / swarm (2), never bare swarm — live-probed
2026-08-15 against the real /actions/tasks response: every current task in
the last 40 entries checked is suffixed, none bare. That means
claim_alive_runs() has returned [] in production since the matrix landed:
claim_won's own-id short-circuit was the only signal any host ever had for
"is my claim the lowest live one", so a racing host always saw the OTHER
host's earlier claim as dead (never in the always-empty alive set) and
declared itself the sole winner too — both hosts "win" independently. That's
exactly the reported symptom: fd9d69e4d645 and
elitebook-distributed-server-03 both fully implemented #536.

Why a two-way door: a one-line jq filter change, reverted by a commit;
proved by two new offline claim-lib-test.sh cases that reproduce the exact
double-win (fail red against the pre-fix filter — confirmed before the fix —
and pass green after). No credentials, no security-posture widening, no
trust-surface accept, no data destroyed, no hardware touched.

What proves it:

  • a3324a8 — .name == "swarm" or (.name | test("^swarm \\("))
  • New cases: "matrix-suffixed swarm jobs count as alive" and "earlier claim
    wins under matrix-suffixed alive runs / later claim correctly loses — no
    double-win" (the second is the direct #541 regression test).
  • Full .sandcastle/tests/*.sh sweep: all 34 suites green on this host.
  • Live probe: GET /actions/tasks?limit=100&page=1 on 2026-08-15 — real
    entries are "swarm (1)"/"swarm (2)", confirming the filter's exact
    match could never have matched production traffic since the matrix landed.

Scope note: schedule-backstop.sh's in-flight check for swarm.yml has
the identical .name == $n exact-match blind spot (a different symptom —
redundant backstop dispatches, not duplicate ticket implementations). Left
unfixed here to keep this diff scoped to the reported/proven bug; filed as
#588 (ready-for-agent).

The "confirm a single live claim owner right before the agent begins work"
direction in the original report turned out to be a symptom-level mitigation
of a bug that made EVERY claim-time check unreliable, not the root cause —
the actual fix restores the alive-runs check itself, so the existing
claim-then-verify flow (already the first thing prompt.md does each
iteration) is now trustworthy again without needing a second re-check layer.

## Ruled by agent under ADR 0174 — veto anytime **Ruling:** root-caused and fixed in code, not a one-way door. `claim-lib.sh`'s `claim_alive_runs()` filtered `/actions/tasks` with an exact `.name == "swarm"` match (`39c5a23`, 2026-08-11), predating `swarm.yml`'s 2-wide worker matrix (`strategy.matrix.worker:[1,2]`, `44fe333`, the "POOL CUTOVER"). Forgejo names each matrix job `swarm (1)` / `swarm (2)`, never bare `swarm` — **live-probed** 2026-08-15 against the real `/actions/tasks` response: every current task in the last 40 entries checked is suffixed, none bare. That means `claim_alive_runs()` has returned `[]` in production since the matrix landed: `claim_won`'s own-id short-circuit was the only signal any host ever had for "is my claim the lowest live one", so a racing host always saw the OTHER host's earlier claim as dead (never in the always-empty alive set) and declared itself the sole winner too — both hosts "win" independently. That's exactly the reported symptom: `fd9d69e4d645` and `elitebook-distributed-server-03` both fully implemented #536. **Why a two-way door:** a one-line jq filter change, reverted by a commit; proved by two new offline `claim-lib-test.sh` cases that reproduce the exact double-win (fail red against the pre-fix filter — confirmed before the fix — and pass green after). No credentials, no security-posture widening, no trust-surface accept, no data destroyed, no hardware touched. **What proves it:** - `a3324a8` — `.name == "swarm" or (.name | test("^swarm \\("))` - New cases: "matrix-suffixed swarm jobs count as alive" and "earlier claim wins under matrix-suffixed alive runs / later claim correctly loses — no double-win" (the second is the direct #541 regression test). - Full `.sandcastle/tests/*.sh` sweep: all 34 suites green on this host. - Live probe: `GET /actions/tasks?limit=100&page=1` on 2026-08-15 — real entries are `"swarm (1)"`/`"swarm (2)"`, confirming the filter's exact match could never have matched production traffic since the matrix landed. **Scope note:** `schedule-backstop.sh`'s in-flight check for `swarm.yml` has the identical `.name == $n` exact-match blind spot (a different symptom — redundant backstop dispatches, not duplicate ticket implementations). Left unfixed here to keep this diff scoped to the reported/proven bug; filed as #588 (`ready-for-agent`). The "confirm a single live claim owner right before the agent begins work" direction in the original report turned out to be a symptom-level mitigation of a bug that made EVERY claim-time check unreliable, not the root cause — the actual fix restores the alive-runs check itself, so the existing claim-then-verify flow (already the first thing `prompt.md` does each iteration) is now trustworthy again without needing a second re-check layer.
Author
Owner

Close report

Landed: a3324a8 on main (pushed to origin/main).

  • .sandcastle/claim-lib.sh: claim_alive_runs() now matches job name
    swarm OR swarm (N), not just the pre-matrix bare swarm.
  • .sandcastle/tests/claim-lib-test.sh: two new cases — matrix-suffixed
    names count as alive; a same-issue two-claim race under matrix-suffixed
    alive runs resolves to exactly one winner (this second case is the direct
    #541 regression test, confirmed red against the pre-fix filter before the
    fix landed).
  • STATUS.md updated in the same commit (header + milestone entry).
  • Filed #588 (ready-for-agent) for the identical exact-match blind spot in
    schedule-backstop.sh's swarm.yml in-flight check — out of scope here.

Proof:

  • bash .sandcastle/tests/claim-lib-test.sh — 28/28 pass (was 26/28 with the
    two new cases added pre-fix, confirming red-before-green).
  • Full .sandcastle/tests/*.sh sweep (34 suites) — all green on this host.
  • Live probe of GET /actions/tasks?limit=100&page=1 on 2026-08-15 confirmed
    the real API returns "swarm (1)"/"swarm (2)", never bare "swarm",
    matching swarm.yml's strategy.matrix.worker:[1,2] (44fe333) and
    explaining why the pre-fix filter always saw zero live runs.

Ruling posted above under ADR 0174 (two-way door: revertible commit, provable
by the new regression test + the live probe). No credentials, security
widening, trust-surface accept, data destruction, or hardware involved.

Closing.

## Close report **Landed:** `a3324a8` on `main` (pushed to `origin/main`). - `.sandcastle/claim-lib.sh`: `claim_alive_runs()` now matches job name `swarm` OR `swarm (N)`, not just the pre-matrix bare `swarm`. - `.sandcastle/tests/claim-lib-test.sh`: two new cases — matrix-suffixed names count as alive; a same-issue two-claim race under matrix-suffixed alive runs resolves to exactly one winner (this second case is the direct #541 regression test, confirmed red against the pre-fix filter before the fix landed). - `STATUS.md` updated in the same commit (header + milestone entry). - Filed #588 (`ready-for-agent`) for the identical exact-match blind spot in `schedule-backstop.sh`'s `swarm.yml` in-flight check — out of scope here. **Proof:** - `bash .sandcastle/tests/claim-lib-test.sh` — 28/28 pass (was 26/28 with the two new cases added pre-fix, confirming red-before-green). - Full `.sandcastle/tests/*.sh` sweep (34 suites) — all green on this host. - Live probe of `GET /actions/tasks?limit=100&page=1` on 2026-08-15 confirmed the real API returns `"swarm (1)"`/`"swarm (2)"`, never bare `"swarm"`, matching `swarm.yml`'s `strategy.matrix.worker:[1,2]` (`44fe333`) and explaining why the pre-fix filter always saw zero live runs. Ruling posted above under ADR 0174 (two-way door: revertible commit, provable by the new regression test + the live probe). No credentials, security widening, trust-surface accept, data destruction, or hardware involved. Closing.
ben closed this issue 2026-08-15 09:01:45 +00:00
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#541
No description provided.