Repository navigation
Studio: repair duplicate package metadata during updates - #8515
danielhanchen merged 60 commits into
Conversation
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Reviewed this on Linux against merge base ReproductionThrowaway venv, a package whose current Through the post-update guard, which is what the user actually sees: The old advice was the actively harmful part: "reinstall over the top" cannot fix a stale record, so the user loops. Other things that check out:
One thing worth changing
For Two ways out, either is fine:
Smaller note
Low impact, since Codex threadsAll 14 look addressed by the later commits. I verified the ones that are checkable on Linux: every stale record removed before reinstall, the active-directory-only foreign scan, malformed and nameless records isolated per distribution and treated as conflicts, malformed metadata removed directly rather than handed to pip, the editable foreign requirements probe, and the CI and local overlay provenance being restored after repair. The Windows launcher one I could not exercise here; the Nothing blocking apart from the uninstall-before-reinstall gap. Nice fix. |
purelib hardcodes lib while platlib follows sys.platlibdir, and venv creates lib64 as a symlink to lib. On Fedora and SuSE the two schemes are therefore two names for one directory, and deduplicating the scan roots by string kept both. installed_versions() then returned every record twice, so metadata_conflict() was true for every installed package in a perfectly healthy environment: update would exit 1 telling the user to recreate the venv, and the repair could never converge because the duplication was an illusion. Deduplicate on the real path instead.
_rewrite_minimal_metadata already refuses a record with no RECORD, because nothing then knows which files that release owned. The repair only honoured that when no other record survived. With one surviving, the count stayed nonzero, pip uninstalled just the readable record, and the quarantine was discarded on success, so whatever the older release owned alone stayed importable and the directory that was the evidence was deleted for good. Measured before the change: repair returned True, the stale module was still importable, and the stale dist-info was gone. Now the repair stops with the directory untouched, so a later run can still see the conflict. Four tests built their malformed record without a RECORD and asserted the repair continued, which is the behaviour above. They use an unversioned directory name instead, so the rewrite still fails and the quarantine path they exist to cover is unchanged. Reported by review.
The previous commit only covered records with no RECORD. Any unrewritable record leaks the same way: quarantining it hides it, pip removes just the readable records, the quarantine is discarded once the reinstall succeeds, and whatever that release owned alone stays importable while the repair reports success and deletes the directory that was the evidence. The reachable route is a METADATA that exists but cannot be read, as an elevated install leaves root-owned. Measured in a real venv with the file unreadable: repair returned True, the stale module was still importable and its dist-info was gone. It now stops with the tree as found. An unreadable METADATA that can be rewritten still repairs, as does an ordinary duplicate. Quarantine-and-proceed had no remaining purpose once nothing runs after an unusable record, so it is gone and its three tests collapse into one that pins the invariant. Quarantine itself is still used for pip's ~ leftover, which is what the restore-on-staging-failure test now covers.
When the rewritten record has already been uninstalled and a later uninstall fails, _restore_from_staged reinstalls the package before the finally block runs quarantine.restore(). If the staged wheel recreates the same dist-info path, restore then either overwrote the wheel's valid METADATA with the original corrupt bytes or, where the original was absent, deleted a record pip had just written, leaving the core package malformed after a recovery whose whole purpose was to make it whole. Reproduced as a unit: the repair returned False and reading the resulting METADATA raised UnicodeDecodeError. A successful staged reinstall now drops the backed-up copies, since the wheel's metadata is authoritative. The moved entries are kept, because a record pip cannot consume still has to go back exactly as found. Reported by review.
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
A successful Studio update can report files as missing when stale and current
.dist-infodirectories remain for the same package. The reported files may simply have been removed in the newer release. Duplicate metadata can also make version checks select a stale release.Root cause
Studio assumed each normalized package name had one metadata directory. Python's single-version lookup selects the first matching record, while Studio's integrity check read every matching
RECORD. A stale record could therefore look like installation damage.Fix
Testing
bash -n studio/setup.sh, andgit diff --checkLive validation
GitHub Actions reconstructed the stale
2026.8.12and current2026.8.15metadata state on native Ubuntu and Windows runners. The base commit reproduced all eight false missing-file reports on both systems. This branch reported the metadata conflict instead, completed the production repair, and finished with one metadata record and a clean file scan.