From 81862ff4286fa893670c25eb5a4e6d75400db3d7 Mon Sep 17 00:00:00 2001 From: Lucas Colley Date: Mon, 2 Nov 2026 16:26:34 +0000 Subject: [PATCH] fix(exclude-newer): resolve relative cutoffs once per workspace load Each lock-file solve resolved a relative cutoff such as `14d` against its own `Utc::now()`, so compute keys carrying the resolved cutoff, such as the build backend environment, differed by microseconds between environments and were not deduplicated: the same backend environment was solved once per environment and platform. Anchor the resolution to `WorkspaceManifest::loaded_at`, set when the manifest is loaded, for both the conda and the PyPI cutoffs. `pixi global` keeps resolving against the current time. Fixes #7430 --- crates/pixi_global/src/project/mod.rs | 1 + crates/pixi_manifest/src/exclude_newer.rs | 43 +++++++--------- crates/pixi_manifest/src/features_ext.rs | 2 + .../pixi_manifest/src/manifests/workspace.rs | 50 ++++++++++++++++++- crates/pixi_manifest/src/toml/manifest.rs | 1 + 5 files changed, 70 insertions(+), 27 deletions(-) diff --git a/crates/pixi_global/src/project/mod.rs b/crates/pixi_global/src/project/mod.rs index 03b5feef0d..147675eb91 100644 --- a/crates/pixi_global/src/project/mod.rs +++ b/crates/pixi_global/src/project/mod.rs @@ -976,6 +976,7 @@ impl Project { channels, self.global_channel_config(), std::iter::empty(), + chrono::Utc::now(), ) } diff --git a/crates/pixi_manifest/src/exclude_newer.rs b/crates/pixi_manifest/src/exclude_newer.rs index cb6d4e3d6b..048da6bd05 100644 --- a/crates/pixi_manifest/src/exclude_newer.rs +++ b/crates/pixi_manifest/src/exclude_newer.rs @@ -238,28 +238,12 @@ pub enum ExcludeNewerError { /// /// `package_overrides` are the per-package cutoffs of the deprecated top-level /// `[exclude-newer]` table. They keep working until that table is removed. +/// Relative cutoffs are resolved as if the current time were `now`. pub fn resolve_exclude_newer<'a>( config: &ExcludeNewerConfig, channels: impl IntoIterator, channel_config: &ChannelConfig, package_overrides: impl IntoIterator, -) -> Result, ExcludeNewerError> { - resolve_exclude_newer_at( - config, - channels, - channel_config, - package_overrides, - Utc::now(), - ) -} - -/// Like [`resolve_exclude_newer`], with relative cutoffs resolved as if the -/// current time were `now`. -fn resolve_exclude_newer_at<'a>( - config: &ExcludeNewerConfig, - channels: impl IntoIterator, - channel_config: &ChannelConfig, - package_overrides: impl IntoIterator, now: DateTime, ) -> Result, ExcludeNewerError> { let mut exclude_newer = config @@ -351,7 +335,7 @@ where let mut resolved = environments .into_iter() .map(|channels| { - resolve_exclude_newer_at( + resolve_exclude_newer( config, channels, channel_config, @@ -362,7 +346,7 @@ where .collect::, _>>()?; // Without environments, the exemptions apply to the ones added later. if resolved.is_empty() { - resolved.push(resolve_exclude_newer_at( + resolved.push(resolve_exclude_newer( config, [], channel_config, @@ -400,16 +384,17 @@ where /// /// `package_overrides` are the per-package cutoffs of the deprecated top-level /// `[pypi-exclude-newer]` table. They keep working until that table is -/// removed. +/// removed. Relative cutoffs are resolved as if the current time were `now`. pub fn resolve_pypi_exclude_newer<'a>( config: &PypiExcludeNewerConfig, fallback_cutoff: Option, package_overrides: impl IntoIterator, + now: DateTime, ) -> ResolvedPypiExcludeNewer { let mut exclude_newer = config .cutoff .or(fallback_cutoff) - .map(|cutoff| ResolvedPypiExcludeNewer::from_datetime(cutoff.cutoff())) + .map(|cutoff| ResolvedPypiExcludeNewer::from_datetime(cutoff.cutoff_at(now))) .unwrap_or_default(); for (name, package_exclude_newer) in package_overrides { @@ -421,8 +406,10 @@ pub fn resolve_pypi_exclude_newer<'a>( exclude_newer.with_exempt_package(name.as_normalized().clone()) } else { #[allow(deprecated)] - exclude_newer - .with_package_cutoff(name.as_normalized().clone(), package_exclude_newer.cutoff()) + exclude_newer.with_package_cutoff( + name.as_normalized().clone(), + package_exclude_newer.cutoff_at(now), + ) }; } @@ -755,7 +742,7 @@ mod tests { }; let channels = [channel("conda-forge", Some("7d"))]; let configured_hash = |config: &ExcludeNewerConfig, now: &str| { - let resolved = resolve_exclude_newer_at( + let resolved = resolve_exclude_newer( config, &channels, &ChannelConfig::default_with_root_dir("/".into()), @@ -799,8 +786,12 @@ mod tests { ), ]; - let resolved = - resolve_pypi_exclude_newer(&config, None, overrides.iter().map(|(n, c)| (n, c))); + let resolved = resolve_pypi_exclude_newer( + &config, + None, + overrides.iter().map(|(n, c)| (n, c)), + Utc::now(), + ); assert_eq!( resolved.exempt_packages.iter().collect::>(), diff --git a/crates/pixi_manifest/src/features_ext.rs b/crates/pixi_manifest/src/features_ext.rs index 7ddb9194b0..5dc8ca3708 100644 --- a/crates/pixi_manifest/src/features_ext.rs +++ b/crates/pixi_manifest/src/features_ext.rs @@ -118,6 +118,7 @@ pub trait FeaturesExt<'source>: HasWorkspaceManifest<'source> + HasFeaturesIter< self.prioritized_channels().into_values(), channel_config, &workspace.exclude_newer_package_overrides, + self.workspace_manifest().loaded_at, ) } @@ -128,6 +129,7 @@ pub trait FeaturesExt<'source>: HasWorkspaceManifest<'source> + HasFeaturesIter< &workspace.pypi_exclude_newer, workspace.exclude_newer.cutoff, &workspace.pypi_exclude_newer_package_overrides, + self.workspace_manifest().loaded_at, ) } diff --git a/crates/pixi_manifest/src/manifests/workspace.rs b/crates/pixi_manifest/src/manifests/workspace.rs index ca55de63b2..8f5ea9875a 100644 --- a/crates/pixi_manifest/src/manifests/workspace.rs +++ b/crates/pixi_manifest/src/manifests/workspace.rs @@ -6,6 +6,7 @@ use std::{ str::FromStr, }; +use chrono::{DateTime, Utc}; use indexmap::{Equivalent, IndexMap, IndexSet}; use itertools::Itertools; use miette::SourceCode; @@ -40,7 +41,7 @@ use crate::{ /// Holds the parsed content of the workspace part of a pixi manifest. This /// describes the part related to the workspace only. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Clone)] pub struct WorkspaceManifest { /// Information about the project pub workspace: Workspace, @@ -56,6 +57,22 @@ pub struct WorkspaceManifest { /// The solve groups that are part of the project. pub solve_groups: SolveGroups, + + /// The time relative `exclude-newer` cutoffs are resolved against, fixed + /// at load so that every environment resolves them to the same time. + pub loaded_at: DateTime, +} + +impl Default for WorkspaceManifest { + fn default() -> Self { + Self { + workspace: Workspace::default(), + features: IndexMap::default(), + environments: Environments::default(), + solve_groups: SolveGroups::default(), + loaded_at: Utc::now(), + } + } } impl WorkspaceManifest { @@ -6680,6 +6697,37 @@ exclude-newer = { cutoff = "2015-12-02T02:07:43Z", exemptions = { polars = "1.43 assert!(config.is_excluded(&uploaded_record("pandas", "2.0.0", None))); } + /// Regression test. Every solve resolved a relative cutoff against its + /// own `Utc::now()`, so the compute keys carrying the resolved cutoff, + /// such as the build backend environment, were never deduplicated. + #[test] + fn test_relative_exclude_newer_resolves_against_load_time() { + let contents = r#" +[workspace] +name = "foo" +channels = [] +platforms = [] +exclude-newer = "14d" +"#; + let manifest = parse_pixi_toml(contents).manifest; + let features = DefaultFeature(&manifest); + let expected = manifest.loaded_at - chrono::Duration::days(14); + + let resolve = || { + features + .exclude_newer_config_resolved(&default_channel_config()) + .unwrap() + .unwrap() + }; + let first = resolve(); + assert_eq!(first.cutoff, expected); + assert_eq!(first, resolve()); + + let pypi = features.pypi_exclude_newer_config_resolved(); + assert_eq!(pypi.cutoff, Some(expected)); + assert_eq!(pypi, features.pypi_exclude_newer_config_resolved()); + } + #[test] fn test_pypi_exclude_newer_config_falls_back_to_conda_cutoff() { let contents = r#" diff --git a/crates/pixi_manifest/src/toml/manifest.rs b/crates/pixi_manifest/src/toml/manifest.rs index 9db741cb3a..d2eb948248 100644 --- a/crates/pixi_manifest/src/toml/manifest.rs +++ b/crates/pixi_manifest/src/toml/manifest.rs @@ -647,6 +647,7 @@ impl TomlManifest { features, environments, solve_groups, + loaded_at: chrono::Utc::now(), }; workspace_manifest.register_composed_platforms()?;