Skip to content

feat: keep Copilot BYOK agent turns alive in server Agent Host - #8047

Open
khanhkit wants to merge 1 commit into
coder:mainfrom
khanhkit:fix/copilot-byok-background
Open

khanhkit wants to merge 1 commit into
coder:mainfrom
khanhkit:fix/copilot-byok-background

Conversation

@khanhkit

@khanhkit khanhkit commented Oct 8, 2026 •

Copy link
Copy Markdown

Fixes #8046

Motivation

code-server is a remote IDE, so long-running agent work should be owned by a server-side lifecycle rather than by a browser tab. For direct-capable Copilot Chat BYOK providers, this change lets the remote Agent Host own model execution so an active turn is not tied to renderer/tab lifetime.

Design

  • Direct-capable BYOK providers are synchronized to Agent Host as bounded, ephemeral descriptors and registered directly with the server-side Copilot SDK.
  • Provider configurations that cannot be represented faithfully stay on the existing renderer bridge rather than being silently normalized.
  • Credential-bearing syncEphemeralByokModels data stays process-memory-only and is centrally redacted before AHP JSONL serialization.
  • Model capability metadata (vision, tool calling, reasoning effort) is preserved.
  • Agent Host Changes-pill defaults follow isolation when there is no provider override: folder -> Session Changes, worktree -> Branch Changes.
  • Native Copilot authentication semantics are not bypassed; this change is for the direct BYOK path.

Files changed

  • patches/copilot-background-byok.diff
  • patches/copilot-agenthost-session-changes.diff
  • patches/series

Current VS Code 1.141 verification

Current PR head: 73f71d62f4b26c04dd50b595a3837231a1b5b6aa

Pinned VS Code gitlink: 2a59476c9bfcb90b3ddc372c36762471b7dfad1c (VS Code 1.141)

Executed on the 1.141 port:

  • full code-server patch series clean apply: 31/31;
  • regenerated feature patches reproduce 22/22 target files byte-for-byte from the validated scratch tree;
  • copilotSessionLauncher.test: 109/109 pass;
  • byokLmBridgeRegistry.test: 11/11 pass;
  • protocolServerHandler.test: 175/175 pass;
  • ahpJsonlLogger.test: 14/14 pass, including the credential-redaction sentinel;
  • browser AgentHostByokLmHandler: 22/22 pass;
  • browser AgentHostSessionInputPills: 22/22 pass, including folder -> Session Changes.

Exact-head isolated ARM64 release verification is now GREEN for 73f71d62f4b26c04dd50b595a3837231a1b5b6aa: full build:vscode completed (including core-ci desktop/server/server-web bundles), code-server build completed, release materialized successfully, and a fresh out-of-container checksum verification passed 5897/5897 files. The built runtime reports 73f71d62f4b26c04dd50b595a3837231a1b5b6aa with Code 1.141.0.

GitHub Actions status

Upstream Build run 37796020383 was created for exact head 73f71d62f4b26c04dd50b595a3837231a1b5b6aa, but GitHub currently reports action_required with zero jobs created. The workflow is waiting for the repository's fork-workflow approval; no CI test has executed or failed yet.

Historical note

The earlier VS Code 1.140 candidate 95c0eb85d4265925751949f729851901e8e9db0d passed its isolated build, fork CI, and live background/detach acceptance. Those results are historical evidence only and are not presented as exact-head verification for this 1.141 port.

Upstream coordination

A code-server maintainer suggested upstreaming this behavior directly to VS Code rather than maintaining the server-ownership change as a code-server patch.

VS Code already tracks the exact remote-BYOK ownership/continuity problem in microsoft/vscode#340335, under the broader BYOK plan in microsoft/vscode#340086. The VS Code direction is Agent Host-owned model-provider plugins rather than a direct port of chatLanguageModels.json. The validated implementation and evidence from this PR have been posted to that issue for reference: microsoft/vscode#340335 (comment).

This PR remains open as the exact tested reference. I am not opening a competing VS Code implementation until the owner confirms which pieces should be adapted to the plugin-provider direction.

@khanhkit
khanhkit requested a review from a team as a code owner October 8, 2026 09:47
@khanhkit
khanhkit force-pushed the fix/copilot-byok-background branch from 95c0eb8 to 73f71d6 Compare October 8, 2026 14:52
@code-asher

Copy link
Copy Markdown
Member

Thank you for the PR! The reasoning makes sense, but this looks like a significant change. Could we propose this change upstream directly rather than try maintaining it as a patch here? I think the VS Code maintainers would find it valuable as well, since presumably Codespaces has the same problems, or anyone running regular VS Code in the web.

@khanhkit

khanhkit commented Oct 8, 2026

Copy link
Copy Markdown
Author

