sandcastle: schedule-backstop.sh's swarm in-flight check has the same matrix-suffix name-match blind spot as #541 #588

Closed
opened 2026-08-15 08:58:26 +00:00 by ben · 2 comments
Owner

Symptom (follow-up from #541)

While fixing #541 (the multi-host swarm-claim mechanism's claim_alive_runs()
in .sandcastle/claim-lib.sh never matched a live run, because it exact-matched
job name "swarm" while swarm.yml's 2-wide worker matrix
(strategy.matrix.worker:[1,2], landed 44fe333) makes Forgejo name each
matrix job "swarm (1)" / "swarm (2)", never bare "swarm" — live-probed
2026-08-15 against the real /actions/tasks response), I found the identical
exact-match pattern in .sandcastle/schedule-backstop.sh's in-flight check:

inflight="$(printf '%s' "$runs" | jq -r --arg n "$name" --arg c "$cutoff" \
  '[.workflow_runs[]?
     | select(.name == $n)
     | select((.status == "waiting") or (.status == "running") or ((.run_started_at // "") >= $c))
   ] | length')"

schedule-backstop.sh swarm.yml <window> sets name="swarm" — the same
string that never matches a real matrix-suffixed task. The crontab install
(docs/agents/swarm-atlas.md) runs this backstop for swarm.yml, so in
production it can never see a swarm run as "in flight" and may pile on
redundant swarm.yml dispatches within its window even while matrix workers
are already running — a plausible amplifier of #541's race (more concurrent
swarm runs racing the same ready-ticket list).

Likely cause

Same drift as #541: the exact-match filter predates the matrix
(schedule-backstop.sh's select(.name == $n) is unchanged since before
44fe333); schedule-backstop-test.sh only exercises bare "swarm" task
names, so the suite stayed green through the drift.

Suggested direction

Generalize the match the same way #541 fixed claim-lib.sh: select(.name == $n or (.name | test("^" + $n + " \\("))), plus a test case asserting a
matrix-suffixed in-flight run suppresses a redundant dispatch. Left unfixed
in #541 to keep that diff scoped to the reported/proven duplicate-work bug;
this ticket is the tracked follow-up.

Filed by agent session under ADR 0174 while working #541 (ready-for-agent —
mechanical, revertible, provable by an added test case; no one-way door).

## Symptom (follow-up from #541) While fixing #541 (the multi-host swarm-claim mechanism's `claim_alive_runs()` in `.sandcastle/claim-lib.sh` never matched a live run, because it exact-matched job name `"swarm"` while `swarm.yml`'s 2-wide worker matrix (`strategy.matrix.worker:[1,2]`, landed `44fe333`) makes Forgejo name each matrix job `"swarm (1)"` / `"swarm (2)"`, never bare `"swarm"` — live-probed 2026-08-15 against the real `/actions/tasks` response), I found the identical exact-match pattern in `.sandcastle/schedule-backstop.sh`'s in-flight check: ``` inflight="$(printf '%s' "$runs" | jq -r --arg n "$name" --arg c "$cutoff" \ '[.workflow_runs[]? | select(.name == $n) | select((.status == "waiting") or (.status == "running") or ((.run_started_at // "") >= $c)) ] | length')" ``` `schedule-backstop.sh swarm.yml <window>` sets `name="swarm"` — the same string that never matches a real matrix-suffixed task. The crontab install (`docs/agents/swarm-atlas.md`) runs this backstop for `swarm.yml`, so in production it can never see a swarm run as "in flight" and may pile on redundant `swarm.yml` dispatches within its window even while matrix workers are already running — a plausible amplifier of #541's race (more concurrent swarm runs racing the same ready-ticket list). ## Likely cause Same drift as #541: the exact-match filter predates the matrix (`schedule-backstop.sh`'s `select(.name == $n)` is unchanged since before `44fe333`); `schedule-backstop-test.sh` only exercises bare `"swarm"` task names, so the suite stayed green through the drift. ## Suggested direction Generalize the match the same way #541 fixed `claim-lib.sh`: `select(.name == $n or (.name | test("^" + $n + " \\(")))`, plus a test case asserting a matrix-suffixed in-flight run suppresses a redundant dispatch. Left unfixed in #541 to keep that diff scoped to the reported/proven duplicate-work bug; this ticket is the tracked follow-up. Filed by agent session under ADR 0174 while working #541 (ready-for-agent — mechanical, revertible, provable by an added test case; no one-way door).
Author
Owner

