auto-rebase's disk guard reads an unmeasurable df as zero and silently switches itself off #1651

Closed
opened 2026-11-16 11:14:31 +00:00 by jaylouisw · 0 comments
Owner

What is wrong

.forgejo/workflows/auto-rebase.yml measures free space before it checks the repository out, and its own rule is:

Unmeasurable is not the same as full. A df that answers nothing must not be able to switch this workflow off silently, so the default is to run the batch.

The code could not honour that. It read the figure into a number inside awk:

free=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print int($4/1024)}') || free=""
case "${free:-}" in
  ''|*[!0-9]*) echo "could not measure..."; ;;   # unreachable once int() has run

int() maps anything it cannot parse to 0, so the [!0-9] branch only ever fired when df printed nothing at all. When df succeeds but cannot state a figure — a dash or n/a in the Available column, which is what GNU df prints for a filesystem whose statvfs it cannot report on (stale autofs/NFS, a container whose lower layer has gone) — the guard read 0 MB free, printed 0 MB free, set room=false, and stood the job down. Green tick, six times an hour, with the rebase switched off and a log line claiming the disk was full.

Reproduced, not inferred

The guard step is executed against a df this test controls:

df says: /dev/sda1 1000 999 n/a 99% /
log:     0 MB free in ... (a checkout of this repository needs about 512 MB)
         ::error title=Not enough disk::0 MB free ... - see #1507
verdict: room=false

Why it matters more than a cosmetic log line

The guard was added by #1508 to stop a full host turning into six red crosses an hour. In this shape it converts the other failure — a df that cannot answer — into a silent outage that reports green, which is the one outcome nobody investigates. The two readings 0 MB free and could not read the figure are indistinguishable in the log.

Fix

Keep the column as df printed it, and 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

a df that cannot say how much room there is must run the batch; only a numeric reading below the threshold stands the tick down. Asserted behaviourally in test/ci-disk-hygiene.test.js (three cases: unreadable → run, 1 KB → stand down with the reason, failing df → run).

## What is wrong `.forgejo/workflows/auto-rebase.yml` measures free space before it checks the repository out, and its own rule is: > Unmeasurable is not the same as full. A `df` that answers nothing must not be able to switch this workflow off silently, so the default is to run the batch. The code could not honour that. It read the figure into a number *inside awk*: ```sh free=$(df -Pk "$dir" 2>/dev/null | awk 'NR==2 {print int($4/1024)}') || free="" case "${free:-}" in ''|*[!0-9]*) echo "could not measure..."; ;; # unreachable once int() has run ``` `int()` maps anything it cannot parse to `0`, so the `[!0-9]` branch only ever fired when `df` printed *nothing at all*. When `df` succeeds but cannot state a figure — a dash or `n/a` in the Available column, which is what GNU `df` prints for a filesystem whose `statvfs` it cannot report on (stale autofs/NFS, a container whose lower layer has gone) — the guard read **0 MB free**, printed `0 MB free`, set `room=false`, and stood the job down. Green tick, six times an hour, with the rebase switched off and a log line claiming the disk was full. ## Reproduced, not inferred The guard step is executed against a `df` this test controls: ``` df says: /dev/sda1 1000 999 n/a 99% / log: 0 MB free in ... (a checkout of this repository needs about 512 MB) ::error title=Not enough disk::0 MB free ... - see #1507 verdict: room=false ``` ## Why it matters more than a cosmetic log line The guard was added by #1508 to stop a full host turning into six red crosses an hour. In this shape it converts the *other* failure — a `df` that cannot answer — into a silent outage that reports green, which is the one outcome nobody investigates. The two readings `0 MB free` and `could not read the figure` are indistinguishable in the log. ## Fix Keep the column as `df` printed it, and 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 ``` `a df that cannot say how much room there is` must run the batch; only a numeric reading below the threshold stands the tick down. Asserted behaviourally in `test/ci-disk-hygiene.test.js` (three cases: unreadable → run, 1 KB → stand down with the reason, failing `df` → run).
Sign in to join this conversation.
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#1651
No description provided.