harness: a transient Forgejo 5xx reds the whole swarm tick as preflight-red (the #20 probe has no retry), and the empty verdict error block sends the healer chasing a guard that never broke #1359

Closed
opened 2026-09-09 21:54:14 +00:00 by matou-build-agent · 2 comments

Symptom

Swarm run 20865 (Matou/idss, 2026-09-09T21:46:04Z) died after 7 seconds with reason=preflight-red exit=1 (~/swarm/logs/run-swarm-verdicts.log), and left the healer a verdict of exactly this:

stage=preflight self-tests (#446)
exit=1
--- error lines ---

Nothing under the marker. No worker log for the window, empty runner journal. The healer signature keyed on the bare stage name, so the incident read as "a silent-failure guard has rotted" — when nothing in the harness had changed.

Root cause — two independent gaps, stacked

1. Preflight's one live network call has no retry and fails CLOSED.
Forgejo was 5xx-ing at that minute. The sibling Matou/matou-app verdict written in the same minute is:

stage=git-setup (clone/fetch/checkout/reset)
exit=128
--- error lines ---
fatal: unable to access 'https://git.matou.nz/Matou/matou-app.git/': The requested URL returned error: 503

and the healer's own probe recorded api_seconds=timeout with an empty workflow_runs list.

guard_issue_write_permission (#20) is preflight's only live call — forgejo_issue_write_probe → forgejo_get "" — and _forgejo_get is a bare curl -sf --max-time 30 with no retry, unlike list-ready-tasks.sh:api(), which was given exactly this posture by #52 for exactly this reason. One 503 returned instantly, the guard reported "cannot confirm the bot can write issues", preflight failed closed, and the tick was gone in 7s.

Forgejo answered 200 in 0.9s by the time the healer probed, and preflight-swarm.sh run live against the same token is green (issue_write_permission OK, all 10 guards fired). Nothing was ever wrong with the bot's permissions — the probe reported a permission verdict it never actually read.

2. preflight_gate never records the failing guard as the verdict's error line.
The guard FATALs to stderr, not to an errlog file — the #9 case verdict_error exists to close. preflight_gate prints the PREFLIGHT RED line to the job log and to Mattermost but never calls verdict_error, so verdict_write emits an empty --- error lines --- block and the healer keys on the bare stage. That is what burned this investigation.

Fix (written and verified, needs landing)

Both files are vendored from Matou/dev-factory (FACTORY_MANIFEST), so the healer could not land this itself — it must go to the factory root source and then be re-vendored (ADR 0180). The patch below is byte-clean against factory root 4d7b1af and applies with git apply.

  • forgejo-lib.sh — forgejo_issue_write_probe retries with exponential backoff (FORGEJO_PROBE_RETRIES=3, FORGEJO_PROBE_BACKOFF=2, each attempt bounded by _forgejo_get's --max-time; #52's posture). A sustained outage still fails closed, but says TRANSPORT, not a permission verdict (the bot's write access was never read) instead of "the bot has no write access".
  • preflight-lib.sh — preflight_gate records the PREFLIGHT RED line(s) via verdict_error before returning, so the verdict, the runlog and the healer signature all name the failing guard. A red with no PREFLIGHT RED line still leaves a non-empty line.
  • Tests: 5 new pins in tests/forgejo-lib-test.sh (rides out a transient 5xx; a sustained outage is named TRANSPORT; never claims lost write access; the probe demonstrably retried) and 2 in tests/preflight-lib-test.sh.

Red-before-green confirmed: on unpatched code the new pins fail —
forgejo-lib: 55 passed, 3 failed and FAIL: the gate must record the failing guard as the verdict's error line, got ''.

Green after, in the factory tree: preflight-lib 9 groups, forgejo-lib 58/0, preflight-swarm 6 scenarios, run-swarm-stages 10 groups. Also green in an idss clone: preflight-triage, run-swarm-ready-list, run-swarm-cold-store, provision-lib, policy-lib, claim-lib, close-report-lib, landing-lib, heal-lib.

Landing steps

  1. Apply the patch to the root source in Matou/dev-factory (forgejo-lib.sh, preflight-lib.sh, tests/forgejo-lib-test.sh, tests/preflight-lib-test.sh) and push there.
  2. Re-vendor into Matou/idss: bump .sandcastle/FACTORY_REF (51c8dc66 → new factory SHA) and re-vendor the manifest set. Note idss is currently one factory commit behind (4d7b1af, the rehearsal-heal de-numbering), which the bump will also carry in.
  3. Append GOTCHAS #217 (draft text below) in the same commit as the idss re-vendor.

Patch

diff --git a/forgejo-lib.sh b/forgejo-lib.sh
index 1ba371fc..09abea94 100644
--- a/forgejo-lib.sh
+++ b/forgejo-lib.sh
@@ -217,6 +217,17 @@ forgejo_repo_default_merge_style() { # forgejo_repo_default_merge_style -> the r
   esac
 }
 
+# Transient-5xx posture for the #20 probe, matching list-ready-tasks.sh's api()
+# (#52): the probe is preflight's ONE live network call and preflight fails
+# CLOSED, so a brief Forgejo blip used to red the whole tick — 7 seconds in,
+# with the run reported as `preflight-red` as if the bot had lost its write
+# access (run 20865, 2026-09-09T21:46Z, GOTCHAS #217). Retry with exponential
+# backoff, each attempt bounded by _forgejo_get's `--max-time`. A sustained
+# outage still exhausts the attempts and reds, but names TRANSPORT, never a
+# permission verdict it never actually read.
+FORGEJO_PROBE_RETRIES="${FORGEJO_PROBE_RETRIES:-3}"
+FORGEJO_PROBE_BACKOFF="${FORGEJO_PROBE_BACKOFF:-2}"
+
 forgejo_issue_write_probe() { # forgejo_issue_write_probe -> rc 0 if the bot has repo write; LOUD + rc 1 otherwise (#20)
   # Zero-token preflight probe: GET the repo root with the bot token and assert
   # the caller's `permissions` block grants write. #19 looked like four
@@ -228,10 +239,17 @@ forgejo_issue_write_probe() { # forgejo_issue_write_probe -> rc 0 if the bot has
   # deeper — close-report.sh closes-then-verifies and claim_mark_working pages
   # on a 403 label write — so the three layers together never again read a
   # permission gap as a clean close.
-  local resp push
-  resp="$(forgejo_get "")" || {
-    echo "forgejo: repo probe GET failed — cannot confirm the bot can write issues on $(forgejo_repo_slug)"
-    return 1; }
+  local resp push attempt=1 delay="$FORGEJO_PROBE_BACKOFF"
+  while :; do
+    resp="$(forgejo_get "")" && break
+    if [ "$attempt" -ge "$FORGEJO_PROBE_RETRIES" ]; then
+      echo "forgejo: repo probe GET failed after $attempt attempt(s) — $(forgejo_repo_slug) is unreachable or 5xx-ing; this is TRANSPORT, not a permission verdict (the bot's write access was never read)"
+      return 1
+    fi
+    sleep "$delay"
+    delay=$((delay * 2))
+    attempt=$((attempt + 1))
+  done
   push="$(jq -r '.permissions.push // false' <<<"$resp" 2>/dev/null)"
   [ "$push" = "true" ] && return 0
   echo "forgejo: the bot has no write access (permissions.push=$push) on $(forgejo_repo_slug) — issue label/state writes will 403 (the machines team needs repo.issues + repo.pulls write, not just repo.code)"
diff --git a/preflight-lib.sh b/preflight-lib.sh
index 0cdc6546..ec33fabe 100644
--- a/preflight-lib.sh
+++ b/preflight-lib.sh
@@ -34,16 +34,24 @@ _preflight_notify() { bash "$PREFLIGHT_NOTIFY" "$1" || true; }
 # when a guard did not fire on its fixture; the captured output is printed either
 # way so a green preflight is still visible in the job log.
 preflight_gate() {
-  local repo_slug="$1" out
+  local repo_slug="$1" out red
   verdict_stage "preflight self-tests (#446)"
   if out="$(bash "$PREFLIGHT_SCRIPT" 2>&1)"; then
     printf '%s\n' "$out"
     return 0
   fi
   printf '%s\n' "$out"
+  red="$(printf '%s\n' "$out" | grep 'PREFLIGHT RED' | head -20 || true)"
+  # #9: the guard FATALs to stderr, never to an errlog file, so without this the
+  # verdict's `--- error lines ---` block is EMPTY and the healer keys its
+  # signature on the bare stage name — which is exactly what run 20865 handed it
+  # (a whole investigation off `stage=preflight self-tests (#446) exit=1` with
+  # nothing under it, GOTCHAS #217). Record the failing guard line(s) so the
+  # verdict, the runlog and the healer all name the cause.
+  verdict_error "$(printf '%s' "${red:-preflight-swarm.sh exited non-zero without a PREFLIGHT RED line}" | tr '\n' ' ')"
   _preflight_notify ":rotating_light: **Swarm preflight RED** in \`$repo_slug\` — a silent-failure guard did not fire on its fixture; NO worker was spawned. Fix before the swarm can run:
 \`\`\`
-$(printf '%s\n' "$out" | grep 'PREFLIGHT RED' | head -20)
+$red
 \`\`\`"
   SWARM_EXIT_REASON="preflight-red"
   return 1
diff --git a/tests/forgejo-lib-test.sh b/tests/forgejo-lib-test.sh
index b163c1db..3d367d6a 100644
--- a/tests/forgejo-lib-test.sh
+++ b/tests/forgejo-lib-test.sh
@@ -85,6 +85,15 @@ case "$url" in
     echo '{"number":101,"head":{"ref":"agent/issue-7"}}'
     ;;
   */repos/Matou/idss)   # repo-root GET — #20 write probe + #15 default_merge_style
+    # PROBE_FAILS_N: 5xx the first N calls (the #52 transient posture, GOTCHAS
+    # #217). The counter is a file so it survives the probe's retry subshells.
+    if [ -n "${PROBE_FAIL_COUNTER:-}" ]; then
+      n="$(cat "$PROBE_FAIL_COUNTER" 2>/dev/null || echo 0)"
+      if [ "$n" -lt "${PROBE_FAILS_N:-0}" ]; then
+        echo $((n + 1)) > "$PROBE_FAIL_COUNTER"
+        exit 22
+      fi
+    fi
     echo "{\"permissions\":{\"push\":${PROBE_PUSH:-true}},\"default_merge_style\":\"${MERGE_STYLE:-merge}\"}"
     ;;
   *)
@@ -259,6 +268,27 @@ probe_out="$( ( export PROBE_PUSH=false; forgejo_issue_write_probe ) 2>&1 || tru
 check "issue-write probe names the missing write access" \
   'grep -q "no write access" <<<"$probe_out"'
 
+# GOTCHAS #217 (run 20865): preflight's ONE live network call fails CLOSED, so a
+# transient Forgejo 5xx used to red the whole tick as `preflight-red` — reported
+# as if the bot had lost its write access. Retry with backoff (list-ready-tasks'
+# #52 posture); a sustained outage still reds, but names TRANSPORT.
+export PROBE_FAIL_COUNTER="$tmp/probe-fails"
+export FORGEJO_PROBE_BACKOFF=0
+: > "$PROBE_FAIL_COUNTER"
+check "issue-write probe rides out a transient 5xx and still reads the permission" \
+  '( export PROBE_FAILS_N=2 PROBE_PUSH=true; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe >/dev/null )'
+: > "$PROBE_FAIL_COUNTER"
+check "issue-write probe reds on a SUSTAINED outage" \
+  '! ( export PROBE_FAILS_N=99; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe >/dev/null 2>&1 )'
+outage_out="$( ( export PROBE_FAILS_N=99; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe ) 2>&1 || true )"
+check "a sustained outage is named TRANSPORT, never a permission verdict" \
+  'grep -q "TRANSPORT, not a permission verdict" <<<"$outage_out"'
+check "a sustained outage does NOT claim the bot lost write access" \
+  '! grep -q "no write access" <<<"$outage_out"'
+check "the probe actually retried before ruling" \
+  '[ "$(cat "$PROBE_FAIL_COUNTER")" -ge 3 ]'
+unset PROBE_FAIL_COUNTER FORGEJO_PROBE_BACKOFF
+
 # forgejo_label_applied_at (#99): the LATEST label-ADD timestamp from the issue
 # timeline, ignoring removes and earlier adds; empty for a label never added.
 timeline="$tmp/timeline.json"
diff --git a/tests/preflight-lib-test.sh b/tests/preflight-lib-test.sh
index 5afb34eb..c4c5b3ec 100644
--- a/tests/preflight-lib-test.sh
+++ b/tests/preflight-lib-test.sh
@@ -80,6 +80,24 @@ grep -q 'PREFLIGHT RED' <<<"$out" || fail "the failing guard must reach the job
 grep -q 'Swarm preflight RED' "$NOTIFY_LOG" || fail "a red preflight must alarm: $(cat "$NOTIFY_LOG")"
 grep -q 'healer signature rails' "$NOTIFY_LOG" || fail "the alarm must name the failing guard, not just say 'red'"
 grep -q 'NO worker was spawned' "$NOTIFY_LOG" || fail "the alarm must say nothing was started"
+# #9 / GOTCHAS #217: the guard FATALs to stderr, so the verdict's error block is
+# empty unless the gate records the line — run 20865 handed the healer a bare
+# `stage=preflight self-tests (#446) exit=1` with NOTHING under it.
+grep -q 'healer signature rails' <<<"${VERDICT_ERROR:-}" \
+  || fail "the gate must record the failing guard as the verdict's error line, got '${VERDICT_ERROR:-}'"
+pass=$((pass+1))
+
+# A red with NO `PREFLIGHT RED` line still must not leave an empty error block.
+: > "$NOTIFY_LOG"; SWARM_EXIT_REASON=""
+cat > "$tmp/preflight-mute" <<'SH'
+#!/usr/bin/env bash
+exit 1
+SH
+chmod +x "$tmp/preflight-mute"
+RC=0
+PREFLIGHT_SCRIPT="$tmp/preflight-mute" preflight_gate Acme/widget >"$tmp/pf.out" 2>&1 || RC=$?
+[ "$RC" = 1 ] || fail "a mute red preflight must still abort, got $RC"
+[ -n "${VERDICT_ERROR:-}" ] || fail "a mute red must still leave the healer a non-empty error line"
 pass=$((pass+1))
 
 # ── 2. the policy gate (#12, ADR 0002) ────────────────────────────────────

GOTCHAS #217 draft

217. ⭐⭐ Preflight's ONE live network call fails CLOSED with no retry, so a transient Forgejo 5xx reds the whole swarm tick as preflight-red — and because the guard FATALs to stderr, the verdict's error block is EMPTY and the healer keys a full investigation on a bare stage name

Symptom: swarm run 20865 (Matou/idss, 2026-09-09T21:46:04Z) died after 7 seconds with reason=preflight-red exit=1 (~/swarm/logs/run-swarm-verdicts.log) and a verdict of exactly three useful bytes:

stage=preflight self-tests (#446)
exit=1
--- error lines ---

Nothing under the marker. No worker log for the window, no runner journal. The healer signature keyed on the bare stage, so the incident read as "a silent-failure guard broke" — a guard rot alarm — when nothing in the harness had changed.

Cause: two independent gaps stacked. (1) Forgejo was 5xx-ing at that minute — the sibling Matou/matou-app verdict written in the SAME minute is fatal: unable to access 'https://git.matou.nz/Matou/matou-app.git/': The requested URL returned error: 503, and the healer's own probe recorded api_seconds=timeout with an empty workflow_runs list. guard_issue_write_permission is preflight's only live call (forgejo_issue_write_probe → forgejo_get ""), and _forgejo_get is a bare curl -sf --max-time 30 with no retry — unlike list-ready-tasks.sh:api(), which was given exactly this posture by #52 for exactly this reason. One 503 returned instantly, the guard reported "cannot confirm the bot can write issues", preflight failed closed, and the tick was gone in 7 s. (2) preflight_gate printed the PREFLIGHT RED line to the job log and to Mattermost but never called verdict_error, and the guard FATALs to stderr rather than to an errlog file — the #9 case verdict_error exists to close. So verdict_write emitted an empty --- error lines --- block. Forgejo answered 200 in 0.9 s by the time the healer probed, and the issue_write_permission guard passes live against the same token: nothing was ever wrong with the bot's permissions.

Rule: a probe that cannot reach the server has not obtained a verdict — it must never be reported as the verdict it was asking about. forgejo_issue_write_probe now retries with exponential backoff (FORGEJO_PROBE_RETRIES=3, FORGEJO_PROBE_BACKOFF=2, each attempt bounded by _forgejo_get's --max-time — #52's posture), and a sustained outage still fails closed but says TRANSPORT, not a permission verdict (the bot's write access was never read) instead of "the bot has no write access". Separately, every fail-closed gate whose guard FATALs to stderr must record that line with verdict_error before it returns: preflight_gate does, so the verdict, the runlog and the healer signature all name the failing guard. An empty --- error lines --- block under a named stage is not a diagnosis — it is a wasted investigation. Pinned by tests/forgejo-lib-test.sh (rides out a transient 5xx; a sustained outage is named TRANSPORT and never claims lost write access; the probe demonstrably retried) and tests/preflight-lib-test.sh (the gate records the failing guard, and a red with no PREFLIGHT RED line still leaves a non-empty error line).

## Symptom Swarm run [20865](https://git.matou.nz/Matou/idss/actions/runs/20865) (`Matou/idss`, 2026-09-09T21:46:04Z) died after **7 seconds** with `reason=preflight-red exit=1` (`~/swarm/logs/run-swarm-verdicts.log`), and left the healer a verdict of exactly this: ``` stage=preflight self-tests (#446) exit=1 --- error lines --- ``` Nothing under the marker. No worker log for the window, empty runner journal. The healer signature keyed on the bare stage name, so the incident read as "a silent-failure guard has rotted" — when nothing in the harness had changed. ## Root cause — two independent gaps, stacked **1. Preflight's one live network call has no retry and fails CLOSED.** Forgejo was 5xx-ing at that minute. The sibling `Matou/matou-app` verdict written in the *same minute* is: ``` stage=git-setup (clone/fetch/checkout/reset) exit=128 --- error lines --- fatal: unable to access 'https://git.matou.nz/Matou/matou-app.git/': The requested URL returned error: 503 ``` and the healer's own probe recorded `api_seconds=timeout` with an empty `workflow_runs` list. `guard_issue_write_permission` (#20) is preflight's **only** live call — `forgejo_issue_write_probe` → `forgejo_get ""` — and `_forgejo_get` is a bare `curl -sf --max-time 30` with **no retry**, unlike `list-ready-tasks.sh:api()`, which was given exactly this posture by #52 for exactly this reason. One 503 returned instantly, the guard reported "cannot confirm the bot can write issues", preflight failed closed, and the tick was gone in 7s. Forgejo answered 200 in 0.9s by the time the healer probed, and `preflight-swarm.sh` run live against the same token is green (`issue_write_permission OK`, all 10 guards fired). **Nothing was ever wrong with the bot's permissions** — the probe reported a permission verdict it never actually read. **2. `preflight_gate` never records the failing guard as the verdict's error line.** The guard FATALs to *stderr*, not to an errlog file — the #9 case `verdict_error` exists to close. `preflight_gate` prints the `PREFLIGHT RED` line to the job log and to Mattermost but never calls `verdict_error`, so `verdict_write` emits an empty `--- error lines ---` block and the healer keys on the bare stage. That is what burned this investigation. ## Fix (written and verified, needs landing) Both files are **vendored** from `Matou/dev-factory` (`FACTORY_MANIFEST`), so the healer could not land this itself — it must go to the factory root source and then be re-vendored (ADR 0180). The patch below is byte-clean against factory root `4d7b1af` and applies with `git apply`. - `forgejo-lib.sh` — `forgejo_issue_write_probe` retries with exponential backoff (`FORGEJO_PROBE_RETRIES=3`, `FORGEJO_PROBE_BACKOFF=2`, each attempt bounded by `_forgejo_get`'s `--max-time`; #52's posture). A **sustained** outage still fails closed, but says `TRANSPORT, not a permission verdict (the bot's write access was never read)` instead of "the bot has no write access". - `preflight-lib.sh` — `preflight_gate` records the `PREFLIGHT RED` line(s) via `verdict_error` before returning, so the verdict, the runlog and the healer signature all name the failing guard. A red with *no* `PREFLIGHT RED` line still leaves a non-empty line. - Tests: 5 new pins in `tests/forgejo-lib-test.sh` (rides out a transient 5xx; a sustained outage is named TRANSPORT; never claims lost write access; the probe demonstrably retried) and 2 in `tests/preflight-lib-test.sh`. **Red-before-green confirmed:** on unpatched code the new pins fail — `forgejo-lib: 55 passed, 3 failed` and `FAIL: the gate must record the failing guard as the verdict's error line, got ''`. **Green after, in the factory tree:** `preflight-lib` 9 groups, `forgejo-lib` 58/0, `preflight-swarm` 6 scenarios, `run-swarm-stages` 10 groups. Also green in an idss clone: `preflight-triage`, `run-swarm-ready-list`, `run-swarm-cold-store`, `provision-lib`, `policy-lib`, `claim-lib`, `close-report-lib`, `landing-lib`, `heal-lib`. ## Landing steps 1. Apply the patch to the **root source** in `Matou/dev-factory` (`forgejo-lib.sh`, `preflight-lib.sh`, `tests/forgejo-lib-test.sh`, `tests/preflight-lib-test.sh`) and push there. 2. Re-vendor into `Matou/idss`: bump `.sandcastle/FACTORY_REF` (`51c8dc66` → new factory SHA) and re-vendor the manifest set. Note idss is currently one factory commit behind (`4d7b1af`, the rehearsal-heal de-numbering), which the bump will also carry in. 3. Append GOTCHAS #217 (draft text below) in the same commit as the idss re-vendor. ## Patch ```diff diff --git a/forgejo-lib.sh b/forgejo-lib.sh index 1ba371fc..09abea94 100644 --- a/forgejo-lib.sh +++ b/forgejo-lib.sh @@ -217,6 +217,17 @@ forgejo_repo_default_merge_style() { # forgejo_repo_default_merge_style -> the r esac } +# Transient-5xx posture for the #20 probe, matching list-ready-tasks.sh's api() +# (#52): the probe is preflight's ONE live network call and preflight fails +# CLOSED, so a brief Forgejo blip used to red the whole tick — 7 seconds in, +# with the run reported as `preflight-red` as if the bot had lost its write +# access (run 20865, 2026-09-09T21:46Z, GOTCHAS #217). Retry with exponential +# backoff, each attempt bounded by _forgejo_get's `--max-time`. A sustained +# outage still exhausts the attempts and reds, but names TRANSPORT, never a +# permission verdict it never actually read. +FORGEJO_PROBE_RETRIES="${FORGEJO_PROBE_RETRIES:-3}" +FORGEJO_PROBE_BACKOFF="${FORGEJO_PROBE_BACKOFF:-2}" + forgejo_issue_write_probe() { # forgejo_issue_write_probe -> rc 0 if the bot has repo write; LOUD + rc 1 otherwise (#20) # Zero-token preflight probe: GET the repo root with the bot token and assert # the caller's `permissions` block grants write. #19 looked like four @@ -228,10 +239,17 @@ forgejo_issue_write_probe() { # forgejo_issue_write_probe -> rc 0 if the bot has # deeper — close-report.sh closes-then-verifies and claim_mark_working pages # on a 403 label write — so the three layers together never again read a # permission gap as a clean close. - local resp push - resp="$(forgejo_get "")" || { - echo "forgejo: repo probe GET failed — cannot confirm the bot can write issues on $(forgejo_repo_slug)" - return 1; } + local resp push attempt=1 delay="$FORGEJO_PROBE_BACKOFF" + while :; do + resp="$(forgejo_get "")" && break + if [ "$attempt" -ge "$FORGEJO_PROBE_RETRIES" ]; then + echo "forgejo: repo probe GET failed after $attempt attempt(s) — $(forgejo_repo_slug) is unreachable or 5xx-ing; this is TRANSPORT, not a permission verdict (the bot's write access was never read)" + return 1 + fi + sleep "$delay" + delay=$((delay * 2)) + attempt=$((attempt + 1)) + done push="$(jq -r '.permissions.push // false' <<<"$resp" 2>/dev/null)" [ "$push" = "true" ] && return 0 echo "forgejo: the bot has no write access (permissions.push=$push) on $(forgejo_repo_slug) — issue label/state writes will 403 (the machines team needs repo.issues + repo.pulls write, not just repo.code)" diff --git a/preflight-lib.sh b/preflight-lib.sh index 0cdc6546..ec33fabe 100644 --- a/preflight-lib.sh +++ b/preflight-lib.sh @@ -34,16 +34,24 @@ _preflight_notify() { bash "$PREFLIGHT_NOTIFY" "$1" || true; } # when a guard did not fire on its fixture; the captured output is printed either # way so a green preflight is still visible in the job log. preflight_gate() { - local repo_slug="$1" out + local repo_slug="$1" out red verdict_stage "preflight self-tests (#446)" if out="$(bash "$PREFLIGHT_SCRIPT" 2>&1)"; then printf '%s\n' "$out" return 0 fi printf '%s\n' "$out" + red="$(printf '%s\n' "$out" | grep 'PREFLIGHT RED' | head -20 || true)" + # #9: the guard FATALs to stderr, never to an errlog file, so without this the + # verdict's `--- error lines ---` block is EMPTY and the healer keys its + # signature on the bare stage name — which is exactly what run 20865 handed it + # (a whole investigation off `stage=preflight self-tests (#446) exit=1` with + # nothing under it, GOTCHAS #217). Record the failing guard line(s) so the + # verdict, the runlog and the healer all name the cause. + verdict_error "$(printf '%s' "${red:-preflight-swarm.sh exited non-zero without a PREFLIGHT RED line}" | tr '\n' ' ')" _preflight_notify ":rotating_light: **Swarm preflight RED** in \`$repo_slug\` — a silent-failure guard did not fire on its fixture; NO worker was spawned. Fix before the swarm can run: \`\`\` -$(printf '%s\n' "$out" | grep 'PREFLIGHT RED' | head -20) +$red \`\`\`" SWARM_EXIT_REASON="preflight-red" return 1 diff --git a/tests/forgejo-lib-test.sh b/tests/forgejo-lib-test.sh index b163c1db..3d367d6a 100644 --- a/tests/forgejo-lib-test.sh +++ b/tests/forgejo-lib-test.sh @@ -85,6 +85,15 @@ case "$url" in echo '{"number":101,"head":{"ref":"agent/issue-7"}}' ;; */repos/Matou/idss) # repo-root GET — #20 write probe + #15 default_merge_style + # PROBE_FAILS_N: 5xx the first N calls (the #52 transient posture, GOTCHAS + # #217). The counter is a file so it survives the probe's retry subshells. + if [ -n "${PROBE_FAIL_COUNTER:-}" ]; then + n="$(cat "$PROBE_FAIL_COUNTER" 2>/dev/null || echo 0)" + if [ "$n" -lt "${PROBE_FAILS_N:-0}" ]; then + echo $((n + 1)) > "$PROBE_FAIL_COUNTER" + exit 22 + fi + fi echo "{\"permissions\":{\"push\":${PROBE_PUSH:-true}},\"default_merge_style\":\"${MERGE_STYLE:-merge}\"}" ;; *) @@ -259,6 +268,27 @@ probe_out="$( ( export PROBE_PUSH=false; forgejo_issue_write_probe ) 2>&1 || tru check "issue-write probe names the missing write access" \ 'grep -q "no write access" <<<"$probe_out"' +# GOTCHAS #217 (run 20865): preflight's ONE live network call fails CLOSED, so a +# transient Forgejo 5xx used to red the whole tick as `preflight-red` — reported +# as if the bot had lost its write access. Retry with backoff (list-ready-tasks' +# #52 posture); a sustained outage still reds, but names TRANSPORT. +export PROBE_FAIL_COUNTER="$tmp/probe-fails" +export FORGEJO_PROBE_BACKOFF=0 +: > "$PROBE_FAIL_COUNTER" +check "issue-write probe rides out a transient 5xx and still reads the permission" \ + '( export PROBE_FAILS_N=2 PROBE_PUSH=true; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe >/dev/null )' +: > "$PROBE_FAIL_COUNTER" +check "issue-write probe reds on a SUSTAINED outage" \ + '! ( export PROBE_FAILS_N=99; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe >/dev/null 2>&1 )' +outage_out="$( ( export PROBE_FAILS_N=99; echo 0 > "$PROBE_FAIL_COUNTER"; forgejo_issue_write_probe ) 2>&1 || true )" +check "a sustained outage is named TRANSPORT, never a permission verdict" \ + 'grep -q "TRANSPORT, not a permission verdict" <<<"$outage_out"' +check "a sustained outage does NOT claim the bot lost write access" \ + '! grep -q "no write access" <<<"$outage_out"' +check "the probe actually retried before ruling" \ + '[ "$(cat "$PROBE_FAIL_COUNTER")" -ge 3 ]' +unset PROBE_FAIL_COUNTER FORGEJO_PROBE_BACKOFF + # forgejo_label_applied_at (#99): the LATEST label-ADD timestamp from the issue # timeline, ignoring removes and earlier adds; empty for a label never added. timeline="$tmp/timeline.json" diff --git a/tests/preflight-lib-test.sh b/tests/preflight-lib-test.sh index 5afb34eb..c4c5b3ec 100644 --- a/tests/preflight-lib-test.sh +++ b/tests/preflight-lib-test.sh @@ -80,6 +80,24 @@ grep -q 'PREFLIGHT RED' <<<"$out" || fail "the failing guard must reach the job grep -q 'Swarm preflight RED' "$NOTIFY_LOG" || fail "a red preflight must alarm: $(cat "$NOTIFY_LOG")" grep -q 'healer signature rails' "$NOTIFY_LOG" || fail "the alarm must name the failing guard, not just say 'red'" grep -q 'NO worker was spawned' "$NOTIFY_LOG" || fail "the alarm must say nothing was started" +# #9 / GOTCHAS #217: the guard FATALs to stderr, so the verdict's error block is +# empty unless the gate records the line — run 20865 handed the healer a bare +# `stage=preflight self-tests (#446) exit=1` with NOTHING under it. +grep -q 'healer signature rails' <<<"${VERDICT_ERROR:-}" \ + || fail "the gate must record the failing guard as the verdict's error line, got '${VERDICT_ERROR:-}'" +pass=$((pass+1)) + +# A red with NO `PREFLIGHT RED` line still must not leave an empty error block. +: > "$NOTIFY_LOG"; SWARM_EXIT_REASON="" +cat > "$tmp/preflight-mute" <<'SH' +#!/usr/bin/env bash +exit 1 +SH +chmod +x "$tmp/preflight-mute" +RC=0 +PREFLIGHT_SCRIPT="$tmp/preflight-mute" preflight_gate Acme/widget >"$tmp/pf.out" 2>&1 || RC=$? +[ "$RC" = 1 ] || fail "a mute red preflight must still abort, got $RC" +[ -n "${VERDICT_ERROR:-}" ] || fail "a mute red must still leave the healer a non-empty error line" pass=$((pass+1)) # ── 2. the policy gate (#12, ADR 0002) ──────────────────────────────────── ``` ## GOTCHAS #217 draft ## 217. ⭐⭐ Preflight's ONE live network call fails CLOSED with no retry, so a transient Forgejo 5xx reds the whole swarm tick as `preflight-red` — and because the guard FATALs to stderr, the verdict's error block is EMPTY and the healer keys a full investigation on a bare stage name **Symptom:** swarm run 20865 (`Matou/idss`, 2026-09-09T21:46:04Z) died after **7 seconds** with `reason=preflight-red exit=1` (`~/swarm/logs/run-swarm-verdicts.log`) and a verdict of exactly three useful bytes: ``` stage=preflight self-tests (#446) exit=1 --- error lines --- ``` Nothing under the marker. No worker log for the window, no runner journal. The healer signature keyed on the bare stage, so the incident read as "a silent-failure guard broke" — a guard rot alarm — when nothing in the harness had changed. **Cause:** two independent gaps stacked. (1) Forgejo was 5xx-ing at that minute — the sibling `Matou/matou-app` verdict written in the SAME minute is `fatal: unable to access 'https://git.matou.nz/Matou/matou-app.git/': The requested URL returned error: 503`, and the healer's own probe recorded `api_seconds=timeout` with an empty `workflow_runs` list. `guard_issue_write_permission` is preflight's only live call (`forgejo_issue_write_probe` → `forgejo_get ""`), and `_forgejo_get` is a bare `curl -sf --max-time 30` with **no retry** — unlike `list-ready-tasks.sh:api()`, which was given exactly this posture by #52 for exactly this reason. One 503 returned instantly, the guard reported "cannot confirm the bot can write issues", preflight failed closed, and the tick was gone in 7 s. (2) `preflight_gate` printed the `PREFLIGHT RED` line to the job log and to Mattermost but never called `verdict_error`, and the guard FATALs to stderr rather than to an errlog file — the #9 case `verdict_error` exists to close. So `verdict_write` emitted an empty `--- error lines ---` block. Forgejo answered 200 in 0.9 s by the time the healer probed, and the `issue_write_permission` guard passes live against the same token: nothing was ever wrong with the bot's permissions. **Rule:** a probe that cannot reach the server has not obtained a verdict — it must never be reported as the verdict it was asking about. `forgejo_issue_write_probe` now retries with exponential backoff (`FORGEJO_PROBE_RETRIES=3`, `FORGEJO_PROBE_BACKOFF=2`, each attempt bounded by `_forgejo_get`'s `--max-time` — #52's posture), and a **sustained** outage still fails closed but says `TRANSPORT, not a permission verdict (the bot's write access was never read)` instead of "the bot has no write access". Separately, every fail-closed gate whose guard FATALs to stderr must record that line with `verdict_error` before it returns: `preflight_gate` does, so the verdict, the runlog and the healer signature all name the failing guard. An empty `--- error lines ---` block under a named stage is not a diagnosis — it is a wasted investigation. Pinned by `tests/forgejo-lib-test.sh` (rides out a transient 5xx; a sustained outage is named TRANSPORT and never claims lost write access; the probe demonstrably retried) and `tests/preflight-lib-test.sh` (the gate records the failing guard, and a red with no `PREFLIGHT RED` line still leaves a non-empty error line).
Author
Member

Handed to ready-for-session — this is a protected-path + cross-repo machinery change a swarm worker cannot land.

Every file this fix touches is a vendored, protected .sandcastle/ path:

  • .sandcastle/forgejo-lib.sh
  • .sandcastle/preflight-lib.sh
  • .sandcastle/tests/forgejo-lib-test.sh
  • .sandcastle/tests/preflight-lib-test.sh

and the landing steps additionally require bumping .sandcastle/FACTORY_REF (51c8dc66 → new factory SHA) and re-vendoring the FACTORY_MANIFEST set. All of that is under .sandcastle/, which the protected-paths fingerprint (#445) rolls back and fails loud on any swarm run — a worker literally cannot make these edits stick. Beyond that, landing step 1 requires applying the patch to the root source in Matou/dev-factory and pushing there (ADR 0180), a repo the swarm worker has no worktree or write access to. The filing healer already noted this: "the healer could not land this itself — it must go to the factory root source and then be re-vendored."

Only docs/GOTCHAS.md #217 is a non-protected path here, and landing it alone would document a fix that does not exist — worse than leaving it.

Per ADR 0174 §5, work that needs an interactive session's standing for a protected .sandcastle/ path (per #445) is ready-for-session, not ready-for-agent and not Ben. The patch in the issue body is byte-clean against factory root 4d7b1af and comes with red-before-green evidence, so a session can:

  1. apply it to Matou/dev-factory root (forgejo-lib.sh, preflight-lib.sh, and both test files) and push;
  2. re-vendor into idss — bump .sandcastle/FACTORY_REF and re-vendor the manifest set (carries in the one-behind 4d7b1af too);
  3. append GOTCHAS #217 in the same idss re-vendor commit.

Swapping ready-for-agent → ready-for-session and releasing the swarm claim.

**Handed to `ready-for-session` — this is a protected-path + cross-repo machinery change a swarm worker cannot land.** Every file this fix touches is a vendored, protected `.sandcastle/` path: - `.sandcastle/forgejo-lib.sh` - `.sandcastle/preflight-lib.sh` - `.sandcastle/tests/forgejo-lib-test.sh` - `.sandcastle/tests/preflight-lib-test.sh` and the landing steps additionally require bumping `.sandcastle/FACTORY_REF` (`51c8dc66` → new factory SHA) and re-vendoring the `FACTORY_MANIFEST` set. All of that is under `.sandcastle/`, which the protected-paths fingerprint (#445) rolls back and fails loud on any swarm run — a worker literally cannot make these edits stick. Beyond that, landing step 1 requires applying the patch to the **root source in `Matou/dev-factory` and pushing there** (ADR 0180), a repo the swarm worker has no worktree or write access to. The filing healer already noted this: *"the healer could not land this itself — it must go to the factory root source and then be re-vendored."* Only `docs/GOTCHAS.md` #217 is a non-protected path here, and landing it alone would document a fix that does not exist — worse than leaving it. Per **ADR 0174 §5**, work that needs an interactive session's standing for a protected `.sandcastle/` path (per #445) is `ready-for-session`, not `ready-for-agent` and not Ben. The patch in the issue body is byte-clean against factory root `4d7b1af` and comes with red-before-green evidence, so a session can: 1. apply it to `Matou/dev-factory` root (`forgejo-lib.sh`, `preflight-lib.sh`, and both test files) and push; 2. re-vendor into idss — bump `.sandcastle/FACTORY_REF` and re-vendor the manifest set (carries in the one-behind `4d7b1af` too); 3. append GOTCHAS #217 in the same idss re-vendor commit. Swapping `ready-for-agent` → `ready-for-session` and releasing the swarm claim.
Author
Member

Close-report — landed under ADR 0174 (session-runner, veto anytime)

Both gaps fixed at the factory root and re-vendored into idss. Ruled two-way by agent under ADR 0174: revertible (commit/vendor bump) and provable (existing + new self-tests, red-before-green).

dev-factory Matou/dev-factory@6ea8ba0 — forgejo-lib.sh, preflight-lib.sh, tests/forgejo-lib-test.sh, tests/preflight-lib-test.sh:

  • forgejo_issue_write_probe (#20) now retries with exponential backoff (FORGEJO_PROBE_RETRIES=3, FORGEJO_PROBE_BACKOFF=2, each attempt bounded by _forgejo_get's --max-time — list-ready-tasks.sh:api()'s #52 posture). A sustained outage still fails closed but says TRANSPORT, not a permission verdict (the bot's write access was never read) instead of "the bot has no write access".
  • preflight_gate records the PREFLIGHT RED line(s) via verdict_error before returning, so the verdict, the runlog and the healer signature all name the failing guard; a red with no PREFLIGHT RED line still leaves a non-empty error line.

idss 54040f3b — re-vendored FACTORY_REF 51c8dc66 → 6ea8ba0 (carried in the 4d7b1af rehearsal-heal de-numbering idss was one commit behind; rendered rehearsal-heal-prompt.md regenerated), GOTCHAS #217 appended, STATUS.md noted. check-harness-drift: OK.

Proof (red-before-green, reproduced this session):

  • Unpatched: forgejo-lib: 55 passed, 3 failed; preflight-lib FAIL the gate must record the failing guard as the verdict's error line, got '' — exactly the ticket's expected red.
  • Patched: forgejo-lib 58/0, preflight-lib 9 groups, preflight-swarm 6 scenarios, run-swarm-stages 10 groups — green both in the factory tree and in the idss vendored copy.

No one-way door touched: factory push used the host swarm credential (repo-scoped, not personal), the re-vendor was anonymous (clean # Source: line, git grep token-free), no security posture widened.

## Close-report — landed under ADR 0174 (session-runner, veto anytime) Both gaps fixed at the factory root and re-vendored into idss. Ruled two-way by agent under ADR 0174: revertible (commit/vendor bump) and provable (existing + new self-tests, red-before-green). **dev-factory `Matou/dev-factory@6ea8ba0`** — `forgejo-lib.sh`, `preflight-lib.sh`, `tests/forgejo-lib-test.sh`, `tests/preflight-lib-test.sh`: - `forgejo_issue_write_probe` (#20) now retries with exponential backoff (`FORGEJO_PROBE_RETRIES=3`, `FORGEJO_PROBE_BACKOFF=2`, each attempt bounded by `_forgejo_get`'s `--max-time` — `list-ready-tasks.sh:api()`'s #52 posture). A **sustained** outage still fails closed but says `TRANSPORT, not a permission verdict (the bot's write access was never read)` instead of "the bot has no write access". - `preflight_gate` records the `PREFLIGHT RED` line(s) via `verdict_error` before returning, so the verdict, the runlog and the healer signature all name the failing guard; a red with no `PREFLIGHT RED` line still leaves a non-empty error line. **idss `54040f3b`** — re-vendored FACTORY_REF `51c8dc66` → `6ea8ba0` (carried in the `4d7b1af` rehearsal-heal de-numbering idss was one commit behind; rendered `rehearsal-heal-prompt.md` regenerated), GOTCHAS #217 appended, STATUS.md noted. `check-harness-drift: OK`. **Proof (red-before-green, reproduced this session):** - Unpatched: `forgejo-lib: 55 passed, 3 failed`; `preflight-lib` FAIL `the gate must record the failing guard as the verdict's error line, got ''` — exactly the ticket's expected red. - Patched: `forgejo-lib 58/0`, `preflight-lib 9 groups`, `preflight-swarm 6 scenarios`, `run-swarm-stages 10 groups` — green both in the factory tree and in the idss vendored copy. No one-way door touched: factory push used the host `swarm` credential (repo-scoped, not personal), the re-vendor was anonymous (clean `# Source:` line, `git grep` token-free), no security posture widened.
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#1359
No description provided.