Skip to content

sessions: Open remote editor folders on their remote agent hosts - #345832

Merged
Christof Marti (chrmarti) merged 7 commits into
mainfrom
chrmarti/agents-window-remote-handoff
Nov 5, 2026
Merged

Christof Marti (chrmarti) merged 7 commits into
mainfrom
chrmarti/agents-window-remote-handoff

Conversation

@chrmarti

@chrmarti Christof Marti (chrmarti) commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes microsoft/vscode-internalbacklog#10484

What changed

"Open in Agents Window" from an SSH, WSL or Tunnel editor window opened the Agents Window without the folder. Only local folders and local Dev Containers were handed off, so the composer fell back to an unrelated local folder, and telemetry recorded unsupportedWorkspace.

  • Same folder, same host. The window-opening handoff resolves vscode-remote folders through a new provider-neutral IRemoteWorkspaceHandoffService (sessions/common), implemented by the remote agent host contribution. It matches the registered SSH, WSL or Tunnel host, or registers it the way Remotes management does. It then preselects the folder in that host's vscode-agent-host URI space, reveals the host, and starts a user-initiated connection.

  • Dev Containers on SSH and Tunnel hosts, and in WSL (identified by a \\wsl.localhost\… source path), resolve to the source folder on that host with the Dev Container preferred. This is the inverse of the existing Open in Editor mapping.

  • No silent fallback. Remotes that can't be used start with no workspace and a notification explaining why, with a Choose Workspace action. This covers Codespaces, attached containers, WSL on another machine, and failed host lookups.

  • Inferred defaults ("Open Agents Window", folderUriIsDefault) only replace an automatic default. They never add or connect a host while a created session is visible. selectNoWorkspace now returns a WorkspaceSelectionResult and honors isDefault, like selectWorkspace.

  • A restored Chat choice no longer cancels the handoff. When the composer started, restoring a saved "no workspace" choice reported a user selection and a navigation. That cancelled a pending handoff before its remote folder resolved, so the Agents Window silently kept the previous choice. It now restores like the automatic fallback next to it.

  • Signing in to find a tunnel. When no signed-in account lists the tunnel and an account needs to sign in first, a dialog explains which account is needed and why. If the user selects Sign In, the handoff signs in with that account and looks again. Declining the dialog or cancelling the sign-in explains that signing in is needed. A tunnel the Agents Window already knows gets the same check before the handoff connects it; previously a signed-out account made that connection fail with "No cached authentication available to connect the tunnel." An account without tunnel configuration (Code OSS has no Microsoft tunnel scopes) no longer hides the sign-in behind "No authentication is available to enumerate tunnels."

  • SSH user and port. Like Remote - SSH, an SSH authority without a config alias uses the user and port of SSH config where it omits them. The handoff matches and stores hosts by those effective values, so an omitted user doesn't match another account's host. A stored host without a port is compared on SSH config's port, the one it connects on.

  • Cancelled handoffs change nothing. Once a handoff is cancelled, for example by picking another workspace, it stops before storing a host, caching a distribution or tunnel, clearing a tunnel dismissal or offering a sign-in.

  • Starting without a workspace counts as applied only once Chat has opened. Until a quick-chat target is available, the handoff keeps trying.

  • Telemetry. agents/firstTimeWindowOpen and agents/workspaceSelectionOutcome gain a bounded workspaceArgumentRemoteKind: none, ssh, wsl, tunnel, codespaces, attachedContainer or other. For Dev Containers it is the host of the source folder. It never contains an authority.

  • Authority formats are checked against the Remote - SSH, WSL, Tunnels and Dev Containers extension sources:

    • Remote - SSH hex JSON and plain [user@]host[:port]
    • wsl+default and wsl+<distro>@<host>
    • tunnel+<name> and tunnel+<id>.<cluster>, looked up with both the GitHub and Microsoft accounts
    • the \\wsl\, \\wsl$\ and \\wsl.localhost\ prefixes

    sshAuthorityString (Open in Editor) now mirrors Remote - SSH's HostInfo.toAuthorityString, so an SSH config alias with uppercase letters is encoded the same way Remote - SSH encodes it.

The remote agent host provider spec gains a paragraph on this registration path.

Reviewer notes

  • A chat draft handed off to a remote that is slow to connect still hits the existing 15-second handoff timeout and its Retry notification.
  • Remote - SSH ignores an encoded port for a configured alias; the Agents Window keeps it. This only affects alias:port typed by hand.
  • Codespaces are not supported yet; they get a dedicated notification.
  • A restored Chat choice still wins over an inferred default (_getWorkspaceDefaultBlocker). Because the restore no longer cancels the handoff, an inferred default from a remote editor window now finishes resolving and connects that host even when the Chat choice stays. Without a saved Chat choice, that already happened.
  • The tunnel sign-in happens for inferred defaults too, because resolving the folder needs it. The browser tunnel service has no signIn, so on the web the handoff still only explains that signing in is needed.
  • SSH hosts added manually in Remotes management without a port are still keyed as port 22, although they connect on SSH config's port. That keying predates this PR.

