← Back to Pull requests

crate_universe: resolve annotation patches against the current module #4425

Closed
unknown closed this pull request without merging on Nov 28, 2026 15:21 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 09:07 UTC
Author

Problem

crate.annotation(patches = ...) labels are stored in cargo-bazel-lock.json as canonical strings, so their form depends on which module was root when the lockfile was pinned (@@//… vs @@my_module+//…). Since #3521 the digest ignores the repo part, so the lockfile is reused unchanged when the module is consumed by another root. _generate_hub_and_spokes then passes the stored string straight to http_archive/git_repository, and @@// resolves to the consumer's main repo:

Error in patch: Cannot find patch file: /path/to/consumer/bazel/patches/foo.patch

Re-pinning from the consumer only moves the breakage: the module then fails as root. No single lockfile works in both setups.

Fix

Build an index from the current invocation's annotation tags, (crate, repo-stripped label) → label as resolved now, and use it to rewrite lockfile patch labels before creating crate repos. The repo-stripping is the same normalization the digest already uses. Labels with no matching annotation keep their lockfile value. There's no lockfile format change, no digest change and no forced re-pin.

Testing

A module owns a crate.from_cargo hub with a patched crate annotation and its own lockfile pinned as root. A second root module depends on it through local_path_override and include()s its *.MODULE.bazel.

  • Before: the crate fetch fails because the patch path resolves inside the consumer.

  • After: the patch resolves inside the owning module from both roots.
  • Happy to add a regression test under test/ (a nested module with a lockfile and a patch annotation, built as root and as a dependency) if that's the preferred shape.

    Notes

    Other label-valued annotation fields (deps, build_script_data, additive_build_file, …) may have the same problem when rendered into spoke BUILD files. This PR only fixes patches, which extensions.bzl consumes directly.

    Assisted-by: Claude Code:claude-opus-5-5

    Diff: 245 lines (+183 / -62) across 3 files Reviewer: UebelAndre Review duration: 20534m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 245 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.329
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4425"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.9% (MEDIUM) · Higher = larger blast radius
    38.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.3% · Safe to merge
    15.3%