Skip to content

Add BYOK model bridge for remote Agent Host - #346352

Open
NicolasWeb (NicolasWeb) wants to merge 3 commits into
microsoft:mainfrom
NicolasWeb:feat/ai4dev-remote-agent-host-byok
Open

NicolasWeb (NicolasWeb) wants to merge 3 commits into
microsoft:mainfrom
NicolasWeb:feat/ai4dev-remote-agent-host-byok

Conversation

@NicolasWeb

@NicolasWeb NicolasWeb (NicolasWeb) commented Nov 5, 2026 •

Copy link
Copy Markdown

Fixes #332085

Summary

Adds the BYOK language-model bridge between a window's renderer and an Agent Host that runs in a Remote-WSL server, so a Custom Endpoint / BYOK model configured in the window can be selected and used by the native Agents window when the Agent Host is remote.

Before this change the BYOK handler existed only inside the window's own process: a remote Agent Host saw the capability as absent and the BYOK models never reached the model picker of the Agents window.

Design

  • src/vs/platform/agentHost/common/agentHostByokLmProtocol.ts (new): the private AHP method names, the metadata key and the runtime shape validators for the bridge. It is private protocol, not a public extension API: no contribution point, command or package.json API is added or changed.
  • agentHostExtensionProtocol.ts: one capability flag and the bridge meta/command entries, so an extension host can advertise and negotiate the bridge the same way the existing chat-state and worktree capabilities do.
  • protocolServerHandler.ts: registers the per-connection bridge, relays resolveModel and the chat-request calls to the registered handler, and removes the registration when the connection or the handler goes away. A connection that never advertised the capability, a disconnected handler and an unknown call are all refused instead of queued.
  • byokLmBridgeRegistry.ts / agentHostServerMain.ts: the standalone server keeps its own handler registry; the wiring is a registry lookup, no new state owner.
  • agentHostClientByokLmChannel.ts: the renderer's throttled model-snapshot stream moves out of the channel class into the exported createAgentHostByokLmModelSnapshotEvent(), so the AHP bridge and the in-process reverse channel publish the same snapshot from one implementation; the channel calls it instead of owning it.
  • Tests: the new bridge cases live in test/node/protocolServerHandler.test.ts (dispatch, refusal of an unadvertised or disconnected handler, cleanup), test/electron-browser/agentHostProtocolClient.test.ts (registration gating on the advertised capability, snapshot publish, unregister on disposal) and chat/test/browser/remoteAgentHost/remoteAgentHostChatContribution.test.ts (the handler is registered on every connection).
  • agentService.ts: registerByokLmHandler? on the agent-host client surface.
  • agentHostProtocolClient.ts + remoteAgentHostChatContribution.ts: the renderer side registers the handler over its existing AHP connection, keeps its remembered-credential and entitlement gates exactly where they are (the credential never crosses into the Agent Host process), and handles the model snapshot updates in place, including reconnect and disposal.
  • serviceBootstrapping.md: documents the data flow, the per-connection cleanup and the renderer credential/policy boundary.

How to test?

# node lane (protocol server handler, includes the new bridge cases)
pnpm run test-node --run src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts

# browser lane (renderer contribution, including the new BYOK handler cases)
pnpm run test-browser-no-install -- --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/remoteAgentHostChatContribution.test.ts --browser chromium

# electron-browser lane (renderer protocol client)
./scripts/test.sh --run src/vs/platform/agentHost/test/electron-browser/agentHostProtocolClient.test.ts

The recorded totals are from those runs at head 619d97a: node 564 passing (protocolServerHandler.test.ts, including the BYOK bridge cases), browser 13 passing (remoteAgentHostChatContribution) plus 22 passing (editorRemoteAgentHostServiceClient), electron-browser 432 passing. The electron-browser directory is collected only by test/unit/electron/index.js (the node and browser runners exclude it), which is why that lane is the one that exercises agentHostProtocolClient.test.ts. Manual: in a Remote-WSL window with a BYOK Custom Endpoint provider whose endpoint is reachable from the WSL distro, open the Agents window and select the BYOK model; the model is listed, the request streams (deltas travel over vscode/byokLmDelta), and the Agent Host process holds no credential (checkpoint in serviceBootstrapping.md). The live Remote-WSL session check is still to be run by the feature owner; its result will be posted on this thread.