This ticket cannot be worked by a Sandcastle swarm agent: both files it changes — .sandcastle/schedule-backstop.sh and .sandcastle/tests/schedule-backstop-test.sh — sit directly under .sandcastle/, a fingerprinted protected directory (PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo" in .sandcastle/protected-paths-lib.sh; not exempt — only *matou-heal-* is). Per #445 / ADR 0174 the swarm worker's before/after tree-fingerprint would roll back any edit here and fail the run loud. A protected .sandcastle/ path needs an interactive session's standing, not a swarm agent.

The bug itself is confirmed real and the ticket's suggested direction is correct:

  • schedule-backstop.sh:70 filters select(.name == $n) — exact-match, blind to swarm.yml's matrix-suffixed job names ("swarm (1)" / "swarm (2)"), the same drift #541 fixed in claim-lib.sh.
  • .sandcastle/tests/schedule-backstop-test.sh has no matrix-suffixed in-flight case, so the drift stayed green.
  • Fix to mirror #541: select(.name == $n or (.name | test("^" + $n + " \\("))), plus a test asserting a matrix-suffixed in-flight run suppresses a redundant dispatch.

Re-arm: this is the same class as its sibling #541 (which is correctly ready-for-session). I am removing ready-for-agent and adding ready-for-session so an interactive session picks it up. No human decision is pending — just the session's standing to edit the machinery.

(swarm run 6859, blocked per ADR 0174 escape path while claimed from the ready-for-agent queue)

This ticket cannot be worked by a Sandcastle swarm agent: both files it changes — `.sandcastle/schedule-backstop.sh` and `.sandcastle/tests/schedule-backstop-test.sh` — sit directly under `.sandcastle/`, a **fingerprinted protected directory** (`PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"` in `.sandcastle/protected-paths-lib.sh`; not exempt — only `*matou-heal-*` is). Per #445 / ADR 0174 the swarm worker's before/after tree-fingerprint would roll back any edit here and fail the run loud. A protected `.sandcastle/` path needs an interactive session's standing, not a swarm agent. The bug itself is confirmed real and the ticket's suggested direction is correct: - `schedule-backstop.sh:70` filters `select(.name == $n)` — exact-match, blind to `swarm.yml`'s matrix-suffixed job names (`"swarm (1)"` / `"swarm (2)"`), the same drift #541 fixed in `claim-lib.sh`. - `.sandcastle/tests/schedule-backstop-test.sh` has **no** matrix-suffixed in-flight case, so the drift stayed green. - Fix to mirror #541: `select(.name == $n or (.name | test("^" + $n + " \\(")))`, plus a test asserting a matrix-suffixed in-flight run suppresses a redundant dispatch. **Re-arm:** this is the same class as its sibling #541 (which is correctly `ready-for-session`). I am removing `ready-for-agent` and adding `ready-for-session` so an interactive session picks it up. No human decision is pending — just the session's standing to edit the machinery. (swarm run 6859, blocked per ADR 0174 escape path while claimed from the ready-for-agent queue)
Author
Owner

Ruled by agent under ADR 0174 — veto anytime. This is a two-way door: a mechanical jq-filter fix mirroring #541's already-accepted claim-lib.sh pattern, revertible by a single commit revert, and provable by an added offline test case (no credentials, no security-posture change, no member-facing trust accept, no data destruction, no non-routine spend).

Close report

Fixed: .sandcastle/schedule-backstop.sh's in-flight check exact-matched select(.name == $n) against name="swarm", so it could never see a real swarm run (Forgejo names matrix jobs "swarm (1)"/"swarm (2)" since 44fe333) as in-flight — a redundant swarm.yml dispatch could pile onto an already-running matrix, a plausible amplifier of #541's race.

Fix: generalized the match the same way #541 fixed claim_alive_runs(): select(.name == $n or (.name | test("^" + $n + " \\("))).

Proof: added a case to .sandcastle/tests/schedule-backstop-test.sh asserting a "swarm (1)" running run suppresses dispatch — reproduced red against the pre-fix filter (via git stash), then green after. Full .sandcastle/tests/*.sh sweep: all 34 suites green.

Commit: b741af8391 (pushed to main)

STATUS.md: updated in the same commit.

advances #588

Ruled by agent under ADR 0174 — veto anytime. This is a two-way door: a mechanical jq-filter fix mirroring #541's already-accepted `claim-lib.sh` pattern, revertible by a single commit revert, and provable by an added offline test case (no credentials, no security-posture change, no member-facing trust accept, no data destruction, no non-routine spend). ## Close report **Fixed:** `.sandcastle/schedule-backstop.sh`'s in-flight check exact-matched `select(.name == $n)` against `name="swarm"`, so it could never see a real swarm run (Forgejo names matrix jobs `"swarm (1)"`/`"swarm (2)"` since `44fe333`) as in-flight — a redundant `swarm.yml` dispatch could pile onto an already-running matrix, a plausible amplifier of #541's race. **Fix:** generalized the match the same way #541 fixed `claim_alive_runs()`: `select(.name == $n or (.name | test("^" + $n + " \\(")))`. **Proof:** added a case to `.sandcastle/tests/schedule-backstop-test.sh` asserting a `"swarm (1)"` running run suppresses dispatch — reproduced red against the pre-fix filter (via `git stash`), then green after. Full `.sandcastle/tests/*.sh` sweep: all 34 suites green. **Commit:** b741af839178cdc00b5eb301a9cb5f1f80fbc9f8 (pushed to `main`) **STATUS.md:** updated in the same commit. advances #588
ben closed this issue 2026-08-15 10:12:54 +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#588
No description provided.