* fix(scripts): grep -q is never the reader of a pipe under pipefail
`echo "$x" | grep -q PAT` under `set -o pipefail` can report "not found"
for text that IS there: grep -q exits on its first match and closes the
pipe, the writer takes SIGPIPE (141), and pipefail makes the pipeline
status 141, so an `if` takes the else branch on a successful match.
It is not confined to payloads past the ~4KB pipe buffer. Measured in
loki (loki#874) on a real 1,158-byte output, 3,000 calls: 2/3000 false
misses for a phrase near the top, 0/3000 via a here-string. Rare per
call; a suite makes hundreds. loki's retire-site suite went red on
exactly those phrases twice this week.
48 copies in 14 scripts here, rewritten to `grep -q PAT <<<"$x"`,
including:
- auto-merge-sweep.sh: the required-check coverage test. A false miss
marks a green job "uncovered".
- gc-merged-worktrees.sh: `in_use`. A false miss reads a live session's
worktree as unused. The pushed / clean / MERGED guards still stand, so
it cannot lose work, but it can remove a directory from under a live
session.
- cicd-hygiene, nav-contract, org-drift, verify-floor audits and
verify-predicates: false passes and false findings.
Checked: all 14 files pass `bash -n`; every file is a 1:1 line swap (48
lines); the 8 line-continuation sites keep the here-string before the
trailing backslash; fleet's 30 CI test scripts pass before and after
(30/30 -> 30/30); workflows still parse.
Gate: scripts/ci/test-no-grep-q-in-a-pipe.sh, wired into ci.yml. Scans
scripts/ and templates/, self-tests its detector both ways, and was
proven by restoring the original auto-merge-sweep.sh line.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
* fix(ci): main was red on a ratchet that fell, and a sweep test lied
Two failures on fleet main that were blocking every PR, including this
one. Neither was caused by the grep -q rewrite: main (7ed94a2, the base
of this branch) failed CI on the same step for the same reason.
1. org-drift ratchet fell. `org-drift-audit.sh --check` failed on main
since c43464d with "baseline entries with no matching violation - the
ratchet fell: bitbaum/README.md". Good news: someone fixed that drift.
Nobody lowered the baseline, so main stayed red and the auto-merge
sweep refused everything. Line removed; --check now passes (44 repos
swept, 3 known violations, no new contradictions).
2. test-auto-merge-sweep.sh lied. Its verdict `[ "$FAIL" -eq 0 ]` sat at
line 400 of 473, with ~70 lines of tests appended after it. A bash
script exits with its LAST command's status, so the verdict was
discarded: the suite exited 0 while printing "27 passed, 1 failed",
and its later tests were not even counted. Verdict moved to the end;
the suite now counts 38.
The hidden failure was real and was mine: test 13 asserted the sweep
always "waits for CI to catch up" when the newest base run is for an
older commit. The deadlock fix changed that - it waits only while a
run is in flight, and otherwise dispatches CI. Test 13 now asserts
both cases (13a waits and dispatches nothing; 13b dispatches and does
not merge). `rearms()` moved above its first use.
Proven by mutation: an injected late failure now fails the suite;
reverting the sweep to always-wait fails 13b; making it never wait fails
13a.
Gate: scripts/ci/test-verdict-is-last.sh, wired into ci.yml, requires
every suite's verdict to be its file's last command. Proven by restoring
the old mid-file verdict. All 34 fleet CI commands are now green, and
none exits 0 while reporting a failure.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
---------
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The product was renamed on 2026-09-14: bitbaum/loki, loki.orangecat.ch,
LOKI_* env keys, loki-* units. This repo referenced the old name in
38 files changed, 119 insertions(+), 119 deletions(-).
Email addresses at the old sending domain stay until the new domain is
verified in Resend.
Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
stranded-work.sh examines each checkout's CURRENT branch. A branch that was
never pushed and is not checked out is invisible to it — which is exactly the
work GitHub cannot see, the thing that guard exists to find.
First run: 243 such branches across 24 repos, 564 commits. Most are old and
superseded. Some were not. A 1.1 GB clone nested inside fleetcrown looked
entirely redundant — clean tree, nothing unpushed on its checked-out branch —
and held three commits from the previous day on a DIFFERENT branch with no
remote ref. It was one `rm -rf` from gone.
A clean tree is a statement about one branch. It says nothing about the
other forty in the same repository.
Three filters, all needed. Commits absent from the default branch, by patch id.
No remote-tracking ref. And no PR ever opened from the branch name — because
`git cherry` cannot see a squash-merge, which rewrites several commits into one
with a different patch id, so a merged branch scores "absent" forever. Without
that third filter the report is mostly work that shipped weeks ago. The
converse is not covered: a PR opened from a different branch name still reads
as orphaned, so the count is an upper bound and the output is a list to look
at, not a verdict.
--days narrows to recent work, and --push preserves it without opening a PR, so
nothing merges and nothing deploys. --push without --days is refused: pushing
every orphan would put hundreds of stale refs across the remotes.
Fixture branch names (stale, other, main, master) are never reported and never
pushed. Publishing a fixture is how a pre-push hook once force-pushed test data
over main.
15 tests against real git repos with real remotes. Two of them are a regression
guard with a story: while being written, this suite ran `git -C "" add -A` and
`commit` inside the real fleet checkout, because make_repo aborted on a `local
name="$1" dir="$TMP/$name"` that is not reliably in scope under `set -u`, and
returned an empty path. It swept two untracked files into a fixture commit,
created six junk branches and pushed one to the remote. All cleaned up. git_q
now refuses any path that is not under $TMP, and the EXIT trap — inherited by
every $(...) subshell — only fires in the process that made the directory.
Claude-Session: https://claude.ai/code/session_01TE8oRvuwExm6GXkQVW3Jf9
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
The report counted dirty files and their age, which cannot tell a session
mid-work from a worktree abandoned a fortnight ago. Both come out as "N
uncommitted, oldest 15d".
What made that concrete: seven orangecat worktrees each reported "9
uncommitted, oldest 15d". Identical counts, because the diff was identical —
one identity sweep (maonakamoto -> bitbaum) left uncommitted in every worktree
it was run in. Main had not only made that rename, it had moved past it to a
different org path, so treating those as work to rescue would have REVERTED
main. All seven sat 202-215 commits behind. The live worktrees that same day
sat at 0-2.
So scan_repo measures the distance to the default branch and decide() prints it
when it crosses a threshold (STRANDED_BEHIND, default 50 — the fleet's data has
a wide empty gap between 2 and 99). Today that splits a flat 30-line list into
13 directories to delete and 17 pieces of work to finish, which are different
actions.
The marker annotates and never filters: nothing is dropped and the exit status
is unchanged, because a branch left alone for a fortnight can still hold the
only copy of something. It only lets a reader tell the two apart — which is the
difference between a report that gets acted on and one that gets muted, and
this script's own header explains why that is the whole game.
A sentinel is never rendered as a distance. An unreachable default branch
reports -1 and a caller written before this column sends no field at all;
neither is zero, and calling either one "up to date" is exactly the failure the
column exists to prevent. Six-column rows still decide correctly.
30 tests pass (24 existing, 6 new), and four mutations confirm the new ones
catch what they claim: a sentinel rendered as a distance, the marker filtering
instead of annotating, the threshold hardcoded, and a current worktree marked
abandoned. A fifth mutation was dropped as equivalent code — swapping the -n
guard for ${behind:-0} changes nothing for any positive threshold, so it proved
nothing; that guard prevents a silent shell error, not a wrong verdict.
Claude-Session: https://claude.ai/code/session_01TE8oRvuwExm6GXkQVW3Jf9
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
The audits, the golden CI templates, the shared-package registry and the
reusable auto-merge sweep now live in a repo whose only job is gating the
fleet. dotfiles goes back to being the environment — a repo holding a .bashrc
is the wrong place for machinery that 16 repos call as a reusable workflow,
and keeping them together made every fleet change look like an environment
change and vice versa (three sessions and the owner collided there in one
week).
Layout is unchanged (SHARED.md, scripts/{ci,fleet,audit}, templates/ci,
.github/workflows), so every script's relative paths still hold. The
reusable sweep now checks out bitbaum/fleet; dotfiles keeps a forwarding
shim so its 16 existing callers keep working unchanged.
All six test suites pass in the new location: shared-inventory 7,
verify-predicates 29, auto-merge-sweep 17, stranded-work 24, worktree-gc 9,
model-pin-audit 102.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZCNYHwjEeqxNpYCUk6Yna