Skip to content

sessions: Share SSH, WSL and tunnel agent hosts as GitHub environments - #347402

Merged
Christof Marti (chrmarti) merged 6 commits into
mainfrom
chrmarti/remote-github-environment
Nov 12, 2026
Merged

Christof Marti (chrmarti) merged 6 commits into
mainfrom
chrmarti/remote-github-environment

Conversation

@chrmarti

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

Copy link
Copy Markdown
Collaborator

Adds a Share {0} as GitHub Environment row action to SSH, WSL and Dev Tunnel remotes in the Remotes editor. Sharing registers the remote's existing agent host as a GitHub environment with the user's GitHub account, so other apps that support GitHub environments can reach it. Once a remote is shared, the action changes to Stop Sharing {0} as GitHub Environment.

How it works

  • Protocol: two new VS Code-private AHP extension methods, vscode/registerGitHubEnvironment (account id + credential) and vscode/unregisterGitHubEnvironment (account id).
  • Status: supporting hosts report their GitHub environment status under the namespaced _meta key vscode.githubEnvironment in the initialize and reconnect results, and broadcast changes with the vscode/githubEnvironment/changed notification. The status is { instanceId, registration?: { accountId, environmentId, name }, registeredByHost? }:
    • instanceId identifies the agent host process. A registration doesn't survive a restart, so a new id tells clients to register again.
    • registeredByHost means the host registered itself through the CLI --github-environment bootstrap.
    • The host sends the notification before it responds to a register or unregister request.
  • Agent host: a new MissionControlClientRegistration registers the host with the client's credential (projects: []), keeps the registration fresh and reports its status. It serves one owner account per agent host and refuses a host that is already registered through the bootstrap. It is only created for agent hosts launched by the VS Code CLI (SSH, WSL and tunnel servers).
  • Gating on the host: the methods and the status are only served to direct clients of a configured host. Relay clients (relay roots, relay metadata, relay transports) and hosts with extension methods disabled are refused, and the status is not sent to them.
  • Keep-alive: while registered, the server agent host manager keeps an auto-shutdown server alive, so the environment doesn't disappear when the last VS Code window disconnects.
  • Client: the protocol client exposes the status as an observable. IRemoteGitHubEnvironmentSharingService combines it with the user's stored choice per remote:
    • Registered with this account, from another computer: shown as shared; Stop Sharing removes it.
    • Registered by another account or by the host itself: the action is disabled and its label explains why. A stored share is forgotten without unregistering.
    • Registration missing from the same host process: another client stopped sharing, so the stored share is forgotten.
    • Registration missing after a restart (new instanceId): registers again with a fresh credential.
    • Reconnects: a remote registers again with a fresh credential whenever it returns to the connected set, including after a protocol reconnect.
    • Other windows: shares are stored in application storage. Each window follows changes other windows make, writes only the address it changes, and withdraws a background registration that another window stopped sharing meanwhile.
    • When GitHub environments are unavailable (the setting, AI features or availability gate is off), the registration is withdrawn but the choice is kept.
    • When the GitHub account changes or signs out, sharing stops and the registration is withdrawn.
    • A withdrawal that can't reach the remote (disconnected, or the request fails) is retried after the next connection, if the host still reports that registration.
  • Logging: AHP JSONL logs redact the credential of vscode/registerGitHubEnvironment requests.
  • De-duplication: environments shared from a configured remote are hidden from the environment picker, auto-connect, and the Remotes table, so the same machine isn't listed twice.
  • Accessibility: the share state is part of the row's accessible label, and the Remotes help text describes the action, including the disabled state.

