Repository navigation
Conversation
On derekross#884 the maintainer invited a lint beside tests/grep-q-pipes for a head that can exit before its writer. Every head form (-1, -n N, -c N, bare) stops reading once it has its lines or bytes; a writer that writes again gets SIGPIPE, and pipefail fails the pipeline. A "|| fail" check then fails at random, a "set -e" assignment ends the script, and an "if ...; then fail" check passes. tests/rootfs-smoke's last check is that case: with more than five files in the image that still name the old project, head -5 exits while grep -v is still writing, the pipeline ends 141, and the check prints five of the files and then "ok". On a made-up ext4 image with 3000 such files it passed 3 of 3 runs on main; it now fails 3 of 3, and still passes on a clean image. Each pipe into head in a pipefail test script changes by one rule: head -n N (and -1, -N) becomes sed -n '1,Np' (sed -n 1p for one line), and head -c N becomes { head -c N; cat >/dev/null; }. Both read all their input and give the same bytes and status as the head they replace: checked for every form used against empty input, one line, fewer and more lines than N, no trailing newline, NUL bytes and long input. Lines that couldn't race change too, so that no test pipes into head. One line in tests/nv-backup stays: that test closes nv-backup's stdout early on purpose (its check's name no longer says "| head"). tests/head-pipes keeps it that way, in grep-q-pipes' style: it checks its pattern on lines it must and must not match (derekross#884's head -c 64 | head -1 among them), fails by name when a pathspec matches no pipefail script, and allows the one nv-backup line only by its whole text. It scans tests and packages/*/test, without nv-overlay (left for derekross#457, as grep-q-pipes leaves it). bin, tools, tools/lib and rootfs (59 lines in 18 files) are left for a follow-up. AGENTS.md's grep -q gotcha now names head. Tested: the lint fails on main's tree with 34 lines in 20 files (the 33 lines that pipe into head, and nv-backup's old check name) and passes here; a weakened pattern, a pathspec typo or an edit to the allowed line each make it fail. tools/pr-check origin/main passes. In a sandbox with no network, tests/all passes up to tests/extract-vendor-firmware, whose two real-ext4 cases fail there on main too and pass outside it on both; the suites after it pass one by one. The touched packages' test/all (via tests/packages) end as on main in that sandbox: omamobile-audio's check against the host's UCM files and omamobile-shell's portal check fail the same way on both; omamobile-audio passes with the host's UCM files hidden, and the shell's sleepd.sh, which that suite runs after the portal check, passes on its own. Not run: notifications-reply and the owl scripts (they need their container), and omamobile-voice's server check (network). Test-only, so no package versions change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
This is the lint invited on #884: a check beside
tests/grep-q-pipesfor a pipe intoheadin a script that sets pipefail.headwith a count can exit before its writer is done; the writer gets SIGPIPE and pipefail fails the pipeline, so aset -eassignment ends the script, a|| failcheck fails at random, or anif ...; then failcheck passes.tests/rootfs-smoke's last check is that last case: ingrep -rIl omandroid ... | grep -v ... | head -5 | grep ., with many leftover files, the pipeline ends 141 and the check prints five of them, thenok.This is step 1 of 2, as #575 was for
grep -q.tests/head-pipesscanstestsandpackages/*/testwith the samenv-overlayexclusion astests/grep-q-pipes. I changed 35 pipes intoheadon 33 lines at d0028d0 by one rule:head -n Nbecomessed -n '1,Np',head -c Nbecomes{ head -c N; cat >/dev/null; }. Both read all their input, with the same bytes and exit status. One line oftests/nv-backupis allowed by its whole text: that test closes stdout early on purpose.bin,tools,tools/libandrootfs(59 lines in 18 files at d0028d0) are for step 2, as #587 was.tests/allruns the lint; AGENTS.md'sgrep -qgotcha now nameshead.I had AI agents make every run here. Reproduction (in the block): green main 143f2ce's and this commit's
tests/rootfs-smokeon a made-up root image with 3000 leftover files. Regression test:tests/head-pipes, which fails on d0028d0's tree and on #884'shead -c 64 "$tmp" | head -1.Device and build
uname -r): no phonetest/scripts of eleven packages)Checks (no phone needed)
tools/pr-check origin/mainpasses (AI agent)tests/allpasses (AI agent, in a no-network sandbox; below)tests/packagespasses (or the packages I touched: all eleven, AI agent, in a no-network sandbox; below)versionbumped, and the new version is in the commit subject: test scripts only, as in tests: read the whole pipe instead of grep -q under pipefail #575Co-Authored-By:orAssisted-by:trailer, never aSigned-off-by:On the phone
userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)tools/phone-smokereportNot applicable: test scripts that never run on a phone (CONTRIBUTING.md §6.5).
I had AI agents make every run in this description, on an x86_64 desktop running Ubuntu 26.04. Each transcript below names its own commit.
Setup: Ubuntu 26.04 on x86_64, bash 5.3.9, uutils coreutils 0.10.0, e2fsprogs 1.47.2; a fresh
git archiveof each commit, run in a sandbox with no network.Steps: build a made-up ext4 root image with
mkfs.ext4 -dthat passes every earlier check oftests/rootfs-smoke, with 3000 files under/usr/share/omamobilethat containomandroid→tests/rootfs-smoke standin-root.imgBefore, on green main 143f2ce7:
After, on 7c3c1255:
The candidate branches from d0028d00. Three runs each: 143f2ce ended
okand exit 0 in 3 of 3, 7c3c125not okand exit 1 in 3 of 3, and so did the cleangit merge-treeof 7c3c125 with 143f2ce (tree4e1ea6a5). With 3 such files every tree fails the check, and with none every tree passes.tests/head-pipeson 7c3c125 passes (149 scripts; 150 on the merge with 143f2ce). Run on d0028d0's tree it lists 34 lines in 20 files: those 33, and the old check name intests/nv-backup. Withfirst=$(head -c 64 "$tmp" | head -1)added totests/pr-check, or an edit to the allowed line, it fails and lists that line. Each replacement form, against empty input, one line, fewer and more lines than N, no final newline, NULs and long input, gives the same bytes and exit status as theheadit replaces. Fed a long input under pipefail, every old form exits 141, and every new one exits 0.AI agents ran the host checks on 7c3c125 with Docker and fastboot stubs, in a sandbox with no network.
tests/all, whole and unchanged, exits 0 (823 ok) with the user mapped to root in the sandbox's own user namespace. As the ordinary user there,debugfs rdumpreports "Invalid argument" instead of "Operation not permitted" when it can't change a file's owner,tools/extract-vendor-firmwarelets only the second through, and two real-ext4 cases fail, on d0028d0 too. The two permission checks omitted from the mapped-root run pass in the ordinary user's runs.tests/packagesfor the eleven touched packages exits 0 as the ordinary user, on 7c3c125 and d0028d0, with the host's UCM files and AppArmor hidden from the sandbox, as in a container: with them, omamobile-audio's UCM check counts an extra alsa-lib error line, and omamobile-shell's D-Bus check can't query AppArmor.Links: the commit 7c3c1255; the lint
tests/head-pipes; the invite on #884; the precedent #575 and #587.Prior PRs: #575, #587 and #597, my
grep -qlint, which this one copies (its pathspec check is #597's).Not shown:
packages/omamobile-omarchy/test/notifications-replyand the twotests/owlcontainer scripts (they need Docker or their container), and omamobile-voice's server check (network).bin,tools,tools/libandrootfspipes, left for step 2.headon the line after a pipe,| head>file,| { head -1; }, and scripts that setpipefailwithset -e -o pipefail. No scanned script has any of these at d0028d0. It can also mistake a Git scan error for no matches.tools/build-rootfs. The sandbox runs had neither the AOSP image tools nor a built root image.Generated with Claude Opus 5.5 in T3 Code Nightly