ci: an unreadable df must not read as zero free space (#1651) #1652

Merged
jaylouisw merged 2 commits from fix/1116-1105 into main 2026-11-16 11:15:42 +00:00
Owner

Fixes #1651

The disk guard added by #1508 kept the number awk had already parsed:

free=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print int($4/1024)}') || free=""

int() maps anything it cannot parse to 0, so a df that succeeds but cannot state a figure — the dash or n/a GNU df prints in the Available column of a filesystem it cannot measure (stale autofs/NFS, a container whose lower layer is gone) — became a reading of 0 MB free. The guard then printed 0 MB free, set room=false, and stood the job down: green tick, six times an hour, rebase switched off, and a log line claiming the disk was full. The ''|*[!0-9]* branch that says "unmeasurable runs the batch" was unreachable once int() had run, so the comment above it was documentation of behaviour the code did not have.

Change

Keep the column exactly as df printed it; apply arithmetic only to a value already proved numeric:

free_kb=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print $4}') || free_kb=""
free=""
case "${free_kb:-}" in
  ''|*[!0-9]*) ;;
  *) free=$(( free_kb / 1024 )) ;;
esac

Side effect: a genuinely tight disk now reports 1 MB free where the truncation used to print 0 MB free.

Test

test/ci-disk-hygiene.test.js gained three cases that execute the step, against a df the test owns — reading it as text cannot distinguish 0 MB free from could not read the figure, which is the whole defect:

df answers verdict log
n/a in Available room=true (was room=false) "could not read free space … running the batch anyway"
1 KB available room=false ::error title=Not enough disk::… see #1507
fails, prints nothing room=true "could not read free space …"

First case reproduced room=false before the fix. The harness skips on a host with no bash, since the step only ever runs on a Linux runner.

Gates

node scripts/syntax-check.js                      Syntax-checked 348 files: all OK
node --test test/ci-disk-hygiene.test.js          12 tests, 12 pass, 0 fail
node --test test/canonical-urls.test.js             test/classify-change.test.js          7 tests, 7 pass, 0 fail

No engine or shared code touched, so no full-suite run. Workflow still parses as YAML with the block scalar intact (checked with PyYAML, 52-line guard body).

One thing this does not fix: the guard's fail-open policy is still the same one — a df that answers nothing runs the batch. That is deliberate per #1508, but it means a runner whose df is broken will spend bytes it was meant to protect. Reported to Jay rather than changed here.

Fixes #1651 The disk guard added by #1508 kept the number awk had already parsed: ```sh free=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print int($4/1024)}') || free="" ``` `int()` maps anything it cannot parse to `0`, so a `df` that succeeds but cannot state a figure — the dash or `n/a` GNU `df` prints in the Available column of a filesystem it cannot measure (stale autofs/NFS, a container whose lower layer is gone) — became a reading of **0 MB free**. The guard then printed `0 MB free`, set `room=false`, and stood the job down: green tick, six times an hour, rebase switched off, and a log line claiming the disk was full. The `''|*[!0-9]*` branch that says "unmeasurable runs the batch" was unreachable once `int()` had run, so the comment above it was documentation of behaviour the code did not have. ## Change Keep the column exactly as `df` printed it; apply arithmetic only to a value already proved numeric: ```sh free_kb=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print $4}') || free_kb="" free="" case "${free_kb:-}" in ''|*[!0-9]*) ;; *) free=$(( free_kb / 1024 )) ;; esac ``` Side effect: a genuinely tight disk now reports `1 MB free` where the truncation used to print `0 MB free`. ## Test `test/ci-disk-hygiene.test.js` gained three cases that **execute the step**, against a `df` the test owns — reading it as text cannot distinguish `0 MB free` from `could not read the figure`, which is the whole defect: | `df` answers | verdict | log | |---|---|---| | `n/a` in Available | `room=true` (was `room=false`) | "could not read free space … running the batch anyway" | | `1` KB available | `room=false` | `::error title=Not enough disk::… see #1507` | | fails, prints nothing | `room=true` | "could not read free space …" | First case reproduced `room=false` before the fix. The harness skips on a host with no `bash`, since the step only ever runs on a Linux runner. ## Gates ``` node scripts/syntax-check.js Syntax-checked 348 files: all OK node --test test/ci-disk-hygiene.test.js 12 tests, 12 pass, 0 fail node --test test/canonical-urls.test.js test/classify-change.test.js 7 tests, 7 pass, 0 fail ``` No engine or shared code touched, so no full-suite run. Workflow still parses as YAML with the block scalar intact (checked with PyYAML, 52-line guard body). One thing this does *not* fix: the guard's fail-open policy is still the same one — a `df` that answers nothing runs the batch. That is deliberate per #1508, but it means a runner whose `df` is broken will spend bytes it was meant to protect. Reported to Jay rather than changed here.
ci: an unreadable df must not read as zero free space (#1651)
Some checks failed
CI / Classify the change (pull_request) Successful in 14s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 20s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 31s
CI / Test (Node 18) (pull_request) Failing after 1m36s
CI / Test (Node 20) (pull_request) Failing after 1m35s
CI / Test (Node 22) (pull_request) Failing after 1m44s
8f572fbded
The auto-rebase disk guard kept the awk-parsed number, and `int()` maps
anything it cannot parse - the dash or `n/a` GNU df prints in the Available
column of a filesystem it cannot measure - to 0. That is indistinguishable
from a full disk, so the guard printed "0 MB free", set room=false, and
switched the rebase off for as long as df kept answering that way: a green
tick and a log claiming a full disk, while its own comment promises that
unmeasurable runs the batch. The `[!0-9]` branch was unreachable once int()
had run.

Keep the column exactly as df printed it, and do arithmetic only after the
value has been proved numeric.

The step is now executed in the test against a df the test controls, because
reading it as text cannot tell "0 MB free" from "could not read the figure":
unreadable -> run, 1 KB -> stand down with the reason, failing df -> run.
jaylouisw scheduled this pull request to auto merge when all checks succeed 2026-11-16 11:15:31 +00:00
jaylouisw force-pushed fix/1116-1105 from 8f572fbded
Some checks failed
CI / Classify the change (pull_request) Successful in 14s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 20s
CI / Server smoke test (pull_request) Successful in 28s
CI / Docker build (pull_request) Successful in 31s
CI / Test (Node 18) (pull_request) Failing after 1m36s
CI / Test (Node 20) (pull_request) Failing after 1m35s
CI / Test (Node 22) (pull_request) Failing after 1m44s
to 218f63f66d
All checks were successful
CI / Classify the change (pull_request) Successful in 15s
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 14s
CI / Test (Node 18) (pull_request) Has been skipped
CI / Test (Node 20) (pull_request) Has been skipped
CI / Test (Node 22) (pull_request) Has been skipped
CI / Server smoke test (pull_request) Has been skipped
CI / Docker build (pull_request) Has been skipped
2026-11-16 11:15:36 +00:00
Compare
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1652
No description provided.