Repository navigation
Agent and hosted mode ignore the interpreter PDM records in .pdm-python (venv.in_project = false, pdm use <venv>), so the real env is skipped or a stray .venv / the PATH python is patched, and VEX attests an unpatched install #502
Description
Activity
- addedbugSomething isn't workingSomething isn't workingbughuntFound by a scheduled package-manager bug-hunt agentFound by a scheduled package-manager bug-hunt agentpm:pdmPDMPDM
on Oct 1, 2026 - added a commit that references this issue
on Oct 1, 2026 mikolalysenko commented
on Oct 1, 2026 CollaboratorAuthorMore actions[agent] Triaged as
priority:p1(PDM). Confirmed on main61cfb9b:find_local_venv_site_packages_with(crates/socket-patch-core/src/crawlers/python_crawler.rs) has Pipenv and Poetry branches but nothing reads.pdm-python, so a PDM project falls through to./.venv/./venvand then the global fallback. Not a duplicate. Related to #476, which is in the same function but has a different cause: Poetry'suses_in_project_venvdecision, not a missing probe. No open fix PR.
Generated by Claude Code
mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] New information for the fix: PDM before 2.5 doesn't write
.pdm-python. It records the interpreter in.pdm.tomlunder[python] path = "…", so a fix that only reads.pdm-pythonwould still miss these projects.Reproduced on main
61cfb9b(Linux) with PDM 1.15.5 (lock_version 3.1) and 2.0.3 (lock_version 4.0):python3 -m venv --copies /elsewhere/env pdm config -l python.use_venv true pdm use -f /elsewhere/env/bin/python # .pdm.toml: [python] path = "/elsewhere/env/bin/python" pdm install # urllib3 1.26.18 -> /elsewhere/env/lib/python3.11/site-packages socket-patch scan --mode agent --yes --json
Both versions give
status: success, exit 0,apply.patches[0] = {action: skipped, errorCode: package_not_installed}, and the env keeps upstream bytes. (Without--copies, PDM 1.15 resolves the venv's symlinked python to/usr/bin/python3.11and installs into__pypackages__, which is the documented PEP 582 case.) Hosted mode refuses both lock versions as documented, so only agent mode applies here.Suggested probe order:
.pdm-python(≥ 2.5), then.pdm.tomlpython.path(1.x – 2.4).
Generated by Claude Code
- added a commit that references this issue
on Oct 2, 2026 mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] Claiming this issue (with #525, #528; shared root cause:
find_local_venv_site_packagesnever resolves the env the project's package manager records (PDM.pdm-python/__pypackages__, uvUV_PROJECT_ENVIRONMENT), so discovery falls through to./.venvor the PATH interpreter). Branch: agent/fix-python-manager-project-env. Claim-ID: 2026-10-02T07:21:09Z-11e135
Generated by Claude Code
mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions- added a commit that references this issue
on Oct 2, 2026 mikolalysenko commented
on Oct 2, 2026 CollaboratorAuthorMore actions[agent] PDM bug-hunt re-triage: I tested PR #540 (head
60dfb81) with real PDM against a local mock of the patch API. It fixes thevenv.in_project = falsecase in both agent and hosted mode. Main61cfb9bstill reproduces it.Setup:
pdm config -l venv.in_project false,pdm venv create,pdm use --venv in-project,pdm install..pdm-pythonthen points at~/.local/share/pdm/venvs/<proj>-<hash>-3.12/bin/python, which holds upstream urllib3 1.26.18, and there's no./.venv. I reset the venv withpdm sync --reinstallbefore each run.PDM build agent scan --mode agenthosted stale-install warning hosted vexbefore reinstall2.29.2 main [skip] … not installed, venv unpatchednone exit 0, not_affected(wrong)2.29.2 PR #540 1 applied, venv patched printed exit 1, omitted 2.12.4 main — none exit 0, not_affected(wrong)2.12.4 PR #540 — printed exit 1, omitted After
pdm sync,vexisnot_affectedon both builds, which is correct. I didn't re-run the PDM < 2.5.pdm.toml[python] pathvariant this time; the PR reads that key inpdm_saved_interpreter. Leaving this open until #540 merges.
Generated by Claude Code
[agent] Found by the scheduled PDM bug-hunt routine (ledger #312).
Summary
PDM records the project's interpreter in
.pdm-python. Withvenv.in_project = falseit points at PDM's out-of-tree venv (<data_dir>/pdm/venvs/<project>-<hash>-<py>/bin/python), and afterpdm use <path>it points at whatever venv the user picked.pdm sync,pdm installandpdm runall use that interpreter. The Python crawler's local discovery (find_local_venv_site_packages_with) has dedicated probes for Pipenv's and Poetry's out-of-tree venvs, but none for PDM. It only checksVIRTUAL_ENV,./.venvand./venv, and then falls back to the global interpreters. So on a PDM project whose env isn't./.venv:scan --mode agentreports[skip] … (not installed; run your package manager's install first …). The package is installed, in the envpdm runuses../.venvexists (for example left over from before switching toin_project = false), or ifpython3onPATHhas the package, that tree is patched (applied: 1). PDM's env stays upstream.scan --mode hostedwith no reinstall, the in-project control prints thestill differ from the patched hasheswarning, andvexomits the package asnot_applied(exit 1). With the out-of-tree env there's no warning, andvexemitsnot_affected/inline_mitigations_already_exist("redirected", exit 0) whilepdm run pythonimports the unpatched bytes.The Poetry and Pipenv versions of this were filed and fixed (#327, #329, #334, #384; #476 is open), so this is the PDM gap in the same probe.
Impact
Agent mode silently doesn't patch, or patches an environment the app never runs in, and still exits 0 with
applied: 1. VEX then claims a mitigation that isn't installed.venv.in_project = falseis a documented, commonly used PDM setting (centralized venvs), andpdm use <venv>is the standard way to bind an existing venv.Repro (Linux, PDM 2.29.2, main
61cfb9b)The patch API was a local mock serving the free
urllib3@1.26.18patch (SOCKET_PROXY_URL). Any PyPI patch will do.Expected vs actual
./.venv,./venv, Pipenv's out-of-treeWORKON_HOMEvenv"). For a PDM project,.pdm-python(or PDM'svenv.location/venv.in_projectresolution) should decide the env, and a./.venvthat PDM doesn't use shouldn't be patched. A stale install must keep the hosted warning and the VEXnot_appliedomission, as in the in-project control.Matrix (Linux; each cell reproduced at least twice)
venv.in_project=falsein_project=false+ stray./.venvapplied: 1./.venvin_project=false,python3on PATH has urllib3applied: 1in_project=true,pdm use -f <external venv>/bin/pythonvenv.in_project=false(± stray.venv)applied: 1to./.venv./.venv.venvnot_applied(correct)macOS and Windows weren't probed. The probe is OS-independent (PDM's venv dir is under platformdirs' user data dir on every OS).
First bad version: not a regression. The published
socket-patch4.0.0 (PyPI) behaves the same (stray.venvpatched, PDM env upstream). PDM discovery has never existed.Suspect code
crates/socket-patch-core/src/crawlers/python_crawler.rs:336(find_local_venv_site_packages_with): steps 2–3 special-case Pipenv and Poetry. There's no PDM step, so a PDM project falls through to./.venv/./venv(line 381) and then the global fallback. A fix would read.pdm-python(PDM ≥ 2.0; PDM 1.x storedpython.pathin.pdm.toml). When it names an interpreter, it would probe that interpreter's prefix and nothing else, the same as the Pipenv branch.vexuse the same crawler, which is why (3) follows from it.