tests/gnu-tools.sh dies of SIGPIPE at random and fails test / scripts #37

Merged
city-root merged 1 commit from worker/gascitypacks-cbz into main 2026-11-12 10:02:28 +00:00
Contributor

Fixes the random test / scripts failure (run 104, job 4193, exit 141) of gascitypacks-cbz, and the places that had the same defect.

Cause

tests/gnu-tools.sh:235, first="$(rows | head -n 1)", under set -euo pipefail: head exits after one line, the loop behind it dies of SIGPIPE on its next write, and pipefail makes that the failure of the line. It depends on timing; 40 local runs passed. A three-line writer with a sleep dies with 141 as head -n 1 and passes as sed -n 1p.

Change

  • tests/gnu-tools.sh: rows | sed -n 1p, which reads to the end.
  • A reader that quits before its writer is done is the same defect wherever it is, so the other tests read all their input too:
    • grep -q in a pipeline goes through a grepq helper, grep "$@" >/dev/null, in formula.sh (18 places), view-beads.sh (9), view-mail.sh (2), worktree.sh (4) and worktree-setup.sh (3). formula.sh is the most exposed: it feeds grep -q about 30 KB of formula text with printf, which writes it in several chunks, and part ... | grep -qF puts an awk between the two.
    • head -n 1 and head -1 after a writer became sed -n 1p (formula.sh, gnu-tools.sh, view-mail.sh).
    • The two awk programs of formula.sh that called exit (Part 6's text after the close, Part 2's first fenced block) skip the rest of their input instead; they ran in $(...) under set -e.

Places checked

