Skip to content

fix(skills): a found match reported as missing — grep -q SIGPIPEd awk - #608

Merged
athvin merged 1 commit into
mainfrom
fix/skills-check-sigpipe
Nov 5, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/skills-check-sigpipe

Conversation

@athvin

@athvin athvin commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Root cause of the #606 failure, where agent skills (lint + drift) claimed
frontend-design-system never names frontend-design — against a tree where it does,
at body line 26 — then passed on rerun.

The bug

names_skill_in_backticks() {
    skill_body "$file" | grep -qF "\`$skill\`"   # under set -euo pipefail
}

grep -q exits the instant it matches. That closes the pipe while awk is still
writing the rest of the body, awk takes SIGPIPE, the pipeline exits 141, and
the function reports the name missing. The match was found; the plumbing threw it
away.

Proven deterministically — the string is present once, and the shipped helper denies it:

--- the string IS present:      occurrences: 1
--- the repo's check says:      FAIL (claims it never names it)
--- raw pipeline status:        pipeline exit=141
                                awk alone exit=0

Why it looked unreproducible

It's a race. Three independent reproductions of the exact refs/pull/606/merge
tree
— the branch, a synthesized merge, and the fetched merge ref, each running
all faithfully — all passed. That is what a race looks like from outside.

All three house skills are exposed, not just the one that fired:

House skill Match at body line Bytes left to write after it
frontend-design-system 26 of 206 9,739
frontend-data-ui 34 of 181 7,557
rust-conventions 31 of 165 6,627

The largest remainder is frontend-design-system's — and that is the one that failed.

The repo already knew this pattern

tf-helpers-test.sh carries a comment avoiding it verbatim — "grep -q would also
SIGPIPE the guard on the way"
— and ci-and-supply-chain's skill states the rule for
detect jobs: grep -c, not grep -q, on anything behind a pipe, because a false
skip beats a failure. skills-check.sh just had an instance nobody had connected to
it. The O4 row-pairing check had the same shape with a small writer; hardened too.

Fixed by capturing and then matching in bash — no pipe at all.

A race can't be trusted to the gate's own green

So it gets scripts/ci/skills-check-test.sh, wired into the existing toolchain-free
skills job. It forces the losing side every time (239 kB of body after an early
match, so the writer must block), and carries two guards against itself:

  • a negative control — a genuinely absent name must still report missing, or the
    suite would pass against a function that returns true unconditionally;
  • a mutation check asserting the pre-fix implementation fails the same case.
    Without it the suite couldn't tell the fix from the bug.

It also greps the gate for new | grep -q instances, because the fix is one line from
being tidied back off.

Observed failing on purpose

Reverting the one-line fix in place turns the suite red on two assertions and names the
file and line:

  FAIL  finds a name early in a 238997-byte body (the SIGPIPE case)
        this is the #606 failure: the name IS present and the check denies it
  FAIL  an unbounded writer is piped into 'grep -q' in scripts/skills-check.sh
        360:	skill_body "$file" | grep -qF "\`$skill\`"

Restored byte-identically afterwards (diff -q clean).

Verification

  • skills-check.sh all green: 20 skills, 3 overrides, references current.
  • New suite 5/5, and 2 failures when mutated.
  • rust.yml parses as YAML; actionlint.sh clean — 426 uses: references, all
    S9-pinned.
  • make check green.

🤖 Generated with Claude Code

Root cause of the #606 failure, where `agent skills (lint + drift)` claimed
`frontend-design-system` never names `frontend-design` against a tree where it
does, at body line 26, and then passed on rerun.

`names_skill_in_backticks` was

    skill_body "$file" | grep -qF "\`$skill\`"

under `set -euo pipefail`. `grep -q` exits the instant it matches, which closes
the pipe while `awk` is still writing the rest of the body. `awk` takes SIGPIPE,
the PIPELINE exits 141, and the function reports the name missing. The match was
found; the plumbing threw it away.

It is a race, which is why three independent reproductions of the exact
`refs/pull/606/merge` tree all passed locally and why the rerun was green. All
three house skills are exposed, not just the one that fired: each names its
counterpart at body line 26, 31 or 34, leaving 6.6-9.7 kB still to write. The
largest remainder belongs to `frontend-design-system` -- 9,739 bytes -- which is
the one that failed.

The repository already knew this pattern. `tf-helpers-test.sh` carries a comment
avoiding it verbatim ("`grep -q` would also SIGPIPE the guard on the way"), and
ci-and-supply-chain's skill states the rule for `detect` jobs: `grep -c`, not
`grep -q`, on anything behind a pipe, because a false skip beats a failure.
`skills-check.sh` simply had an instance nobody had connected to it. The O4 row
pairing check had the same shape with a small writer; hardened too.

Fixed by capturing and then matching in bash, which needs no pipe at all.

A race cannot be trusted to the gate's own green, so it gets a suite:
`scripts/ci/skills-check-test.sh`, wired into the existing toolchain-free
`skills` job. It forces the losing side of the race deterministically -- 239 kB
of body after an early match, so the writer MUST block -- and carries two guards
against itself: a negative control (a genuinely absent name must still report
missing) and a mutation check asserting the PRE-FIX implementation fails the
same case. Without that second one the suite could not tell the fix from the
bug. It also greps the gate for new `| grep -q` instances, because the fix is
one line away from being tidied back off.

Observed failing on purpose: reverting the one-line fix in place turns the suite
red on two assertions and names the file and line. Restored byte-identically.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin
athvin merged commit d4368b8 into main Nov 5, 2026
39 checks passed
athvin added a commit that referenced this pull request Nov 29, 2026
…or it (#641) (#1425)

`writer | grep -q` under pipefail is a race: grep exits on the first
match, the writer takes SIGPIPE, and the pipeline returns 141, so a
needle that WAS present reads as absent. #608 fixed the one instance that
fired. The rule was stated only for detect jobs, and the guard scanned one
file.

- All 23 live sites (not just the four the ticket listed) drop -q and
  redirect to /dev/null instead. grep without -q drains its input, so
  the exit status is the same and the writer is never cut off.
  skills-check-test's pre-fix form stays as its mutation control and
  carries the exception marker.
- scripts/ci/piped-grep-q-check.sh scans every tracked *.sh, ignoring
  comments and '# piped-grep-q: intentional'. Its self-test must FAIL on a
  planted violation first. It runs in make check and in rust.yml's
  ungated layout steps.
- ci-and-supply-chain states the rule repo-wide, and tf-helpers-test.sh
  cross-references it.

Co-authored-by: bmoore813 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants