Fix Pipenv venv discovery order (#334, #384) - #388
Conversation
Assisted-by: Claude Code:claude-opus-5-5
Agent mode picked a Pipenv project's venv with a generic probe order, so it could patch the wrong venv, or none, and still exit 0: - an activated VIRTUAL_ENV won even with PIPENV_ACTIVE or PIPENV_IGNORE_VIRTUALENVS set, which patched another project's or a tool's venv (#384) - a stray venv/ directory, or a ./.venv that PIPENV_VENV_IN_PROJECT=0 or the Pipfile's [pipenv] venv_in_project = false rules out, shadowed Pipenv's WORKON_HOME venv (#334) Discovery now follows Pipenv's own resolution for Pipenv projects. With an auto-detected .venv and an existing WORKON_HOME venv, both are returned, because Pipenv 2026.2+ and older releases disagree. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Autofix Details
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Unguarded Pipfile read can hang
- Replaced bare std::fs::read_to_string with read_regular_to_string_sync to prevent hanging when Pipfile is a FIFO or device.
Or push these changes by commenting:
@cursor push 2b7913a01e
Preview (2b7913a01e)
diff --git a/crates/socket-patch-core/src/crawlers/python_crawler.rs b/crates/socket-patch-core/src/crawlers/python_crawler.rs
--- a/crates/socket-patch-core/src/crawlers/python_crawler.rs
+++ b/crates/socket-patch-core/src/crawlers/python_crawler.rs
@@ -380,7 +380,7 @@
Some(Err(text)) if !text.is_empty() => return Some(true),
_ => {}
}
- let text = std::fs::read_to_string(cwd.join("Pipfile")).ok()?;
+ let text = read_regular_to_string_sync(&cwd.join("Pipfile")).ok()?;
let doc = text.parse::<toml_edit::DocumentMut>().ok()?;
let value = doc.get("pipenv")?.get("venv_in_project")?.as_value()?;
// Python's `bool(value)` for the scalar shapes a Pipfile can hold.You can send follow-ups to the cloud agent here.
The Pipenv venv lookup reads the Pipfile's [pipenv] venv_in_project key. A Pipfile.lock alone marks the project, so a FIFO or device at Pipfile could be opened and wedge scan and apply. Read it with the module's non-blocking, regular-files-only helper instead. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
Bring the Pipenv venv-resolution fix up to date with the v5 workflow consolidation (#277), so it can land on top of it. main still used the generic VIRTUAL_ENV -> .venv/venv -> Poetry -> WORKON_HOME probe order for Pipenv projects. This keeps the PR's Pipenv-aware resolution in place of that order: honour PIPENV_ACTIVE / PIPENV_IGNORE_VIRTUALENVS and PIPENV_VENV_IN_PROJECT / [pipenv] venv_in_project, and never use venv/. README.md takes main's rewritten version, which no longer has the Pipenv section the PR edited. The Pipenv compatibility table keeps main's "index kept as Pipenv wrote it" wording and the PR's agent-mode venv description. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GQoii5oP1pwcJh5mzzo1HU
|
bugbot run Generated by Claude Code |
When Pipenv had no venv yet, discovery fell through to the generic ./.venv and ./venv probes. That picked a stray venv/ (which no Pipenv release uses) or a ./.venv an explicit PIPENV_VENV_IN_PROJECT=0 rules out, so scan/apply patched a leftover tree and exited 0. A Pipenv project now returns only what Pipenv resolves. Co-Authored-By: Claude <noreply@anthropic.com>
|
bugbot run Generated by Claude Code |
|
[burn-down agent] Ready for review on Generated by Claude Code |
#330 reordered Poetry venv discovery in the same function. Keep both: a Pipenv project uses only the venv Pipenv resolves, then Poetry's out-of-tree env when Poetry would not use ./.venv, then the generic .venv / venv probes. Assisted-by: Claude Code:claude-opus-5-5
|
BugBot review Generated by Claude Code |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit cdcc2b3. Configure here.
|
Burn-down agent check: ready for review at
Generated by Claude Code |


LLM Description written by Claude Code:claude-opus-5-5
Fixes #334
Fixes #384
Summary
For a Pipenv project, agent mode now uses the venv Pipenv itself would use. Before, it could patch the wrong venv, or none, and still exit 0.
Root cause
find_local_venv_site_packages(crates/socket-patch-core/src/crawlers/python_crawler.rs) checked the same places for every project, in a fixed order:VIRTUAL_ENV, then./.venvand./venv, and Pipenv's own$WORKON_HOMEvenv only when all of those came up empty. Pipenv decides differently. I checked its venv-lookup code (Project.virtualenv_location/get_location_for_virtualenv, andVenvLocatorin 2026.x) in the 2022.12.19, 2023.12.1 and 2026.8.0 wheels:VIRTUAL_ENVcounts only whenPIPENV_ACTIVEis absent andbool(PIPENV_IGNORE_VIRTUALENVS)is false (Agent-mode scan patches the activated VIRTUAL_ENV even when PIPENV_IGNORE_VIRTUALENVS or PIPENV_ACTIVE tells Pipenv to ignore it, leaving the Pipenv venv unpatched with exit 0 #384).venv/is never used (Agent-mode scan skips Pipenv's out-of-tree venv when the project has a stray venv/ directory or a .venv with PIPENV_VENV_IN_PROJECT=0, and still exits 0 #334).PIPENV_VENV_IN_PROJECT=0(orPIPENV_NO_VENV_IN_PROJECT=1), and on 2026.2+ the Pipfile's[pipenv] venv_in_project = false, make Pipenv ignore a./.venvdirectory (Agent-mode scan skips Pipenv's out-of-tree venv when the project has a stray venv/ directory or a .venv with PIPENV_VENV_IN_PROJECT=0, and still exits 0 #334)../.venv(Agent-mode scan skips Pipenv's out-of-tree venv when the project has a stray venv/ directory or a .venv with PIPENV_VENV_IN_PROJECT=0, and still exits 0 #334).Fix
pipenv_project_site_packagesfollows Pipenv's order. For a Pipenv project (aPipfileorPipfile.lock),find_local_venv_site_packagesuses it right after aVIRTUAL_ENVthat Pipenv would honour. The generic.venv/venv/ Poetry checks run only when Pipenv's venv doesn't exist yet, so a project with a stray Pipfile and no Pipenv venv behaves as before. Even in that case, an opted-outVIRTUAL_ENVis never used.get_from_env/env_to_booldoes it, including thePIPENV_NO_*negations../.venvis only auto-detected, nothing explicit is set, and a WORKON_HOME venv exists. Pipenv up to 2026.1 uses./.venv, while 2026.2+ uses the WORKON_HOME venv. We can't tell the version without running Pipenv, so both are returned (WORKON_HOME first). Whichever one the installed Pipenv uses is patched, and both are this project's own venvs.docs/testing/pipenv-compatibility.md.Only Rust code changed. The npm, PyPI and gem wrappers don't discover venvs themselves, so they need no parallel change.
Tests (per issue)
crawlers::python_crawler::tests::pipenv_opt_outs_keep_virtual_env_from_hijacking_the_projectcoversPIPENV_IGNORE_VIRTUALENVS= 1 / true / non-boolean text,PIPENV_NO_IGNORE_VIRTUALENVS=0, andPIPENV_ACTIVE= 1 / empty. It also checks that an opted-outVIRTUAL_ENVisn't used even when Pipenv has no venv. Controls: falsy values, and non-Pipenv projects. At the CLI level,in_process_python_envs::pipenv_opt_outs_keep_activated_virtual_env_from_hijacking_scanrunsscanand checks that the activated venv's package is never queried.pipenv_stray_venv_dir_does_not_shadow_the_workon_home_venv,pipenv_venv_in_project_settings_decide_about_dot_venv(env var 0 / false / Off, theNO_form, Pipfile true and false, env var beating the Pipfile) andpipenv_auto_detected_dot_venv_and_workon_home_venv_are_both_returned. At the CLI level,in_process_python_envs::pipenv_stray_venv_dirs_do_not_shadow_the_pipenv_venvcoversvenv/, and.venvwithPIPENV_VENV_IN_PROJECT=0.Red on
main(before the fix), green with it:Local runs:
cargo clippy --workspace --all-features -- -D warnings: clean.cargo test --workspace --all-features --no-fail-fast: 10398 passed and 22 failed. All 22 failures come from this sandbox running as root, and none of them touch the Python crawler. 21 are write-failure tests that chmod a directory read-only, which root ignores (setup_silent_keeps_apply_phase_error_output,redirect_ledger_write_failure_*,*_write_failure_*, and so on). The last isstage_local_artifact_caps_oversized_artifact_before_buffering, which re-runs itself in a child process to measure memory use. CI runs as a regular user.cargo fmt --all -- --checkalready fails onmain(60 files with the pinned 1.93.1 toolchain), and CI doesn't run it. The lines this PR touches are rustfmt-clean.SOCKET_PATCH_PIPENV_E2E_REQUIRED=1 SOCKET_PATCH_PIPENV_E2E_VERSIONS=2026.8.0 cargo test -p socket-patch-cli --all-features --test e2e_vex_build -- pipenv:: --ignored: 1 passed (pipenv_every_major_hosted_and_vendored_end_in_manifest_less_vex, 33s).🤖 Generated with Claude Code
Note
Medium Risk
Changes which site-packages paths are scanned for Pipenv projects (agent mode and stale-install checks that call the same helper); wrong discovery would patch or warn against the wrong environment, but scope is limited to Pipenv layout logic with heavy test coverage.
Overview
Fixes Pipenv venv discovery so agent-mode scan/patch targets the environment Pipenv would use, not a generic probe order that could patch the wrong venv or miss the real one (#334, #384).
For projects with a
PipfileorPipfile.lock,find_local_venv_site_packagesnow branches early: it honorsVIRTUAL_ENVonly when Pipenv would (PIPENV_ACTIVE/PIPENV_IGNORE_VIRTUALENVSparsing mirrors Pipenv), then resolves venvs via newpipenv_project_site_packages(WORKON_HOME placement, in-project rules from env and Pipfile[pipenv] venv_in_project, nevervenv/). Generic.venv/venv/Poetry probing no longer runs for Pipenv projects, avoiding stray trees shadowing Pipenv’s venv or false positives when Pipenv has no venv yet. When both WORKON_HOME and auto-detected./.venvcould apply (Pipenv version ambiguity), both are returned so the active one is covered.Adds injectable env for tests, FIFO-safe Pipfile reads, broad unit tests in
python_crawler, end-to-endscantests inin_process_python_envs, and updatesdocs/testing/pipenv-compatibility.mdfor agent-mode behavior.Reviewed by Cursor Bugbot for commit cdcc2b3. Configure here.
Generated by Claude Code