Does this introduce a change that needs to be updated with docs?

No documentation change beyond src/vs/platform/agentHost/node/serviceBootstrapping.md; the change is internal protocol plumbing and adds no user-facing setting or command.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 19:48

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 break web remote-host initialization, leave native WSL and remote-authority model bridging incomplete, and allow hosts to invoke BYOK handlers without negotiating bridge support.

4 open issues
What changed in this PR

Adds a renderer-to-Agent Host BYOK bridge intended to make window-configured models available to remote Agents sessions, addressing #332085 while keeping provider credentials in the renderer.

Changes:

  • Defines private protocol methods, capability negotiation, and payload validators for model snapshots and chat requests.
  • Adds client registration, server routing, and standalone-server registry wiring, reusing the existing model snapshot implementation.
  • Adds bridge lifecycle tests and documents the credential boundary.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​remoteAgentHost/​remoteAgentHostChatContribution.test.ts Tests handler registration and disposal.
src/​vs/​workbench/​contrib/​chat/​browser/​remoteAgentHost/​remoteAgentHostChatContribution.ts Registers the renderer handler on remote connections.
src/​vs/​platform/​agentHost/​test/​node/​protocolServerHandler.test.ts Tests model publication, chat routing, and cleanup.
src/​vs/​platform/​agentHost/​test/​electron-browser/​agentHostProtocolClient.test.ts Tests capability-gated publication, chat dispatch, and disposal.
src/​vs/​platform/​agentHost/​node/​serviceBootstrapping.md Documents bridge flow and credential ownership.
src/​vs/​platform/​agentHost/​node/​protocolServerHandler.ts Adds connection-scoped registry entries and reverse chat requests.
src/​vs/​platform/​agentHost/​node/​byokLmBridgeRegistry.ts Updates the no-op registry’s documentation only.
src/​vs/​platform/​agentHost/​node/​agentHostServerMain.ts Shares a renderer-backed registry with the standalone server.
src/​vs/​platform/​agentHost/​common/​agentService.ts Adds optional BYOK handler registration to connections.
src/​vs/​platform/​agentHost/​common/​agentHostExtensionProtocol.ts Declares bridge capability and command contracts.
src/​vs/​platform/​agentHost/​common/​agentHostClientByokLmChannel.ts Extracts the reusable model snapshot event.
src/​vs/​platform/​agentHost/​common/​agentHostByokLmProtocol.ts Defines bridge method names and payload validators.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Publishes models and handles reverse chat requests.

Review effort: Balanced

@NicolasWeb

Copy link
Copy Markdown
Author

\

@NicolasWeb

NicolasWeb (NicolasWeb) commented Nov 5, 2026 •

Copy link
Copy Markdown
Author

Follow-up: the three high-impact actions from the review are done.

  1. All four findings are fixed in the pushed commit: (1) the chat-command path is now gated on the agentHostByokLmBridge capability (protocol v14, plus a client test asserting the ungated case answers the error reply), (2) the Sessions handler is now a delayed registerSingleton, (3) the dynamic WebSocket path wires ByokLmBridgeRegistry into both configuration forms, (4) the editor window gained a public registerByokLmHandler(handler): IDisposable on IEditorRemoteAgentHostServiceClient, disposed by the caller through the returned disposable; the Chat-side contribution registers through the service (never the protocol client) only when the Sessions window has not registered the accessor, so neither window double-registers and neither is silent.
  2. Every review thread carries a reply with the exact hunk and the test evidence; the threads are resolved.
  3. Pointer posted in Copilot Harness: BYOK custom-endpoint model not selectable for Remote Scenarios (WSL, Dev Containers, SSH etc) #332085 (this bridge is the BYOK-on-Remote-WSL route discussed there; it changes no existing behavior and carries no new telemetry).