Notes for reviewers

  • Needs security review: the client's GitHub credential is sent to the remote agent host over the direct AHP connection. Direct agent hosts already receive the user's GitHub token for Copilot.
  • Earlier builds of this PR advertised the capability as true. Clients now ignore that value and treat the host as unsupported; the protocol is unreleased.
  • A computer that has GitHub environments disabled withdraws the registration. Other computers that shared the same remote then see it as unshared by another client and forget their share.
  • When another window starts sharing, this window may briefly show the remote as unshared until its own connection reports the registration.
  • The host's own bootstrap registration doesn't raise a change event, so a change to it reaches clients with their next connection.
  • Removing a remote outside the Remotes editor doesn't unshare it. Removing it in the Remotes editor unshares first, bounded to 5s.
  • WSL agent hosts use WSL_DISTRO_NAME for the environment name. I haven't verified that this variable reaches the agent host process.

Smoke test

The Agents Window (WSL AgentHost, Kerberos proxy) suite gets a test that opens the Remotes editor, connects the WSL remote if needed, and waits for its Share … as GitHub Environment action. The action appears only if the WSL agent host reports a GitHub environment status, so the test covers the host side, the protocol and the client. Sharing itself needs a GitHub account and isn't exercised.

The test runs only when the WSL agent host is of the client's commit, as in Azure product builds, which run this build's Linux server in WSL. PR CI runs a published server, so the test skips there.

Validation

  • pnpm run oxlint <changed files>: passed
  • pnpm run typecheck-client: passed
  • pnpm run valid-layers-check: passed
  • pnpm run build-fast --client-only: passed
  • test/smoke: pnpm run compile: passed
  • scripts\test.bat --reporter dot --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts --run src/vs/platform/agentHost/test/node/missionControlClientRegistration.test.ts --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/remoteGitHubEnvironmentSharingService.test.ts --run src/vs/workbench/contrib/sessions/providers/remoteAgentHost/test/browser/remotesModel.test.ts --run src/vs/workbench/contrib/sessions/providers/remoteAgentHost/test/browser/remotesWidget.test.ts: passed
  • scripts\test.bat --reporter dot --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts: passed
  • scripts\test.bat --reporter dot --run src/vs/platform/agentHost/test/common/ahpJsonlLogger.test.ts --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/remoteGitHubEnvironmentSharingService.test.ts: passed (after the review fixes)
  • Earlier commits also passed serverAgentHostManager.test.ts, missionControlEnvironmentService.test.ts, missionControlAgentHostContribution.test.ts and remotesEditor.test.ts.
  • Azure product build (Windows x64 and Linux x64, no publishing) at 4a0d1e4: passed. The new smoke test ran in Run WSL Kerberos proxy smoke tests (Electron) and passed (Offers to share a WSL AgentHost as a GitHub Environment).
  • GitHub CI: passed (the smoke test skips in Windows / Electron-Smoke (WSL) as expected).

Sharing and the share status were tested manually against a WSL agent host built from this branch.

Copilot AI balanced review requested due to automatic review settings November 10, 2026 17:38

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

Unresolved issues can expose GitHub tokens in debug logs, leave or restore sharing after disablement, sign-out, or unsharing, and prevent credential refresh after reconnects.

5 open issues
What changed in this PR

Adds GitHub environment sharing for SSH, WSL, and Dev Tunnel agent hosts through the Remotes editor, allowing other supported applications to reach those hosts using the same GitHub account.

Changes:

  • Adds capability-gated registration methods for direct clients and keeps registered remote servers alive.
  • Introduces persistent sharing choices, reconnect synchronization, and duplicate-environment filtering.
  • Adds sharing controls, accessible status descriptions, and focused tests.