Exact-head VS Code 1.141 verification update:

  • candidate: 73f71d62f4b26c04dd50b595a3837231a1b5b6aa
  • full build:vscode: PASS (core-ci, desktop/server/server-web bundles)
  • code-server build + release: PASS
  • fresh release checksum verification: 5897/5897
  • runtime identity: exact candidate with Code 1.141.0

Upstream Actions run 37796020383 is still action_required with zero jobs, so it is awaiting repository approval for the fork workflow; no upstream CI test has failed.

@khanhkit

khanhkit commented Oct 9, 2026

Copy link
Copy Markdown
Author

Yes — I found an existing VS Code issue that tracks the same problem directly: microsoft/vscode#340335 ("BYOK Support for Copilot Agent Host Harness"). It explicitly calls out both the Extension Host dependency and continuity across remote clients.

I added the validated code-server/web reproduction, the 1.140 live detach result, and the exact VS Code 1.141 test/build evidence there:

microsoft/vscode#340335 (comment)

Their proposed long-term direction is Plugin-provided configurable model providers, which is broader than the direct-descriptor bridge in this PR. I am leaving this PR open as a tested reference rather than opening a competing VS Code PR blindly; I can adapt/split the implementation once the VS Code owner confirms which pieces fit that direction.

@khanhkit

Copy link
Copy Markdown
Author

Upstream coordination update and recommendation after a deeper revalidation of the VS Code/Copilot Agent Host path:

Current upstream status

I followed the upstream direction from microsoft/vscode#340335 rather than opening a competing VS Code PR blindly. The intended long-term architecture is now clear: BYOK should be provided by GitHub Copilot Plugin model providers owned by Agent Host, with provider plugins running outside individual session scope and serving models across sessions/clients.

The blocker is that this architecture is not publicly implementable yet from the VS Code side:

  • microsoft/vscode#340335 remains open; its model-provider-plugin tasks are still unchecked.
  • Current VS Code main revalidated at e3c2316227ee9a4b24449b779409e3ff4d0126a9 still has no modelProviders plugin-manifest contribution.
  • VS Code currently still pins @github/copilot-sdk@1.0.19-preview.0.
  • Public SDK stable 1.0.19, prerelease 1.0.20-preview.2, and current public SDK main still expose provider discovery/configuration through session.providers.*; there is no public global/out-of-session provider catalog/lifecycle API that implements the #340335 design.
  • The newer SDK bump work and managed-plugin lifecycle work I inspected do not add that missing global model-provider contract. They therefore do not provide a safe migration target for this patch yet.
  • The existing renderer BYOK bridge remains client/renderer-owned, which is exactly the continuity problem #340335 is intended to solve for remote clients.

So there is currently no minimal upstream VS Code patch I can submit that both solves the remote lifetime problem and follows the architecture the VS Code owners selected. Porting this PR's direct-provider implementation upstream unchanged would instead pre-empt/duplicate the provider-plugin architecture.

Downstream status

This PR remains the exact tested implementation for code-server:

  • head: 73f71d62f4b26c04dd50b595a3837231a1b5b6aa
  • GitHub currently reports the PR as mergeable.
  • full VS Code 1.141 patch stack: 31/31 clean apply
  • feature target reproduction: 22/22 files byte-identical
  • targeted tests: launcher 109/109, registry 11/11, protocol 175/175, JSONL/redaction 14/14, browser BYOK 22/22, Changes pill 22/22
  • exact-head isolated ARM64 build:vscode / core-ci desktop/server/server-web: PASS
  • code-server build + release: PASS
  • fresh release verification: 5897/5897 checksums, runtime reports exact 73f71d62 / Code 1.141.0

The repository Actions run 37796020383 is still action_required with zero jobs created. This remains a maintainer/admin fork-workflow approval gate, not a test failure; no upstream CI job has executed yet.

Recommendation

Given that the upstream replacement architecture is specified but the required public runtime/plugin contract is not available yet, I recommend merging this PR as a temporary code-server compatibility patch, after the repository's normal maintainer-required CI/approval gate is allowed to execute.

That gives code-server users the server-owned BYOK continuity behavior now instead of leaving the bug open for an indeterminate upstream-runtime dependency. I would keep the downstream patch narrowly scoped and avoid growing it into a parallel provider architecture while #340335 is being implemented.

Retirement commitment

This patch is intended to be temporary, not a permanent code-server fork of Copilot provider architecture.

Once VS Code/Copilot Agent Host ships the #340335-equivalent capability for the environments code-server consumes — specifically an Agent Host-owned, global/out-of-session plugin model-provider lifecycle with the required local/remote configuration path — I will revalidate behavior against code-server's remote/browser-detach acceptance case and remove/simplify the downstream patches in favor of the upstream implementation.

In other words: merge/retain this compatibility layer while the upstream environment is unavailable; retire it once upstream provides equivalent remote BYOK ownership/continuity and that path is verified in code-server.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Copilot Chat BYOK turns should survive browser disconnects via server Agent Host

2 participants