healer: the api-timing probe reports every curl failure as timeout, so auth faults and remote degradation are indistinguishable in the evidence #1462

Closed
opened 2026-09-12 22:11:19 +00:00 by matou-build-agent · 2 comments

Symptom

heal.sh's Forgejo latency probe writes api_seconds=timeout into the
evidence directory on any curl failure, not just a timeout:

curl -sf --max-time 35 -o /dev/null -H "Authorization: token $FORGEJO_TOKEN" \
  "$FORGEJO_API/actions/tasks?limit=1&page=1" \
  && echo "api_seconds=$((SECONDS - t0))" > "$EVIDENCE/api-timing.txt" \
  || echo "api_seconds=timeout" > "$EVIDENCE/api-timing.txt"

curl -sf fails identically for a 35s stall, a fast 401/403 (expired or
mis-synced token), a 5xx, and DNS/connect failure. The || branch labels all
four timeout.

Why it matters

This is the healer's only evidence about whether the Forgejo API was
reachable, and several run-verdict faults (preflight (list untriaged issues)
exits 22 via preflight-triage.sh's api() retry wrapper, which also uses
curl -sf and so swallows the body) leave an empty error block. So for a
whole class of incidents the healer is choosing between "remote API degraded"
(transient-external, no repair) and "the bot's token is broken"
(harness-infra, repairable) on evidence that cannot distinguish them.

Observed on heal run heal-Matou-idss-1789250785-2562903 (signature
f4b342f26065, triage run 22846): api_seconds=timeout + an empty error
block forced live re-probing with the bind-mounted token to rule out auth
before the incident could be classified. The same probe answers in ~1-2s when
the instance is healthy, so the failure was real — but the evidence file did
not say which failure.

What to build

Record the distinguishing facts instead of one ambiguous word. Capture
curl's own outcome:

read -r code t <<<"$(curl -s -o /dev/null --max-time 35 \
  -w '%{http_code} %{time_total}' \
  -H "Authorization: token $FORGEJO_TOKEN" \
  "$FORGEJO_API/actions/tasks?limit=1&page=1")"; rc=$?

and write api_http=<code>, api_seconds=<t>, api_curl_exit=<rc> — so a
401 reads as auth, a 000/exit 28 as a genuine timeout, a 5xx as remote
degradation. Keep an api_seconds= line (heal.sh:521 and the watchdog parse
it) so existing consumers do not break.

Acceptance criteria

  • AC1 — a healthy instance writes api_http=200, a real elapsed
    api_seconds=<n>, and api_curl_exit=0.
  • AC2 — a 401/403 is recorded as such (api_http=401, api_curl_exit=0) and
    is NOT reported as timeout.
  • AC3 — a genuine stall past --max-time records api_curl_exit=28 and
    api_seconds=timeout, preserving today's line for existing parsers.
  • AC4 — heal.sh:521's existing read of api_seconds= still works on all three
    shapes (covered by tests/heal-lib-test.sh or a sibling).

Contract

.sandcastle/heal.sh is vendored factory core (FACTORY_MANIFEST line 25,
FACTORY_REF 72496a4). Land the fix in Matou/dev-factory, bump
FACTORY_REF, and re-vendor — a direct edit here reds the
"Factory core: vendored .sandcastle files match FACTORY_REF" CI stage
(#571/#602).

Filed by the swarm healer while diagnosing triage run 22846 — a side-finding,
not that run's root cause (which was remote Forgejo degradation,
transient-external).

