fix: changing package.build.config does not invalidate caches#5371
Conversation
This fixes an issue where changes to `[package.build.config]` in pixi.toml (such as `noarch = true` to `noarch = false`) would not invalidate the metadata cache, causing the lock file to appear up-to-date when it should have been re-solved. The fix introduces a `ConfigurationHash` that captures changes to both the `configuration` and `target_configuration` fields from the build backend. This hash is now: - Computed when creating metadata via `call_conda_outputs` - Stored in `CachedCondaMetadata` - Checked during cache freshness verification in `verify_cache_freshness` When the configuration changes, the metadata cache is invalidated, triggering a re-query of the build backend and subsequent lock file update. Fixes prefix-dev#5309
Hofer-Julian
left a comment
There was a problem hiding this comment.
Looks good. Would be great to have a test for this though
ruben-arts
left a comment
There was a problem hiding this comment.
Works as expected, added two small nitpicks.
Adds a test that verifies changing `[package.build.config]` correctly invalidates the metadata cache and causes the build backend to be re-queried. The test uses ObservableBackend to verify that: 1. The backend is called once for initial lock file generation 2. The backend is NOT called again when nothing changes (cache hit) 3. The backend IS called again when `[package.build.config]` changes 4. The backend is NOT called again after the cache is updated This tests the fix for issue prefix-dev#5309.
e949513 to
7d2d168
Compare
Changed ConfigurationHash::compute to always return a hash value instead of Option<Self>. This simplifies the API and ensures consistent behavior whether configs are empty or not. Added Default impl for backward compatibility with existing cache files.
Extended test_build_config_change_invalidates_cache to verify that: 1. Starting with no [package.build.config] section works 2. Adding an empty [package.build.config] section does NOT invalidate the cache (empty config hashes the same as no config) 3. Adding actual config values DOES invalidate the cache 4. Changing config values also invalidates the cache
|
@ruben-arts Should work now! |
diff --git a/examples/pixi-build/cpp-sdl/pixi.toml b/examples/pixi-build/cpp-sdl/pixi.toml
index 868ed770c..4a52af73c 100644
--- a/examples/pixi-build/cpp-sdl/pixi.toml
+++ b/examples/pixi-build/cpp-sdl/pixi.toml
@@ -32,6 +32,7 @@ channels = [
name = "pixi-build-cmake"
version = "0.3.*"
+[package.build.config]
[package.host-dependencies]
# This ensures that SDL2 is available at build time.This will still trigger a rebuild. |
|
@ruben-arts Are you sure you cleared the cache? There is a test that literally checks that. |
|
@ruben-arts I just tried it myself and it seems to work for me! |
I did recheck with clean cache ( Maybe this reproducer helps: |
Replaced the single PackageBuildInputHash in CachedBuildSourceInfo with separate project_model_hash and configuration_hash fields. This aligns the build cache with the metadata cache structure, using the same hash types (ProjectModelHash and ConfigurationHash) for both caching systems. Removed PackageBuildInputHash and PackageBuildInputHashBuilder as they are no longer needed.
481bfd1 to
2ff419c
Compare
|
@ruben-arts OKE! Should be good now. :) All caches now use the same mechanism for the configuration. |
Description
This fixes an issue where changes to
[package.build.config]in pixi.toml (such asnoarch = truetonoarch = false) would not invalidate the metadata cache, causing the lock file to appear up-to-date when it should have been re-solved.The fix introduces a
ConfigurationHashthat captures changes to both theconfigurationandtarget_configurationfields from the build backend. This hash is now:call_conda_outputsCachedCondaMetadataverify_cache_freshnessWhen the configuration changes, the metadata cache is invalidated, triggering a re-query of the build backend and subsequent lock file update.
Fixes #5309
How Has This Been Tested?
AI Disclosure
Tools: Claude Code Opus 4.5
Checklist:
schema/model.py.