Skip to content

usb-ready: wait for a queued unit, not just a running one - #148

Merged
eliasbakken merged 2 commits into
mainfrom
fix-147-usb-ready-queued-job
Sep 16, 2026
Merged

eliasbakken merged 2 commits into
mainfrom
fix-147-usb-ready-queued-job

Conversation

@eliasbakken

Copy link
Copy Markdown
Contributor

Fixes #147.

ConditionResult is no both for a unit systemd has skipped and for one it
has not evaluated yet, so usb-ready's fallback for the skipped case also
fired in the window before ssh-keygen-boot started. Reflash mounted
/dev/sda2 while expand-usb's mkfs was still running inside that unit, the
mount failed with bad superblock, storage was marked FAILED and no host keys
were written - so the board came up serving HTTP with no sshd.

Job is the property that separates them. Measured on the board's own systemd
257, and on 237:

case ActiveState ConditionResult Job
skipped by its condition inactive no (empty)
queued, not started yet inactive no 12561
ExecStart running activating yes 12561
finished active yes (empty)

ConditionTimestamp and ExecMainStartTimestamp are 0 for both of the first
two rows, so the discriminator was not among the properties being read.

On the test

The existing case for this window stubbed ConditionResult as yes, which is
not what systemd reports there - so it passed while the real thing failed. It
now stubs what a board reports (inactive / no / a job id), and fails
against the old script
, which is how I checked it reproduces the bug:

not ok 26 usb-ready: false while the owning unit has not started yet   <- old script
ok 26 usb-ready: false while the owning unit has not started yet       <- with this fix

make test-bats is otherwise unchanged and green.

Not covered here

Whether a stick left half-formatted by this race repairs itself on the next
boot, or stays broken because expand-usb early-exits on [ -b /dev/sda2 ].
That is the same "partition exists, filesystem does not" state seen on a6, and
it deserves its own fix.

eliasbakken and others added 2 commits September 16, 2026 21:04
ConditionResult is "no" both for a unit systemd has skipped and for one it has
not evaluated yet, so the fallback written for the skipped case also fired in
the window before ssh-keygen-boot started. Reflash took that as permission to
mount, and mounted /dev/sda2 while expand-usb's mkfs was still running inside
that unit: "bad superblock", storage FAILED, no host keys, no sshd. The board
served HTTP fine and looked, from outside, like a board that would not boot.

The Job property is what separates the two. Measured on systemd 257 (the
board's own) and 237:

  case                       ActiveState  ConditionResult  Job
  skipped by its condition   inactive     no               (empty)
  queued, not started yet    inactive     no               12561
  ExecStart running          activating   yes              12561
  finished                   active       yes              (empty)

Everything else is identical in the first two rows, including
ConditionTimestamp and ExecMainStartTimestamp, which are 0 for both - so the
discriminator this needed was never in the properties it was reading.

The existing test for this window stubbed ConditionResult as "yes", which is
not what systemd reports there, so it passed while the real case failed. It now
stubs what a board actually reports, and fails against the old script.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The helper's job is to imitate systemd, and the last version of it was written
from what seemed reasonable rather than from what a board says: it stubbed
ConditionResult=yes for a unit that had not started, where systemd says "no".
The test passed, the real case failed, and #147 went unnoticed until a board
came up without sshd.

The table is measured, with the probe's shape and the systemd versions it was
taken on, so the next stub can be written from it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@eliasbakken
eliasbakken merged commit 5fa73b4 into main Sep 16, 2026
4 checks passed
@eliasbakken
eliasbakken deleted the fix-147-usb-ready-queued-job branch September 16, 2026 20:56
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.

usb-ready releases the drive before ssh-keygen-boot has run, so Reflash mounts sda2 mid-mkfs

1 participant