Skip to content

docs(fm-stat-lib): correct inverted GNU stat -f failure-mode comments - #132

Merged
trillium merged 2 commits into
mainfrom
fix/robots-qyim-inverted-stat-comments
Aug 22, 2026
Merged

trillium merged 2 commits into
mainfrom
fix/robots-qyim-inverted-stat-comments

Conversation

@trillium

@trillium trillium commented Aug 22, 2026 •

Copy link
Copy Markdown
Owner

What Changed

  • Corrected comments in bin/fm-stat-lib.sh, bin/fm-bootstrap.sh, bin/fm-supervise-daemon.sh, bin/fm-test-run.sh, bin/fm-watch.sh, and bin/fm-x-lib.sh that described GNU stat -f as exiting 0 with a filesystem dump so the || fallback "never fires" — real GNU writes the dump to stdout and then exits 1, so the fallback does fire and its integer is appended to the dump, yielding a multi-line non-integer at overall rc=0.
  • Updated the GNU stat fixture in tests/fm-remote-job.test.sh to exit 1 after printing the filesystem dump, matching the real binary's behavior instead of the previously documented (incorrect) exit-0 shape.
  • Rewrote the shim rationale comment in tests/fm-busy-state.test.sh to match the corrected failure mode and documented why uname is deliberately not shimmed there.

Risk Assessment

✅ Low: The change is comments-only plus a test-fixture exit-status correction that makes the fake match real GNU behavior; both prior findings are verified fixed in the current code, the fixture change cannot alter the code path the tests exercise (the library probes -c first and never runs -f under the GNU dialect), and a repo-wide grep confirms no inverted exit-status claims remain.

Testing

Empirically validated every corrected comment claim against real GNU coreutils 9.7 (stat -f dumps to stdout then exits 1; the || fallback fires and appends its integer at overall rc=0, with the cited 223-byte dump measured exactly), ran both affected test files which pass fully including the dialect-detection test exercising the exit-1 fixture change, and confirmed fm_stat_mtime returns a clean integer end-to-end with GNU stat resolved as stat; no visual evidence applies since this is a shell-comment and test-fixture change with no UI surface.

Evidence: GNU stat 9.7 behavior verification (exit status, dump bytes, ||-chain failure mode)

$ gstat -f %m /tmp; echo exit=$? File: "/tmp" ... Type: apfs ... (223 bytes on stdout) exit=1 $ v=$(gstat -f %m /tmp 2>/dev/null || gstat -c %m /tmp 2>/dev/null) overall rc=0 — fallback DID fire; its output is appended to the dump

== Empirical verification of corrected comment claims (GNU coreutils 9.7) ==

$ gstat --version | head -1
stat (GNU coreutils) 9.7

$ gstat -f %m /tmp; echo "exit=$?"
gstat: cannot read file system information for '%m': No such file or directory
  File: "/tmp"
    ID: 100000d0000001a Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 242837545  Free: 12726789   Available: 12726789
Inodes: Total: 527126461  Free: 509071560
exit=1

stdout captured through 2>/dev/null: rc=1, bytes on stdout: 223

== The failure mode the comments now describe: '-f || -c' chain ==
$ v=$(gstat -f %m /tmp 2>/dev/null || gstat -c %m /tmp 2>/dev/null); echo rc=$?; printf '%s
' "$v"
overall rc=0
value received by caller:
  File: "/tmp"
    ID: 100000d0000001a Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 242837545  Free: 12726790   Available: 12726790
Inodes: Total: 527126501  Free: 509071600
/

^ note: the fallback DID fire (its integer is the last line), appended to the
  filesystem dump, and the whole substitution reported rc=0 — exactly what the
  corrected comments claim, and the opposite of the old 'exits 0, || never fires' text.
Evidence: fm-stat-lib end-to-end with real GNU stat resolved as `stat`

stat (GNU coreutils) 9.7 fm_stat_mtime /tmp -> [1770268403] rc=0 clean integer: OK

== fm-stat-lib.sh end-to-end against real GNU stat resolved as 'stat' ==
$ PATH=$TMPD:$PATH; stat --version | head -1
stat (GNU coreutils) 9.7
fm_stat_mtime /tmp -> [1770268403] rc=0
clean integer: OK

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-watch.sh:100 - bin/fm-watch.sh:100 still asserts the inverted claim this branch exists to fix ("GNU's -f ... writes a filesystem dump to stdout and the || never fires"). Measured GNU coreutils 9.7 behavior: stat -f exits 1 after dumping, so the fallback DOES fire and appends its integer to the dump. The corrected fm-stat-lib.sh header now directly contradicts this comment while explicitly pointing readers at fm-watch.sh ("see the comment this replaces in fm-watch.sh"), recreating the exact hazard robots-qyim describes: a maintainer who tests the false 'exits 0' claim and finds it wrong may conclude the chain is safe. Fix: reword fm-watch.sh:99-102 to match the corrected wording used in fm-supervise-daemon.sh:232-234.
  • ℹ️ bin/fm-bootstrap.sh:278 - bin/fm-bootstrap.sh:277-278 carries the same inverted exit-status fact ("GNU -f is --file-system, so the Darwin branch would print an apfs dump at exit 0"). Measured: GNU exits 1 after the dump. The comment's conclusion (non-numeric token reaches the caller) is still correct, but the stated exit code is wrong in the same way the three ticket-named comments were. Worth correcting in the same sweep.

