harness: a 5xx from Mattermost reds the whole swarm run — run-swarm.sh:304 is the only unguarded notify call site #1424

Closed
opened 2026-09-12 06:12:15 +00:00 by matou-build-agent · 2 comments

Symptom

Swarm run 22284 died with
an empty verdict error block:

stage=list ready tasks
exit=22
--- error lines ---

…but the host runlog proves the listing succeeded:

2026-09-12T06:06:00Z repo=Matou/idss ready=[1410,1409] reason=died-in:list ready tasks exit=22 duration=33s run=22284 host=bens-mac-04

ready_nums is only assigned after schedule_list_ready_or_verdict returns 0,
and [1410,1409] is non-empty — so the lister worked and two real tickets were
in hand. Compare the genuine listing failure in the same window, which looks
completely different (Matou/dev-factory, 05:57Z): exit=1 with a populated
error line, because schedule_list_ready_or_verdict calls verdict_error and
run-swarm.sh then exit 1s.

Cause

exit=22 is curl -sf's "HTTP response >= 400". Between the successful listing
and the next verdict_stage (provision_env_materialize, provision-lib.sh:54)
there is exactly one curl in the whole path:

# .sandcastle/run-swarm.sh:304
bash "$here/notify-mattermost.sh" ":inbox_tray: **Swarm picking up $n task(s)** in \`$repo_slug\`:
$(jq -r '.[] | "- [#\(.number) \(.title)](\(.url))"' <<<"$ready")"

notify-mattermost.sh is set -euo pipefail and ends in
curl -sf --max-time 30 -X POST … "$MATTERMOST_URL/api/v4/posts", so a 5xx from
the chat front door exits 22 — and that call site is unguarded, so set -e
kills the whole run.

This is the only unguarded notify call site in the harness apart from one
sibling. Every other caller already treats a chat post as best-effort:

call site guard
preflight-lib.sh:31 _preflight_notify || true
report-lib.sh:34 _report_notify || true
execute-lib.sh:59 _execute_notify || true
landing-lib.sh:318 _landing_notify || true
verify-lib.sh:43 _verify_notify || true
heal.sh:302 || true
rehearsal-report.sh:203 || true
session-runner.sh:136 || printf …
scheduler-canary.sh:106 || true
run-swarm.sh:304 none ← this bug
run-triage.sh:317 none ← same latent bug, triage workflow