File Description
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​test/​browser/​remotesWidget.test.ts Extends the widget test model with sharing operations.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​test/​browser/​remotesWidget.fixture.ts Adds sharing support to the component fixture.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​test/​browser/​remotesModel.test.ts Tests sharing gates, deduplication, and removal ordering.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​browser/​remotesWidget.ts Handles sharing actions and accessible row state.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​browser/​remotesTable.ts Renders sharing controls, indicators, and tooltips.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​browser/​remotesModel.ts Integrates sharing state and withdrawal before removal.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​browser/​missionControlAgentHostContribution.ts Excludes shared remotes from duplicate picker entries and auto-connect.
src/​vs/​workbench/​contrib/​sessions/​providers/​remoteAgentHost/​browser/​media/​remotesWidget.css Styles sharing indicators and their hidden state.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​remoteAgentHost/​remoteGitHubEnvironmentSharingService.test.ts Tests registration, gating, account changes, and deferred withdrawal.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​remoteGitHubEnvironmentSharingService.ts Implements persistent remote sharing and synchronization.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​remoteAgentHost.contribution.ts Registers the remote sharing service.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​missionControlSharingService.ts Reuses the extracted authentication helper.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​gitHubEnvironmentAccount.ts Centralizes GitHub account and session selection.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​test/​electron-browser/​remotesEditor.test.ts Updates the editor test model for sharing.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​test/​browser/​missionControlAgentHostContribution.test.ts Tests shared-remote picker and auto-connect exclusions.
src/​vs/​sessions/​contrib/​providers/​remoteAgentHost/​electron-browser/​remotes.contribution.ts Documents sharing in accessibility help.
src/​vs/​server/​test/​node/​serverAgentHostManager.test.ts Tests registration-based server lifetime retention.
src/​vs/​server/​node/​serverAgentHostManager.ts Keeps the server alive while client sharing is registered.
src/​vs/​platform/​agentHost/​test/​node/​protocolServerHandler.test.ts Tests direct-client registration and relay restrictions.
src/​vs/​platform/​agentHost/​test/​node/​missionControlClientRegistration.test.ts Tests ownership, credential refresh, and failure cleanup.
src/​vs/​platform/​agentHost/​node/​protocolServerHandler.ts Advertises and handles gated registration methods.
src/​vs/​platform/​agentHost/​node/​missionControl/​missionControlClientRegistration.ts Manages host registration for one client account.
src/​vs/​platform/​agentHost/​node/​agentHostMain.ts Wires registration into CLI-launched hosts and lifetime notifications.
src/​vs/​platform/​agentHost/​common/​missionControlEnvironment.ts Defines the remote sharing service contract.
src/​vs/​platform/​agentHost/​common/​meta/​agentHostGitHubEnvironmentMeta.ts Defines and reads the sharing capability.
src/​vs/​platform/​agentHost/​common/​agentService.ts Adds registration methods and lifetime events to interfaces.
src/​vs/​platform/​agentHost/​common/​agentHostExtensionProtocol.ts Defines registration requests, validators, and results.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Sends capability-checked registration and withdrawal requests.

Review effort: Balanced

Adds a Share as GitHub Environment action to the Remotes table. A directly
connected client registers the remote agent host with its own GitHub account
through a VS Code-private AHP extension method, so other apps that support
GitHub environments can reach that agent host.

Co-authored-by: Copilot <[email protected]>
The share action kept a fixed label and only set checked, which the Remotes toolbar does not render. Swap the label like Connect/Disconnect instead.

Co-authored-by: Copilot <[email protected]>
The agent host now reports its GitHub environment registration in the initialize and reconnect metadata and broadcasts changes to its direct clients. The Remotes editor derives Share/Stop Sharing from that status, so the state stays correct across windows, machines, host restarts and GitHub accounts, and shows a disabled state when another account or the host itself registered the remote.

Co-authored-by: Copilot <[email protected]>
Runs when the WSL AgentHost is of the client's build, as in Azure product builds, and checks that the Remotes editor offers to share it as a GitHub Environment.

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

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.

Redact registration credentials in AHP logs, follow sharing changes from other windows, withdraw shares when the account signs out, re-register after protocol reconnects, and retry stopping shares from other computers after the next connection.

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

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.

A window whose GitHub environments are disabled no longer marks a share another window added as synchronized, so it withdraws the registration while keeping the stored choice.

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

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.

🔵 Needs a closer look

Human assessment is needed because a stalled operation can block unrelated remotes’ sharing withdrawals, allowing disconnection before withdrawal and leaving an environment shared.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@chrmarti
Christof Marti (chrmarti) marked this pull request as ready for review November 12, 2026 12:14
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