← Back to Pull requests

crate_universe: use repository_ctx APIs instead of `cp`/`find` in `local_crate_mirror` #4427

Closed
unknown closed this pull request without merging on Nov 16, 2026 16:24 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 09:04 UTC
Author

Fixes #4426.

Replaces cp -r and the find + read loop with a Starlark copy (readdir, read, file) plus repository_ctx.watch_tree, so local_crate_mirror works on Windows.

  • Files are copied rather than symlinked, so the mirror stays self-contained. An earlier revision of this PR used symlinks and failed local_path (external): that test vendors into mktemp -d, and the Linux sandbox hides /tmp.

  • legacy_utf8 = False keeps the copy byte-exact on Bazel 7.

  • The walk passes watch = "no" because watch_tree already covers the tree. With the default watches, deleting a subdirectory of the crate failed the refetch with "Inconsistent filesystem operations".

  • watch_tree is called before the copy, so an edit made during the copy still refetches.

  • repository_ctx cannot read file modes, so every copied file is executable. cp -r kept modes, but this keeps any script a build script runs working.

  • Symlinks inside the crate are followed. cp -r kept them as links.
  • This does what the #3025 review asked for (no shell, watch_tree). That review left watch erroring on out-of-workspace paths as an open concern; it is retested below.

    Tested with stock rules_rust 0.75.0 plus this change, using the repro in #4426:

  • The repro builds on Bazel 8.7.0 and 7.4.1. The mirror has no symlinks, and every file matches its source byte for byte.

  • A file of all 256 byte values, a UTF-8 file and nested directories copy byte-exact on both versions.

  • An edit to the linked crate rebuilds it: appending compile_error! fails the build and reverting it builds again. This holds for in-workspace paths and for absolute out-of-workspace paths.

  • Adding a nested directory to the crate shows up in the mirror, and deleting it removes it (3 cycles, no errors).

  • Our monorepo's Windows build, which failed as in #4426, passes with the symlink revision of this change. The copy revision has not been run on Windows yet.
  • repository_ctx.copy (Bazel 10) could replace the walk once that is the minimum version.

    Diff: 253 lines (+189 / -64) across 3 files Reviewer: UebelAndre Review duration: 440m
    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 · 253 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.331
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4427"
    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: 39.1% (MEDIUM) · Higher = larger blast radius
    39.1%
    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.4% · Safe to merge
    15.4%