GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Poetry venv selection ignoring envs.toml (#476, #526) by mikolalysenko · Pull Request #527 · SocketDev/socket-patch

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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

Fixes #476
Fixes #526

Summary

Agent mode, hosted mode's stale-install check, and VEX now use the Poetry virtualenv that Poetry itself uses. Before this change, two common Poetry setups led socket-patch to patch (or inspect) the wrong environment. The env behind poetry run stayed unpatched while the run reported success, and vex attested not_affected.

Root cause

Poetry venv discovery in crates/socket-patch-core/src/crawlers/python_crawler.rs approximated Poetry's EnvManager.get() instead of following it:

  • With several Poetry envs for one project (poetry env use on two Python minors), agent mode patches the alphabetically first env instead of the one Poetry activated, and VEX attests not_affected #526: it never read <virtualenvs.path>/envs.toml, where poetry env use records the activated env. With several <name>-<hash>-py* envs it returned all of them in lexicographic order, so the first one (often a dead older minor) got patched. It also let an unrelated activated VIRTUAL_ENV win, but Poetry ignores VIRTUAL_ENV once envs.toml names the project (second trigger in the issue thread).
  • Poetry with virtualenvs.in-project = true but no ./.venv keeps using its out-of-tree env, which socket-patch never probes: agent patches the global interpreter and hosted VEX falsely attests #476: it read virtualenvs.in-project = true as "only ./.venv" and poetry_virtualenvs_root returned None for it. Poetry only uses ./.venv when the directory exists (in_project_venv_exists). Otherwise it keeps installing into the existing out-of-tree env.

Fix

Follow EnvManager.get() for Poetry projects:

  • load_poetry_project reads envs.toml under virtualenvs.path ([<name>-<hash>] minor = "X.Y"). When the project has an entry, only <name>-<hash>-pyX.Y is probed.
  • The VIRTUAL_ENV shortcut is gated the way Poetry gates it: it's skipped when envs.toml has an entry, CONDA_PREFIX is honoured like VIRTUAL_ENV, and conda's base env doesn't count as an activated venv. This mirrors the existing Pipenv gate (pipenv_uses_virtual_env).
  • ./.venv is the env only when it exists and in-project isn't an explicit false. virtualenvs.path is resolved whatever in-project says, and create = false still opts out.
  • load_poetry_project now takes the injected environment instead of reading the process env. This also removes a race between the new tests and the existing serial env-mutating test.
  • docs/testing/poetry-compatibility.md "Mode notes" are updated to match.

Hosted mode's redirect_pypi_stale_install check and vex both go through find_local_venv_site_packages, so they pick up the fix with no further changes. There are no wrapper changes: npm/, pypi/ and gem/ only dispatch to the binary.

Per-issue checklist

Issue Regression test main this PR
#526 activated env (3.12/3.9/3.11 among 3.9–3.12; 3.10 vs 3.9 lexicographic trap) crawlers::python_crawler::tests::poetry_envs_toml_activated_env_is_the_only_one_probed ❌ all 4 envs returned ✅
#526 envs.toml beats VIRTUAL_ENV; conda prefix / base crawlers::python_crawler::tests::poetry_envs_toml_entry_overrides_virtual_env ❌ VIRTUAL_ENV returned ✅
#476 in-project = true (poetry.toml and POETRY_VIRTUALENVS_IN_PROJECT) with no ./.venv crawlers::python_crawler::tests::poetry_in_project_true_without_dot_venv_keeps_the_out_of_tree_env ❌ [] ✅

Two existing assertions encoded the #476 behaviour (in-project = true ⇒ nothing probed, and a None virtualenvs root). They now assert Poetry's behaviour instead.

Test evidence (Linux)

  • New tests on main's code: 3 failed (output above). With the fix: cargo test -p socket-patch-core --lib -- crawlers::python_crawler gives 57/57 passed.
  • Real Poetry 2.1.1 (not committed; a throwaway probe of find_local_venv_site_packages):
    • With several Poetry envs for one project (poetry env use on two Python minors), agent mode patches the alphabetically first env instead of the one Poetry activated, and VEX attests not_affected #526 layout: poetry env use python3.11, install, then poetry env use python3.12, install. The probe returns only envmulti-…-py3.12, which is what poetry env info -p prints. It still returns that env with an unrelated VIRTUAL_ENV=/tmp/other, and so does Poetry.
    • Poetry with virtualenvs.in-project = true but no ./.venv keeps using its out-of-tree env, which socket-patch never probes: agent patches the global interpreter and hosted VEX falsely attests #476 layout: a default install, then poetry config --local virtualenvs.in-project true and install again, leaving no ./.venv. The probe returns ipapp-…-py3.11, matching poetry env info -p.
  • cargo clippy --workspace --all-features -- -D warnings: clean.
  • cargo test --workspace --all-features --no-fail-fast: all pass except 12 permission-based write-failure tests. They fail only because this sandbox runs as uid 0 (root ignores read-only bits), they fail the same way on main, and all 12 pass when re-run as uid 65534.
  • rustfmt --check on the changed file: clean. main isn't cargo fmt-clean workspace-wide, so unrelated reflows were left out.

Follow-ups (not in scope)

  • With several envs and no envs.toml entry, Poetry picks the env matching the interpreter it would use (python on PATH or its own, depending on virtualenvs.use-poetry-python). Resolving that would mean running an interpreter, so in that case every env is still returned, as before.
  • vex collapsing to the first copy (collapse_to_first) is tracked for npm in Agent-mode npm vex hashes only the first installed copy of a package, so it attests not_affected while another nested copy of the same name@version is unpatched #516 / Fix agent vex checking only one installed copy (#516) #517.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rh6wkfBxavb2aj1JWKbSxM


Note

Medium Risk
Changes which site-packages paths agent mode patches—a wrong choice previously left the real Poetry env unpatched; the new logic is more complex but targets documented Poetry behavior with regression tests.

Overview
Agent-mode Python crawling now picks the same virtualenv Poetry uses, instead of approximating it.

envs.toml (#526): The crawler reads <virtualenvs.path>/envs.toml for the env poetry env use recorded and probes only that <name>-<hash>-py<minor> tree. When that entry exists, an unrelated VIRTUAL_ENV is ignored; otherwise VIRTUAL_ENV or a non-base CONDA_PREFIX can still win, matching Poetry’s EnvManager.get().

In-project setting (#476): virtualenvs.in-project = true no longer blocks out-of-tree discovery when ./.venv is missing—only an existing ./.venv (and not an explicit in-project = false) counts as the in-project env. virtualenvs.path / envs.toml resolution is unchanged by in-project.

load_poetry_project takes an injected env lookup for tests; regression tests and docs/testing/poetry-compatibility.md agent-mode notes are updated. Anything that already uses find_local_venv_site_packages (hosted stale-install checks, VEX, etc.) inherits the fix.

Reviewed by Cursor Bugbot for commit 0b4a2df. Configure here.


Generated by Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@claude
Start fix for #476, #526
8db315e
Assisted-by: Claude Code:claude-opus-5-5
This was referenced Oct 2, 2026
Poetry with virtualenvs.in-project = true but no ./.venv keeps using its out-of-tree env, which socket-patch never probes: agent patches the global interpreter and hosted VEX falsely attests #476
Closed
With several Poetry envs for one project (poetry env use on two Python minors), agent mode patches the alphabetically first env instead of the one Poetry activated, and VEX attests not_affected #526
Closed
@claude
Patch the Poetry env that Poetry actually uses
0b4a2df
Agent mode, hosted mode's stale-install check and VEX picked the wrong
Poetry virtualenv in two common setups, so the env `poetry run` uses
stayed unpatched while the run reported success and VEX attested
not_affected:

- After `poetry env use 3.12` on a project that also has a 3.11 env,
  the alphabetically first env was patched. An unrelated activated
  VIRTUAL_ENV also won, although Poetry ignores it once envs.toml names
  the project (#526).
- With `virtualenvs.in-project = true` but no ./.venv, the existing
  out-of-tree env Poetry keeps using was never probed (#476).

Venv discovery now follows Poetry's EnvManager.get(): it reads
envs.toml under virtualenvs.path, takes ./.venv only when it exists and
in-project isn't false, and gates VIRTUAL_ENV / CONDA_PREFIX the way
Poetry does.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 2, 2026 03:55
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

cursor[bot] reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cursor[bot]
cursor Bot reviewed Oct 2, 2026
View reviewed changes

@cursor cursor Bot left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

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 0b4a2df. Configure here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

[agent] Ready for review at 0b4a2df.

  • CI: 333/333 non-skipped check runs green, including the real-Poetry e2e_vex_build legs and the Pipenv workflow.
  • Bugbot: no findings on the current head.
  • Mergeable, 0 commits behind main.

Generated by Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko Mikola Lysenko (mikolalysenko) mentioned this pull request Oct 2, 2026
Agent mode patches only the WORKON_HOME venv when a Pipenv project also has an auto-detected ./.venv, so Pipenv 2018–2026.1 keep running the unpatched .venv and VEX attests not_affected (regression from #388) #529
Closed
@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Oct 2, 2026
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

[burn-down agent] Labeled Ready for review at 0b4a2dffb2.

  • CI: 340/340 check runs finished on the head, none failed (success, skipped, or neutral).
  • Bugbot: reviewed 0b4a2dffb2, no new issues. No unresolved review threads.
  • Mergeable against main. Still needs a human approval.

Generated by Claude Code

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Tanmay182003
Tanmay Singla (Tanmay182003) approved these changes Oct 2, 2026
View reviewed changes
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed 0b4a2dffb2654381f11426e23469d84a21cd7772. Recommendation: ready to merge as-is from code review.

No actionable correctness/security regressions found. Checked envs.toml selection, activated virtualenv/conda precedence, in-project fallback, and the shared stale-install/VEX discovery path against Poetry's environment manager.

Validation: cargo test -p socket-patch-core --lib crawlers::python_crawler — 57 passed on macOS. Full workspace/platform matrix not rerun.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko
Mikola Lysenko (mikolalysenko) merged commit 8eec03a into main Oct 2, 2026
340 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-poetry-env-selection branch October 2, 2026 14:28
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Oct 2, 2026
@claude
Merge main into agent/fix-python-manager-project-env
db9160b
Resolve the python_crawler.rs conflict with the Poetry env selection
fix (#527): keep main's poetry_active_prefix for VIRTUAL_ENV and add
the PDM_IGNORE_ACTIVE_VENV gate on top.

Assisted-by: Claude Code:claude-opus-5-5
This was referenced Oct 2, 2026
Fix Python env discovery ignoring uv/PDM env (#502, #525, #528) #540
Merged
Benchmark tracking: socket-patch scan #580
Open
With {data-dir} in Poetry's virtualenvs.path, agent mode also patches an unrelated activated VIRTUAL_ENV / conda env, even though poetry env use pins the project's env, and hosted VEX then refuses a correctly installed patch #866
Closed
Scan of a fresh Poetry checkout (no Poetry env yet, default virtualenvs.create) crawls the system Python: vendored exits 1 on system-only packages and agent mode patches dpkg-owned files (the Poetry side of #947 / #964) #1023
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@Tanmay182003 Tanmay Singla (Tanmay182003) Tanmay182003 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

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

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

With several Poetry envs for one project (poetry env use on two Python minors), agent mode patches the alphabetically first env instead of the one Poetry activated, and VEX attests not_affected Poetry with virtualenvs.in-project = true but no ./.venv keeps using its out-of-tree env, which socket-patch never probes: agent patches the global interpreter and hosted VEX falsely attests

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mikolalysenko @Tanmay182003 @claude
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.