Repository navigation
agentHost: record the default chat role instead of reading the default chat URI shape - #341293
Merged
Sandeep Somavarapu (sandy081) merged 16 commits intoOct 13, 2026
Merged
Conversation
…t URI shape Block 2a m1 (host core). The host now decides whether a chat is a session's primary chat, and finds a session's primary chat, from what is recorded rather than from the `ahp-chat://default/...` URI shape: - AgentHostStateManager/ownership service: `getPrimaryChat(session)` and `isPrimaryChat(session, chat)` read the recorded primary (live entry, eviction record, announced summary). Unknown sessions have none; the minting fallback of `getDefaultChatUri` is removed. - `restoreSession` requires the recorded primary (`summary.defaultChat`) and hands it to the storage callback; `createSession` keeps minting for new sessions. `creationTimeChatStorageResource` takes the primary chat. - `deriveLegacyPrimaryChat` is the single legacy derivation, used only for legacy sources that record no primary (restore, catalog import and reconciliation, surfaced title reads/writes, legacy subagent sessions, the registered default-chat index) after every recorded source. - The default-chat index skips sessions whose normalized catalog records a primary that is not one of their derived aliases (registrations now carry the normalized catalogs' recorded primaries). - agentService, agentSideEffects, protocolServerHandler and automation use the recorded primary for teardown order, storage, archive rules, workspace changes, title snapshots and run completion. Co-authored-by: Copilot <[email protected]>
…d primary chat Block 2a m2. Host services decide the primary-chat role from what is recorded instead of the default URI shape: - Changeset service/coordinator/operations/scope, git state, review, PR status, title controller, completion providers, utility model, agent merge, artifacts, server tools, prompt service and session-open telemetry use `isPrimaryChat`/`getPrimaryChat` (or the shared `isRegisteredPrimaryChat` for a chat whose owner is recorded). - Hook payloads carry the role where the chat may not be registered yet: `IHydrationContext.isPrimaryChat`. Local chat commands get `isPrimaryChat` on their context; server tools resolve a link without a chat id to the listed or recorded primary chat. - `buildDefaultChangesetCatalog` takes the owner's role explicitly. - Teardown uses values captured at registration: workspace conversion records each session's primary chat when it registers, and title state is cleared for the chats the caller lists (rollback passes the primary). - Providers decide session-backed (primary) chats from the host-supplied chat context (storage under the session) or their recorded chat scopes. Provider-native sessions discovered or migrated outside Agent Host, and the legacy per-session peer catalog, use `deriveLegacyPrimaryChat`. Co-authored-by: Copilot <[email protected]>
Clients route an unselected chat to the host's advertised `defaultChat` (`SessionState.defaultChat` / `SessionSummary.defaultChat`) instead of the default-shaped chat URI. `getAdvertisedDefaultChat` is the single place a client falls back to that shape, and only for identified VS Code hosts that predate advertising `defaultChat`; any other host without one has no default chat. `getSessionChatResource` and `resolveChatChangesetCatalogue` take the default explicitly. Co-authored-by: Copilot <[email protected]>
`_resumeSession` requires the addressed chat and passes it as the session's identity, so `_createAgentSession` always receives the host's chat and no longer derives a default-shaped chat for a session bound to none. A test covers a provider that lists and discovers the default-shaped chat of a registered session whose recorded default has a generation query: listing and restore keep the recorded default. Co-authored-by: Copilot <[email protected]>
Rename the host's "primary chat" API and its uses to "default chat", the term AHP uses for `SessionState.defaultChat`: `getDefaultChat`, `isDefaultChat`, `isRegisteredDefaultChat`, `deriveLegacyDefaultChat` and the hydration, local-command, server-tool and completion members. A session's default chat is recorded by the host and is exactly what the host advertises, which the ownership service and AGENTS.md now state. Co-authored-by: Copilot <[email protected]>
DI-created consumers read the default chat through `IAgentHostChatOwnershipService` (`getDefaultChat`, `isDefaultChat`, and the new `isRegisteredDefaultChat` method that replaces the free function); classes constructed with `new` and free helpers keep the state manager. `deriveLegacyDefaultChat` moves next to the service as a pure, legacy-only function. No behavior change. Co-authored-by: Copilot <[email protected]>
`AgentHostStateManager.createSession` takes the caller's minted default chat like `restoreSession` does, instead of minting a default-shaped one when the summary has none. `AgentService` is the only production caller and already mints it. Test fixtures pass `buildDefaultChatUri(resource)`. Co-authored-by: Copilot <[email protected]>
`toRemoteSessionMessageMetadata` takes the source session's advertised default chat, which the resolved remote source now carries, for a source chat without a fragment, instead of building the default-shaped chat URI. Without an advertised default the metadata names no source chat. Peer and subagent fragments are unchanged. Co-authored-by: Copilot <[email protected]>
`deriveLegacyDefaultChat` lives alone in `common/agentHostLegacyDefaultChat.ts` and owns the historical `ahp-chat://default/<base64url(session)>` encoding instead of calling the minting helper. The host's legacy sources and the client's `getAdvertisedDefaultChat` fallback for older VS Code hosts import it from there. `buildDefaultChatUri` is now only the scheme that mints a new session's default chat, and it may change. A golden test pins the legacy URIs. A separate test asserts that both helpers still agree and should be deleted when minting changes. Co-authored-by: Copilot <[email protected]>
Test connections that address the default chat by its default-shaped URI without advertising `defaultChat` now identify as VS Code hosts through `initializeResult`, as `getAdvertisedDefaultChat` requires. A failing after-each hook in the response file changes suite had aborted the rest of the client run, which hid these failures. An untitled advertised default chat now inherits the session title even when it is not default-shaped: the advertised default chat is the session's default chat. Co-authored-by: Copilot <[email protected]>
No code decides that a chat is a session's default chat from its URI shape. Test fakes that stand in for a host's recorded default chat use the test-only `isMintedTestDefaultChat`. A restore test covers a registered session that records no default chat: it restores with the legacy default chat and records it. Co-authored-by: Copilot <[email protected]>
The protocol client fills `defaultChat` on every full session state and summary that enters the client (subscribe, reconnect and restore snapshots, listings, `root/sessionAdded`) for older VS Code hosts that did not advertise it, through `getOlderHostDefaultChat` in the new `browser/agentHostOlderHostCompatibility.ts`. It builds new objects and never overrides an advertised value. The rest of the client reads `SessionState.defaultChat` / `SessionSummary.defaultChat` directly, so `getAdvertisedDefaultChat` is removed. The sessions provider subscribes a new session's default chat, and hydrates a resumed session's draft agent and model, once the session state advertises the default chat instead of only when it is already known. Co-authored-by: Copilot <[email protected]>
`buildOpenSessionLinkForChat` takes the owner's default chat and gives a session-only link to that chat (and to a bare session) instead of to any chat whose id is `default`. A non-default chat whose id is `default` gets no link, because the link format reads that id as the default chat. Callers pass the ownership service's default chat (attachment links, Markdown plan guidance), the provider's backend default chat, or, for the chat-reference chip, the default chat the client owner lookup now returns with the owner. Co-authored-by: Copilot <[email protected]>
…og trigger `send_message` and `rename_chat` resolve a session's recorded default chat first and use the default chat its listing names only for a session that records none. The registration-generation trigger on catalog updates fires only for catalogs that have or gain normalized authority, since only those feed the default-chat index. Tests cover the trigger and `normalizedCatalogs` on a real database and through the compatibility database, and the Copilot state and plan files of a restored default chat that is not resumed yet. Co-authored-by: Copilot <[email protected]>
- The usage recorder remembers a chat as non-default only when a held or listed session names it as a peer; an unknown chat or a failed listing is looked up again on the next usage. Owner lookups return the chat's role. - A session's creation reference reads the creator's default chat reactively, so it updates when the creator becomes known. - A session that advertises no default chat has no default-chat changesets: the first chat is no longer treated as the default, and the unused `getDefaultChat(SessionState)` helper with that fallback is removed. - The older-host default chat also identifies a host from its root state, including the root a relay re-reads after authentication. Co-authored-by: Copilot <[email protected]>
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Ulugbek Abdullaev (@ulugbekna)Matched files:
Ben Villalobos (@benvillalobos)Matched files:
TylerLeonhardtMatched files:
|
Dirk Bäumer (dbaeumer)
previously approved these changes
Oct 13, 2026
Contributor
|
Base:
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Live Chat Debug refresh can permanently miss the recorded default chat when session state loads after its watcher is armed.
1 open finding
What changed in this PR
This PR makes the recorded or advertised defaultChat authoritative throughout Agent Host, replacing URI-shape inference while retaining explicit legacy compatibility.
Changes:
- Centralizes host-side default-chat lookup, persistence, restoration, and indexing.
- Propagates advertised defaults through client sessions, changesets, links, telemetry, and remote metadata.
- Adds broad compatibility, migration, and regression coverage.
One correctness issue remains: Chat Debug live refresh may never attach when session state loads asynchronously.
| File | Description |
|---|---|
exportAgentHostDebugLogs.test.ts |
Updates default-chat resource expectations. |
agentHostChatContribution.test.ts |
Covers advertised-default title behavior. |
agentHostUsageSidecar.test.ts |
Tests retryable usage classification. |
agentHostSessionInputPills.test.ts |
Supplies recorded defaults to owner lookup. |
agentHostChatDebugProvider.ts |
Resolves debug subscriptions from session state. |
chatAttachmentWidgets.ts |
Builds links using recorded defaults. |
agentHostSessionListController.ts |
Removes URI-shape default detection. |
agentHostUsageSidecar.ts |
Classifies usage using advertised defaults. |
agentHostChatContribution.ts |
Routes chat behavior through recorded defaults. |
agentHostModelInputState.ts |
Uses explicit default-chat metadata. |
chatSessionMoveService.ts |
Preserves default identity while moving chats. |
chatWidget.ts |
Passes recorded default-chat context. |
chat.ts |
Updates chat-facing default metadata. |
baseAgentHostSessionsProvider.ts |
Models the advertised default as the main chat. |
agentHostChangesetProvider.ts |
Resolves changesets against recorded defaults. |
agentHostSessionChangesets.ts |
Subscribes using advertised chat roles. |
agentHostRemoteSessionMetadata.ts |
Carries default-chat metadata remotely. |
remoteSessions.contribution.ts |
Integrates remote default-chat support. |
agentHostSessionController.ts |
Uses recorded defaults in session control. |
remoteAgentHostSessionsProvider.ts |
Propagates remote advertised defaults. |
chatSessions.ts |
Extends session chat metadata. |
workbench.desktop.main.ts |
Loads remote session services. |
sessionsRemoteServices.ts |
Registers remote session infrastructure. |
agentHostNewChatSuggestionsProvider.ts |
Excludes the recorded default from suggestions. |
sessionsConfiguration.ts |
Updates related session configuration. |
agentHostPeerChatStorage.ts |
Records legacy peer defaults. |
copilotCloudAgentHandler.ts |
Supplies explicit default-chat data. |
node/agentService.ts |
Mints and records defaults during creation. |
agentHostSessionOpenTelemetry.ts |
Classifies telemetry from recorded roles. |
claudeCodeSdkAgent.ts |
Normalizes listed Claude defaults. |
codexSdkAgent.ts |
Normalizes listed Codex defaults. |
copilotSdkAgent.ts |
Normalizes listed Copilot defaults. |
agentHostChatOwnershipService.ts |
Centralizes default-chat ownership queries. |
agentHostDatabase.ts |
Indexes persisted recorded defaults. |
agentHostRpcReplayService.ts |
Replays sessions with explicit defaults. |
agentHostStateManager.ts |
Removes synthesized default fallback. |
sessionSubscriber.ts |
Waits for advertised default state. |
agentServiceImpl.test.ts |
Tests explicit default creation and restoration. |
agentChatActionProcessor.test.ts |
Tests recorded-default action routing. |
agentHostStateManager.test.ts |
Tests default lookup and registration. |
agentHostDatabase.test.ts |
Tests persisted default indexing. |
agentHostE2ETestUtils.ts |
Updates end-to-end session fixtures. |
agentHostLegacyDefaultChat.test.ts |
Adds legacy encoding golden tests. |
agentHostChatOwnershipService.test.ts |
Tests authoritative role resolution. |
agentHostSessionOpenTelemetry.test.ts |
Tests delayed telemetry classification. |
sessionSubscriber.test.ts |
Tests default-aware subscriptions. |
sessionSubscriber.chatSubscribers.test.ts |
Tests chat subscription timing. |
claudeCodeSdkAgent.test.ts |
Tests Claude default normalization. |
codexSdkAgent.test.ts |
Tests Codex default normalization. |
copilotSdkAgent.test.ts |
Tests Copilot default normalization. |
testRecordingBackend.ts |
Records explicit defaults in fixtures. |
agentHostLegacyDefaultChat.ts |
Encapsulates frozen legacy derivation. |
common/agentService.ts |
Updates shared session contracts. |
agentHostUri.ts |
Separates minting from interpretation. |
state/protocol/state.ts |
Requires advertised default fields. |
state/sessionState.ts |
Removes URI-shape role helpers. |
agentHostFileSystemProviderClient.ts |
Uses explicit default context. |
agentHostOpenLink.ts |
Omits chat IDs only for actual defaults. |
agentHostTypes.ts |
Updates Agent Host metadata types. |
changeset.ts |
Passes explicit default-chat identity. |
agentHostProtocolClient.ts |
Fills defaults at compatibility boundaries. |
agentHostProtocolService.ts |
Propagates protocol default metadata. |
remoteAgentHostService.ts |
Extends remote session contracts. |
remoteAgentHostServiceImpl.ts |
Implements remote default propagation. |
agentHostOlderHostCompatibility.ts |
Derives defaults only for older VS Code hosts. |
agentHostOlderHostCompatibility.test.ts |
Tests compatibility host detection. |
agentHostProtocolClient.test.ts |
Covers all client ingress paths. |
agentHostOpenLink.test.ts |
Tests recorded-default link behavior. |
agentHostSessionChangesets.test.ts |
Tests default-aware changesets. |
baseAgentHostSessionsProvider.test.ts |
Tests session presentation and routing. |
agentHostSessionInputController.test.ts |
Tests recorded-default input routing. |
agentHostSessionFiles.test.ts |
Tests per-chat session output. |
agentHostRemoteSessionMetadata.test.ts |
Tests remote metadata serialization. |
remoteAgentHostSessionsProvider.test.ts |
Tests remote default behavior. |
AGENT_HOST_SESSIONS_PROVIDER.md |
Documents authoritative default identity. |
agentHostChat.ts |
Adds explicit chat-role metadata. |
chatDebugLogService.ts |
Resolves debug logs using recorded defaults. |
chatDebugService.ts |
Updates debug session integration. |
chatSession.ts |
Extends session chat representation. |
chatSessionMove.ts |
Updates move contracts for defaults. |
Chat Debug TODO.md |
Updates follow-up documentation. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The Agent Debug Logs panel read the session state's default chat once when it started watching a session. If the session subscription was still loading, no chat listener was installed and live usage tiles stopped updating until the panel was reopened. Observe the existing session subscription and (re)bind the chat listener whenever it advertises or changes its default chat, e.g. once it loads or when the default chat is recreated. Co-authored-by: Copilot <[email protected]>
Anthony Kim (anthonykim1)
approved these changes
Oct 13, 2026
Aiday Marlen Kyzy (aiday-mar)
approved these changes
Oct 13, 2026
Henning Dieterichs (hediet)
approved these changes
Oct 13, 2026
Sandeep Somavarapu (sandy081)
deleted the
agents/block2a-default-chat-role
branch
October 13, 2026 14:52
Don Jayamanne (DonJayamanne)
added a commit
that referenced
this pull request
Oct 13, 2026
…xploration-vscode * origin/main: (40 commits) MSRC fixes (#341342) chat: render input attachments for the input model's session (#341350) chat: center subagent tool activity hooks (#341258) Manage Copilot plugin marketplaces through Agent Host (#341301) fix: linux setuid sandbox helper permissions (#341292) agentHost: resolve #chat chips on the host of the chat that shows them (#341332) [Perf] agentHost: limit archived sessions over Mission Control (#341327) Remember expanded state for "Other Models" in model picker (#341335) Offer Stop for copilot detached background shells (#341310) agentHost: allow inherited peer chats to move workspaces (#341317) [Perf] agentHost: reduce Mission Control relay overhead (#341223) Fix Customizations modal spacing (#341144) Fix dependency cycle in QuickInputService and EditorResolverService (#341321) Fix Explorer refresh on restoring deleted workspace root folder (#341323) chat: Share and rate-limit core utility model requests (#340100) agentHost: open #chat chips on the connection that owns the chat (#341313) Fix flaky StorageMainService tests by awaiting storage warm-up (#341305) agentHost: record the default chat role instead of reading the default chat URI shape (#341293) welcome: preserve tab icon color with Modern Icons Fix flaky test in diskFileSystemProvider.test.ts (#341304) ... # Conflicts: # src/vs/platform/agentHost/node/agentService.ts # src/vs/platform/agentHost/node/protocolServerHandler.ts # src/vs/platform/agentHost/test/node/protocolServerHandler.test.ts # src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Goal
This is Block 2a of moving chats between sessions, following #341191 (Block 1, chat owners from records). A session's default chat is now a recorded role instead of a URI shape. No production code decides whether a chat is the default chat by checking for
ahp-chat://default/<session>.The term is AHP's: the host's recorded default chat is exactly what it advertises as
SessionState.defaultChat/SessionSummary.defaultChat. VS Code still mints new default chats the same way. There is no schema change, no change to persisted data, and no AHP protocol change.Design
Host
IAgentHostChatOwnershipService.getDefaultChat(session)/isDefaultChat(session, chat)/isRegisteredDefaultChat(chat)answer every default-chat question for DI consumers. Helpers that are not DI-created use the state manager.getDefaultChatUri, which minted the shaped URI when nothing was recorded, is gone.createSessionandrestoreSessionnow requiredefaultChat.buildDefaultChatUrionly inagentServicewhen it creates a session, including the?generation=recreation mint.deriveLegacyDefaultChat(incommon/agentHostLegacyDefaultChat.ts) is a frozen copy of the historical encoding, separate from minting, with golden tests. It runs only for legacy sources that record no default, and only after every recorded source has been checked; its result is then recorded.Client
defaultChat.AgentHostProtocolClientfills it once at the protocol boundary, on every path where a full session state or summary enters the client: subscribe, reconnect and restore snapshots,listSessions, andsessionAdded. The filled value is the legacy shape, set only for positively identified VS Code hosts (browser/agentHostOlderHostCompatibility.ts). Every other consumer reads the field directly.Links
buildOpenSessionLinkForChat(owner, chat, defaultChat)drops the chat id only for the owner's actual default chat.APIs
Every API this PR adds or changes is required: no optional members, no default parameters.
Behavior changes
None of these affect chats that VS Code creates today; VS Code hosts still mint
default-id default chats.?generation=Ndefault inherits the session title, and a chat whose URI only looks like the default is treated as a peer.AHP_SESSION_NOT_FOUND. Previously it silently created an empty, unforked chat.defaultgets no open-session link, because the link format reads that id as "the default chat". Previously its link opened the wrong chat.rename_chatandsend_messageresolve the recorded default chat, even when a provider listing names a different one.Bugs found and fixed along the way
These timing bugs were hidden by the shape fallback:
Both now wait until the state advertises
defaultChat.Chat Debug usage recording permanently stopped for a default chat after one failed or early owner lookup; it now retries.
Scope (follow-ups)
ahp-chat:/<uuid>), subagent role from records, and client chat ids that don't collide withdefaultare Block 2b.Performance
Measured on ff97fc1b8a4 vs base e29d835. Seeded mixed DB (60% v2, 30% legacy with peers, 10% legacy default-only) at 2,000 and 10,000 sessions. Fresh DB and service per run, base and branch interleaved, n=40 per metric per side, load average 2–4. Every SQL statement was captured and diffed between base and branch.
listSessions;createSession/createChat/ first turn;How to test
Live validation in Code OSS with real Copilot, comparing branch against main:
#chatchip to a peer chat#chatcompletion, on main either; covered by widget testsrename_chaton the default chat and a peer chat;send_messageto a peerValidation
All results are for a clean tree at the rebased HEAD
62a5708555b, on main7e092ca6c3c, withCOPILOT_*environment variables unset. The rebase applied with no conflicts, and all 15 patches are unchanged (git range-diff). A later main commit (2b0c23ebbd8) merges cleanly and doesn't touch default-chat logic.npm run typecheck-clientnpm run eslint -- <157 .ts files changed vs main>npm run hygienenpm run valid-layers-checknpm run check-cyclic-dependencies./scripts/test.sh --runGlob "vs/platform/agentHost/test/**/*.test.js"(Electron)node test/unit/node/index.js --runGlob "vs/platform/agentHost/test/{node,common}/**/*.test.js"(Node lane)./scripts/test.sh --runGlob "vs/{workbench/contrib/chat/test/browser,sessions/contrib/providers,sessions/contrib/remoteSessions,platform/agentHost/test/{common,browser,electron-browser}}/**/*.test.js"VoiceInputModeActionViewItemtests fail on main: 13500 passing, 2 failing)srcisDefaultChatUri: 0.getAdvertisedDefaultChat: 0.buildDefaultChatUri(appears only in its definition and theagentServicemint.agentHostLegacyDefaultChat.tsis imported only by the compatibility file on the client and by six host files (agentService, the ownership service, the peer-chat store, Claude, Codex, Copilot).Every behavior fix has a mutation-checked test: reverting the fix makes at least one test fail.