The .forgejo/workflows/*.yml inline Mattermost posts all carry || true too.

Two consequences, both bad:

  1. A purely informational "Swarm picking up N task(s)" announcement reds a run
    that had claimable work.
    The run never provisioned, never spawned a worker;
    #1410 and #1409 went unworked for that tick.
  2. The verdict is mis-keyed with an empty error block. VERDICT_STAGE is
    still the stale "list ready tasks" (nothing re-keys it between the listing
    and provision_env_materialize) and verdict_stage cleared VERDICT_ERROR,
    so verdict_write emits nothing. The healer keys its signature on a stage
    that succeeded. This is GOTCHAS #7's implicit-set -e sibling one hop
    later than #52 fixed, and the same shape as the preflight case at GOTCHAS
    line 6989.

Trigger: the matou.nz front door was 5xx-ing in that window — the healer's
probe recorded api_seconds=26, workflow_runs came back empty, and manual
probes at 06:1xZ returned 502/503 three-for-three on git.matou.nz
(recovered to 200 by 06:2xZ). Three repos recorded died-in:list ready tasks
in the same window (Matou/coa, Matou/dev-factory, Matou/idss). The outage
is transient and self-heals; the unguarded notify is the durable defect that
turned it into a red instead of a shrug.

Fix

  1. Guard the call — the settled idiom used by all nine other call sites:
    bash "$here/notify-mattermost.sh" "…" || true
    
    at run-swarm.sh:304 and run-triage.sh:317.
  2. Consider re-keying the stage: either verdict_stage "notify + provision"
    right after the listing, or have the (now non-fatal) notify not leave the
    stale stage standing — so the next fault in that window is not attributed to
    a stage that passed.

Where the fix goes

run-swarm.sh and run-triage.sh are factory-vendored
(.sandcastle/FACTORY_MANIFEST lines 54 / ‹run-triage.sh›, pin
FACTORY_REF=26f142c). Verified: git show 26f142c:run-swarm.sh in
Matou/dev-factory has the identical unguarded line 304 — this is an upstream
defect, not local drift. A hand-edit here would trip check-harness-drift.sh
(the #932 pre-push drift gate) and red every subsequent run.

So: fix upstream in Matou/dev-factory, then bump FACTORY_REF and re-vendor —
the pattern of 6e26d903, 9d5bd2b0, 8734b3a1. All four consumers
(idss, matou-app, coa, matou-website) carry the bug.

Acceptance

  • run-swarm.sh / run-triage.sh survive a Mattermost POST that returns 5xx:
    the run logs the failed notice and proceeds to provision/execute.
  • A factory unit test pins it (shim NOTIFY to a script that exit 22s, assert
    the run continues) — .sandcastle/tests/ already has the shim seams
    (EXECUTE_NOTIFY, REPORT_NOTIFY, …) for exactly this.
  • FACTORY_REF bumped in Matou/idss; bash .sandcastle/check-harness-drift.sh
    green.

Filed by the swarm healer — incident signature a64670d097e9, heal run
heal-Matou-idss-1789193216-2342186, evidence
/tmp/matou-heal-Matou-idss.8dal9L on bens-mac-04.

## Symptom Swarm run [22284](https://git.matou.nz/Matou/idss/actions/runs/22284) died with an **empty** verdict error block: ``` stage=list ready tasks exit=22 --- error lines --- ``` …but the host runlog proves the listing **succeeded**: ``` 2026-09-12T06:06:00Z repo=Matou/idss ready=[1410,1409] reason=died-in:list ready tasks exit=22 duration=33s run=22284 host=bens-mac-04 ``` `ready_nums` is only assigned *after* `schedule_list_ready_or_verdict` returns 0, and `[1410,1409]` is non-empty — so the lister worked and two real tickets were in hand. Compare the genuine listing failure in the same window, which looks completely different (`Matou/dev-factory`, 05:57Z): `exit=1` with a populated error line, because `schedule_list_ready_or_verdict` calls `verdict_error` and `run-swarm.sh` then `exit 1`s. ## Cause `exit=22` is `curl -sf`'s "HTTP response >= 400". Between the successful listing and the next `verdict_stage` (`provision_env_materialize`, `provision-lib.sh:54`) there is **exactly one** curl in the whole path: ```sh # .sandcastle/run-swarm.sh:304 bash "$here/notify-mattermost.sh" ":inbox_tray: **Swarm picking up $n task(s)** in \`$repo_slug\`: $(jq -r '.[] | "- [#\(.number) \(.title)](\(.url))"' <<<"$ready")" ``` `notify-mattermost.sh` is `set -euo pipefail` and ends in `curl -sf --max-time 30 -X POST … "$MATTERMOST_URL/api/v4/posts"`, so a 5xx from the chat front door exits 22 — and that call site is **unguarded**, so `set -e` kills the whole run. This is the *only* unguarded notify call site in the harness apart from one sibling. Every other caller already treats a chat post as best-effort: | call site | guard | | --- | --- | | `preflight-lib.sh:31` `_preflight_notify` | `\|\| true` | | `report-lib.sh:34` `_report_notify` | `\|\| true` | | `execute-lib.sh:59` `_execute_notify` | `\|\| true` | | `landing-lib.sh:318` `_landing_notify` | `\|\| true` | | `verify-lib.sh:43` `_verify_notify` | `\|\| true` | | `heal.sh:302` | `\|\| true` | | `rehearsal-report.sh:203` | `\|\| true` | | `session-runner.sh:136` | `\|\| printf …` | | `scheduler-canary.sh:106` | `\|\| true` | | **`run-swarm.sh:304`** | **none** ← this bug | | **`run-triage.sh:317`** | **none** ← same latent bug, triage workflow | The `.forgejo/workflows/*.yml` inline Mattermost posts all carry `|| true` too. Two consequences, both bad: 1. **A purely informational "Swarm picking up N task(s)" announcement reds a run that had claimable work.** The run never provisioned, never spawned a worker; #1410 and #1409 went unworked for that tick. 2. **The verdict is mis-keyed with an empty error block.** `VERDICT_STAGE` is still the stale `"list ready tasks"` (nothing re-keys it between the listing and `provision_env_materialize`) and `verdict_stage` cleared `VERDICT_ERROR`, so `verdict_write` emits nothing. The healer keys its signature on a stage that *succeeded*. This is GOTCHAS #7's implicit-`set -e` sibling one hop later than #52 fixed, and the same shape as the preflight case at GOTCHAS line 6989. **Trigger:** the matou.nz front door was 5xx-ing in that window — the healer's probe recorded `api_seconds=26`, `workflow_runs` came back empty, and manual probes at 06:1xZ returned `502`/`503` three-for-three on `git.matou.nz` (recovered to 200 by 06:2xZ). Three repos recorded `died-in:list ready tasks` in the same window (`Matou/coa`, `Matou/dev-factory`, `Matou/idss`). The outage is transient and self-heals; the *unguarded notify* is the durable defect that turned it into a red instead of a shrug. ## Fix 1. Guard the call — the settled idiom used by all nine other call sites: ```sh bash "$here/notify-mattermost.sh" "…" || true ``` at `run-swarm.sh:304` **and** `run-triage.sh:317`. 2. Consider re-keying the stage: either `verdict_stage "notify + provision"` right after the listing, or have the (now non-fatal) notify not leave the stale stage standing — so the next fault in that window is not attributed to a stage that passed. ### Where the fix goes `run-swarm.sh` and `run-triage.sh` are **factory-vendored** (`.sandcastle/FACTORY_MANIFEST` lines 54 / ‹run-triage.sh›, pin `FACTORY_REF=26f142c`). Verified: `git show 26f142c:run-swarm.sh` in `Matou/dev-factory` has the identical unguarded line 304 — this is an upstream defect, not local drift. A hand-edit here would trip `check-harness-drift.sh` (the #932 pre-push drift gate) and red every subsequent run. So: fix upstream in `Matou/dev-factory`, then bump `FACTORY_REF` and re-vendor — the pattern of 6e26d903, 9d5bd2b0, 8734b3a1. **All four consumers** (`idss`, `matou-app`, `coa`, `matou-website`) carry the bug. ## Acceptance - `run-swarm.sh` / `run-triage.sh` survive a Mattermost POST that returns 5xx: the run logs the failed notice and proceeds to provision/execute. - A factory unit test pins it (shim `NOTIFY` to a script that `exit 22`s, assert the run continues) — `.sandcastle/tests/` already has the shim seams (`EXECUTE_NOTIFY`, `REPORT_NOTIFY`, …) for exactly this. - `FACTORY_REF` bumped in `Matou/idss`; `bash .sandcastle/check-harness-drift.sh` green. --- *Filed by the swarm healer — incident signature `a64670d097e9`, heal run `heal-Matou-idss-1789193216-2342186`, evidence `/tmp/matou-heal-Matou-idss.8dal9L` on `bens-mac-04`.*
Author
Member

Blocked for a sandcastle worker — needs ready-for-session

This ticket is entirely a change to protected .sandcastle/ machinery, so a sandcastle swarm worker cannot implement it (this is the fifth consecutive claim — runs 22291, 22287, 22303, 22305, 22323 — all looping because there is nothing here a worker is permitted to touch).

Why it cannot be done by a worker:

  • The two unguarded call sites are .sandcastle/run-swarm.sh:304 and .sandcastle/run-triage.sh:317. .sandcastle/ is a fingerprinted protected root (protected-paths-lib.sh, PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo", #445): any edit is fingerprinted, rolled back, and reds the run.
  • Both files are factory-vendored byte-identical from Matou/dev-factory at FACTORY_REF (.sandcastle/FACTORY_MANIFEST). As the ticket itself notes, a hand-edit trips check-harness-drift.sh (the #932 pre-push drift gate). The real fix must go upstream in Matou/dev-factory, then FACTORY_REF bumped and re-vendored — an upstream repo not reachable from the worker sandbox.

This is precisely the escape path spelled out verbatim in protected-paths-lib.sh (PP_ESCAPE_PATH) and rule 9 / ADR 0174 / #445: a protected .sandcastle/ machinery change needs an interactive session's standing (a session escalates to ready-for-human itself only if it finds a genuine one-way door). The fix here is a two-way door (a || true guard + a factory unit test), so it is a session's call, not Ben's.

What a session must do (already fully specified in the issue body)

  1. In Matou/dev-factory: guard both notify call sites with the settled || true idiom (run-swarm.sh:304, run-triage.sh:317), and optionally re-key VERDICT_STAGE after the listing so a later fault in the same window is not mis-attributed to a stage that passed.
  2. Add the pinning factory unit test (shim NOTIFY to exit 22, assert the run proceeds — the .sandcastle/tests/ shim seams already exist).
  3. Bump FACTORY_REF and re-vendor into all four consumers (idss, matou-app, coa, matou-website); confirm bash .sandcastle/check-harness-drift.sh green — the pattern of 6e26d903 / 9d5bd2b0 / 8734b3a1.

Relabelling ready-for-agent → ready-for-session so it stops re-entering the swarm queue.

## Blocked for a sandcastle worker — needs `ready-for-session` This ticket is **entirely a change to protected `.sandcastle/` machinery**, so a sandcastle swarm worker cannot implement it (this is the fifth consecutive claim — runs 22291, 22287, 22303, 22305, 22323 — all looping because there is nothing here a worker is permitted to touch). Why it cannot be done by a worker: - The two unguarded call sites are `.sandcastle/run-swarm.sh:304` and `.sandcastle/run-triage.sh:317`. `.sandcastle/` is a **fingerprinted protected root** (`protected-paths-lib.sh`, `PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"`, #445): any edit is fingerprinted, **rolled back, and reds the run**. - Both files are **factory-vendored** byte-identical from `Matou/dev-factory` at `FACTORY_REF` (`.sandcastle/FACTORY_MANIFEST`). As the ticket itself notes, a hand-edit trips `check-harness-drift.sh` (the #932 pre-push drift gate). The real fix must go **upstream in `Matou/dev-factory`**, then `FACTORY_REF` bumped and re-vendored — an upstream repo not reachable from the worker sandbox. This is precisely the escape path spelled out verbatim in `protected-paths-lib.sh` (`PP_ESCAPE_PATH`) and rule 9 / ADR 0174 / #445: a protected `.sandcastle/` machinery change **needs an interactive session's standing** (a session escalates to `ready-for-human` itself only if it finds a genuine one-way door). The fix here is a two-way door (a `|| true` guard + a factory unit test), so it is a session's call, not Ben's. ### What a session must do (already fully specified in the issue body) 1. In `Matou/dev-factory`: guard both notify call sites with the settled `|| true` idiom (`run-swarm.sh:304`, `run-triage.sh:317`), and optionally re-key `VERDICT_STAGE` after the listing so a later fault in the same window is not mis-attributed to a stage that passed. 2. Add the pinning factory unit test (shim `NOTIFY` to `exit 22`, assert the run proceeds — the `.sandcastle/tests/` shim seams already exist). 3. Bump `FACTORY_REF` and re-vendor into all four consumers (`idss`, `matou-app`, `coa`, `matou-website`); confirm `bash .sandcastle/check-harness-drift.sh` green — the pattern of 6e26d903 / 9d5bd2b0 / 8734b3a1. Relabelling `ready-for-agent` → `ready-for-session` so it stops re-entering the swarm queue.
Author
Member

Close report — landed & proven (ADR 0174)

Ruled by agent under ADR 0174 — veto anytime. A two-way door: a revertible best-effort guard + verdict re-key on a vendored harness script, plus a FACTORY_REF pin bump — proven red-before-green offline, no security-posture or credential change. The notify is informational, so losing it must cost nothing.

What landed

The two unguarded notify call sites are now best-effort, matching all nine siblings:

  • run-swarm.sh — the "Swarm picking up N task(s)" post is guarded || true, and the stage is re-keyed verdict_stage "notify + provision" before the post (nothing re-keyed it between the listing and provision, so a fault in that window was mis-attributed to the list ready tasks stage that had passed, with VERDICT_ERROR cleared → the empty error block this ticket opened on).
  • run-triage.sh — the "Triage needs you" digest post is guarded || true. It already keyed "human-gate digest + notify" before the post, so it needed only the guard.
  • Both posts take a SWARM_NOTIFY / TRIAGE_NOTIFY env seam (the EXECUTE_NOTIFY/REPORT_NOTIFY pattern) so a 5xx post is shim-able offline.

Where it landed (factory-vendored, as the ticket called out)

run-swarm.sh / run-triage.sh are FACTORY_MANIFEST-vendored — a hand-edit here would trip the #932 drift gate. So the fix landed upstream in Matou/dev-factory (72496a4) and was re-vendored:

  • dev-factory commit 72496a4 — guard + re-key + seams + tests; dev-factory GOTCHAS 56.
  • idss commit 1f116eb0 — FACTORY_REF 26f96ce → 72496a4, re-vendored byte-identical; bash .sandcastle/check-harness-drift.sh OK; STATUS.md updated.

The bump also adopts the intervening dev-factory #142 / #1425 / #1426 (all offline-test-green), exactly as prior re-vendors did.

Proof (acceptance)

  • New test tests/run-swarm-notify-guard-test.sh (2 scenarios, a symlink-farm whole-script run):
    1. a notify shimmed to exit 22 → the run reaches provision at exit 0, no verdict (the guard);
    2. a subsequent provision fault → the verdict names notify + provision, never the stale list ready tasks (the re-key).
  • tests/run-triage-test.sh gains a #1424 scenario: a 5xx digest post leaves the tick green (exit 0).
  • Both are red against the pre-fix files, and the guard is isolated (they still red with the seam present but || true removed). Full dev-factory offline suite green (80 files). Affected idss vendored tests re-run green post-vendor.

Follow-up filed (not this ticket)

The pin bump adopted dev-factory's run-swarm-ready-list-test.sh, which has a pre-existing flaky race in its curl-shim countdown file (a concurrent 503→200 flip). It is inert in idss (idss does not run .sandcastle/tests/ in CI; only the pre-push drift gate). Filed upstream as Matou/dev-factory#144.

Closing: work landed and proven.

## Close report — landed & proven (ADR 0174) **Ruled by agent under ADR 0174 — veto anytime.** A two-way door: a revertible best-effort guard + verdict re-key on a vendored harness script, plus a FACTORY_REF pin bump — proven red-before-green offline, no security-posture or credential change. The notify is *informational*, so losing it must cost nothing. ### What landed The two unguarded notify call sites are now best-effort, matching all nine siblings: - **`run-swarm.sh`** — the "Swarm picking up N task(s)" post is guarded `|| true`, **and** the stage is re-keyed `verdict_stage "notify + provision"` *before* the post (nothing re-keyed it between the listing and provision, so a fault in that window was mis-attributed to the `list ready tasks` stage that had **passed**, with `VERDICT_ERROR` cleared → the empty error block this ticket opened on). - **`run-triage.sh`** — the "Triage needs you" digest post is guarded `|| true`. It already keyed `"human-gate digest + notify"` before the post, so it needed only the guard. - Both posts take a `SWARM_NOTIFY` / `TRIAGE_NOTIFY` env seam (the `EXECUTE_NOTIFY`/`REPORT_NOTIFY` pattern) so a 5xx post is shim-able offline. ### Where it landed (factory-vendored, as the ticket called out) `run-swarm.sh` / `run-triage.sh` are FACTORY_MANIFEST-vendored — a hand-edit here would trip the #932 drift gate. So the fix landed **upstream in `Matou/dev-factory`** (`72496a4`) and was **re-vendored**: - dev-factory commit `72496a4` — guard + re-key + seams + tests; dev-factory GOTCHAS **56**. - idss commit **`1f116eb0`** — `FACTORY_REF 26f96ce → 72496a4`, re-vendored byte-identical; `bash .sandcastle/check-harness-drift.sh` **OK**; STATUS.md updated. The bump also adopts the intervening dev-factory **#142 / #1425 / #1426** (all offline-test-green), exactly as prior re-vendors did. ### Proof (acceptance) - **New test `tests/run-swarm-notify-guard-test.sh`** (2 scenarios, a symlink-farm whole-script run): 1. a notify shimmed to `exit 22` → the run **reaches provision at exit 0**, no verdict (the guard); 2. a subsequent provision fault → the verdict names **`notify + provision`**, never the stale `list ready tasks` (the re-key). - **`tests/run-triage-test.sh`** gains a `#1424` scenario: a 5xx digest post leaves the tick **green** (exit 0). - Both are **red against the pre-fix files**, and the guard is isolated (they still red with the seam present but `|| true` removed). Full dev-factory offline suite green (80 files). Affected idss vendored tests re-run green post-vendor. ### Follow-up filed (not this ticket) The pin bump adopted dev-factory's `run-swarm-ready-list-test.sh`, which has a **pre-existing flaky race** in its curl-shim countdown file (a concurrent 503→200 flip). It is **inert in idss** (idss does not run `.sandcastle/tests/` in CI; only the pre-push drift gate). Filed upstream as **Matou/dev-factory#144**. Closing: work landed and proven.
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#1424
No description provided.