Skip to content

Retain configuration provenance in hash and index diagnostics - #2326

Draft
zaniebot wants to merge 8 commits into
mainfrom
zb/configuration-provenance
Draft

zaniebot wants to merge 8 commits into
mainfrom
zb/configuration-provenance

Conversation

@zaniebot

@zaniebot zaniebot commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

--require-hashes and --no-index failures can be caused by configuration or nested requirements directives whose origins are lost during settings resolution. Introduce Sourced<T> to carry effective source information into hash and resolver diagnostics, identifying environment variables, configuration keys, and requirements file line numbers and include chains.

Scalar precedence retains the winning declaration, while cumulative flags retain every enabling declaration. Source metadata is excluded from value equality, hashing, serialization, and configuration schemas.

Includes the nested-constraints hash enforcement from astral-sh#22275, so included constraints retain both their policy and its source.

@zaniebot
zaniebot deployed to automations October 7, 2026 20:15 — with GitHub Actions Active
@astral-automations-bot astral-automations-bot Bot added area:error-messages Messaging when something goes wrong enhancement New feature or request labels Oct 7, 2026
@zaniebot
zaniebot deployed to automations October 7, 2026 20:20 — with GitHub Actions Active
input: requirements_txt.clone(),
line: calculate_row_column(content, start).0,
});
data.require_hashes = data.require_hashes.or(sub_constraints.require_hashes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Separate nested-constraint enforcement from provenance tracking

This also changes which inputs enable hash enforcement. With requirements.txt containing -c policy.txt and an unhashed pinned requirement, --require-hashes in policy.txt now makes install/sync fail; the base implementation only merged constraint entries here. The new nested-constraint tests therefore cover a policy change as well as diagnostics. Move this enforcement change and its regression tests into a separate preparatory fix so its compatibility implications can be reviewed independently of the provenance plumbing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed this during review, I think I agree that it'd be best as a separate PR.

@zaniebot
zaniebot deployed to automations October 7, 2026 20:26 — with GitHub Actions Active
@codspeed

codspeed Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 16.3%

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 68 untouched benchmarks
⏩ 35 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ ⚠️ Simulation discover_workspace_from_all_members_with_excludes 165.6 ms 142.4 ms +16.3%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing zb/configuration-provenance (a0081fb) with main (64e2ac8)

Open in CodSpeed

Footnotes

  1. 35 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

impl FromArgMatches for HashCheckingArgs {
fn from_arg_matches(matches: &ArgMatches) -> Result<Self, clap::Error> {
let args = HashCheckingOptions::from_arg_matches(matches)?;
let setting = |yes, no, name, yes_id, no_id, yes_flag, no_flag| {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how I'd improve this necessarily, but flagging that it's pretty hard to read.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also FWICT any hints here get dropped anyways in enabled_hints?)

Comment on lines +75 to 94
let sources = match (&self.verification, &constraints.verification) {
(
HashVerification::Required(_),
HashVerification::None | HashVerification::IfPresent(_),
) => self.verification_sources.clone(),
(
HashVerification::None | HashVerification::IfPresent(_),
HashVerification::Required(_),
) => constraints.verification_sources.clone(),
(HashVerification::Required(_), HashVerification::Required(_))
| (
HashVerification::None | HashVerification::IfPresent(_),
HashVerification::None | HashVerification::IfPresent(_),
) => {
let mut sources = self.verification_sources.clone();
sources.extend(&constraints.verification_sources);
sources
}
};
let (requirement_hashes, mode) = match &self.verification {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two match statements could be merged for clarity.

input: requirements_txt.clone(),
line: calculate_row_column(content, start).0,
});
data.require_hashes = data.require_hashes.or(sub_constraints.require_hashes);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed this during review, I think I agree that it'd be best as a separate PR.

@zaniebot
zaniebot deployed to automations October 8, 2026 20:11 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 8, 2026 20:18 — with GitHub Actions Active
Comment on lines +134 to +139
fn _schemars_private_non_optional_json_schema(generator: &mut SchemaGenerator) -> Schema {
T::_schemars_private_non_optional_json_schema(generator)
}

fn _schemars_private_is_option() -> bool {
T::_schemars_private_is_option()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Derive the transparent schema instead of forwarding private hooks

This implementation delegates every schema method to T, including _schemars_private_* hooks. A feature-gated JsonSchema derive with transparent schema behavior handles the single non-skipped field, following the existing DisplaySafeUrl pattern in uv-redacted. Use that derive and retain #[serde(skip)] on sources; this preserves the value-only schema while avoiding handwritten coupling to schemars internals.

hint: `--no-index` was enabled by `tool.uv.no-index` in `script.py`
");

uv_snapshot!(context.run().arg("script.py"), @"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Put command-specific regressions in their existing test suites

This uv run scenario and hash_sync_environment are registered under the pip_install test target, so focused runs of the existing run and pip_sync suites miss their new provenance coverage. The script test also combines two independent command paths. Move this invocation into a separately named test in crates/uv/tests/project/run.rs, and move the sync case into crates/uv/tests/pip/pip_sync.rs, alongside their existing script-configuration and hash-checking tests.

collect_hint::<uv_lock_operations::LockError>(cause, &mut hints);
collect_hint::<uv_resolve_operations::Error>(cause, &mut hints);
collect_hint::<uv_install_operations::Error>(cause, &mut hints);
collect_hint::<uv_types::HashStrategyError>(cause, &mut hints);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Update the existing nested-constraints snapshot

Collecting these hints also changes install_require_hashes_in_nested_constraints_txt in crates/uv/tests/pip_install/pip_install.rs. Its fixture enables hash checking through -c constraints.txt, so it now emits the hint identifying constraints.txt at line 1, included from requirements.txt at line 1. The existing snapshot still expects only the error and will no longer match. Update that snapshot alongside the new provenance tests.

Comment thread crates/uv-settings/src/lib.rs Outdated
options
};
Ok(options)
Ok(options.with_config_source(&path.into(), ""))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Keep filesystem configuration sources explicitly local

From<&Path> interprets the literal path - as RequirementsInput::Stdin, but read_file reads it as an ordinary file. Consequently, --config-file - with pip.require-hashes = true attributes the resulting error to “script metadata read from stdin” instead of the configuration file. Construct RequirementsInput::Local(path.to_path_buf()) here so attaching provenance does not reinterpret the known filesystem source.

@zaniebot
zaniebot deployed to automations October 13, 2026 16:49 — with GitHub Actions Active
@zaniebot
zaniebot deployed to automations October 13, 2026 16:55 — with GitHub Actions Active
Comment thread crates/uv-resolver/src/error.rs Outdated
Comment on lines +915 to +924
if self.index_locations.no_index()
&& derivation_tree_packages(&self.error)
.filter_map(PubGrubPackage::name_no_root)
.any(|name| {
matches!(
self.unavailable_packages.get(name),
Some(UnavailablePackage::NoIndex)
)
})
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Generate provenance in the existing index-hint path

This introduces a second index-hint eligibility check over the unreduced error tree. The existing PubGrubReportFormatter::generate_hints uses the reduced tree and invokes index_hints for Custom/NoVersions incompatibilities; this pass also includes packages mentioned only in dependency edges. Attribution consequently follows different relevance rules, and future hint changes must maintain both paths. Generate a structured provenance hint in the existing UnavailablePackage::NoIndex handling, including its find-links branch, and leave this implementation responsible for rendering the collected hints.

@zaniebot
zaniebot deployed to automations October 13, 2026 17:09 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:error-messages Messaging when something goes wrong enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

⌂ 换网址