Skip to content

Fix vendored PDM missing stale-install warning (#641) - #1727

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pdm-vendored-stale-install
Oct 26, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pdm-vendored-stale-install

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Fixes #641

Summary

scan --mode vendored (and vendor) on a PDM project whose pdm.lock was written by PDM before 2.11 now warns pypi_pdm_stale_install when the env PDM installs into still holds the upstream release. Before, it said nothing, the next pdm sync kept the unpatched bytes, and vex attested not_affected with a "re-run your install" hint that doesn't work on those releases. The warning names the remedy that works for that release line, and vex's vendored_tree_out_of_sync hint now names it too.

Root cause

PDM < 2.11 (lock_version 2 / 4.3 / 4.4) keeps a release already installed at the same version on pdm sync / pdm install. Hosted mode already accounted for this (redirect_pdm_stale_install_risk plus the installed-byte probe). The vendored flavors had an installed-byte probe only for Pipenv and Hatch, so the PDM flavor never checked.

Changes

  • vendor/pypi.rs: new pdm_stale_install_warning, the PDM twin of the Pipenv/Hatch probes. It reuses stale_install_sites over non_hatch_local_venv_site_packages, which already resolves PDM's env (.pdm-python, an activated or in-project venv, PEP 582 __pypackages__). It runs on a fresh vendor, an in-sync re-run, and a superseding re-wire. A copy inherited from a --system-site-packages base interpreter is named separately with a remedy that reaches it.
  • vendor/pypi_pdm.rs: stale_install_remedy gives pdm sync --reinstall on PDM 2.x. For lock_version 2 (PDM before 2.0, which has no --reinstall), it says to remove the installed copy and then run pdm sync. stale_install_lock / stale_install_note build the VEX addendum, only for a package the governing pdm.lock wires to a vendored artifact, and read pdm.lock once per run.
  • utils/pdm_lock.rs: keeps_installed_release is now shared by hosted (redirect/pdm.rs) and vendored mode.
  • commands/vex.rs: the vendored_tree_out_of_sync detail appends the PDM remedy.
  • Docs: a new row in the CLI_CONTRACT.md warning table plus the vex hint note, and docs/testing/pdm-compatibility.md.
  • The npm/PyPI/gem wrappers only pass warning codes through, so they need no change.

Test evidence

Issue Test Red without fix → green with fix
#641 (lock 4.3/4.4 venv, fresh + in-sync re-run; 4.4.1/4.5.0 silent; patched env silent) vendor::pypi::tests::pdm_vendor_warns_about_a_stale_install_before_pdm_2_11 failed left: 0 right: 1 (only vendor_prebuilt_downloaded) → ok
#641 (PDM 1.x lock_version 2, PEP 582 __pypackages__) vendor::pypi::tests::pdm_1x_vendor_warns_about_a_stale_pep582_install failed left: 0 right: 1 → ok
#641 (vex hint) vendor::pypi_pdm::tests::stale_install_note_follows_the_lock_and_its_wiring new helper → ok
#641 end to end with real PDM e2e_vex_build pdm::pdm_vendored_install_then_manifest_less_vex (new stale_install_flow: the warning fires, real pdm sync keeps upstream six, and the named remedy installs the patched wheel) PDM 2.10.4 on pre-fix sources: pdm 2.10.4 lock 4.4 stale install: [] FAILED → ok on 2.10.4 (lock 4.4), 1.4.5 (lock 2) and 2.29.2 (lock 4.5.1, silent)

Commands run locally:

  • cargo fmt --all -- --check: ok
  • cargo clippy --workspace --all-features -- -D warnings: ok
  • SOCKET_PATCH_PDM_E2E_REQUIRED=1 SOCKET_PATCH_PDM_E2E_VERSION={2.10.4,1.4.5,2.29.2} cargo test -p socket-patch-cli --all-features --test e2e_vex_build -- pdm:: --ignored: 2 passed per release
  • cargo test --workspace --all-features --no-fail-fast: 228 of 239 suites passed. The 11 failing tests come from this sandbox and are outside the code this PR touches:
    • 9 tests inject a write failure by making a file read-only, which root ignores (the container runs as uid 0).
    • 2 e2e_bun_lockb tests need network access to patches-api.socket.dev and the bun release CI pins (bun 1.4.4 is installed locally).

Review

I ran /code-review high and fixed findings 1-7 in dd2a447: base-interpreter copies, the VEX note limited to packages pdm.lock wires, one pdm.lock parse per run, the superseding path, a shared lock-version predicate, parse_pypi_purl, and the wording. I didn't fix this one:

  • The probe runs twice per package, because pypi_prelude runs from both service_preflight and the real run. The Pipenv and Hatch probes already share this cost through the same prelude. Splitting the prelude is a separate refactor.

https://claude.ai/code/session_01JGE2ajfBnCgDHnaCM2D1NK


Note

Low Risk
Additive warnings and clearer VEX hints on vendored PyPI/PDM paths; no change to patch application or auth behavior.

Overview
Fixes #641 by surfacing when vendored PDM wiring leaves upstream bytes in the live env on locks written by PDM < 2.11 (lock_version 2 / 4.3 / 4.4), where pdm sync does not replace a same-version install.

Vendored vendor / scan now emits pypi_pdm_stale_install (mirroring Pipenv/Hatch): it probes PDM’s install target (venv or PEP 582 __pypackages__), names pdm sync --reinstall on PDM 2.x or manual removal before sync on lock_version 2, and treats inherited --system-site-packages copies separately. The warning runs on fresh vendor, in-sync re-run, and superseding re-wire.

keeps_installed_release in pdm_lock is shared with hosted redirect_pdm_stale_install_risk. vex appends the same PDM remedy to vendored_tree_out_of_sync when the governing pdm.lock wires the package to a vendored artifact.

CLI contract and PDM compatibility docs document the new code; unit and e2e PDM tests assert warning text, silence on 2.11+ locks, and that the named remedy actually installs the patched wheel.

Reviewed by Cursor Bugbot for commit dd2a447. Configure here.


Generated by Claude Code

Assisted-by: Claude Code:claude-opus-5-5
Vendoring a patch into a PDM project whose pdm.lock was written by
PDM before 2.11 (lock_version 2, 4.3 or 4.4) left an env that already
held the package unpatched: PDM keeps a same-version install on
`pdm sync`, the scan said nothing, and `vex` attested not_affected
with a "re-run your install" hint that does not help.

The vendored PDM flavor now probes the env PDM installs into (its
venv or PEP 582 __pypackages__) like the Pipenv and Hatch flavors,
and warns pypi_pdm_stale_install with the remedy that release line
supports: `pdm sync --reinstall` on PDM 2.x, or removing the
installed copy before `pdm sync` on PDM 1.x, which has no
--reinstall. vex's vendored_tree_out_of_sync hint names the same
remedy. A 2.11+ lock stays silent.

Fixes #641

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
Review follow-ups for the PDM < 2.11 stale-install warning:

- warn on a superseding re-wire too, not only fresh and in-sync runs
- name a copy inherited from the base interpreter of a
  --system-site-packages venv apart, with a remedy that reaches it
- add vex's PDM hint only for a package pdm.lock wires to a vendored
  artifact, reading pdm.lock once per run instead of once per package
- share the "keeps an installed release" lock-version check between
  hosted and vendored mode
- say "PDM before 2.0" for lock_version 2, which PDM 0.x writes too

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

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dd2a447. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 26, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Labeled Ready for review (burn-down agent).

  • Head: dd2a4472
  • CI: 38/38 non-skipped checks green, no failures; mergeable, no conflicts
  • Bugbot: reviewed dd2a447, no findings
  • Reviewer focus: the new pypi_pdm_stale_install warning in vendor/pypi_pdm.rs and the shared keeps_installed_release helper in utils/pdm_lock.rs (now used by both hosted and vendored paths).

Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final review brief

What it does. PDM releases before 2.11 (pdm.lock lock_version 2 / 4.3 / 4.4) keep a package that is already installed at the same version on pdm sync. Because of that, vendoring a patch left the unpatched upstream bytes live, and nothing warned about it. This PR adds a pypi_pdm_stale_install warning to vendored PDM, matching the existing Pipenv/Hatch warnings. The warning names pdm sync --reinstall, or for lock_version 2 (PDM before 2.0) tells you to remove the installed copy first. vex's vendored_tree_out_of_sync hint now gives the same remedy.

Risk: low. It only adds a warning and extends a hint. It doesn't change patch application, lock wiring or auth. The lock-version check is now one shared predicate, and hosted mode behaves the same as before.

Look here

  • vendor/pypi.rs:910: the new probe, including the split for --system-site-packages base copies
  • vendor/pypi.rs:1250: where the probe runs (fresh vendor, in-sync re-run, superseding re-wire; refusals return before it)
  • vendor/pypi_pdm.rs:123: the remedy for each release line, and :156, which adds the VEX note only for packages pdm.lock wires to a vendored artifact
  • commands/vex.rs:1062: pdm.lock is loaded once per run and skipped in global mode
  • utils/pdm_lock.rs:30: keeps_installed_release, now shared with hosted mode

Verified

  • Read the full diff (8 files, +501/-7).
  • keeps_installed_release covers every lock_version the parser accepts that keeps installs (2/4.3/4.4). 4.4.1/4.5.x stay silent.
  • The unit tests cover 4.3, 4.4, 4.4.1 and 4.5.0, PEP 582 on lock_version 2, and a patched env staying silent. The Windows Lib\\site-packages layout is handled.
  • The e2e test runs real PDM 2.10.4, 1.4.5 and 2.29.2. The PR description says the new tests fail on the pre-fix code.
  • No CHANGELOG edit, no leftover debug code.
  • CI: ci-ok and clippy green on dd2a447 (38/38 per the burn-down). Bugbot: clean on dd2a447. No unresolved threads.

Changes I made: none.

Open questions: none blocking. As the PR description notes, the probe runs twice per package (preflight plus the real run), the same as Pipenv and Hatch.

Auto-merge is armed, so approving sends this straight to the merge queue.


Generated by Claude Code

Merged via the queue into main with commit 6395098 Oct 26, 2026
88 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-pdm-vendored-stale-install branch October 26, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vendored PDM < 2.11 gives no stale-install warning, so after pdm sync the unpatched release stays installed while vex attests not_affected

3 participants