Skip to content

feat(cli): add fbuild doctor --check-disk (#1750 item 5) - #1770

Merged
zackees merged 1 commit into
mainfrom
agent/doctor-check-disk
Oct 28, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/doctor-check-disk

Conversation

@zackees

@zackees zackees commented Oct 28, 2026

Copy link
Copy Markdown
Member

fbuild doctor --check-disk — report disk space before a build fails

Item 5 of #1750 ("Optional: fbuild doctor / --check-disk — print per-root free space and reclaimable totals without building").

Why

#1767 added the ESP32 pre-flight (#1750 item 2) and #1768 translated a mid-build ENOSPC (item 4), but both only speak when a build runs. A user on a nearly full host — or CI deciding whether to bother — had no way to ask "will this fit?" without starting a build, and no view of how many bytes the caches could give back.

What

fbuild doctor [--check-disk] [PROJECT_DIR] — read-only, in-process, no daemon:

  • measures every root a cold ESP32 build writes (cache, project build tree, <cache>/tmp scratch) through fbuild_build_engine::disk_preflight::measure, i.e. the same FreeSpace seam, the same required byte counts (disk_requirements::disk_roots) and the same reclaimable-cache walk a real build uses;
  • prints per-root free / required with an ok (N margin) or SHORT by N verdict;
  • lists the reclaimable depth-one caches under the cache root, largest first, with a total;
  • reuses PreflightReport::failure_message verbatim when something is short, so the text a doctor prints is the text the build would have failed with;
  • exit code carries the verdict (1 when short) so CI can gate on it. An unmeasurable volume is a printed line, never a failure; FBUILD_MIN_DISK_BYTES=0 prints skipped instead of walking the cache;
  • --check-disk is currently the only check, so bare fbuild doctor runs it too.

No build behavior changes: nothing new is enforced during a build, no cache is evicted, and disk_preflight/disk_requirements keep their existing semantics. Two edits outside the new files:

  • pub mod disk_requirements; (was private) so the CLI reads the same requirement constants instead of duplicating them.
  • disk_preflight::measure now measures the nearest existing ancestor when a root's path does not exist yet. The first E2E run of doctor surfaced it: a fresh host has no <cache>/tmp, so the scratch root reported could not be measured on every fresh machine (the same false warning the build pre-flight emitted). Only NotFound walks up — a permission or I/O error is still an unmeasurable root, so a genuinely unreadable volume is still reported as such. A not-yet-created root is on a real volume, and its requirement (64 MB scratch) is a subset of the cache root's 2 GB on the same volume, so no build that passed before can now fail.

Tests

crates/fbuild-cli/src/cli/doctor_tests.rs (8 tests, injected volumes — never this host's real free space): roomy report, shortfall arithmetic and failure text, only-the-short-root flagged, unmeasurable-is-a-warning, reclaimable ordering + total, empty cache root, disabled check, project-dir absolutisation.

Plus 3 engine tests for the ancestor walk (a_root_that_does_not_exist_yet_is_measured_on_its_volume, a_root_nested_under_missing_dirs_walks_to_the_first_existing_ancestor, a_permission_error_is_still_unmeasurable_and_never_walks_up).

RED-first evidence: disabling the is_sufficient() branch (forcing ok) makes a_short_root_names_the_shortfall_and_fails and only_the_short_root_is_flagged fail; restoring it is green.

soldr test -p fbuild-cli --bin fbuild cli::doctor::tests           -> 8 passed; 0 failed
soldr test -p fbuild-build-engine --lib disk_preflight             -> 13 passed; 0 failed
bash test (short TMPDIR)                                           -> EXIT 0, 47 suites, 3898 passed, 0 failed

Real E2E (locally built CLI, no daemon)

$ fbuild doctor --check-disk
disk roots a cold ESP32 build writes:
  cache    /home/niteris/.fbuild/prod/cache  226.48GB free, 2.00GB required  ok (224.48GB margin)
  project  /home/niteris/dev/fbuild-wt-doctor  226.48GB free, 256.00MB required  ok (226.23GB margin)
  temp     /home/niteris/.fbuild/prod/cache/tmp  226.48GB free, 64.00MB required  ok (226.42GB margin)
reclaimable under /home/niteris/.fbuild/prod/cache:
  platforms                32.34GB
  toolchains               10.50GB
  ...
  total                    43.41GB
verdict: ok — every measured root has room          # exit 0

$ FBUILD_MIN_DISK_BYTES=999000000000 fbuild doctor --check-disk
  cache    ...  SHORT by 703.91GB
verdict: FAIL — a cold ESP32 build would not fit    # exit 1, then the actionable
                                                     # build-shaped message + reclaim list

$ FBUILD_MIN_DISK_BYTES=0 fbuild doctor
disk check skipped: FBUILD_MIN_DISK_BYTES=0 disables the pre-flight requirement   # exit 0

Gates run locally

soldr fmt --all -- --check          0 diffs
soldr clippy --workspace --all-targets -- -D warnings   EXIT 0
bash test (short TMPDIR)                                  EXIT 0 (47 suites, 3898 passed)
ci/check_dylint_allowlists.py       allowlist paths are current
ci/enforce_platform_boundary.py --print-totals          rows=44 (unchanged)
ci/run_dylint --package fbuild-cli  EXIT 0
ci/run_dylint --package fbuild-build-engine  EXIT 0

Refs #1750 (items 3 — on-demand reclaim — and 5 is this PR; the issue stays open for item 3).

`doctor` reports, without building, the free space of every root a cold
ESP32 build writes plus the bytes the cache root could give back. It reuses
`fbuild_build_engine::disk_preflight` (the same FreeSpace seam, requirement
constants and reclaimable-cache walk a build uses), so the numbers and the
failure wording cannot drift from what the build acts on. The exit code
carries the verdict; an unmeasurable volume is a printed line, never a
failure, and FBUILD_MIN_DISK_BYTES=0 prints `skipped`.

`disk_preflight::measure` now measures the nearest existing ancestor for a
root that does not exist yet: a fresh host has no `<cache>/tmp`, so the
scratch root used to report `could not be measured` on every fresh machine.
Only NotFound walks up — permission/I-O errors stay unmeasurable.

RED-first: forcing the `is_sufficient()` branch makes the two shortfall
tests fail. 8 CLI tests + 3 engine tests; `bash test` 47 suites, 3898
passed.
@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@zackees
zackees added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 7a0b3ec Oct 28, 2026
36 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Oct 29, 2026
@zackees
zackees deleted the agent/doctor-check-disk branch November 5, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant