Skip to content

feat(disk): release a pre-committed reserve when a build hits ENOSPC (#1750 item 6) - #1774

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

zackees merged 1 commit into
mainfrom
agent/disk-reserve

Conversation

@zackees

@zackees zackees commented Oct 28, 2026

Copy link
Copy Markdown
Member

Why

Pre-flight (#1767) refuses a build that starts on a full volume, and disk_full (#1768) translates ENOSPC at a tool boundary. Neither helps when the volume fills during a build: at that instant the failure path still has to write — a build log, a daemon status file, a partially written image — onto the same full volume, and PR #1773's footprint numbers show a cold ESP32 build can consume ~4–5 GiB after the check passed.

This is #1750 item 6: copy the delete-to-recover emergency reserve that the sibling running-process daemon ships (zackees/running-process#390).

What it does

New fbuild_core::disk_reserve:

  • EmergencyReserve::initialize_in(dir) commits 32 MiB of real bytes at <dir>/emergency-reserve.bin. set_len alone yields a sparse file on most filesystems and would reserve nothing, so the file is written through in 1 MiB chunks and sync_alled; a partial file from a crashed run is recreated, never trusted.
  • release(reason) deletes it, idempotently, and reports true only when this call freed something. A file already gone is tolerated.
  • release_if_enospc(io_error) / release_if_full_message(stderr) spend it only on a real full volume, reusing disk_full::is_enospc_io / enospc_signature so the reserve and the error translator agree on what "full" means.
  • An arm that cannot allocate (usually because the volume is already full) logs and degrades — it never fails a build that might otherwise work.

Process-wide wiring, because the release must happen at every boundary that can report a full volume and none of them owns the build's disk bookkeeping:

  • Armed in preflight_esp32_disk before measuring free space, so the pre-flight numbers are space the build can actually use.

  • Released from disk_full::disk_full_error / disk_full_io_error and disk_preflight::enospc_failure, which append one line to the message:

    released the 32 MiB emergency reserve so this failure could still be recorded; the next build re-arms it
    
  • Re-armed by the next build (arm_in replaces a released reserve).

Deliberate non-goals: this is not a budget — 32 MiB does not make a large build fit. Real space comes from fbuild cache reclaim, which stays explicit and never runs mid-build (#1341). fbuild doctor --check-disk is unchanged.

Tests

  • crates/fbuild-core/src/disk_reserve_tests.rs — 8 unit tests: real-byte allocation, release idempotency, externally-deleted file, only-ENOSPC releases, tool-stderr vs errno paths, partial-file rebuild, degrade on unallocatable path, byte formatting.
  • crates/fbuild-core/tests/disk_reserve.rs — one end-to-end test of the process-wide cycle (own binary, since the state is global): arm → unrelated failure leaves it → ENOSPC releases it and the message says so → second failure claims nothing → next build re-arms. The two negative/positive paths share one test on purpose: two tests in that binary would race the same global.

Test scratch dirs are tempdir_in(<crate>/target/...) (ban_unrooted_tempdir), and the reserve leaf name is a bare name, not a hand-spelled path layout (ban_raw_fbuild_path caught exactly that in the first draft).

Related: #1750 (items 1–5 landed in #1773, #1772, #1770, #1768, #1767), #1341, #1370, zackees/running-process#390.

@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.

…1750 item 6)

A volume that fills *during* a build also starves the failure path: the log,
the status file and the partial image all go to the same full volume.

Following running-process #390, fbuild now commits 32 MiB of real bytes at
<cache root>/emergency-reserve.bin before a build and deletes it the moment a
write reports a full volume, so the error path can still be recorded and the
next build has a margin.

- fbuild_core::disk_reserve: EmergencyReserve (armed/released/degraded),
  chunked non-sparse allocation, idempotent release, ENOSPC-only spending via
  disk_full's existing signatures, graceful degrade when it cannot allocate.
- Armed in the ESP32 pre-flight before free space is measured, so the check
  counts space the build can actually use.
- Released from disk_full::{disk_full_error,disk_full_io_error} and
  disk_preflight::enospc_failure, each appending one line naming the bytes
  freed; re-armed by the next build.

Not a budget: 32 MiB does not make a large build fit. Reclaim stays explicit
(fbuild cache reclaim, #1750 item 3) and never runs mid-build (#1341).
@zackees
zackees force-pushed the agent/disk-reserve branch from 22c0791 to 3c41d6c Compare October 28, 2026 18:21
@zackees
zackees added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit 39a96f0 Oct 28, 2026
35 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Oct 29, 2026
@zackees
zackees deleted the agent/disk-reserve 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