verdict_write: a no-match grep kills the EXIT trap, so no verdict is ever written #154

Closed
opened 2026-09-20 19:03:16 +00:00 by ben · 1 comment
Owner

Symptom

A run whose error log holds no line matching verdict_write's regex writes no verdict at all, so the healer keys on a bare workflow-name signature with Trigger error line: unknown.

Cause

verdict_write (verdict-lib.sh) greps the errlog without || true:

errs="$(grep -hiE 'error|fail|…' "$VERDICT_ERRLOG" 2>/dev/null | grep -v '^==> ' | tail -12)"
[ -z "$errs" ] && errs="$(grep -vE '^[[:space:]]*$' "$VERDICT_ERRLOG" 2>/dev/null | tail -8)"

Callers run under set -euo pipefail and wire verdict_write into an EXIT trap. On a no-match, grep exits 1, pipefail propagates it, and errexit kills the trap on that very line. The breadcrumb has already been erased two lines above, so the run leaves neither breadcrumb nor verdict — and the no-match fallback on the next line, written for exactly this case, is unreachable.

Real trigger: host-slot-wait's host capacity still busy after 1800s — giving up (matou-app ci run 21727) contains none of the regex words.

Fix

|| true on both greps, with a comment saying why it is load-bearing, plus a scenario in tests/verdict-lib-test.sh that reproduces the real caller posture (set -euo pipefail + EXIT trap + a no-match errlog) and asserts a verdict is still written with the log's own last lines. Red before green against the current file.

Provenance / drift

This fix was written and proven in Matou/matou-app (commit 9dd432e, 2026-09-18) but landed directly in that repo's vendored copy instead of here, so .sandcastle/verdict-lib.sh there has drifted from FACTORY_REF cca3e27. That drift fails check-harness-drift.sh and blocked an agent push on matou-app#186 (the pre-push gate fires when a push's range touches a vendored path). Landing it here and re-vendoring matou-app clears the drift and gives every consumer the fix.

Refs matou-app#186, matou-app#380 (the missing-verdict class).

## Symptom A run whose error log holds no line matching `verdict_write`'s regex writes **no verdict at all**, so the healer keys on a bare workflow-name signature with `Trigger error line: unknown`. ## Cause `verdict_write` (`verdict-lib.sh`) greps the errlog without `|| true`: ```sh errs="$(grep -hiE 'error|fail|…' "$VERDICT_ERRLOG" 2>/dev/null | grep -v '^==> ' | tail -12)" [ -z "$errs" ] && errs="$(grep -vE '^[[:space:]]*$' "$VERDICT_ERRLOG" 2>/dev/null | tail -8)" ``` Callers run under `set -euo pipefail` and wire `verdict_write` into an EXIT trap. On a no-match, `grep` exits 1, `pipefail` propagates it, and `errexit` kills the trap on that very line. The breadcrumb has already been erased two lines above, so the run leaves neither breadcrumb nor verdict — and the no-match fallback on the next line, written for exactly this case, is unreachable. Real trigger: `host-slot-wait`'s `host capacity still busy after 1800s — giving up` (matou-app ci run 21727) contains none of the regex words. ## Fix `|| true` on both greps, with a comment saying why it is load-bearing, plus a scenario in `tests/verdict-lib-test.sh` that reproduces the real caller posture (`set -euo pipefail` + EXIT trap + a no-match errlog) and asserts a verdict is still written with the log's own last lines. Red before green against the current file. ## Provenance / drift This fix was written and proven in `Matou/matou-app` (commit `9dd432e`, 2026-09-18) but landed **directly in that repo's vendored copy** instead of here, so `.sandcastle/verdict-lib.sh` there has drifted from `FACTORY_REF` `cca3e27`. That drift fails `check-harness-drift.sh` and blocked an agent push on matou-app#186 (the pre-push gate fires when a push's range touches a vendored path). Landing it here and re-vendoring matou-app clears the drift and gives every consumer the fix. Refs matou-app#186, matou-app#380 (the missing-verdict class).

This was generated by AI during triage.

Agent Brief

Category: bug
Summary: verdict_write's unguarded greps kill the EXIT trap on a no-match errlog, so no verdict is written and the healer keys on Trigger error line: unknown.

Verification: Confirmed against the current file at FACTORY_REF 2445159. verdict_write (in the verdict lib) filters the errlog with an error-word grep -hiE ... | grep -v '^==> ' and then a non-blank fallback grep -vE '^[[:space:]]*$', neither guarded with || true. Callers source this under set -euo pipefail and fire verdict_write from an EXIT trap. When the errlog holds no line matching the error-word regex, the first pipeline exits non-zero, pipefail propagates it, and errexit terminates the trap on that line — after the breadcrumb has already been removed and before the no-match fallback and the verdict write below can run. Real trigger: host-slot-wait's host capacity still busy after 1800s — giving up (matou-app CI run 21727) matches none of the regex words.

