Repository navigation
Add BYOK model bridge for remote Agent Host - #346352
NicolasWeb (NicolasWeb) wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 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
|
\ |
|
Follow-up: the three high-impact actions from the review are done.
Validation of the follow-up commit: eslint on all changed 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 |
|
@microsoft-github-policy-service agree |
1090965 to
2cbd5b7
Compare
|
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. |
There was a problem hiding this comment.
🟡 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'; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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>
80fa2a6 to
619d97a
Compare
|
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 Re-validated at Three questions so I can spend effort where you need it:
|
|
new project |


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 orpackage.jsonAPI 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, relaysresolveModeland 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 exportedcreateAgentHostByokLmModelSnapshotEvent(), 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.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) andchat/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?
The recorded totals are from those runs at head
619d97a: node564passing (protocolServerHandler.test.ts, including the BYOK bridge cases), browser13passing (remoteAgentHostChatContribution) plus22passing (editorRemoteAgentHostServiceClient), electron-browser432passing. Theelectron-browserdirectory is collected only bytest/unit/electron/index.js(the node and browser runners exclude it), which is why that lane is the one that exercisesagentHostProtocolClient.test.ts. Manual: in a Remote-WSL window with a BYOKCustom Endpointprovider 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 overvscode/byokLmDelta), and the Agent Host process holds no credential (checkpoint inserviceBootstrapping.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.