Nothing feels safer in a Bash CI script than set -euo pipefail. Until you pipe a large file or command output into grep -q and watch your check fail precisely because it found what it was looking for—or worse, silently pass a forbidden-pattern check because the pipeline exited 141.
We hit this on 2026-11-21 in Intent Studio. A check script used set -o pipefail with producer | grep -q pattern. When the pattern matched early in a large stream, grep -q did its job and exited immediately with 0—closing the read end of the pipe. The upstream producer kept writing, received SIGPIPE, and died with exit code 141 (128 + 13).
Because pipefail returns the rightmost non-zero exit code in a pipeline, the entire pipeline exited 141 (failure).
How this silently inverts security checks
The truly nasty version is inside an if statement checking for forbidden content (like leaked secrets, MUTANT: markers, or disallowed imports):
set -euo pipefail
# BROKEN: if `cat large.log` gets SIGPIPE (141) after grep -q matches early,
# the pipeline fails (non-zero), so the `if` branch NEVER RUNS!
if cat large.log | grep -q "FORBIDDEN_SECRET"; then
echo "FAIL: secret found!" >&2
exit 1
fi
echo "PASS: clean"
Read that again:
large.logcontainsFORBIDDEN_SECRETon line 3 (out of 5,000 lines).grep -qmatches line 3 and immediately exits0.cattries to write the rest oflarge.logto a closed pipe and dies withSIGPIPE(141).pipefailsees141and marks the pipeline as failed (false).- The
ifstatement skips theexit 1and printsPASS: clean.
The bigger your output gets (past the OS pipe buffer, typically 64 KB on Linux or 16–64 KB on macOS), the more reliably your check lies to you.
The fix: never pipe into grep -q
If you already have a file, pass it directly to grep -q—no pipe, no SIGPIPE:
set -euo pipefail
# Check the input exists first so a missing file doesn't look "clean"
[[ -f "$report" ]] || { echo "FAIL: missing $report" >&2; exit 1; }
if grep -q "FORBIDDEN_SECRET" "$report"; then
echo "FAIL: secret found in $report" >&2
exit 1
fi
If the input comes from a command rather than a file, capture it to a temporary file first (so you also verify the producer exited 0!) and then run grep -q on the file:
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
# Producer's own exit code is checked cleanly here
my_tool --dump > "$tmp"
if grep -q "FORBIDDEN_SECRET" "$tmp"; then
echo "FAIL: secret found" >&2
exit 1
fiProve every check script can actually go red
Our workspace rule since 2026-11-21 is simple: a check script is not done until a test feeds it a known-bad input and asserts that it exits non-zero.
- Feed a 200 KB file with the forbidden pattern on line 1 (large enough to exceed the OS pipe buffer).
- Assert the check script fails.
- And in GitHub Actions, remember that steps after a failing step are skipped unless you add
if: ${{ !cancelled() }}—otherwise a red check can silently hide downstream suites.