# workspace: Fix toolchain not recovered correctly in remote development \(\#60030\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/febe242c0bf7eab5a283fc26f16d49c2fb9ae607)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: febe242c0bf7eab5a283fc26f16d49c2fb9ae607

Requested commit: febe242c0bf7eab5a283fc26f16d49c2fb9ae607

Commit: febe242c0bf7eab5a283fc26f16d49c2fb9ae607

Tree: 5c43d29db01bd3499aece5cbf32dde2cb474d09b

Author: Xin Zhao

Committer: GitHub

## Message

```
workspace: Fix toolchain not recovered correctly in remote development (#60030)

# Objective

Closes #55925
Closes #59094

When a Python project is opened and a toolchain is selected, Zed
stores/persists this choice in the database. When the project is
reopened later, that saved toolchain should be automatically selected.
However, this recovery mechanism requires the associated worktree to be
loaded first.

In local development, the worktrees are loaded first, after which the
toolchain is restored and activated:

https://github.com/zed-industries/zed/blob/afaef857b987d924c5ec09265a83feb030283f48/crates/workspace/src/workspace.rs#L1916-L1955

But in remote development, the toolchain restoration block runs at the
very beginning of initialization, before any worktrees are loaded:

https://github.com/zed-industries/zed/blob/afaef857b987d924c5ec09265a83feb030283f48/crates/workspace/src/workspace.rs#L10381-L10413

Because the worktree does not exist yet when the toolchain is processed,
`find_worktree` always returns `None`, and the saved toolchain is never
activated. This breaks toolchain persistence for remote workspaces.

## Solution

Move the toolchain activation block in `open_remote_project_inner` so it
runs after the worktrees have been loaded, matching the sequence used in
`new_local`. This ensures the worktree is present in the project when we
perform the ID lookup and activate the toolchain.

## Testing

Tested locally with a Windows client connecting to a remote Linux
server, verifying that the previously selected virtual environment is
correctly restored upon reopening the workspace.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [ ] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed Python virtual environments not automatically restoring when
reopening a remote development workspace.

Co-authored-by: Lukas Wirth <lukas@zed.dev>
```

## Parents

- [b76e4db15df16b79f8ab8383904a92d7ebc60fca](https://git.cafe/gitcafe/zed/commit/b76e4db15df16b79f8ab8383904a92d7ebc60fca?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/febe242c0bf7eab5a283fc26f16d49c2fb9ae607?format=markdown)
