Skip to content

Selected toolchain persistence does not work (python virtual environment) #42268

@olejorgenb

Description

@olejorgenb

Summary

Zed do not remember previously selected python virtual environment across program restarts.

Description

Steps to reproduce:

  1. Open a python project
  2. Select a virtual environment other than the auto-detected one
  3. Restart Zed

Expected Behavior:

The previously selected environment is remembered. It seems clear to me that the PR introducing this intended it to be remembered. The selected environment is also written to the ~/.local/share/zed/db/0-global/db.sqlite DB.

Actual Behavior:

The virtual environment is just set back to the auto-detected environment on startup. If you set it again, the database accumulate entries for the workspace:

Image

As far as I can see this is due to worktree_id not being an stable id, yet it is used as one:

PRIMARY KEY (workspace_id, worktree_id, language_name, relative_worktree_path)) STRICT;
|
.set_toolchain(workspace_id, worktree_id, relative_path, toolchain.clone())

I'm not sure I've traced the code correct, but I think worktree_id originates from here which originates from here and ultimately here:

let id = self.ref_counts.write().counts.insert(1.into());
(?)

AFAIC there's nothing which makes this a stable identifier?

The whole thing is a bit perplexing to me though since it seems strange that this was not tested, and there's even been follow-up PRs on the feature related to persistence: #36035

This user claim it works. Though this other user says it's still an issue.

This comment indicates something is off.

I see that there's also a concept of a "remote worktree". Perhaps that id is stable?

(This issue is possibly/likely the same as this closed issue #21470)

I was planning to suggest a full fix, but I've since changed from conda to uv, and now the auto-detected venv is correct, so my motivation has wilted.

Zed Version and System Specs

Zed: v0.211.6 (Zed)
OS: Linux Wayland fedora 41
Memory: 62 GiB
Architecture: x86_64
GPU: AMD Radeon Graphics (RADV RAPHAEL_MENDOCINO) || radv || Mesa 25.0.7

Metadata

Metadata

Labels

area:integrations/terminalFeedback for terminal integration, shell commands, etcarea:languages/pythonPython programming language supportfrequency:uncommonBugs that happen for a small subset of users, special configurations, rare circumstances, etcpriority:P2Average run-of-the-mill bugsstate:reproducibleVerified steps to reproduce included and someone on the team managed to reproduce

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions