Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

In multi-root workspaces, the first folder's venv selection is unconditionally overwritten by python.defaultInterpreterPath on every extension reload. Subsequent folders are unaffected.

Root Cause

resolveDefaultInterpreter() in /src/helpers.ts (lines 299-303) always calls api.setEnvironment(workspace.workspaceFolders[0].uri, newEnv) when:

  • python.defaultInterpreterPath is set
  • python-envs.defaultEnvManager is NOT set
// Current behavior - no check for existing selection
if (workspace.workspaceFolders?.[0] && findEnvManager) {
    await api.setEnvironment(workspace.workspaceFolders[0].uri, newEnv);
}

The function doesn't check if an environment is already explicitly selected for that workspace folder.

Recommended Fix

Use the existing setEnvironmentsIfUnset pattern already in the codebase:

if (workspace.workspaceFolders?.[0] && findEnvManager) {
    const existingEnv = await api.getEnvironment(workspace.workspaceFolders[0].uri);
    if (!existingEnv || existingEnv.envId.managerId === 'ms-python.python:system') {
        await api.setEnvironment(workspace.workspaceFolders[0].uri, newEnv);
    }
}

Additional Notes

  • The UI/terminal version mismatch (showing 3.14 but running 3.8) is due to the overwrite happening during activation while UI may display cached state
  • Only workspaceFolders[0] is affected - the code doesn't handle multi-root scenarios
  • The defaultInterpreterPath setting is described as "no longer used once an interpreter is selected" but the code doesn't honor this intent
Original prompt

This section details on the original issue you should resolve

<issue_title>Venv for first workspace is overwritten by default</issue_title>
<issue_description>Coming from: #1063 (comment)
Steps to repro:

  1. Set up multi-root workspace with two folders.
  2. Create venv for each of the folders
  3. Notice terminal activates fine, regardless of command, shellStartup,
  4. watch value of default interpreter path after resetting to -> python
  5. reload few times.
  6. 🐛 Value of default interpreter path changed and this switches interpreter selection on the first venv to some default interpreter path.
  7. 🐛 Interpreter selected seems like python3.8 not the 3.14 shown in UI?
    https://github.com/user-attachments/assets/4b165d40-52f7-4eb5-a3e5-1c23436a06e8

Running

anthonykim@Anthonys-MacBook-Pro-2 folder1 %  python3 -c "import sys; print(sys.executable)"
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

Image</issue_description>

<agent_instructions>Investigate how interpreter selection works, comment to explain to maintainer, why there maybe re-written of settings value on reload which is causing this problem. Take your time. </agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix venv for first workspace being overwritten by default Investigation: First workspace folder's venv overwritten by defaultInterpreterPath on reload Feb 2, 2026
Copilot AI requested a review from anthonykim1 February 2, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Venv for first workspace is overwritten by default

2 participants