## Symptom `heal.sh`'s Forgejo latency probe writes `api_seconds=timeout` into the evidence directory on **any** curl failure, not just a timeout: ```sh curl -sf --max-time 35 -o /dev/null -H "Authorization: token $FORGEJO_TOKEN" \ "$FORGEJO_API/actions/tasks?limit=1&page=1" \ && echo "api_seconds=$((SECONDS - t0))" > "$EVIDENCE/api-timing.txt" \ || echo "api_seconds=timeout" > "$EVIDENCE/api-timing.txt" ``` `curl -sf` fails identically for a 35s stall, a fast 401/403 (expired or mis-synced token), a 5xx, and DNS/connect failure. The `||` branch labels all four `timeout`. ## Why it matters This is the healer's *only* evidence about whether the Forgejo API was reachable, and several run-verdict faults (`preflight (list untriaged issues)` exits 22 via `preflight-triage.sh`'s `api()` retry wrapper, which also uses `curl -sf` and so swallows the body) leave an **empty** error block. So for a whole class of incidents the healer is choosing between "remote API degraded" (transient-external, no repair) and "the bot's token is broken" (harness-infra, repairable) on evidence that cannot distinguish them. Observed on heal run `heal-Matou-idss-1789250785-2562903` (signature `f4b342f26065`, triage run 22846): `api_seconds=timeout` + an empty error block forced live re-probing with the bind-mounted token to rule out auth before the incident could be classified. The same probe answers in ~1-2s when the instance is healthy, so the failure was real — but the evidence file did not say which failure. ## What to build Record the distinguishing facts instead of one ambiguous word. Capture curl's own outcome: ```sh read -r code t <<<"$(curl -s -o /dev/null --max-time 35 \ -w '%{http_code} %{time_total}' \ -H "Authorization: token $FORGEJO_TOKEN" \ "$FORGEJO_API/actions/tasks?limit=1&page=1")"; rc=$? ``` and write `api_http=<code>`, `api_seconds=<t>`, `api_curl_exit=<rc>` — so a `401` reads as auth, a `000`/exit 28 as a genuine timeout, a `5xx` as remote degradation. Keep an `api_seconds=` line (heal.sh:521 and the watchdog parse it) so existing consumers do not break. ## Acceptance criteria - AC1 — a healthy instance writes `api_http=200`, a real elapsed `api_seconds=<n>`, and `api_curl_exit=0`. - AC2 — a 401/403 is recorded as such (`api_http=401`, `api_curl_exit=0`) and is NOT reported as `timeout`. - AC3 — a genuine stall past `--max-time` records `api_curl_exit=28` and `api_seconds=timeout`, preserving today's line for existing parsers. - AC4 — heal.sh:521's existing read of `api_seconds=` still works on all three shapes (covered by `tests/heal-lib-test.sh` or a sibling). ## Contract `.sandcastle/heal.sh` is **vendored factory core** (`FACTORY_MANIFEST` line 25, `FACTORY_REF` 72496a4). Land the fix in `Matou/dev-factory`, bump `FACTORY_REF`, and re-vendor — a direct edit here reds the "Factory core: vendored .sandcastle files match FACTORY_REF" CI stage (#571/#602). Filed by the swarm healer while diagnosing triage run 22846 — a side-finding, not that run's root cause (which was remote Forgejo degradation, transient-external).
Author
Member

This ticket cannot be closed by a Sandcastle worker — its entire deliverable is a change to vendored factory core, which is a protected path per #445.