Validation of the follow-up commit: eslint on all changed files PASS (RC=0); transpile build PASS; node lane PASS (519 tests — protocolServerHandler plus the tool suites, covering the F3 listener wiring); electron-browser lane PASS (432 tests, including the extended capability-gate test); browser (chromium) lanes PASS — 13 tests in remoteAgentHostChatContribution, 22 in editorRemoteAgentHostServiceClient including two new BYOK registration tests; full tsc typecheck with zero errors in the changed files (the remaining ones are the clone's missing node_modules/electron, untouched files).

A live Remote-WSL session check against the AI4Dev endpoint is still to be run by the feature owner and is stated in the PR description.

Precision (2026-11-23, measured at head 619d97a8): the lint sentence above predates the upstream eslint.config.js migration. This repository carries no eslint dependency in package.json/pnpm-lock.yaml; its lint lane is the CI Hygiene & oxlint step, which runs the rules of eslint.config.js through oxlint (oxlint.config.ts). On the current head, re-run exactly as CI invokes them: oxlint --changed-since <base> PASS (17 changed files, rc 0) and hygiene --changed-since <base> PASS (18 changed files, rc 0). The earlier eslint RC=0 line is kept verbatim as the historical record of the older config era.

@NicolasWeb

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@NicolasWeb
NicolasWeb (NicolasWeb) force-pushed the feat/ai4dev-remote-agent-host-byok branch from 1090965 to 2cbd5b7 Compare November 6, 2026 20:08
@NicolasWeb

Copy link
Copy Markdown
Author

Vritant Bhardwaj (@vritant24) — could you take a look at #346352, which implements the Remote-WSL BYOK bridge discussed in #332085?

The review findings have been addressed and the branch was rebased. Could you confirm what is currently blocking the PR and whether you’d like any further changes?

The remaining functional validation is a live Remote-WSL test with an AI4Dev BYOK model. I can provide that result once it has been run.

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

Duplicate imports block compilation, an extra test configuration argument breaks type checking and suite setup, and shared client IDs can cause connected transports to lose BYOK model registrations.

3 open issues
4 resolved since last review

Review effort: Balanced

import { createAgentHostByokLmModelSnapshotEvent } from '../common/agentHostClientByokLmChannel.js';
import { byokLmChatRequestValidator, byokLmChatResultValidator, RegisterClientByokLmModelsExtensionMethod, RequestAgentHostByokLmChatExtensionMethod, UnregisterClientByokLmModelsExtensionMethod } from '../common/agentHostByokLmProtocol.js';
import type { IAgentHostByokLmHandler } from '../common/agentHostByokLm.js';
import { ClientProxyChangedExtensionMethod, LookupClientProxyKerberosAuthorizationExtensionMethod, lookupClientProxyKerberosAuthorizationParamsValidator, ResolveClientProxyExtensionMethod, resolveClientProxyParamsValidator, type IAgentHostClientProxyProvider } from '../common/clientProxyProtocol.js';

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed by the rebase onto main (the branch now carries f31439d32be9 as its base). The duplicate clientProxyProtocol.js import is gone — a single import on line 43 carries all these bindings, and the branch compiles clean (compile with 0 errors).

agentService,
stateManager,
server,
protocolServerConfig,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed by the rebase onto main. The handler is now constructed with the single protocolServerConfig argument, which includes the upstream environment and loadEstimator stubs (and the new BYOK test suite came along from main). The suite runs green: 564 passing in the node lane on src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts.

},
onDidChangeModels: modelsEmitter.event,
};
store.add(registry.register(client.clientId, connection));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 619d97a. The registry key is now transport-scoped: _handleByokLmBridgeExtensionRequest mints ${client.clientId}#${++this._byokLmRegistrationSeq} per registration, so a second live transport no longer evicts the first entry or its model listener, and each registration survives until its own disposal. IByokLmBridgeRegistry.register now names the parameter registrationId and documents why two transports may share a client id. Regression test: "BYOK bridge registrations of two transports sharing a clientId survive independently until their own disposal" — closing one transport leaves the peer serving and updatable. The rebase also brought the upstream streaming contract (onDidDelta on IByokLmBridgeConnection / IAgentHostByokLmHandler); the bridge transport now forwards renderer deltas over a vscode/byokLmDelta notification into the registration's delta emitter, keeping the node-minted requestId through validation, with delta-routing assertions on both the client and server test sides.