🔧 Fix: correct remaining inverted GNU stat exit-status comments
1 info still open:

  • ℹ️ tests/fm-busy-state.test.sh:376 - The newly added comment states the shim "would not catch a regression back to uname-keyed dispatch." That claim is host-dependent: on a Darwin test host, a uname-keyed regression would select the stat -f branch, hit the shim's dump-then-exit-1 behavior, and fail the stale-lock reap test — i.e. the regression WOULD be caught there. Only on a Linux host (uname→GNU branch→-c works) does it slip through. The simplification errs toward caution (it undersells coverage rather than overselling safety), so it does not recreate the robots-qyim hazard; noting for precision only.
✅ **Test** - passed

✅ No issues found.

  • Empirical: gstat -f %m /tmp on GNU coreutils 9.7 → exit 1 with 223 bytes of apfs dump on stdout, matching the corrected comment's cited measurement
  • Empirical: v=$(gstat -f %m /tmp 2>/dev/null || gstat -c %m /tmp 2>/dev/null) → fallback fires, output appended to dump, overall rc=0 — the exact failure mode the corrected comments describe
  • bash tests/fm-remote-job.test.sh — all 23 tests pass, including "the mtime reader survives either stat dialect ahead of /usr/bin" which exercises the fixture changed to exit 1 on -f
  • bash tests/fm-busy-state.test.sh — all tests pass, including the GNU-stat-shim dialect test
  • End-to-end: fm_stat_mtime /tmp with real GNU stat first on PATH as stat → clean integer 1770268403, rc=0
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • Documentation

    • Clarified cross-platform stat behavior and detection logic.
    • Documented how GNU stat -f may emit filesystem data before failing, potentially contaminating fallback output.
    • Improved explanations for portable timestamp and file-mode handling across scripts.
  • Tests

    • Updated compatibility fixtures and comments to accurately model GNU stat output and validate clean fallback behavior.

Trillium Smith added 2 commits August 22, 2026 10:35
Six sites state the mechanism backwards. They claim GNU `stat -f <fmt> <path>`
exits 0 and that the `||` in a `stat -f ... || stat -c ...` chain therefore
never fires, leaving the correct call unrun.

Measured, GNU coreutils 9.7:

  $ gstat -f %m /tmp ; echo rc=$?
    File: "/tmp"
      ID: 100000d0000001a Namelen: ?       Type: apfs
  Block size: 4096       Fundamental block size: 4096
  rc=1

rc is 1. GNU takes the operands in order: the format string fails as an operand
and the path prints 223 bytes of filesystem dump to stdout, so the exit is
non-zero and the `||` does fire. The failure is not that the fallback never
runs - it is that the fallback runs and appends its correct integer to the dump
already sitting in the same command substitution. The caller receives a
multi-line non-integer at overall rc=0: invisible to error handling, fatal to
the arithmetic after it.

This matters beyond wording. The stated reason is why nobody may reintroduce
the chain, and bin/fm-stat-lib.sh is the single owner of that explanation, so
its header being wrong is the worst of the six. It also contradicted
bin/fm-busy-event.sh:110 on the same tree, which already said "so the `||` does
fire".

The probe order is unchanged and still correct, but the reason is restated:
`-c` goes first because GNU's `-f` pollutes stdout before failing, so a
`-f`-first probe would contribute junk even when it fails - not because the
`||` fails to fire.

tests/fm-remote-job.test.sh carried the error twice: once in prose, and once in
the GNU shim itself, whose -f arm printed the dump and exited 0. A fixture
labelled "GNU coreutils shape" that disagrees with the binary it stands in for
teaches the next reader the wrong mechanism. It now exits 1. The suite still
passes, which also confirms the correct code path never reaches that arm.

bin/fm-test-run.sh's chain is GNU-FIRST and therefore correct code; only its
justifying comment was wrong, so that site is comment-only.

Reported in robots-qyim, which #102 fixed on its branch (7e7bd9f, ffa1936);
#104 was what merged and it carried the pre-fix prose, plus a new instance in
fm-stat-lib.sh itself.
@trillium

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 33ce929e-bbc7-4b40-9820-1332339fbc47

📥 Commits

Reviewing files that changed from the base of the PR and between 73e0c74 and 28b648a.

📒 Files selected for processing (8)
  • bin/fm-bootstrap.sh
  • bin/fm-stat-lib.sh
  • bin/fm-supervise-daemon.sh
  • bin/fm-test-run.sh
  • bin/fm-watch.sh
  • bin/fm-x-lib.sh
  • tests/fm-busy-state.test.sh
  • tests/fm-remote-job.test.sh

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes align stat portability comments and test fixtures with GNU stat -f behavior. They document filesystem-status output before failure, explain probe ordering, and update one fixture to exit nonzero after emitting output.

Changes

Stat dialect alignment

Layer / File(s) Summary
Stat detection contract and fixture
bin/fm-stat-lib.sh, tests/fm-remote-job.test.sh
The documentation describes GNU and BSD stat probing behavior. The test fixture now prints filesystem-status output and exits with status 1 for GNU stat -f.
Consumer failure documentation
bin/fm-bootstrap.sh, bin/fm-supervise-daemon.sh, bin/fm-test-run.sh, bin/fm-watch.sh, bin/fm-x-lib.sh, tests/fm-busy-state.test.sh
Comments document contaminated fallback output, nonnumeric values, arithmetic parsing failures, and binary-based dispatch validation.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 28b64

This change corrects documentation and aligns a test fixture with GNU stat behavior without changing production runtime logic; affected tests pass, and no actionable merge-blocking risk remains.

Suggested reviewers: kunchenguid

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the main change: correcting GNU stat -f failure-mode comments and documentation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/robots-qyim-inverted-stat-comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@trillium

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@trillium
trillium merged commit ee16fde into main Aug 22, 2026
14 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