What the fix touches, and why a swarm run cannot land it:

  • The probe lives in .sandcastle/heal.sh (listed in FACTORY_MANIFEST, vendored from Matou/dev-factory at FACTORY_REF). The ticket's own Contract states the fix must land in Matou/dev-factory, bump FACTORY_REF, and re-vendor — a direct edit here reds the "Factory core: vendored .sandcastle files match FACTORY_REF" CI stage (#571/#602).
  • .sandcastle/ is a protected path: the protected-paths tree-fingerprint (.sandcastle/protected-paths-lib.sh, #445) rolls back any create/change/delete under it and fails the run loud. A swarm worker also has no Matou/dev-factory checkout in its sandbox, and the re-vendor step itself rewrites .sandcastle/heal.sh.
  • AC4's test target tests/heal-lib-test.sh does not exist in this repo either — it, too, is factory-side.

There is no in-scope, in-repo work a Sandcastle worker can do here: 100% of the change is protected factory core.

Per Rule 9 / ADR 0174, a protected .sandcastle/ machinery change needs an interactive session's standing (a session works in Matou/dev-factory, bumps FACTORY_REF, and re-vendors), not a swarm run. Relabelling ready-for-agent → ready-for-session.

Why session (not human)

The fix is a two-way door (revertible, provable by tests/heal-lib-test.sh per AC4) — it does not need Ben, only the factory-core standing a session has. A session escalates to ready-for-human only if it finds a genuine one-way door.

This ticket cannot be closed by a Sandcastle worker — its entire deliverable is a change to **vendored factory core**, which is a protected path per #445. **What the fix touches, and why a swarm run cannot land it:** - The probe lives in `.sandcastle/heal.sh` (listed in `FACTORY_MANIFEST`, vendored from `Matou/dev-factory` at `FACTORY_REF`). The ticket's own **Contract** states the fix must land in `Matou/dev-factory`, bump `FACTORY_REF`, and re-vendor — a direct edit here reds the "Factory core: vendored .sandcastle files match FACTORY_REF" CI stage (#571/#602). - `.sandcastle/` is a protected path: the protected-paths tree-fingerprint (`.sandcastle/protected-paths-lib.sh`, #445) rolls back any create/change/delete under it and fails the run loud. A swarm worker also has no `Matou/dev-factory` checkout in its sandbox, and the re-vendor step itself rewrites `.sandcastle/heal.sh`. - AC4's test target `tests/heal-lib-test.sh` does not exist in this repo either — it, too, is factory-side. There is no in-scope, in-repo work a Sandcastle worker can do here: 100% of the change is protected factory core. Per **Rule 9 / ADR 0174**, a protected `.sandcastle/` machinery change needs an **interactive session's standing** (a session works in `Matou/dev-factory`, bumps `FACTORY_REF`, and re-vendors), not a swarm run. Relabelling `ready-for-agent` → `ready-for-session`. ## Why session (not human) The fix is a two-way door (revertible, provable by `tests/heal-lib-test.sh` per AC4) — it does not need Ben, only the factory-core standing a session has. A session escalates to `ready-for-human` only if it finds a genuine one-way door.
Author
Member

Close report — landed under ADR 0174 (two-way door; veto anytime)

The api-timing probe now records curl's own outcome instead of collapsing every failure onto one ambiguous timeout.

What landed

  • New probe_api (heal-lib.sh) writes three lines to api-timing.txt: api_http=<code>, api_seconds=<t|timeout>, api_curl_exit=<rc>. It captures curl's -w '%{http_code} %{time_total}' and its real exit code.
  • heal.sh's gather_evidence calls probe_api; the watchdog reads all three facts and trips the forgejo-api incident on any unhealthy probe (transport failure / non-2xx / ≥30s) — the same trip-set the old blanket timeout fired on (curl -sf failed on all of them) — but the errline and evidence now name which fault.

Note on the task's snippet: the suggested read -r code t <<<"$(curl …)"; rc=$? loses curl's exit — $? after read is READ's status (verified: it reports 0 on a connect-refused). probe_api captures the exit off a guarded assignment instead.

Acceptance criteria

  • AC1 — healthy: api_http=200, a real elapsed api_seconds=<n>, api_curl_exit=0. ✓
  • AC2 — a fast 401/403: api_http=401, api_curl_exit=0, and not timeout. ✓
  • AC3 — a genuine --max-time stall: api_curl_exit=28 with api_seconds=timeout preserved. ✓
  • AC4 — the sed -n 's/^api_seconds=//p' read (heal.sh watchdog + prompt) still yields a usable value on all shapes. ✓

Contract honoured: fixed in Matou/dev-factory (1e08738), FACTORY_REF bumped 9aaac50→1e08738, re-vendored byte-identical here — check-harness-drift OK (the vendored-file drift gate stays green).

Commits

  • dev-factory 1e08738 — the fix + tests.
  • idss 44cf7d66 — re-vendor (FACTORY_REF + heal.sh/heal-lib.sh + tests) + STATUS.md.

Proof

  • heal-lib-test: 25 groups (AC1–AC4 over healthy/401/stall/connect shapes).
  • heal-test: 19 scenarios, incl. a new watchdog scenario proving a fast 401 trips the incident but is recorded api_http=401, never timeout.
  • check-harness-drift: OK against dev-factory@1e08738.

Ruled by agent under ADR 0174 — veto anytime. A side-finding of triage run 22846 (root cause: remote Forgejo degradation, transient-external).

**Close report — landed under ADR 0174 (two-way door; veto anytime)** The api-timing probe now records curl's own outcome instead of collapsing every failure onto one ambiguous `timeout`. **What landed** - New `probe_api` (`heal-lib.sh`) writes three lines to `api-timing.txt`: `api_http=<code>`, `api_seconds=<t|timeout>`, `api_curl_exit=<rc>`. It captures curl's `-w '%{http_code} %{time_total}'` and its real exit code. - `heal.sh`'s `gather_evidence` calls `probe_api`; the watchdog reads all three facts and trips the `forgejo-api` incident on any unhealthy probe (transport failure / non-2xx / ≥30s) — the **same trip-set** the old blanket `timeout` fired on (`curl -sf` failed on all of them) — but the errline and evidence now name **which** fault. **Note on the task's snippet:** the suggested `read -r code t <<<"$(curl …)"; rc=$?` loses curl's exit — `$?` after `read` is READ's status (verified: it reports 0 on a connect-refused). `probe_api` captures the exit off a guarded assignment instead. **Acceptance criteria** - **AC1** — healthy: `api_http=200`, a real elapsed `api_seconds=<n>`, `api_curl_exit=0`. ✓ - **AC2** — a fast 401/403: `api_http=401`, `api_curl_exit=0`, and **not** `timeout`. ✓ - **AC3** — a genuine `--max-time` stall: `api_curl_exit=28` with `api_seconds=timeout` preserved. ✓ - **AC4** — the `sed -n 's/^api_seconds=//p'` read (heal.sh watchdog + prompt) still yields a usable value on all shapes. ✓ **Contract honoured:** fixed in `Matou/dev-factory` (`1e08738`), `FACTORY_REF` bumped `9aaac50→1e08738`, re-vendored byte-identical here — `check-harness-drift` OK (the vendored-file drift gate stays green). **Commits** - dev-factory `1e08738` — the fix + tests. - idss `44cf7d66` — re-vendor (`FACTORY_REF` + `heal.sh`/`heal-lib.sh` + tests) + `STATUS.md`. **Proof** - `heal-lib-test`: 25 groups (AC1–AC4 over healthy/401/stall/connect shapes). - `heal-test`: 19 scenarios, incl. a new watchdog scenario proving a fast 401 trips the incident but is recorded `api_http=401`, never `timeout`. - `check-harness-drift`: OK against `dev-factory@1e08738`. Ruled by agent under ADR 0174 — veto anytime. A side-finding of triage run 22846 (root cause: remote Forgejo degradation, transient-external).
matou-build-agent 2026-09-12 23:09:32 +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#1462
No description provided.