How to test

  1. From an SSH, WSL or Tunnel editor window, run Open in Agents Window. The same folder is preselected on the matching remote agent host, which is added if needed and connected.
  2. From a Codespaces window, or with code --agents --folder-uri vscode-remote://codespaces+demo/workspaces/project, the composer starts in Chat with no workspace and shows "The Agents Window cannot open folders from GitHub Codespaces yet."
  3. code --agents --folder-uri vscode-remote://wsl+NoSuchDistro/home/me/project starts with no workspace and explains that the WSL distribution was not found.
  4. In the Agents Window, select Chat (no workspace) and close the window. Then run Open in Agents Window from a remote editor window again: its folder replaces the restored Chat choice.
  5. From a Tunnel editor window, with the Agents Window not signed in to tunnels, run Open in Agents Window. A dialog explains that signing in with GitHub is needed to find the tunnel. After Sign In and the GitHub sign-in, the folder is preselected on the tunnel. If you select Cancel in the dialog, or cancel the sign-in, the notification says "Sign in to find tunnel ''." The same dialog appears for a tunnel the Agents Window already knows, if its account is signed out.

Validation

After rebasing onto main at 8b007fabde2. The rebase adapted the inferred-default check to the focused session host, which replaced ISessionsService.activeSession in #346171:

  • pnpm run typecheck-client: passed.
  • pnpm run eslint <changed files>: passed.
  • node --experimental-strip-types build/hygiene.ts <changed files>: passed.
  • .\scripts\test.bat --run <the 9 test files this PR changes, including electron-browser>: 422 passing.
  • pnpm run test-browser-no-install --run <the 8 browser test files of those> --browser chromium: 408 passing.
  • pnpm run valid-layers-check: passed before the rebase; not rerun.

Manually checked in a dev build of the Agents window, before the rebase:

  • The Codespaces and unavailable WSL notifications.
  • With temporary logging, since removed: from a Tunnel editor window, the restored Chat choice cancelled the handoff as userChanged about 1.6 s after the window opened. The tunnel lookup that kept running found GitHub needing a sign-in and Microsoft unconfigured.
  • From a Tunnel editor window, before the confirmation dialog was added: the handoff started a GitHub sign-in, then preselected the folder on the tunnel.
  • With the dialog, for a tunnel the Agents Window already knew while signed out of GitHub: the dialog appeared, and after signing in the folder was preselected and the tunnel connected.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 15:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical issues can route handoffs to the wrong SSH account or endpoint, allow cancelled requests to mutate state, and falsely report success when workspace-less session creation fails.

4 open issues
What changed in this PR

This PR carries remote editor folders into the Agents Window on the matching remote agent host, rather than falling back to an unrelated local workspace.

Changes:

  • Adds SSH, WSL, Tunnel, and remote Dev Container folder resolution, host registration, and connection.
  • Adds explicit no-workspace handling for unavailable remotes while preserving existing sessions and user choices.
  • Extends remote-kind telemetry, SSH authority encoding, tests, and provider documentation.