Current behavior:
A run whose errlog contains no error-word line leaves neither breadcrumb nor verdict. The healer falls back to a bare workflow-name signature with Trigger error line: unknown. The no-match fallback (tail of the log's own last non-blank lines) written for exactly this case is unreachable.

Desired behavior:
When the errlog exists but no line matches the error-word regex, verdict_write still completes: it falls through to the last-lines fallback (and then, if still empty, the caller-recorded VERDICT_ERROR line) and writes the verdict artifact with those lines. A no-match grep must not abort the function under errexit/pipefail.

Key interfaces:

  • verdict_write — its errlog-extraction greps must tolerate a no-match (exit 1) without aborting the surrounding function when sourced under set -euo pipefail and invoked from an EXIT trap. Add a load-bearing comment at the guard explaining why (the trap + errexit + pipefail interaction), so a later reader doesn't "tidy" it away.
  • The verdict artifact contract is unchanged: stage=, exit=, --- error lines ---, then the extracted lines.

Acceptance criteria:

  • With an errlog present that matches none of the error-word regex, verdict_write <non-zero> fired from an EXIT trap under set -euo pipefail still writes the verdict artifact, populated with the errlog's own last non-blank lines.
  • The existing behaviors are preserved: a matching errlog still yields the error-word lines; a clean (exit 0) run still writes no verdict; a SIGKILL'd run (trap never runs) still leaves no verdict; the breadcrumb is still erased on every trapped exit.
  • tests/verdict-lib-test.sh gains a scenario that reproduces the real caller posture (set -euo pipefail + EXIT trap + a no-match errlog) and asserts a verdict is written with the log's last lines. It is red against the current file and green after the fix (red-before-green demonstrated).
  • The offline suite stays green: for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done.
  • The lib change and its test land in the same commit (per CLAUDE.md).

Out of scope:

  • Changing the error-word regex itself or the tail line counts.
  • Re-vendoring Matou/matou-app's .sandcastle/ copy or touching any product repo — the topology is pull-only (ADR 0001); a human bumps the consumer's FACTORY_REF after this lands. Do not "closes #N" this ticket from a commit message (GOTCHAS: auto-close over-fires).
  • Editing anything under .sandcastle/, the prompt skeletons, or .forgejo/.
> *This was generated by AI during triage.* ## Agent Brief **Category:** bug **Summary:** `verdict_write`'s unguarded `grep`s kill the `EXIT` trap on a no-match errlog, so no verdict is written and the healer keys on `Trigger error line: unknown`. **Verification:** Confirmed against the current file at `FACTORY_REF` `2445159`. `verdict_write` (in the verdict lib) filters the errlog with an error-word `grep -hiE ... | grep -v '^==> '` and then a non-blank fallback `grep -vE '^[[:space:]]*$'`, neither guarded with `|| true`. Callers source this under `set -euo pipefail` and fire `verdict_write` from an `EXIT` trap. When the errlog holds no line matching the error-word regex, the first pipeline exits non-zero, `pipefail` propagates it, and `errexit` terminates the trap on that line — after the breadcrumb has already been removed and before the no-match fallback and the verdict write below can run. Real trigger: `host-slot-wait`'s `host capacity still busy after 1800s — giving up` (matou-app CI run 21727) matches none of the regex words. **Current behavior:** A run whose errlog contains no error-word line leaves **neither breadcrumb nor verdict**. The healer falls back to a bare workflow-name signature with `Trigger error line: unknown`. The no-match fallback (`tail` of the log's own last non-blank lines) written for exactly this case is unreachable. **Desired behavior:** When the errlog exists but no line matches the error-word regex, `verdict_write` still completes: it falls through to the last-lines fallback (and then, if still empty, the caller-recorded `VERDICT_ERROR` line) and writes the verdict artifact with those lines. A no-match `grep` must not abort the function under `errexit`/`pipefail`. **Key interfaces:** - `verdict_write` — its errlog-extraction `grep`s must tolerate a no-match (exit 1) without aborting the surrounding function when sourced under `set -euo pipefail` and invoked from an `EXIT` trap. Add a load-bearing comment at the guard explaining why (the trap + errexit + pipefail interaction), so a later reader doesn't "tidy" it away. - The verdict artifact contract is unchanged: `stage=`, `exit=`, `--- error lines ---`, then the extracted lines. **Acceptance criteria:** - [ ] With an errlog present that matches none of the error-word regex, `verdict_write <non-zero>` fired from an `EXIT` trap under `set -euo pipefail` still writes the verdict artifact, populated with the errlog's own last non-blank lines. - [ ] The existing behaviors are preserved: a matching errlog still yields the error-word lines; a clean (exit 0) run still writes no verdict; a SIGKILL'd run (trap never runs) still leaves no verdict; the breadcrumb is still erased on every trapped exit. - [ ] `tests/verdict-lib-test.sh` gains a scenario that reproduces the real caller posture (`set -euo pipefail` + `EXIT` trap + a no-match errlog) and asserts a verdict is written with the log's last lines. It is red against the current file and green after the fix (red-before-green demonstrated). - [ ] The offline suite stays green: `for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done`. - [ ] The lib change and its test land in the same commit (per CLAUDE.md). **Out of scope:** - Changing the error-word regex itself or the `tail` line counts. - Re-vendoring `Matou/matou-app`'s `.sandcastle/` copy or touching any product repo — the topology is pull-only (ADR 0001); a human bumps the consumer's `FACTORY_REF` after this lands. Do not "closes #N" this ticket from a commit message (GOTCHAS: auto-close over-fires). - Editing anything under `.sandcastle/`, the prompt skeletons, or `.forgejo/`.
ben closed this issue 2026-09-20 20:27:58 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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/dev-factory#154
No description provided.