Routes BYOK language-model calls made by a window renderer to an Agent Host
running in a Remote-WSL server, so a `Custom Endpoint` model configured in the
window is listed and usable in the native Agents window. Before this change the
handler existed only inside the window's own process, so a remote Agent Host saw
the capability as absent and the models never reached the Agents window picker.

The renderer keeps the remembered-credential and entitlement gates where they
are: the credential never crosses into the Agent Host process, which only relays
resolveModel and the chat calls over its existing AHP connection. A connection
that never advertised the capability, a disconnected handler and an unknown call
are refused instead of queued, and each registration is dropped when its
connection goes away.

Related to microsoft#332085
Cover the review findings on the BYOK Language Model bridge:

- Command path: agentHostProtocolClient serves a BYOK chat only when the
  host advertised supportsByokLmBridge, so a host that never opted in gets
  the error reply instead of a served turn; the unsupported-host test now
  asserts that error reply next to the absent chat request.
- Sessions windows: register IAgentHostByokLmHandler in
  remoteAgentHost.contribution.ts, the one contribution every Remote Agent
  Host window loads (Delayed, cost-free where nothing resolves it).
- Web Socket entry point: agentHostMain always creates the
  ByokLmBridgeRegistry and passes it to both the dynamic listener and the
  configured listeners, matching the TCP entry point.
- In-place Remote-WSL renderer: registerByokLmHandler on
  editorRemoteAgentHostServiceClient (delegates when connected, disposable
  no-op with a warning otherwise) plus registration from
  agentHostChatContribution outside Sessions windows, mirroring the MCP
  auto-authenticate precedent, with two boundary tests.

Related to microsoft#332085
Two live transports can share a clientId (e.g. a reconnect whose
previous transport is still draining). Keying the registry by the bare
clientId let the second registration evict the first entry and remove
its model listener. Mint a per-registration id (clientId + sequence) in
_handleByokLmBridgeExtensionRequest so each registration survives until
its own disposal, and document the registry key as a registration id.
Adds a regression test: two transports with the same clientId register,
closing one leaves the other serving and updatable.

Adapt the bridge transport to upstream BYOK streaming: the rebase onto
main surfaced a required onDidDelta on IByokLmBridgeConnection and
IAgentHostByokLmHandler. Forward renderer deltas over a new
vscode/byokLmDelta notification (kind-discriminated validator, sent
only while Connected), route it server-side into the registration's
delta emitter that backs the connection's onDidDelta, and keep the
node-minted requestId by validating it as an optional chat-request
property. Tests assert a delta reaches the bridge connection, an
invalid delta is ignored, and the client forwards and stops forwarding
on disposal.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@NicolasWeb
NicolasWeb (NicolasWeb) force-pushed the feat/ai4dev-remote-agent-host-byok branch from 80fa2a6 to 619d97a Compare November 22, 2026 21:38
@NicolasWeb

Copy link
Copy Markdown
Author

Vritant Bhardwaj (@vritant24) — status refresh since the 2026-11-09 ping; as far as I can tell nothing is waiting on the PR side except review.

Since that ping: the branch was rebased onto current main (single commit 619d97a) and adapted to the upstream streaming contract — IByokLmBridgeConnection / IAgentHostByokLmHandler gained the required onDidDelta; the transport forwards renderer deltas over a new vscode/byokLmDelta notification routed into the registration's delta emitter, keeping the node-minted requestId. That also closed the last open review finding (transport-scoped registry key + regression test). All seven findings from both review passes now carry a reply with the exact hunk and the test evidence.

Re-validated at 619d97a: compile PASS; node lane PASS (564 passing incl. the BYOK bridge and delta cases); client-side suites PASS; oxlint --changed-since and hygiene --changed-since PASS.

Three questions so I can spend effort where you need it:

  1. Is anything blocking triage/labeling on your side, or would a short paired session over a Remote-WSL repro help?
  2. The live Remote-WSL check against a real BYOK endpoint — want it run and posted here before review, or captured in the PR description instead?
  3. If the approach itself needs rework (e.g. bridge vs. hosting the provider inside the Agent Host), better to hear it now than after another rebase.
@psvk1990

Copy link
Copy Markdown

new project

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants