harness: a ~24s Forgejo 5xx reds the swarm tick as invalid-policy — the #12 policy gate's label check has a 6s retry budget, records no verdict error line, and blames a policy file that is valid (the #1359 defect in the other preflight gate) #2052

Closed
opened 2026-10-20 21:51:18 +00:00 by matou-build-agent · 2 comments

Symptom

Swarm run 50573 (Matou/idss, 2026-10-20T21:47:27Z) died after 18 seconds with reason=invalid-policy exit=1 (~/swarm/logs/run-swarm-verdicts.log) and handed the healer a verdict of exactly this:

stage=policy validation (#12)
exit=1
--- error lines ---

Nothing under the marker — so the trigger line the healer keyed on was policy validation (#12) :: with an empty tail, and the Mattermost notice read "Swarm aborted — invalid swarm-policy.sh. Fix the named policy key".

.sandcastle/swarm-policy.sh has not been touched since 2026-08-26 and is valid: run live against the same token during the heal, policy_load && policy_validate returns 0, and all three HUMAN_LABELS names (ready-for-human, agent-blocked, needs-info) are minted. Nothing was ever wrong with the policy.

Root cause — a ~24s Forgejo 5xx blip, reported as a policy misconfiguration

policy_validate ends in one live call — forgejo_get '/labels?limit=100', the HUMAN_LABELS minted check — and on a non-zero rc returns 2 with no distinction between "the file is wrong" and "I could not read the tracker".

Forgejo was 503-ing for that window instance-wide, not just for idss:

  • runner-journal.txt: 38 × ReportState/ReportLog error: unavailable: 503 Service Unavailable from 21:47:19 to 21:47:43 (~24s), across unrelated tasks (235247, 235262) — the runner's own log shipping was down too.
  • the heal bundle's own probe: api-timing.txt → api_http=503, and runs.json → {"workflow_runs":[]}.
  • siblings bracket the blip: dev-factory green at 21:47:05, matou-website green at 21:48:47. Only idss's tick landed inside it.
  • by heal time Forgejo answered 200 in 0.7s, three probes in a row.

Gap 1 — the retry budget is shorter than a real blip. forgejo_get's bounded retry (#2048) is FORGEJO_GET_RETRIES=3 / FORGEJO_GET_BACKOFF=2 → attempt, 2s, attempt, 4s, attempt ≈ 6s of riding out. The blip was 24s, so all three attempts fell inside it and the gate failed closed.

Gap 2 — preflight_policy_gate never calls verdict_error. This is the #12 half of the pair #1359 closed for the #446 half: preflight_gate was taught to record its PREFLIGHT RED line(s) so the verdict, the runlog and the healer signature all name the cause (GOTCHAS #217). preflight_policy_gate was not in that scope, so it still returns 1 with an empty --- error lines --- block — and policy_validate's stderr (policy: could not list the repo's labels to validate HUMAN_LABELS) is written nowhere the healer can read.

Gap 3 — the words are false. A transport fault becomes SWARM_EXIT_REASON=invalid-policy and a notice telling a human to "fix the named policy key". Same defect class as the #20 probe before #1359: a verdict reported about a thing that was never actually read.

Fix

policy-lib.sh and preflight-lib.sh are both vendored from Matou/dev-factory (FACTORY_MANIFEST lines 40/42, pin 7d40af3, drift gate green) — so this lands at the factory root source and is then re-vendored (ADR 0180, the #2048 route), never edited in place here.

  1. policy-lib.sh — split the two failures. policy_validate returns a distinct rc (or sets a named reason) when the labels GET itself failed, and says TRANSPORT — the repo's label set was never read; HUMAN_LABELS was not validated, never "not minted". Consider giving this one call a longer budget than the shared default (a 24s blip needs ~30s+ of riding out; the call is an idempotent GET).
  2. preflight-lib.sh — preflight_policy_gate calls verdict_error with policy_validate's stderr before returning, so the verdict names the cause. On the transport branch, set SWARM_EXIT_REASON=policy-tracker-unreachable (not invalid-policy) and post a notice that says the tracker was unreachable and the policy was not read.
  3. Tests: pins in tests/policy-lib-test.sh (a 5xx on the labels GET is named TRANSPORT and never claims an unminted label; a genuinely unminted label still reds as before) and tests/preflight-lib-test.sh (the gate records a non-empty verdict error line on both branches).
  4. Append a GOTCHAS entry in the same commit as the idss re-vendor, and bump FACTORY_REF.

Why this is worth closing rather than filing under "it self-heals"

The outage genuinely self-heals — but the report does not. It burns a heal cycle chasing a policy key that is correct, and it tells a human to edit a file that is fine. #1359 closed exactly this for the sibling gate; this is the other one.

## Symptom Swarm run [50573](https://git.matou.nz/Matou/idss/actions/runs/50573) (`Matou/idss`, 2026-10-20T21:47:27Z) died after **18 seconds** with `reason=invalid-policy exit=1` (`~/swarm/logs/run-swarm-verdicts.log`) and handed the healer a verdict of exactly this: ``` stage=policy validation (#12) exit=1 --- error lines --- ``` Nothing under the marker — so the trigger line the healer keyed on was `policy validation (#12) ::` with an empty tail, and the Mattermost notice read **"Swarm aborted — invalid `swarm-policy.sh`. Fix the named policy key"**. `.sandcastle/swarm-policy.sh` has not been touched since 2026-08-26 and is **valid**: run live against the same token during the heal, `policy_load && policy_validate` returns 0, and all three `HUMAN_LABELS` names (`ready-for-human`, `agent-blocked`, `needs-info`) are minted. Nothing was ever wrong with the policy. ## Root cause — a ~24s Forgejo 5xx blip, reported as a policy misconfiguration `policy_validate` ends in one live call — `forgejo_get '/labels?limit=100'`, the HUMAN_LABELS minted check — and on a non-zero rc returns 2 with no distinction between "the file is wrong" and "I could not read the tracker". Forgejo was 503-ing for that window instance-wide, not just for idss: - `runner-journal.txt`: 38 × `ReportState/ReportLog error: unavailable: 503 Service Unavailable` from **21:47:19 to 21:47:43** (~24s), across unrelated tasks (235247, 235262) — the runner's own log shipping was down too. - the heal bundle's own probe: `api-timing.txt` → `api_http=503`, and `runs.json` → `{"workflow_runs":[]}`. - siblings bracket the blip: `dev-factory` green at 21:47:05, `matou-website` green at 21:48:47. Only idss's tick landed inside it. - by heal time Forgejo answered **200 in 0.7s**, three probes in a row. **Gap 1 — the retry budget is shorter than a real blip.** `forgejo_get`'s bounded retry (#2048) is `FORGEJO_GET_RETRIES=3` / `FORGEJO_GET_BACKOFF=2` → attempt, 2s, attempt, 4s, attempt ≈ **6s of riding out**. The blip was 24s, so all three attempts fell inside it and the gate failed closed. **Gap 2 — `preflight_policy_gate` never calls `verdict_error`.** This is the #12 half of the pair #1359 closed for the #446 half: `preflight_gate` was taught to record its `PREFLIGHT RED` line(s) so the verdict, the runlog and the healer signature all name the cause (GOTCHAS #217). `preflight_policy_gate` was not in that scope, so it still returns 1 with an empty `--- error lines ---` block — and `policy_validate`'s stderr (`policy: could not list the repo's labels to validate HUMAN_LABELS`) is written nowhere the healer can read. **Gap 3 — the words are false.** A transport fault becomes `SWARM_EXIT_REASON=invalid-policy` and a notice telling a human to "fix the named policy key". Same defect class as the #20 probe before #1359: *a verdict reported about a thing that was never actually read*. ## Fix `policy-lib.sh` and `preflight-lib.sh` are both **vendored** from `Matou/dev-factory` (`FACTORY_MANIFEST` lines 40/42, pin `7d40af3`, drift gate green) — so this lands at the factory root source and is then re-vendored (ADR 0180, the #2048 route), never edited in place here. 1. `policy-lib.sh` — split the two failures. `policy_validate` returns a **distinct rc** (or sets a named reason) when the labels GET itself failed, and says `TRANSPORT — the repo's label set was never read; HUMAN_LABELS was not validated`, never "not minted". Consider giving this one call a longer budget than the shared default (a 24s blip needs ~30s+ of riding out; the call is an idempotent GET). 2. `preflight-lib.sh` — `preflight_policy_gate` calls `verdict_error` with `policy_validate`'s stderr before returning, so the verdict names the cause. On the transport branch, set `SWARM_EXIT_REASON=policy-tracker-unreachable` (not `invalid-policy`) and post a notice that says the tracker was unreachable and the policy was not read. 3. Tests: pins in `tests/policy-lib-test.sh` (a 5xx on the labels GET is named TRANSPORT and never claims an unminted label; a genuinely unminted label still reds as before) and `tests/preflight-lib-test.sh` (the gate records a non-empty verdict error line on both branches). 4. Append a GOTCHAS entry in the same commit as the idss re-vendor, and bump `FACTORY_REF`. ## Why this is worth closing rather than filing under "it self-heals" The outage genuinely self-heals — but the *report* does not. It burns a heal cycle chasing a policy key that is correct, and it tells a human to edit a file that is fine. #1359 closed exactly this for the sibling gate; this is the other one. <!-- filed by the swarm healer, heal run heal-Matou-idss-1792532852-3903464, evidence /tmp/matou-heal-Matou-idss.ATIL0g -->
Author
Member

Cannot land as a swarm worker — this is a protected-path (.sandcastle/) machinery change → ready-for-session

Every substantive file in the proposed fix lives inside .sandcastle/, the fingerprinted-protected tree (#445):

  • .sandcastle/policy-lib.sh (split the transport-vs-unminted failure in policy_validate)
  • .sandcastle/preflight-lib.sh (preflight_policy_gate → verdict_error, SWARM_EXIT_REASON=policy-tracker-unreachable)
  • .sandcastle/tests/policy-lib-test.sh, .sandcastle/tests/preflight-lib-test.sh
  • .sandcastle/FACTORY_REF (re-vendor bump)

PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo" — a swarm worker that writes any of these has its edits rolled back and the run failed loud by protected-paths-lib.sh (#445). The docs/GOTCHAS.md append the ticket calls for is to ride in the same commit as the re-vendor, so there is nothing a swarm worker can land here in isolation.

This is exactly the case the protected-path escape and ADR 0174 route to an interactive session: a .sandcastle/ change needs a session's standing (the vendored-from-dev-factory round-trip — fix at the Matou/dev-factory root, re-vendor here, bump FACTORY_REF, drift gate). The precedent the ticket itself cites, #2048, landed as a harness #2048: session commit (c6b9535a), not a sandcastle: swarm commit — the same route this one needs.

No scope or analysis dispute: the root-cause writeup (24s Forgejo 5xx > 6s retry budget; policy_validate's one live forgejo_get '/labels?limit=100' failing closed as invalid-policy; preflight_policy_gate never calling verdict_error — the #12 half of the pair #1359 closed for the #446 half) all stands. It is only the actor that is wrong: a swarm worker cannot touch the machinery that judges it.

Swapping ready-for-agent → ready-for-session. No separate issue filed — this ticket is itself the machinery-change issue.

## Cannot land as a swarm worker — this is a protected-path (`.sandcastle/`) machinery change → `ready-for-session` Every substantive file in the proposed fix lives inside `.sandcastle/`, the fingerprinted-protected tree (#445): - `.sandcastle/policy-lib.sh` (split the transport-vs-unminted failure in `policy_validate`) - `.sandcastle/preflight-lib.sh` (`preflight_policy_gate` → `verdict_error`, `SWARM_EXIT_REASON=policy-tracker-unreachable`) - `.sandcastle/tests/policy-lib-test.sh`, `.sandcastle/tests/preflight-lib-test.sh` - `.sandcastle/FACTORY_REF` (re-vendor bump) `PP_PROTECTED_DIRS_DEFAULT=".sandcastle .forgejo"` — a swarm worker that writes any of these has its edits **rolled back** and the run **failed loud** by `protected-paths-lib.sh` (#445). The `docs/GOTCHAS.md` append the ticket calls for is to ride *in the same commit as the re-vendor*, so there is nothing a swarm worker can land here in isolation. This is exactly the case the protected-path escape and ADR 0174 route to an interactive **session**: a `.sandcastle/` change needs a session's standing (the vendored-from-dev-factory round-trip — fix at the `Matou/dev-factory` root, re-vendor here, bump `FACTORY_REF`, drift gate). The precedent the ticket itself cites, **#2048**, landed as a `harness #2048:` session commit (`c6b9535a`), not a `sandcastle:` swarm commit — the same route this one needs. No scope or analysis dispute: the root-cause writeup (24s Forgejo 5xx > 6s retry budget; `policy_validate`'s one live `forgejo_get '/labels?limit=100'` failing closed as `invalid-policy`; `preflight_policy_gate` never calling `verdict_error` — the #12 half of the pair #1359 closed for the #446 half) all stands. It is only the **actor** that is wrong: a swarm worker cannot touch the machinery that judges it. Swapping `ready-for-agent` → `ready-for-session`. No separate issue filed — this ticket is itself the machinery-change issue.
Author
Member

Close-report — landed (advances #2052)

Ruled by agent under ADR 0174 — veto anytime. A two-way door: a revertible dev-factory commit + a FACTORY_REF bump + a revertible idss commit, proven by offline tests. Same class as #1359 / ADR 0287 / #2048 — a verdict-honesty tightening, not a security-posture widening; not on ADR 0174's one-way-door list.

What was wrong (reproduced in the code, not taken on faith)

policy_validate (policy-lib.sh) ended in one live call — the HUMAN_LABELS minted check, forgejo_get '/labels?limit=100' — and on a non-zero rc returned 2 with no distinction between "the file is wrong" and "I could not read the tracker". preflight_policy_gate (preflight-lib.sh) called no verdict_error, so a transport fault surfaced as SWARM_EXIT_REASON=invalid-policy, an empty --- error lines --- block, and a notice telling a human to "fix the named policy key" for a valid file. The forgejo_get shared budget (#2048: retries=3/backoff=2 ≈ 6s) was also shorter than the ~24s blip. This is exactly the #1359 defect in preflight_gate's twin, which #1359 left out of scope.

The fix (both files factory-vendored, ADR 0180)

  • policy-lib.sh — policy_validate now returns a distinct rc 3 (TRANSPORT) — policy: TRANSPORT — the repo's label set was never read; HUMAN_LABELS was not validated — when the labels GET itself fails, vs rc 2 for a structurally-invalid file or a genuinely-unminted label. That one idempotent GET rides out a real blip longer (retries=5, backoff=2 ≈ 30s; a healthy tracker still answers on the first attempt).
  • preflight-lib.sh — preflight_policy_gate records policy_validate's stderr via verdict_error on every refusal, and on rc 3 sets SWARM_EXIT_REASON=policy-tracker-unreachable with a notice that the tracker was unreachable and the policy was not read — never invalid-policy.

Proof (offline, green in place)

  • tests/policy-lib-test.sh: 65 checks — pins the rc 2 / rc 3 split (a 5xx on the labels GET is named TRANSPORT and never claims a label is unminted; a genuinely-unminted label still reds rc 2).
  • tests/preflight-lib-test.sh: 10 groups — a non-empty verdict error line on BOTH the invalid and transport branches; the transport branch names policy-tracker-unreachable, says "unreachable", and never says "invalid".
  • dev-factory branch also green: run-swarm-stages-test.sh (12 groups), onboarding/tests/onboard-lib-test.sh (238 passed).
  • check-harness-drift.sh: OK against the new pin.

Commits / artifacts

  • dev-factory cheap-backport branch backport/idss-2052 @ d5be6884b60fd3fe36dd0dc12f72061a073c66e8 (authored off the pin 7d40af3, the #2048 route).
  • idss main @ 3b30cda3 — FACTORY_REF 7d40af3 → d5be688, the two libs + their vendored tests re-vendored, GOTCHAS #397 appended, STATUS.md updated (same commit).

Owed / routed

Forward-port of d5be688's diff onto dev-factory main filed as #2053 (ready-for-session; df is LANDING=push since df #276, so it no longer needs the human merge that routed sibling #2049 to a human). Out of scope here, exactly as #2048 split its own main forward-port to #2049.

The outage self-heals; this made the report honest so it no longer burns a heal cycle on a correct policy key or tells a human to edit a fine file.

## Close-report — landed (advances #2052) **Ruled by agent under ADR 0174 — veto anytime.** A two-way door: a revertible dev-factory commit + a `FACTORY_REF` bump + a revertible idss commit, proven by offline tests. Same class as #1359 / ADR 0287 / #2048 — a verdict-honesty tightening, not a security-posture widening; not on ADR 0174's one-way-door list. ### What was wrong (reproduced in the code, not taken on faith) `policy_validate` (`policy-lib.sh`) ended in one live call — the HUMAN_LABELS minted check, `forgejo_get '/labels?limit=100'` — and on a non-zero rc returned **2 with no distinction** between "the file is wrong" and "I could not read the tracker". `preflight_policy_gate` (`preflight-lib.sh`) called **no `verdict_error`**, so a transport fault surfaced as `SWARM_EXIT_REASON=invalid-policy`, an empty `--- error lines ---` block, and a notice telling a human to "fix the named policy key" for a valid file. The forgejo_get shared budget (#2048: retries=3/backoff=2 ≈ 6s) was also shorter than the ~24s blip. This is exactly the #1359 defect in `preflight_gate`'s twin, which #1359 left out of scope. ### The fix (both files factory-vendored, ADR 0180) - `policy-lib.sh` — `policy_validate` now returns a **distinct rc 3 (TRANSPORT)** — `policy: TRANSPORT — the repo's label set was never read; HUMAN_LABELS was not validated` — when the labels GET itself fails, vs rc 2 for a structurally-invalid file or a genuinely-unminted label. That one idempotent GET rides out a real blip longer (retries=5, backoff=2 ≈ 30s; a healthy tracker still answers on the first attempt). - `preflight-lib.sh` — `preflight_policy_gate` records `policy_validate`'s stderr via `verdict_error` on **every** refusal, and on rc 3 sets `SWARM_EXIT_REASON=policy-tracker-unreachable` with a notice that the tracker was unreachable and the policy was **not read** — never `invalid-policy`. ### Proof (offline, green in place) - `tests/policy-lib-test.sh`: 65 checks — pins the rc 2 / rc 3 split (a 5xx on the labels GET is named TRANSPORT and never claims a label is unminted; a genuinely-unminted label still reds rc 2). - `tests/preflight-lib-test.sh`: 10 groups — a non-empty verdict error line on BOTH the invalid and transport branches; the transport branch names `policy-tracker-unreachable`, says "unreachable", and never says "invalid". - dev-factory branch also green: `run-swarm-stages-test.sh` (12 groups), `onboarding/tests/onboard-lib-test.sh` (238 passed). - `check-harness-drift.sh`: OK against the new pin. ### Commits / artifacts - dev-factory cheap-backport branch `backport/idss-2052` @ `d5be6884b60fd3fe36dd0dc12f72061a073c66e8` (authored off the pin `7d40af3`, the #2048 route). - idss `main` @ `3b30cda3` — `FACTORY_REF 7d40af3 → d5be688`, the two libs + their vendored tests re-vendored, `GOTCHAS #397` appended, `STATUS.md` updated (same commit). ### Owed / routed Forward-port of `d5be688`'s diff onto dev-factory `main` filed as **#2053** (`ready-for-session`; df is LANDING=push since df #276, so it no longer needs the human merge that routed sibling #2049 to a human). Out of scope here, exactly as #2048 split its own main forward-port to #2049. The outage self-heals; this made the **report** honest so it no longer burns a heal cycle on a correct policy key or tells a human to edit a fine file.
matou-build-agent 2026-10-20 22:42:22 +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#2052
No description provided.