Skip to content

fix(pypi): store index misses in facts so lockfile reads need no network - #4582

Open
ZeroDayTea wants to merge 1 commit into
bazel-contrib:mainfrom
ZeroDayTea:fix-pypi-complete-facts
Open

ZeroDayTea wants to merge 1 commit into
bazel-contrib:mainfrom
ZeroDayTea:fix-pypi-complete-facts

Conversation

@ZeroDayTea

@ZeroDayTea ZeroDayTea commented Nov 23, 2026 •

Copy link
Copy Markdown

With experimental_extra_index_urls, the pip extension downloads the root
/simple/ page of every index to find which index hosts each package, and
then each package page. The facts in MODULE.bazel.lock only store hits. For
an index that hosts only some of the requirements (a private index, or the
PyTorch and NVIDIA indexes), and for a package page that does not have every
requested version, the facts are never complete. So every new evaluation of
the extension, for example on a fresh Bazel server in CI, calls all the
indexes again even with an up to date lockfile, and one transient DNS or
index failure fails the build.

To fix, store the misses too:

  • A requested package that is not on an index is stored with an empty URL,
    e.g. "foo@https://example.com/simple/": "". Readers already skip empty
    URLs when they pick an index.
  • The requested versions that a package page does not have are stored under
    a new <distribution>@<root_url>#missing key.

The change is additive, so the facts version stays at v3. Older readers
treat an empty URL as "not on this index" and ignore the new key.

Fixes #4581

Summary by CodeRabbit

  • Bug Fixes
    • The pip extension can now resolve dependencies using only MODULE.bazel.lock when an extra package index contains only some of the requested requirements.
    • Missing packages and package versions are now recorded in the cache, allowing later lookups to correctly report when no matching distributions are available.
    • Cache results now distinguish complete from incomplete coverage of requested versions.

With `experimental_extra_index_urls`, the `pip` extension downloads the root
`/simple/` page of every index to find which index hosts each package, and
then each package page. The facts in `MODULE.bazel.lock` only store hits. For
an index that hosts only some of the requirements (a private index, or the
PyTorch and NVIDIA indexes), and for a package page that does not have every
requested version, the facts are never complete. So every new evaluation of
the extension, for example on a fresh Bazel server in CI, calls all the
indexes again even with an up to date lockfile, and one transient DNS or
index failure fails the build.

To fix, store the misses too:
* A requested package that is not on an index is stored with an empty URL,
  e.g. `"foo@https://example.com/simple/": ""`. Readers already skip empty
  URLs when they pick an index.
* The requested versions that a package page does not have are stored under
  a new `<distribution>@<root_url>#missing` key.

The change is additive, so the facts version stays at `v3`. Older readers
treat an empty URL as "not on this index" and ignore the new key.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 20:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: PyPI facts caching

Layer / File(s) Summary
Record missing packages in index facts
python/private/pypi/pypi_cache.bzl, tests/pypi/pypi_cache/pypi_cache_tests.bzl, news/4581.fixed.md
The cache records requested packages absent from index results as empty URLs. Tests verify that a later cache can answer those lookups from facts. The changelog describes lockfile evaluation with a partial extra index.
Record missing versions in package facts
python/private/pypi/pypi_cache.bzl, tests/pypi/pypi_cache/pypi_cache_tests.bzl
The cache records requested versions without distributions in a #missing fact. Reads use those facts alongside available distribution entries. Tests cover reloads with both available and missing versions.

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to e35e2

This change records packages and versions that are absent from indexes in the lockfile facts, so evaluation with a partial extra index needs fewer network calls. No concrete merge-blocking risk was found; the change is additive and older readers ignore the new key.

Security architecture risk: Moderate · up to e35e2

Recording misses lets builds reuse a lockfile without contacting every package index. But an incomplete response can outlive the outage, and a miss recorded in one environment can cause another environment using the same lockfile to skip its preferred index.

Retained concerns

  • Medium · reliability · inferred: A successful download does not establish that a page is complete. The parser can accept a partial listing or return an empty package-page struct, and the cache can publish omitted versions as definitive misses. Once those facts cover a request, ordinary replay skips the fetch that could discover recovery and copies the misses forward. Before this PR, the same omissions left coverage incomplete and allowed a later evaluation to retry.
  • Medium · security · inferred: Persisted facts use the configured URL rather than the resolved URL or authenticated view. That identity design predates this PR, but persisting misses means a build can reuse an absence recorded against a different endpoint or credential view behind the same configured URL. In multi-index discovery, a cached miss can make the resolver skip an earlier configured index and select a later one. This does not establish that an unconfigured source or an artifact failing digest checks can be accepted.
Security review details

Security Blast Radius

  • inferred — The effect extends to builds that consume the same extension facts and request the affected package or version under the same fact key. An omission on a root listing can affect multiple requested packages; a package-page omission is scoped to that page and its requested versions.

Trust Boundaries and Controls

  • observed — Index content can influence lockfile coverage, but a failed download is not persisted. A negative root fact supplies no destination: the selector skips it and constructs the package URL from a configured index that reported a hit. The inspected artifact selection still looks up supplied requirement digests and excludes yanked candidates.

Resilience and Maintainability Implications

  • observed — Replaying requested misses is deterministic: version misses are deduplicated and sorted, and a positive entry is still returned if a miss for the same version coexists. That coexistence does not trigger a refresh or remove the stale miss during replay.

Hardening Proposals

  • proposed — Keep offline replay for trusted snapshots, but provide a documented refresh path that bypasses and replaces stale negative facts. Avoid persisting misses from responses that cannot be identified as valid listings.
  • proposed — Where lockfiles are shared across different index views, scope negative facts to an explicit non-secret view identifier or decline to reuse them across those views. Do not put resolved credentials in lockfile keys.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a5425ef7-aacc-452f-b984-df7da772e510
Commits

Reviewing files that changed from the base of the PR and between d9c0896 and e35e22a.

Files selected for processing: 3

  • news/4581.fixed.md
  • python/private/pypi/pypi_cache.bzl
  • tests/pypi/pypi_cache/pypi_cache_tests.bzl

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@ZeroDayTea

Copy link
Copy Markdown
Author

AI disclosure: an AI coding agent wrote this change, its tests and the PR text under my direction (semi-autonomous). I read and answer all review comments myself.

@ZeroDayTea

Copy link
Copy Markdown
Author

AI disclosure: an AI coding agent wrote this change, its tests and the PR text under my direction (semi-autonomous). I read and answer all review comments myself.

also let me know if I am missing any context regarding these two issues in general

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pip: lockfile facts are never complete with a partial extra index, so every fresh evaluation calls the indexes

2 participants