Repository navigation
Automatic environment picks are saved like explicit ones; new .venv ignored #1894
Description
Problem: When the extension picks an environment automatically, it saves the pick in the same per-workspace state as a user's explicit choice, and later discovery never revisits it. In a project whose only venv was tools/.venv, creating the project's own .venv (for example python -m venv .venv in a terminal) leaves tools/.venv selected, even after a reload. A fresh profile on the same folder picks .venv. The log reports the old pick as source: autoDiscovery.
Environment: Windows 11, VS Code 1.140.0, Python Environments main @ 52f6ace.
| Run | Folder contents | Selected |
|---|---|---|
| First open | tools/.venv (3.13.15) |
tools/.venv (3.13.15) |
After python -m venv .venv (3.14.8), wait 30 s |
both | tools/.venv (3.13.15) |
| Reopen with the same profile | both | tools/.venv (3.13.15), log: .venv (3.13.15) (source: autoDiscovery) |
| Fresh profile | both | .venv (3.14.8) |
Before: .venv is created from outside VS Code, and the selection stays on tools/.venv:
The same folder in the same profile after reopening (left), and in a fresh profile (right). The tooltips show the selected interpreter:
| Reopen, same profile | Fresh profile |
|---|---|
![]() |
![]() |
Cause:
applyInitialEnvironmentSelectionstores the auto-discovered environment withsetEnvironment(folder.uri, env, false), meant as "cache only".setEnvironmentCorestill callsmanager.set(scope, environment).VenvManager.setthen persists it withsetVenvForWorkspace, the same slot an explicit pick uses.SysPythonManagerdoes the same (sysPythonManager.ts:207).- On the next refresh and startup,
loadEnvMapand the fast path read the saved path first, so it wins over discovery.
Impact:
- A new
.venvis ignored in any project that already has another venv under it (for example one found through the default*/.venvsearch path). - Improvements to automatic selection, such as fix: prefer a project's own .venv over nested venvs (Fixes #1878) #1880, don't reach workspaces that already saved an automatic pick.
Suggested fix: Record whether a saved selection was chosen by the user. Keep using an automatic one for the fast startup path, but run automatic selection again after discovery and replace the saved pick if the result differs. Explicit choices stay as they are.
Steps to verify fix:
- Create a folder with only
tools/.venvand amain.py, open it, and verifytools/.venvis selected. - Run
python -m venv .venvin the folder from a terminal. - Verify the status bar switches to
.venvwithin a few seconds. - Reload the window; verify
.venvstays selected. - Explicitly select
tools/.venvwith Python: Set Project Environment and reload; verify the explicit choice is kept.
Found by Copilot



Activity
Copilot commentedon Oct 13, 2026
The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: E34A:2430C9:36C52B:4848C9:6ACE4BF8)