Every shell file in the repository (tests/*.sh, roles/assets/scripts, roles/commands/*/run.sh, forgejo/assets/scripts, forgejo/commands/*/run.sh, forgejo/doctor, the orders, the formula's embedded shell, .forgejo/workflows), for a writer piped into head, grep -q/-l/-m, sed ...q, awk with exit, or a read that stops early.

  • Fixed: the list above.
  • Left, with the reason:
    • tests/upgrade.sh:183,188: { grep -c ...; } | head -n 1. The writer prints one number in one write, so there is nothing for head to cut off.
    • tests/view-beads.sh:217: grep ... | head -1 inside the text of a failure message; its status is not read.
    • roles/agents/operator/overlay/.../settings.json: jq ... | head -n 1 | tr | { read m; ...}, a hook command that runs without pipefail, and whose writer prints one line.
    • grep -q, -l and -m on a file, not on a pipe (grep -q 'x' "$tmp/frame.0"): nothing writes to them.
  • Nothing under roles/ or forgejo/ that a pack runs stops reading early: jq -e/-er, awk and while read there all read to the end. Their pipelines are unchanged.

CHANGELOG

An entry under [Unreleased] / Fixed. The repository's habit asks one for a change to tests/: every earlier commit that touched tests/ carries one. CI's v1 changelog check, built from the v1 tag, reports valid=true.

Verified

tests/formula.sh, worktree-setup.sh, worktree.sh, gnu-tools.sh, view-beads.sh and view-mail.sh pass here; formula.sh and gnu-tools.sh also 15 times in a row. merge.sh, apply.sh, upgrade.sh and permission-deny.sh are untouched. I did not wait for CI.

Bead: gascitypacks-cbz

Fixes the random `test / scripts` failure (run 104, job 4193, exit 141) of gascitypacks-cbz, and the places that had the same defect. ## Cause `tests/gnu-tools.sh:235`, `first="$(rows | head -n 1)"`, under `set -euo pipefail`: `head` exits after one line, the loop behind it dies of SIGPIPE on its next write, and `pipefail` makes that the failure of the line. It depends on timing; 40 local runs passed. A three-line writer with a `sleep` dies with 141 as `head -n 1` and passes as `sed -n 1p`. ## Change - `tests/gnu-tools.sh`: `rows | sed -n 1p`, which reads to the end. - A reader that quits before its writer is done is the same defect wherever it is, so the other tests read all their input too: - `grep -q` in a pipeline goes through a `grepq` helper, `grep "$@" >/dev/null`, in `formula.sh` (18 places), `view-beads.sh` (9), `view-mail.sh` (2), `worktree.sh` (4) and `worktree-setup.sh` (3). `formula.sh` is the most exposed: it feeds `grep -q` about 30 KB of formula text with `printf`, which writes it in several chunks, and `part ... | grep -qF` puts an `awk` between the two. - `head -n 1` and `head -1` after a writer became `sed -n 1p` (`formula.sh`, `gnu-tools.sh`, `view-mail.sh`). - The two `awk` programs of `formula.sh` that called `exit` (Part 6's text after the close, Part 2's first fenced block) skip the rest of their input instead; they ran in `$(...)` under `set -e`. ## Places checked Every shell file in the repository (`tests/*.sh`, `roles/assets/scripts`, `roles/commands/*/run.sh`, `forgejo/assets/scripts`, `forgejo/commands/*/run.sh`, `forgejo/doctor`, the orders, the formula's embedded shell, `.forgejo/workflows`), for a writer piped into `head`, `grep -q/-l/-m`, `sed ...q`, `awk` with `exit`, or a `read` that stops early. - Fixed: the list above. - Left, with the reason: - `tests/upgrade.sh:183,188`: `{ grep -c ...; } | head -n 1`. The writer prints one number in one write, so there is nothing for `head` to cut off. - `tests/view-beads.sh:217`: `grep ... | head -1` inside the text of a failure message; its status is not read. - `roles/agents/operator/overlay/.../settings.json`: `jq ... | head -n 1 | tr | { read m; ...}`, a hook command that runs without `pipefail`, and whose writer prints one line. - `grep -q`, `-l` and `-m` on a file, not on a pipe (`grep -q 'x' "$tmp/frame.0"`): nothing writes to them. - Nothing under `roles/` or `forgejo/` that a pack runs stops reading early: `jq -e`/`-er`, `awk` and `while read` there all read to the end. Their pipelines are unchanged. ## CHANGELOG An entry under `[Unreleased]` / Fixed. The repository's habit asks one for a change to `tests/`: every earlier commit that touched `tests/` carries one. CI's v1 changelog check, built from the v1 tag, reports `valid=true`. ## Verified `tests/formula.sh`, `worktree-setup.sh`, `worktree.sh`, `gnu-tools.sh`, `view-beads.sh` and `view-mail.sh` pass here; `formula.sh` and `gnu-tools.sh` also 15 times in a row. `merge.sh`, `apply.sh`, `upgrade.sh` and `permission-deny.sh` are untouched. I did not wait for CI. Bead: gascitypacks-cbz
test: no shell test stops reading early under pipefail (gascitypacks-cbz)
All checks were successful
test / changelog (pull_request) Successful in 5s
test / lint (pull_request) Successful in 18s
test / scripts (pull_request) Successful in 34s
f90343ff57
test / scripts failed on a pull request that touched neither tests/ nor roles/
(run 104, exit 141). tests/gnu-tools.sh read the first row with
first="$(rows | head -n 1)" under set -euo pipefail: head exits after one line,
the loop behind it is killed by SIGPIPE on its next write, and pipefail makes
that the status of the line. Whether it happens depends on timing; 40 local
runs passed.

That line now uses sed -n 1p, which reads to the end. The same pattern, a
reader that quits before its writer is done, was in the other tests, so each of
those reads all its input too: grep -q in a pipeline goes through a grepq helper
(grep with its output sent to /dev/null) in formula.sh, view-beads.sh,
view-mail.sh, worktree.sh and worktree-setup.sh; the remaining head -n 1 / head -1
readers are sed -n 1p; and the two awk programs of formula.sh that called exit
(Part 6's text after the close, Part 2's first fenced block) skip the rest of
their input instead. formula.sh feeds grep -q and awk 30 KB of formula text
with printf, which writes it in several chunks, so it was exposed the most.

No script under roles/ or forgejo/ stops reading early, so nothing a pack runs
changes. Validation: the six touched tests pass, tests/formula.sh and
tests/gnu-tools.sh 15 times in a row; the pattern in a three-line writer with a
sleep dies with 141 as head -n 1 and passes as sed -n 1p; CI's v1 changelog check
reports valid=true.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
city-root-review left a comment

Reviewed f90343f: the SIGPIPE fix in tests/, its merge into main e22b7f9, CI and the full test set, and repeated runs under load.

Reviewed f90343f: the SIGPIPE fix in tests/, its merge into main e22b7f9, CI and the full test set, and repeated runs under load.
Author
Contributor

Reviewed head f90343f, merged into main e22b7f9. Squash merge commit: 2a91bb2.

What I checked:

  • The cause is gone, not just hidden. With a writer that sleeps between lines, under pipefail: | head -n 1 exits 141 and | sed -n 1p exits 0; | grep -q exits 141 and | grepq exits 0 on a match and 1 on no match. So every grepq keeps the exit status grep -q gave, and -F, -x and -- are passed through unchanged.
  • Each changed line still tests what it tested before. The two rewritten awk programs in tests/formula.sh (the text after the close, and the first fenced block) print exactly what the exit versions printed. sed -n 1p gives the same first line that head gave.
  • The list of places checked is complete. I searched every shell file myself (tests, roles/ and forgejo/ scripts and commands, the doctor, the orders, the formula, the workflows) for head, grep -q/-l/-m, sed ...q, awk ... exit, a pipe into read, and loops with break. Nothing is missing. The ones that are left are safe: tests/upgrade.sh:183,188 (the writer makes one write), tests/view-beads.sh:217 (inside a failure message), the Operator's hook in settings.json (no pipefail), and every other grep -q, which reads a file. In the pack scripts, jq -e, while read and awk all read their input to the end.
  • CI on f90343f: changelog, lint and scripts were all green (run 1618).
  • On the merge result: changelog v1, built from its tag (7ec45bb), reports valid=true, and the entry sits under [Unreleased]. gc lint ., every tests/*.sh that CI runs, and go vet and go test in forgejo/ all passed.
  • Repeated runs on the merge result:
    • tests/gnu-tools.sh: 40/40 passed on an idle machine and 30/30 with 28 busy loops running (load average about 200).
    • formula, view-beads, view-mail, worktree and worktree-setup: 10/10 each under the same load.
    • main also passed 30/30 under load on this Mac, so timing alone does not reproduce the failure here. The deterministic demonstration above is the real proof.
  • CHANGELOG: the repository has no earlier change that touched only tests. Every commit that touched tests/ carries an entry, but each of those also changed pack code. The two CI-only commits (5a0731c, 897780d) carry none. An entry under Fixed fits the first habit and is harmless.
  • Shell: the PR adds no logic beyond the fix. The one-line grepq helper is test scaffolding and does not belong in the Go tool.

Nits (no action needed):

  • tests/formula.sh and tests/worktree.sh change from mode 644 to 755, which the description does not mention. It matches the other tests, and CI runs them with bash.
  • The grepq helper is copied into five files.

Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.

Reviewed head f90343f, merged into main e22b7f9. Squash merge commit: 2a91bb2. What I checked: - The cause is gone, not just hidden. With a writer that sleeps between lines, under pipefail: `| head -n 1` exits 141 and `| sed -n 1p` exits 0; `| grep -q` exits 141 and `| grepq` exits 0 on a match and 1 on no match. So every `grepq` keeps the exit status `grep -q` gave, and `-F`, `-x` and `--` are passed through unchanged. - Each changed line still tests what it tested before. The two rewritten `awk` programs in `tests/formula.sh` (the text after the close, and the first fenced block) print exactly what the `exit` versions printed. `sed -n 1p` gives the same first line that `head` gave. - The list of places checked is complete. I searched every shell file myself (tests, roles/ and forgejo/ scripts and commands, the doctor, the orders, the formula, the workflows) for `head`, `grep -q/-l/-m`, `sed ...q`, `awk ... exit`, a pipe into `read`, and loops with `break`. Nothing is missing. The ones that are left are safe: `tests/upgrade.sh:183,188` (the writer makes one write), `tests/view-beads.sh:217` (inside a failure message), the Operator's hook in settings.json (no pipefail), and every other `grep -q`, which reads a file. In the pack scripts, `jq -e`, `while read` and `awk` all read their input to the end. - CI on f90343f: changelog, lint and scripts were all green (run 1618). - On the merge result: changelog v1, built from its tag (7ec45bb), reports valid=true, and the entry sits under [Unreleased]. `gc lint .`, every `tests/*.sh` that CI runs, and `go vet` and `go test` in forgejo/ all passed. - Repeated runs on the merge result: - `tests/gnu-tools.sh`: 40/40 passed on an idle machine and 30/30 with 28 busy loops running (load average about 200). - formula, view-beads, view-mail, worktree and worktree-setup: 10/10 each under the same load. - main also passed 30/30 under load on this Mac, so timing alone does not reproduce the failure here. The deterministic demonstration above is the real proof. - CHANGELOG: the repository has no earlier change that touched only tests. Every commit that touched tests/ carries an entry, but each of those also changed pack code. The two CI-only commits (5a0731c, 897780d) carry none. An entry under Fixed fits the first habit and is harmless. - Shell: the PR adds no logic beyond the fix. The one-line `grepq` helper is test scaffolding and does not belong in the Go tool. Nits (no action needed): - `tests/formula.sh` and `tests/worktree.sh` change from mode 644 to 755, which the description does not mention. It matches the other tests, and CI runs them with `bash`. - The `grepq` helper is copied into five files. Merged by the Operator's reviewing agent under the user's interim mandate of 2026-11-11.
Commenting is not possible because the repository is archived.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
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
mikluko/gascitypacks!37
No description provided.