Repository navigation
ci(build): make the PEP 517 backend's staging cache fail closed - #1926
Merged
Merged
Conversation
`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.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
pyproject.tomldeclaresbuild-backend = "build_backend"withbackend-path = ["ci"], so everypip install ./uv sync/ editable install in this repo runsci/build_backend.py. It was carried as untested inci/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
mainwith a fake repo layout:So
FBUILD_BUILD_RELEASE=1 pip install .after a plainpip 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"
Combined with
shutil.copy2, which writes in place, an install killed mid-copy leaves a truncatedci/bin/fbuildwhose 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_nativeextension (_assert_staged_payload). A failed copy can now only orphan a.tmp.Also
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 oldline.startswith("{")prefilter made anisinstancecheck unreachable; there is one check now and it is testable.)_project_field()raises a clearRuntimeErrornaming the missing table/field instead ofIndexError: list index out of rangeon a pyproject without[project].Tests —
ci/test_build_backend.py, 42 testsStaleness 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, nullexecutable, daemon vs CLI,rlibvscdylib, 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 shippedpyproject.toml.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 fromuntested,MAX_UNTESTED2 -> 1, registered inci/local_suites.pyand theci-workflow-drift.ymlunittest command,ci/README.mdbullet.No cargo invocation semantics changed (
soldr cargo build -p fbuild-cli -p fbuild-daemonand-p fbuild-python --features extension-moduleare untouched); a real end-to-endpip install .was not re-run because it compiles the workspace (host load 63) — the changed paths are covered by the tests above.