Skip to content

fix(desktop): remote server switching#17214

Merged
Brendonovich merged 11 commits intoanomalyco:devfrom
OpeOginni:fix/desktop-server-switch
Mar 19, 2026
Merged

fix(desktop): remote server switching#17214
Brendonovich merged 11 commits intoanomalyco:devfrom
OpeOginni:fix/desktop-server-switch

Conversation

@OpeOginni
Copy link
Copy Markdown
Contributor

@OpeOginni OpeOginni commented Mar 12, 2026

Issue for this PR

Closes #17211

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The issue
When switching servers, the provider tree is not properly rebuilt. GlobalSDKProvider and GlobalSyncProvider capture server.current at mount time and build SDK clients, SSE streams, event queues, and child stores around that snapshot. Without a remount boundary, switching servers left the entire subtree pointing at the old server — stale SDK clients, stale SSE connections, stale project data, and stale directory routes causing problems with displaying recent projects and properly spawning terminals.

Fix
This PR wraps the server-bound subtree in a Remount component keyed on server.key. This uses <For each={[key]}>. I tried making use of <Show when{server.key} keyed> (was also used previously before this commit b76ead3#diff-dc4486239f5091faca2b1d9b42efc48d0e5323b5388e53403f37f446a1d63fc8) but it still would not allow for proper remounting of the needed components, so I had situations like the sidebar still showing stale projects and it triggers TypeError: null is not an object (evaluating 'node.owned[i]') error.

This is a small fix I could get working, I believe the best solution for the future would be to make GlobalSDKProvider and GlobalSyncProvider internally reactive to server changes rather than relying on a full subtree remount. Since that will be a large rewrite I decided to make a simpler PR that works even if not as effective.

How did you verify your code works?

Tested on my local machine switching around 2 remote servers while having my terminal open with everything working as it should. Check video below.

Screenshots / recordings

Screen.Recording.2026-03-12.at.17.59.42.mov

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Fix/desktop server switch doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@OpeOginni OpeOginni changed the title Fix/desktop server switch fix(desktop): remote server switching Mar 12, 2026
@Brendonovich Brendonovich enabled auto-merge (squash) March 13, 2026 01:00
auto-merge was automatically disabled March 15, 2026 10:12

Head branch was pushed to by a user without write access

@OpeOginni
Copy link
Copy Markdown
Contributor Author

OpeOginni commented Mar 15, 2026

@Brendonovich I just tried to merge with dev, this issue still happens when using the <Show> Component, when I try to switch from local (sidecar-cli) to a remote majority of the times it gets stuck, with only the titl bar actually showing we are in another server, but the rest of the app remains the same.

Screen.Recording.2026-03-15.at.11.21.10.mov

In the video the whole page doesnt reload to switch to a new server. That was the reason I opted to use the <For> component with just that current server in the array, I am not sure why that ensures better remounting than using . I could try do some more looking today since the solution that worked is not really the best, and there must be a nicer way to go about it

@OpeOginni
Copy link
Copy Markdown
Contributor Author

I have singled out the issue to be related to running PTY instances, when you have none running, server switches happen as it should, but once you open one it breaks, so trying to get some fixes for that, went with adding server scoped terminal caches, even if its a good addition it doesnt solve the issue, so I made it into another PR, while I work on this one to solve the main issue.

@OpeOginni
Copy link
Copy Markdown
Contributor Author

OpeOginni commented Mar 15, 2026

Made a new commit that fixes the issue, makes switching of servers even with the terminal open simple.
The changes are here;

  1. When we switch servers the change allows for navigating home before the server is changed, this removes any issue of using the directory or state of the old server that still remains to make fetches to the new server which will most of the time break if the new server doesnt have the same dir or terminal pty id

  2. In the codebase currently mounted terminal instances outlive the currently active workspace/server. So this is why when you have a teminal open and switch servers everything breaks, so my solution was to bind mounted terminal callbacks to their owning workspace session so reconnect, cleanup, and clone flows update the original terminal store (from previous server) instead of whatever workspace becomes active after a server switch.

Result

Screen.Recording.2026-03-15.at.14.26.21.mov

This PR goes well with this one allowing for proper revival of pty with stale ID

@Brendonovich Brendonovich enabled auto-merge (squash) March 19, 2026 13:23
@Brendonovich Brendonovich disabled auto-merge March 19, 2026 13:23
@Brendonovich Brendonovich enabled auto-merge (squash) March 19, 2026 13:23
@Brendonovich Brendonovich merged commit bd4527b into anomalyco:dev Mar 19, 2026
8 checks passed
AvatarGanymede pushed a commit to AvatarGanymede/opencode-dev that referenced this pull request Mar 19, 2026
filipeandre pushed a commit to filipeandre/opencode that referenced this pull request Mar 19, 2026
raf1hh pushed a commit to raf1hh/opencode that referenced this pull request Mar 20, 2026
demostanis pushed a commit to demostanis/opencode that referenced this pull request Mar 20, 2026
burn2delete pushed a commit to burn2delete/symbolic that referenced this pull request Mar 24, 2026
Co-authored-by: Brendan Allan <[email protected]>
(cherry picked from commit bd4527b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switching to a remote server breaks desktop app, especially when the terminal is open

2 participants