Skip to content

ci(build): make the PEP 517 backend's staging cache fail closed - #1926

Merged
zackees merged 1 commit into
mainfrom
agent/test-build-backend
Nov 6, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/test-build-backend

Conversation

@zackees

@zackees zackees commented Nov 6, 2026

Copy link
Copy Markdown
Member

Why

pyproject.toml declares build-backend = "build_backend" with backend-path = ["ci"], so every pip install . / uv sync / editable install in this repo runs ci/build_backend.py. It was carried as untested in ci/gate_script_tests.toml, and two of its paths exited 0 while installing the wrong artifact.

Defect 1 — the staging cache had no cargo-profile key

_staged_binary_is_up_to_date() / _staged_daemon_is_up_to_date() / _staged_native_ext_is_up_to_date() compared mtimes and nothing else, while the staging paths (ci/bin/fbuild, python/fbuild/_native.so) are shared between the debug and release profiles.

Reproduced on main with a fake repo layout:

staged artifacts up-to-date (fbuild, fbuild-daemon, _native.so); skipping cargo
DEBUG fast-path: SKIPPED CARGO (no profile recorded anywhere)
release profile -> _use_release_profile: True
RELEASE after DEBUG: also fast-pathed -> staged debug binary shipped as release

So FBUILD_BUILD_RELEASE=1 pip install . after a plain pip install . installed the debug binary and reported success (and the reverse shipped a release binary to a caller that asked for the debug profile). Same class as #1843: a cache key may only omit a discriminator when the restore is a warm start that is always refreshed — this restore is not.

Fix: the producing profile is stamped in ci/bin/.build-profile (v1 debug / v1 release) and is part of the cache key. Missing, malformed (v2 debug, v1 debug extra, empty) or other-profile stamps force a rebuild.

Defect 2 — a zero-byte artifact was "current"

zero-byte staged -> up_to_date? True

Combined with shutil.copy2, which writes in place, an install killed mid-copy leaves a truncated ci/bin/fbuild whose mtime is the newest in the tree — so the corruption is adopted as fresh by every later install and packaged into a wheel that builds successfully. Zero bytes never runs.

Fix: non-emptiness is required for "current", staging goes through a sibling temp file + os.replace, and _write_wheel() refuses to wrap a missing/empty CLI, daemon or _native extension (_assert_staged_payload). A failed copy can now only orphan a .tmp.

Also

  • The selection loop existed three times (fbuild, fbuild-daemon, _native) with its JSON tolerance never exercised → one _cargo_artifacts() generator, which skips lines that do not decode to an object. (The old line.startswith("{") prefilter made an isinstance check unreachable; there is one check now and it is testable.)
  • _project_field() raises a clear RuntimeError naming the missing table/field instead of IndexError: list index out of range on a pyproject without [project].

Tests — ci/test_build_backend.py, 42 tests

Staleness rules (mtime, vanishing input, zero-byte, profile stamp in 6 malformed forms), fast-path/rebuild decisions with both builders mocked, atomic staging (an interrupted copy leaves the previous artifact intact), soldr-missing and cargo-failure paths, cargo artifact selection (last-match, null executable, daemon vs CLI, rlib vs cdylib, non-object JSON noise), target-dir fallbacks, and wheel assembly end to end (RECORD sha256/sizes/exec bits, __pycache__ exclusion, Root-Is-Purelib: false, tag, .data/scripts/), plus reconciliation against the shipped pyproject.toml.

42/42 OK
hosted self-test set: 295 -> 337 OK
gate_script_coverage --budget 1 ..... clean
check_python_complexity ............. clean
ruff check / ruff format --check .... clean (new file)
render_workflows --check ............ rc 0
check_test_layout.py ................ ok

RED proven by four in-place mutations, each restored: drop the non-empty check (2 fail), drop the profile stamp from the key (6 fail), stage in place (2 fail), drop the non-object-JSON guard (1 fail).

Ratchet: [scripts.build_backend].tests = ["ci/test_build_backend.py"], removed from untested, MAX_UNTESTED 2 -> 1, registered in ci/local_suites.py and the ci-workflow-drift.yml unittest command, ci/README.md bullet.

No cargo invocation semantics changed (soldr cargo build -p fbuild-cli -p fbuild-daemon and -p fbuild-python --features extension-module are untouched); a real end-to-end pip install . was not re-run because it compiles the workspace (host load 63) — the changed paths are covered by the tests above.

`pyproject.toml` declares `build-backend = "build_backend"`, so every
`pip install .` / `uv sync` in this repo runs `ci/build_backend.py` -- and it
was carried untested in `ci/gate_script_tests.toml`. Two of its paths exited 0
while installing the wrong binary:

* The "staged artifacts are up-to-date" fast path keyed on mtimes only, never
  on the cargo **profile**. Staging paths are shared between debug and release,
  so `pip install .` after `FBUILD_BUILD_RELEASE=1` (or the reverse) silently
  reused the other profile's binary. Reproduced on main: a release request
  returned the debug artifact and printed "staged artifacts up-to-date".
  The profile is now stamped in `ci/bin/.build-profile` and is part of the
  cache key (missing/malformed/other-profile -> rebuild).
* A zero-byte artifact counted as current, and `shutil.copy2` writes in place,
  so an install interrupted mid-copy left a truncated `ci/bin/fbuild` whose
  mtime was the newest in the tree: every later install adopted it as fresh and
  packaged it into a successful wheel. Staging now goes through a temp file +
  `os.replace`, non-emptiness is required, and `_write_wheel` refuses to wrap a
  missing/empty CLI, daemon or `_native` extension.

Also folds the three hand-synced cargo-artifact parsers into one
`_cargo_artifacts()` generator and gives a clear error (instead of IndexError)
for a pyproject without a `[project]` table.

Tests: new `ci/test_build_backend.py` (42 tests) covering the staleness rules,
`soldr`/build failure paths, artifact selection, atomic staging, RECORD
hashes/modes/sizes, METADATA/WHEEL, an end-to-end wheel, and reconciliation
against the shipped pyproject. Registry entry added, `untested` 2 -> 1,
`MAX_UNTESTED` 2 -> 1, both entry points.
@coderabbitai

coderabbitai Bot commented Nov 6, 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

@zackees
zackees added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit d0a28bf Nov 6, 2026
31 checks passed
@zackees
zackees deleted the agent/test-build-backend branch November 6, 2026 01:44
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 6, 2026
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