Fix base conda environment incorrectly resolved to a named environment on reload#1412
Merged
eleanorjboyd merged 2 commits intomicrosoft:mainfrom Mar 30, 2026
Merged
Fix base conda environment incorrectly resolved to a named environment on reload#1412eleanorjboyd merged 2 commits intomicrosoft:mainfrom
eleanorjboyd merged 2 commits intomicrosoft:mainfrom
Conversation
eleanorjboyd
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes microsoft/vscode-python#25814
Problem
After selecting the base conda environment and reloading VS Code, a different named conda environment is shown as active instead. The wrong environment is typically whichever named env has the highest Python version.
Root Cause
findEnvironmentByPath()inCondaEnvManageruses a singleArray.find()with three match strategies evaluated in OR: exact path, parent directory, and grandparent directory.Conda environments have this disk layout:
The grandparent of every named environment (
dirname(dirname(/miniconda3/envs/torch))) equals the base environment's own path (/miniconda3). Since the collection is sorted by Python version descending, any named env with a higher version than base appears before base in the array.Array.find()returns the first match — so the named env matches via grandparent before base can match via exact path.This only triggers on reload/restart (not live selection), because
loadEnvMap()reads the stored path from persistent state and callsfindEnvironmentByPath()to resolve it back to an environment object.Fix
Split the single
find()into two passes — exact match first, then parent/grandparent fallback:This ensures base's prefix
/miniconda3always matches itself exactly before any named env can match via grandparent. The parent/grandparent fallback is preserved for cases where a binary path (e.g..../bin/python) needs resolving.Testing
Added 17 unit tests covering: