Skip to content

fix(fleet): the who recipe reported nobody on a machine full of users - #21

Merged
ralyodio merged 1 commit into
mainfrom
fix/who-recipe-silent
Aug 30, 2026
Merged

fix(fleet): the who recipe reported nobody on a machine full of users#21
ralyodio merged 1 commit into
mainfrom
fix/who-recipe-silent

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

who || w was wrong, and wrong in a way that reads as correct.

who reads utmp, which on a systemd host with pty-less SSH sessions is routinely empty while people are very much logged in — and it exits 0 either way. So || never reached w, and the recipe returned nothing at all.

Confirmed on a live host:

$ who ; echo "exit=$?"        # zero lines
exit=0
$ w
 13:57:34 up 9:53,  2 users,  load average: 2.98, 3.34, 3.14
 anthony   172.12.140.170   13:55   0.00s  0.02s sshd-session: anthony [priv]

The failure mode is empty output, not a non-zero exit, and || cannot see the difference.

Fix

Fall back on emptiness rather than on exit status, and say so when there genuinely is nobody:

found=$(who 2>/dev/null)
[ -z "$found" ] && found=$(w -h 2>/dev/null)
if [ -n "$found" ]; then printf '%s\n' "$found"
else echo "no interactive logins on this host"; fi

That last branch matters. A status command that prints nothing is indistinguishable from a broken one — which is exactly how this got reported.

The wider hunch, checked

The report suspected output had gone missing for other built-ins too. It hasn't — I ran all five reporting recipes through the real fleet path against a live host before touching anything:

Recipe stdout
check-updates 8 lines
disk 6 lines
uptime 1 line
reboot-required 1 line
who 0 lines

So nothing in the streaming path is dropping anything; who was the only silent one. Worth saying plainly rather than "fixed it".

Tests

Adds the invariant that was actually broken — no reporting recipe may produce empty output — plus two asserting who branches on emptiness rather than exit status. 498 tests, up from 491.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UeSWg1Czsb2Lwxj8vHUnA4

`who || w` was wrong, and wrong in a way that reads as correct.

`who` reads utmp, which on a systemd host with pty-less SSH sessions is
routinely empty while people are very much logged in — and it exits 0 either
way. So `||` never reached `w`, and the recipe returned nothing at all.
Confirmed here: `who` prints zero lines and exits 0, while `w` lists two live
sessions on the same box.

The failure mode is empty output, not a non-zero exit, and `||` cannot see the
difference. The recipe now falls back on emptiness, and says "no interactive
logins on this host" when both agree there are none — because a status command
that prints nothing is indistinguishable from a broken one, which is exactly
how this got reported.

Audited the other four reporting recipes through the real fleet path against a
live host first, to check the reporter's hunch that output had gone missing
more widely: check-updates 8 lines, disk 6, uptime 1, reboot-required 1. Only
`who` was silent, so nothing in the streaming path is dropping anything.

Adds a test that no reporting recipe may produce empty output, which is the
invariant that was actually broken, plus two asserting `who` branches on
emptiness rather than on exit status.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UeSWg1Czsb2Lwxj8vHUnA4
@ralyodio
ralyodio merged commit 2488f06 into main Aug 30, 2026
4 checks passed
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.

1 participant