Skip to content

tests: read the whole pipe instead of grep -q under pipefail - #575

Merged
derekross merged 2 commits into
derekross:mainfrom
only21mil:build/tests-no-grep-q-pipes
Nov 9, 2026
Merged

derekross merged 2 commits into
derekross:mainfrom
only21mil:build/tests-no-grep-q-pipes

Conversation

@only21mil

@only21mil only21mil commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What and why

AGENTS.md (Userspace) and review lesson L-15: grep -q exits at its first match, the command still writing into the pipe gets SIGPIPE, and pipefail fails the pipeline. #457 is this race in the modem NV-overlay test (reproduced 10 of 10 with PYTHONUNBUFFERED=1, L-511). The same pattern was in other test scripts that set pipefail: a || fail check fails at random, and a && fail or ! … || fail check can pass when it should fail.

The first commit replaces each … | grep -q with grep -c … >/dev/null, which reads all of its input, in 16 test files (the device packages' bootctl dump and [Network] Gateway= checks, audio, fingerprint, gnss, mirror, modem, remote, tests/initramfs-reproducible, tests/install-phone, tests/rootfs-smoke). Patterns, -x/-E/-v, negations and messages are unchanged, so no check asserts anything new. The audio filter check (one line from grep -c) and the three omamobile-remote checks (a child bash -c without pipefail) can't race; they change only so that no test pipes into grep -q.

Not changed: packages/omamobile-modem/test/nv-overlay lines 104, 194 and 254. On #457 the maintainer offered that fix to the reporter (or to make it), so this leaves it to them.

The second commit adds tests/grep-q-pipes to tests/all: it git-greps the pipefail test scripts for a pipe into grep -q (--quiet, --silent) and fails with the lines it finds, leaving nv-overlay out until #457's fix lands. Open PRs that add the pattern would need the same one-word change after a rebase: #539, #510, #483, #541, #453, #436, #429, #346, #25. It can be dropped without touching the first commit. Per L-549, the tests/all loop line conflicts with other open PRs that edit it (#565, #562, #559, #543): the resolution keeps both entries, with tests/grep-q-pipes after tests/usb-product.

Test-only, so no package versions change (#457).

Old form against new, each run 20 times under set -euo pipefail with a writer that keeps writing after the match:

Pattern Case Old New
P | grep -q X || fail mirror:161, cheetah:32, gnss:187, fingerprint:109, rootfs-smoke exists, install-phone:139 false fail 20/20 pass 20/20
! P | grep -q X || fail cheetah:145, Gateway= present false pass 20/20 fail 20/20
P | grep -q X && fail initramfs-reproducible:44, rootfs-smoke:130, match present false pass 20/20 fail 20/20
(no match) the same checks with nothing to find pass pass

Device and build

  • Phone: none: tests only
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none (test files only)

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes (479 ok, 0 not ok)
  • tests/packages passes for the packages I touched (audio, device-akita, -cheetah, -felix, -husky, -lynx, -panther, -raven, fingerprint, gnss, mirror, modem, remote), apart from two omamobile-audio checks that fail the same way on main on this build machine (the alsaucm HiFi device count at line 42, and the /dev/snd/controlC0 check at line 1013, which use the host's own sound card); the speaker-filter section with line 1030 passes
  • Test-only change; no package version bumps (per tests: intermittent Broken pipe in omamobile-modem NV-overlay tests on Omarchy #457)
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: not applicable, nothing here runs on a phone
  • Runbook steps passed (plan, step, result): n/a
  • What I did not test: tests/rootfs-smoke against a real root image (none built here); its lines were checked with bash -n and the stubbed runs above
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)
tools/phone-smoke report

Not applicable: a test-only change (CONTRIBUTING.md §6.5).

Generated with Claude Opus 5.5 in T3 Code Nightly

only21mil and others added 2 commits November 9, 2026 17:59
AGENTS.md's Userspace gotcha (and review lesson L-15): grep -q exits at
its first match, the command still writing into the pipe gets SIGPIPE,
and pipefail fails the pipeline. Issue derekross#457 is this race in the modem
NV-overlay test, reproduced every time with PYTHONUNBUFFERED=1.

The same pattern sits in other test scripts that set pipefail. A
"|| fail" check then fails at random, and a "&& fail" or "! ... ||
fail" check passes when it should fail. Replace each grep -q with
grep -c ... >/dev/null, which reads all of its input; the patterns,
-x, -E, -v, negations and messages stay as they were, so no check
asserts anything new.

packages/omamobile-modem/test/nv-overlay is left alone: the maintainer
offered its fix to the reporter of derekross#457. Two kinds of line can't race
and change only so that no test pipes into grep -q: the audio filter
check reads one line from grep -c, and the three omamobile-remote
checks run in a child bash without pipefail.

Tested: each racing pattern run 20 times with a writer that keeps
writing after the match (old: a false fail or a false pass 20 of 20;
new: the right result 20 of 20); tests/packages for every touched
package, where omamobile-audio stops at two host-only checks that fail
the same way on main; and tests/all, where only release-upload fails,
on a checkout path containing "/.". Test-only, so no package versions
change (derekross#457).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A small guard so the previous commit's fix holds: it git-greps the test
scripts that set pipefail (tests/ and packages/*/test) for a pipe into
grep -q, --quiet or --silent, and fails with the lines it found. It
first checks its own pattern against lines it must and must not match
(a "||" before grep, a here-string, grep -c). nv-overlay is left out
until derekross#457's fix lands.

Tested: passes on this branch (46 scripts); on origin/main's tree it
fails and lists the lines the previous commit changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you, Victor. This is a tidy one: every conversion keeps its pattern,
flags and message, so no test asserts anything new, and the negated checks
(&& fail) can no longer pass by accident when the writer gets SIGPIPE. I ran
tests/grep-q-pipes here and made it fail on purpose with a stray | grep -q
in tests/install-phone; it names the line, and it leaves nv-overlay alone
until #457's fix lands, as you said.

I'll merge it as it is. tests/all's loop line will conflict with #576 and
#559; I'll keep both entries. The same pattern also appears in a few shipped
tools (bin/omamobile's adb get-state | grep -q device, for one); that's for
a separate issue, not this PR.

@derekross
derekross merged commit c5bf06d into derekross:main Nov 9, 2026
2 checks passed
@only21mil

only21mil commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

The shipped-tools side is in #587: bin/omamobile's adb get-state check and eight more laptop-side sites now use grep -c … >/dev/null. The one that really raced is fingerprint-capture's wait loop, which missed its end line on a long kmsg log. tests/grep-q-pipes now covers bin/, tools/ and rootfs/ too. The phone-side runtime files in packages/ are listed there, unchanged; touching them would require package version bumps and a phone smoke report. initramfs/init is listed separately because it runs under BusyBox sh without pipefail; no package version bump is implied.

derekross added a commit that referenced this pull request Nov 10, 2026
* bin/omamobile, tools, rootfs: no pipe into grep -q under pipefail

The follow-up to #575, which fixed the test scripts: the same pattern
in the laptop-side scripts that set pipefail. grep -q exits at the first
match, a writer still writing gets SIGPIPE, and pipefail fails the
pipeline (AGENTS.md section 4, Userspace). Each site now uses
grep -c ... >/dev/null, which reads all its input, with the same
pattern, flags and truth value.

The one that loses in practice is tools/fingerprint-capture's wait
loop: sed prints the whole log from the step's start, and with the end
line early in a verbose kmsg stream the old check never saw it and the
step ran to its timeout. The others have short writers (adb get-state,
android-info.txt, 64 bytes of the TA, the keyring, the image's
passwd) that fit the pipe buffer before grep exits; they change so
that no script keeps the pattern. Two of them failed open:
build-inside's user-account check and signing.sh's revoked-key check
would have passed on a SIGPIPE.

tests/grep-q-pipes now scans bin/, tools/ and rootfs/ as well, plus
tools/lib (sourced by pipefail scripts), and skips comment lines. It
leaves out five stage tools whose remaining hits are command strings
that tools/phone-ssh runs in the phone's shell, which has no pipefail.
Nothing under packages/ or initramfs/ changes.

Tested: the race harness (old 0/200, new 200/200 per form; the
fingerprint-capture loop old 0/100, new 100/100), tests/grep-q-pipes
with an injected pipe (fails, names the line) and a commented one
(passes), tools/pr-check, tests/all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tests/grep-q-pipes: scan the package tests too, and the two pipes they held

The scan's 'packages/*/test' pathspec matched no file, so no package
test was ever scanned (91 scripts). With 'packages/*/test/*' it reads
164, and found two pipes into grep -q that landed since: device-husky's
speaker_protection check (#453) and omamobile-waydroid's render-node
check (#541). Both now read the whole pipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ss#575)

* tests: read the whole pipe instead of grep -q under pipefail

AGENTS.md's Userspace gotcha (and review lesson L-15): grep -q exits at
its first match, the command still writing into the pipe gets SIGPIPE,
and pipefail fails the pipeline. Issue derekross#457 is this race in the modem
NV-overlay test, reproduced every time with PYTHONUNBUFFERED=1.

The same pattern sits in other test scripts that set pipefail. A
"|| fail" check then fails at random, and a "&& fail" or "! ... ||
fail" check passes when it should fail. Replace each grep -q with
grep -c ... >/dev/null, which reads all of its input; the patterns,
-x, -E, -v, negations and messages stay as they were, so no check
asserts anything new.

packages/omamobile-modem/test/nv-overlay is left alone: the maintainer
offered its fix to the reporter of derekross#457. Two kinds of line can't race
and change only so that no test pipes into grep -q: the audio filter
check reads one line from grep -c, and the three omamobile-remote
checks run in a child bash without pipefail.

Tested: each racing pattern run 20 times with a writer that keeps
writing after the match (old: a false fail or a false pass 20 of 20;
new: the right result 20 of 20); tests/packages for every touched
package, where omamobile-audio stops at two host-only checks that fail
the same way on main; and tests/all, where only release-upload fails,
on a checkout path containing "/.". Test-only, so no package versions
change (derekross#457).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tests/grep-q-pipes: no test script under pipefail pipes into grep -q

A small guard so the previous commit's fix holds: it git-greps the test
scripts that set pipefail (tests/ and packages/*/test) for a pipe into
grep -q, --quiet or --silent, and fails with the lines it found. It
first checks its own pattern against lines it must and must not match
(a "||" before grep, a here-string, grep -c). nv-overlay is left out
until derekross#457's fix lands.

Tested: passes on this branch (46 scripts); on origin/main's tree it
fails and lists the lines the previous commit changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…rekross#587)

* bin/omamobile, tools, rootfs: no pipe into grep -q under pipefail

The follow-up to derekross#575, which fixed the test scripts: the same pattern
in the laptop-side scripts that set pipefail. grep -q exits at the first
match, a writer still writing gets SIGPIPE, and pipefail fails the
pipeline (AGENTS.md section 4, Userspace). Each site now uses
grep -c ... >/dev/null, which reads all its input, with the same
pattern, flags and truth value.

The one that loses in practice is tools/fingerprint-capture's wait
loop: sed prints the whole log from the step's start, and with the end
line early in a verbose kmsg stream the old check never saw it and the
step ran to its timeout. The others have short writers (adb get-state,
android-info.txt, 64 bytes of the TA, the keyring, the image's
passwd) that fit the pipe buffer before grep exits; they change so
that no script keeps the pattern. Two of them failed open:
build-inside's user-account check and signing.sh's revoked-key check
would have passed on a SIGPIPE.

tests/grep-q-pipes now scans bin/, tools/ and rootfs/ as well, plus
tools/lib (sourced by pipefail scripts), and skips comment lines. It
leaves out five stage tools whose remaining hits are command strings
that tools/phone-ssh runs in the phone's shell, which has no pipefail.
Nothing under packages/ or initramfs/ changes.

Tested: the race harness (old 0/200, new 200/200 per form; the
fingerprint-capture loop old 0/100, new 100/100), tests/grep-q-pipes
with an injected pipe (fails, names the line) and a commented one
(passes), tools/pr-check, tests/all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* tests/grep-q-pipes: scan the package tests too, and the two pipes they held

The scan's 'packages/*/test' pathspec matched no file, so no package
test was ever scanned (91 scripts). With 'packages/*/test/*' it reads
164, and found two pipes into grep -q that landed since: device-husky's
speaker_protection check (derekross#453) and omamobile-waydroid's render-node
check (derekross#541). Both now read the whole pipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
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