File Description
src/​vs/​sessions/​test/​browser/​resolveRemoteAuthority.test.ts Tests SSH authority encoding compatibility.
src/​vs/​sessions/​sessions.desktop.main.ts Registers the desktop handoff implementation.
src/​vs/​sessions/​contrib/​sessions/​test/​browser/​sessionsWorkspaceSelectionTelemetry.test.ts Updates selection telemetry expectations.
src/​vs/​sessions/​contrib/​sessions/​test/​browser/​sessionsWindowOpenTelemetry.test.ts Tests remote-kind opening telemetry.
src/​vs/​sessions/​contrib/​sessions/​test/​browser/​sessionsActions.test.ts Updates the no-workspace test stub.
src/​vs/​sessions/​contrib/​sessions/​browser/​sessionsWorkspaceSelectionTelemetry.ts Records remote kind in selection outcomes.
src/​vs/​sessions/​contrib/​sessions/​browser/​sessionsWindowOpenTelemetry.ts Records remote kind in opening events.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​test/​browser/​remoteWorkspaceHandoffService.test.ts Tests parsing, host registration, and connection.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​REMOTE_AGENT_HOST_SESSIONS_PROVIDER.md Documents remote handoff registration.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​browser/​remoteWorkspaceHandoffService.ts Resolves folders and registers matching hosts.
src/​vs/​sessions/​contrib/​chat/​test/​electron-browser/​agentsWindowWorkspaceHandoff.test.ts Tests desktop remote-intent forwarding.
src/​vs/​sessions/​contrib/​chat/​test/​browser/​newChatWidget.test.ts Tests inferred no-workspace defaults.
src/​vs/​sessions/​contrib/​chat/​test/​browser/​agentsWindowWorkspaceHandoff.test.ts Tests remote selection and unavailable-host handling.
src/​vs/​sessions/​contrib/​chat/​test/​browser/​agentsWindowOpenIntent.test.ts Tests remote classification and folder mapping.
src/​vs/​sessions/​contrib/​chat/​electron-browser/​chat.contribution.ts Forwards remote intent and telemetry context.
src/​vs/​sessions/​contrib/​chat/​browser/​newChatWidget.ts Adds acknowledged no-workspace selection.
src/​vs/​sessions/​contrib/​chat/​browser/​chatView.ts Returns widget selection outcomes.
src/​vs/​sessions/​contrib/​chat/​browser/​agentsWindowWorkspaceHandoff.ts Coordinates remote resolution and fallback notifications.
src/​vs/​sessions/​contrib/​chat/​browser/​agentsWindowOpenIntent.ts Parses remote and Dev Container source folders.
src/​vs/​sessions/​common/​workspaceSelection.ts Defines bounded remote-kind telemetry values.
src/​vs/​sessions/​common/​remoteWorkspaceHandoff.ts Defines the provider-neutral handoff contract.
src/​vs/​sessions/​browser/​parts/​sessionView.ts Propagates no-workspace selection results.
src/​vs/​sessions/​browser/​parts/​chatView.ts Extends the no-workspace selection contract.
src/​vs/​sessions/​browser/​parts/​chatGroupView.ts Propagates results through individual groups.
src/​vs/​sessions/​browser/​parts/​chatGroupsView.ts Propagates results through the active group.
src/​vs/​sessions/​browser/​openInVSCodeUtils.ts Aligns SSH authority encoding with Remote - SSH.

Review effort: Balanced

Opening the Agents Window from an SSH, WSL or Tunnel editor window lost the folder: only local folders and local Dev Containers were handed off, so the composer fell back to an unrelated local folder. The window opening handoff now resolves the remote folder through a provider-neutral IRemoteWorkspaceHandoffService, which matches or adds the remote agent host on the same machine, preselects the folder and connects the host. Dev Containers on SSH, Tunnel and WSL hosts resolve to their source folder on that host. Remotes that cannot be used start without a workspace and explain why instead of falling back to a local folder.

Authority parsing and the SSH authority encoding of Open in Editor now mirror the Remote - SSH, WSL, Tunnels and Dev Containers extensions. Telemetry gains a bounded workspaceArgumentRemoteKind.

Fixes microsoft/vscode-internalbacklog#10484

Co-authored-by: Copilot <[email protected]>
…andoffs

Restoring a saved 'no workspace' choice when the composer starts reported a user selection and a navigation. That cancelled a pending handoff from an editor window before its remote folder resolved, so the Agents Window silently kept the previous choice. Restore it without either, like the automatic fallback next to it.

Co-authored-by: Copilot <[email protected]>
When no signed-in account lists the tunnel and an account needs to sign in first, sign in with that account and look again. Cancelling the sign-in explains that signing in is needed. An account without tunnel configuration failing to list no longer hides the sign-in behind 'No authentication is available to enumerate tunnels.'

Co-authored-by: Copilot <[email protected]>
Opening the folder of a Tunnel editor window started a sign-in without explanation. Ask first, naming the account and why it is needed. Declining explains that signing in is needed, like cancelling the sign-in.

Co-authored-by: Copilot <[email protected]>
Like Remote - SSH, an SSH authority without a user or port connects with the user and port of SSH config. Match and store hosts by those effective values, so an omitted user no longer matches another account's host and an omitted port no longer stands for port 22. An entry without a port connects on SSH config's port, so it matches by that port.

A cancelled handoff no longer stores a host, caches a distribution or tunnel, clears a tunnel dismissal or asks to sign in. Every lookup now fails once the handoff is cancelled, even if the lookup already completed.

Co-authored-by: Copilot <[email protected]>
Starting without a workspace for a window-open handoff reported success as soon as the picker showed no workspace, even when no quick chat could be opened yet and the previous draft stayed the session. Report it as not ready instead, so the handoff keeps trying until a quick-chat target is available.

Co-authored-by: Copilot <[email protected]>
A tunnel the Agents Window already knew skipped the sign-in check, so a signed-out account made the connection fail with 'No cached authentication available to connect the tunnel.' Before connecting a known tunnel, check that its account can authenticate, and otherwise explain and offer the sign-in, as for a tunnel that still has to be found. Declining explains that signing in is needed to connect.

Co-authored-by: Copilot <[email protected]>
@chrmarti
Christof Marti (chrmarti) force-pushed the chrmarti/agents-window-remote-handoff branch from 9303ebb to 1886939 Compare November 5, 2026 10:30
@chrmarti
Christof Marti (chrmarti) marked this pull request as ready for review November 5, 2026 11:12
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.

3 participants