You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Honor custom agent model and reasoning-effort pins across harnesses - #343750
Fixes#338949. Supersedes #341716, whose changes are included and rebased onto current main (co-authored).
Selecting a custom agent whose .agent.md frontmatter pins model and/or reasoning-effort can leave the previously selected picker model and effort in place. The harness then sends that selection instead of the agent's pin.
Changes
Copilot agent-host harness (chat view)
Host discovery publishes pins:SessionCustomizationDiscovery reads each discovered workspace or user agent file. It publishes the frontmatter model list (first entry as the protocol model, the ordered list in _meta['vscode.models']) and reasoning-effort (_meta['vscode.reasoningEffort']). AgentCustomizationItemProvider maps these into ICustomAgent. Plugin agents fall back to the protocol model.
Model matching: agent-host models are published under the session-type vendor (agent-host-…), so ILanguageModelChatMetadata.matchesQualifiedName never matches values like Claude Sonnet 4.5 (copilot) or claude-sonnet-4.5. For each pinned value, ChatInputPart tries, in order:
The existing qualified-name match.
An exact metadata.id match among session-targeted models, so an advertised ID such as provider/custom:variant=fast isn't parsed as a configuration suffix.
resolveAgentFileModelIdentifiers.
Pins resolve against the incoming session's model pool (its session type), not the widget's outgoing session while binding. Local harness matching is unchanged.
Reasoning effort:reasoning-effort is parsed into PromptHeader → ICustomAgent → CustomChatMode. A dedicated autorun applies it to the current agent-host model as a read-time overlay in ChatModelConfigurationStore (setPresentedConfiguration), so it follows model changes and late registration.
It uses thinkingLevel in preference to reasoningEffort when a model advertises both, matching the picker and the runtime.
The overlay is validated on every read against the session-scoped schema with the same filter restores use, so host locks, narrowed choices and other schema constraints win.
It never reaches preferences or storage. Overlay values carry an agent source (vscode.modelConfiguration.<key>.source). The Copilot host preserves it in its configuration report, and the store never adopts it as a runtime value.
Captured configuration also carries the conversation's own value underneath (vscode.modelConfiguration.<key>.underlying / .underlyingSource). Restores put that value back in place of the agent-sourced one, even after the store is cleared or another conversation changed the shared bucket. The host ignores these keys.
An explicit choice for that key supersedes the overlay.
User overrides of pins
The input state persists agentPinOverrides ({ modeId, model?, configKeys? }). It's written by InputModel.toJSON and the session operation log, and validated on revival.
It's recorded when the user picks a model other than the pinned one, explicitly sets a pinned configuration key, or edits an earlier request that explicitly chose that key or ran on another model. A handoff's or prompt file's model that differs from the pin (requestModelByQualifiedName) is recorded too, immediately before it applies, while the pin's own automatic application records nothing.
_syncFromModel applies the incoming overrides before the mode sync, so deliberate choices survive navigation and reloads.
Overrides are kept through programmatic fallbacks while an agent registers late, and cleared when the user picks another agent.
Between clients: custom-agent drafts sync the overrides in _meta['vscode.agentPinOverrides'], set to null when there are none.
The synced value is authoritative. Peers adopt each other's model and effort overrides, a re-armed pin clears them, and adopted overrides persist with the input state.
For live drafts from clients that don't sync overrides, effort overrides are derived from the draft's own provenance, on top of the current overrides: explicit adds the key, agent removes it.
The first transferred draft uses only synced overrides, so it never replaces locally saved ones with a guess.
The synced-versus-local draft comparison ignores this key only when the synced draft doesn't carry it. A pending local edit to the overrides alone therefore still wins over a peer update.
Outgoing drafts are built in one place, and peer updates are compared against that same form. A fallback for the channel's own model keeps this client's agent-applied configuration, such as an effort-only agent's pin.
First send: when an untitled agent-host session materializes, or a late send re-targets it, its overrides travel with the transferred mode to the real session. Cleared overrides are transferred too. The mode is identified by its advertised id (IChatRequestModeInfo.modeId), not a remote agent's wrapped instruction URI.
Session restore: when an agent-host session restores from a transferred draft that didn't sync overrides, backfillRestoredPickerState recovers the locally saved ones for the same agent. An explicitly synced null is kept, so a peer's re-armed pins aren't undone by older saved overrides.
Re-apply the pin after input-state restoration, unless the user overrode it, the conversation's in-session selection reason is UserSelection/RestoredChoice, or the state came from a remote peer. This runs outside the sync guard so the result is written back.
Retry an unresolved pin when the model list changes. An explicit or restored choice cancels the retry, and it waits while an authored model request (a handoff or prompt file) is pending. Mode switches and restores still apply the pin.
Keep the hostModelSelection guard so the Agents window's host-owned selection isn't bypassed.
Omit the picker-model override when the selected remote agent pins a model.
How to test
Create .github/agents/pinned.agent.md with model: [claude-sonnet-4.5, Claude Sonnet 4.5 (copilot)] and reasoning-effort: high.
In the chat view with the Copilot harness, select a different model and effort in the picker. Then select the pinned agent.
The picker switches to Claude Sonnet 4.5 / High. The session's events.jsonl shows the agent's model and effort on assistant.message.
Change the model and the effort manually, switch to a conversation in another mode and back, then reload the window. Your choices are kept.
Switch to a mode without reasoning-effort. The effort returns to the conversation's own setting, and new sessions don't inherit High.
Create an agent with only reasoning-effort: high. Its effort applies to whichever model is selected, including after you switch models.
With the same agent-host session open in two windows, override the model or effort in one. The other window keeps that choice instead of re-applying the pin. Re-selecting the agent in the first window re-arms the pin in both, including for a window that was closed at the time and reopened later.
Repeat step 2 in Local chat with model: Claude Haiku 4.5 (copilot).
Validation
Targeted tsc type-check of all changed src files and tests: passed for workbench files. In agent-host files, the only errors are existing ones caused by the missing @github/copilot-sdk types in the minimal toolchain (confirmed against an unmodified baseline). Ran with a minimal toolchain, because a full npm ci wasn't possible locally.
Unit tests (chatInputPart.test.ts, chatModelConfigurationStore.test.ts, chatModel.test.ts, chatService.test.ts, agentHostChatContribution.test.ts, agentCustomizationItemProvider.test.ts, sessionCustomizationDiscovery.test.ts, copilotManagedModelConfiguration.test.ts, promptFileParser.test.ts, copilotCloudSessionsProvider.spec.ts): not run locally; relying on CI.
CI on 935af2f ran the PR's tests at the time. Its only failures were one PR test, fixed in 754c964, and two SessionsList tests broken on main.
Known unrelated failure: main currently fails Compile & Hygiene and two Sessions - SessionsList tests (QUICK_CHATS_SECTION_ID used without an import in sessionsList.test.ts). CI merges this PR with main, so those checks fail here until main is fixed.
Selecting a custom agent whose frontmatter pins `model` and/or
`reasoning-effort` could leave the previously selected picker model and
effort in place, which the harness then sent instead of the agent's pin.
- Copilot agent-host harness: resolve agent-file model values (display
name or model ID) against session-targeted models, which are published
under an `agent-host-*` vendor that qualified-name matching never hits.
- Plumb `reasoning-effort` from agent frontmatter into the chat mode and
present it, session-scoped, on the selected agent-host model.
- Local chat: re-apply the pin after input-state restoration (unless the
user deliberately picked a model in that mode) and when a pinned model
becomes available, writing the result back to the input model.
- Cloud delegation: omit the picker-model override when the selected
remote agent pins a model.
- Keep the host-owned model selection guard for the Agents window.
Fixesmicrosoft#338949
Supersedes microsoft#341716
Co-authored-by: aeschli <6461412+aeschli@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This PR addresses #338949 by making custom-agent model and reasoning-effort pins take precedence over existing picker selections across chat harnesses and cloud delegation.
Changes:
Carries reasoning-effort metadata through prompt parsing, custom agents, and cached chat modes.
Adds harness-aware model resolution, pin restoration, delayed-resolution retries, and session-scoped effort presentation.
Omits cloud picker-model overrides for pinned agents and adds regression tests.
- Agent host: publish each discovered agent's frontmatter `model` list
and `reasoning-effort` (protocol `model` plus `_meta`), and map them in
AgentCustomizationItemProvider so agent-host modes actually carry pins.
- Cancel a pending pin retry when the user explicitly picks a model.
- Apply effort-only pins to the current harness model.
- Keep presented reasoning effort as a read-time overlay in
ChatModelConfigurationStore so it never becomes a durable preference
(unrelated edits, restores and host session reports don't absorb it;
an explicit choice supersedes it).
- Judge restore intent from the incoming conversation alone: keep
UserSelection and RestoredChoice models across navigation and repeated
restores, and cancel any pending pin retry.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved restoration and effort-overlay behavior can lose explicit choices, persist transient values, and conflict with host configuration constraints.
- Namespace agent customization metadata as `vscode.models` and
`vscode.reasoningEffort` so other hosts' `_meta` isn't read as pins.
- Validate the presented effort on every read against the effective
session schema (read-only keys, offered choices, disabled items).
- Tag presented values with an `agent` source so restores recognise
them even after the store is cleared or recreated; the Copilot host
keeps that provenance in its configuration report and the store never
adopts agent-sourced runtime values.
- Persist which pins the user overrode (`agentPinOverrides`) in the
input state and session operation log, so deliberate model and effort
choices survive navigation and reloads. Overrides are set before the
mode sync, kept through programmatic fallbacks while an agent
registers, and cleared when the user picks another agent.
- Reconcile the reasoning-effort overlay in its own autorun that follows
the current model, covering effort-only pins and late model
registration.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Passing `undefined` for the selected model fell back to the parameter
default, so the test began with a model already selected.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Prefer an exact advertised harness model id over agent-file alias
parsing, which reads `:key=value` as a configuration suffix.
- Derive per-key overrides from a peer's draft in the agent host session
handler, where the configuration is known to be the peer's: an
explicitly sourced effort is the peer's choice; its overlay is not.
- Recover saved `agentPinOverrides` when an agent-host session restores
from a transferred draft that doesn't carry them.
- Carry the conversation's own value underneath a presented overlay in
captured configuration, so restoring it after another conversation
changed the shared bucket recovers that value rather than the bucket's.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[P2] Preserve a peer's model override beyond this remote-origin sync. When a peer selects a different, non-pinned model, this guard initially keeps it, but _applyRemoteDraft() records only effort-key overrides. With no matching local intended choice, the selection controller records SessionRestore; a local input update clears origin, and serialization does not retain it either. A later restore can therefore reapply the agent's model pin instead of the peer's choice. Persist model-override intent when adopting a peer selection that differs from the resolved pin, and cover peer selection → local edit → navigation/reload.
- Custom-agent drafts carry the user's pin overrides in `_meta`
(`vscode.agentPinOverrides`, `null` when none), so peers adopt model
and effort overrides, re-armed pins clear them, and adopted overrides
persist with the input state through local edits and reloads.
- The first transferred draft uses only synced intent, so it never
replaces locally saved overrides with a guess; live drafts from peers
that don't sync intent still derive effort overrides from provenance,
layered on the current overrides (explicit adds, `agent` removes).
- Synced-versus-local draft comparison ignores the overrides key, so
derived overrides aren't mistaken for a local edit.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addressed the previously missed finding ("Persist peer model overrides through local edits and reloads", chatInputPart.ts) in ee7611e: a peer that picks a model other than the agent's pin records a model override, which now syncs in the draft's _meta['vscode.agentPinOverrides']. The receiving client adopts it into agentPinOverrides in its input state, so it survives local edits (the merged state keeps it after origin clears) and is serialized for navigation and reloads, rather than relying on the transient selectedModelReason/origin. Covered by the handler test that adopts a synced model override, publishes it back in drafts, and clears it when the peer re-arms the pin.
- Compare synced and local drafts including the overrides key when the
synced draft syncs it, so a pending local edit that changes only the
overrides isn't replaced by a peer update.
- Preserve a transferred draft's explicitly synced `null` overrides
through conversion and `backfillRestoredPickerState`, so a peer's
re-armed pins aren't replaced by locally saved overrides on reload.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ts, and restore edited requests' effort
- Apply a custom agent's effort to `thinkingLevel` before
`reasoningEffort` when a model advertises both, matching the picker and
runtime, so the pin takes effect and picker edits supersede it.
- Skip the model-list pin retry while an authored model request is
pending, so a pinned model registering first doesn't cancel it. Mode
switches and restores still apply the pin and replace stale requests.
- When editing an earlier request, record its explicitly chosen effort as
an override for the conversation, so the agent's effort overlay doesn't
hide the restored value.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Identifier-based request edits still lose model override intent on restoration, and the new mode dependency breaks an existing restoration test fixture.
[P2] Preserve the edited request's model override as well as its effort. With chat.editRequests: input, editing an earlier request restores its model through ChatWidget → requestModelByIdentifier(). If that request used model B and the current agent's pin to A has been re-armed, this selects B with ProgrammaticSelection but records no model override. Navigating away and back or reloading then lets _syncFromModel() reapply A. Record override intent in the identifier resolver before applying B, and sync the changed intent even if B was already selected, as the qualified-name path does. Add an edit → restore regression under a model-pinned agent.
…n fixture
- Editing an earlier request restores its model by identifier; record a
model override when it differs from the agent's resolved pin, in the
resolver before it applies, and sync the changed intent, as authored
requests do, so later restores and reloads keep it.
- Give the existing request-restoration fixture in
chatModelConfigurationStore.test.ts a current (built-in) mode, which
`requestModelByIdentifier` now reads.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addressed the previously missed finding (Preserve the edited request's model override as well as its effort, chatInputPart.ts) in 942ad59: when editing an earlier request restores its model through requestModelByIdentifier(), a model override is now recorded in the resolver before the model applies if it differs from the current agent's resolved pin, and the changed intent is synced even when that model was already selected, as the qualified-name path does. Navigating away and back or reloading therefore keeps the request's model instead of re-applying the pin. Added an edit → restore regression under a model-pinned agent.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Interacting restoration and cross-client synchronization paths need human review, passing targeted tests, and manual multi-window verification before approval.
Capture an explicitly chosen `null` underneath the agent's overlay, as
nullable configuration schemas accept it, so restoring the conversation
recovers `null` rather than another conversation's shared preference.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Cross-client persistence and restoration need current-commit test results and multi-window verification, and an overlay schema-validation issue remains unresolved.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Validate overlay values with the full schema filter
[P2] Validate presented values with the existing schema filter, not just the enum. For example, a host can advertise reasoningEffort with enum: ['low', 'high'] and const: 'low'. A High pin passes this check and is returned in the picker/request configuration, even though filterConfigurationToSchema rejects it. Pattern and length constraints are also skipped. Reuse that filter before adding overlay provenance, retaining the read-only check, and add a regression for an enum value excluded by const. This also keeps overlays consistent with the filter's rejection of unsupported composite schemas.
Check the agent's effort overlay with `filterConfigurationToSchema`
(enum including disabled items, const, type, pattern, length and
unsupported composites) plus the read-only check, so a value the schema
rejects never reaches the picker or request configuration.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Addressed the previously missed finding (Validate overlay values with the full schema filter, chatModelConfigurationStore.ts) in fb4d73b: presented overlay values are now checked with filterConfigurationToSchema, the same filter restores use, which covers the enum including disabled items, const, type, pattern and length constraints, and rejects unsupported composite schemas. The read-only check is kept. The check runs before the overlay's provenance is added, so a value the schema rejects never reaches the picker or request configuration. Added a regression where const excludes an advertised enum value.
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
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.
Fixes #338949. Supersedes #341716, whose changes are included and rebased onto current
main(co-authored).Selecting a custom agent whose
.agent.mdfrontmatter pinsmodeland/orreasoning-effortcan leave the previously selected picker model and effort in place. The harness then sends that selection instead of the agent's pin.Changes
Copilot agent-host harness (chat view)
Host discovery publishes pins:
SessionCustomizationDiscoveryreads each discovered workspace or user agent file. It publishes the frontmattermodellist (first entry as the protocolmodel, the ordered list in_meta['vscode.models']) andreasoning-effort(_meta['vscode.reasoningEffort']).AgentCustomizationItemProvidermaps these intoICustomAgent. Plugin agents fall back to the protocolmodel.Model matching: agent-host models are published under the session-type vendor (
agent-host-…), soILanguageModelChatMetadata.matchesQualifiedNamenever matches values likeClaude Sonnet 4.5 (copilot)orclaude-sonnet-4.5. For each pinned value,ChatInputParttries, in order:metadata.idmatch among session-targeted models, so an advertised ID such asprovider/custom:variant=fastisn't parsed as a configuration suffix.resolveAgentFileModelIdentifiers.Pins resolve against the incoming session's model pool (its session type), not the widget's outgoing session while binding. Local harness matching is unchanged.
Reasoning effort:
reasoning-effortis parsed intoPromptHeader→ICustomAgent→CustomChatMode. A dedicated autorun applies it to the current agent-host model as a read-time overlay inChatModelConfigurationStore(setPresentedConfiguration), so it follows model changes and late registration.thinkingLevelin preference toreasoningEffortwhen a model advertises both, matching the picker and the runtime.agentsource (vscode.modelConfiguration.<key>.source). The Copilot host preserves it in its configuration report, and the store never adopts it as a runtime value.vscode.modelConfiguration.<key>.underlying/.underlyingSource). Restores put that value back in place of theagent-sourced one, even after the store is cleared or another conversation changed the shared bucket. The host ignores these keys.User overrides of pins
agentPinOverrides({ modeId, model?, configKeys? }). It's written byInputModel.toJSONand the session operation log, and validated on revival.modelthat differs from the pin (requestModelByQualifiedName) is recorded too, immediately before it applies, while the pin's own automatic application records nothing._syncFromModelapplies the incoming overrides before the mode sync, so deliberate choices survive navigation and reloads._meta['vscode.agentPinOverrides'], set tonullwhen there are none.explicitadds the key,agentremoves it.IChatRequestModeInfo.modeId), not a remote agent's wrapped instruction URI.backfillRestoredPickerStaterecovers the locally saved ones for the same agent. An explicitly syncednullis kept, so a peer's re-armed pins aren't undone by older saved overrides.Local chat (from #341716, adjusted)
UserSelection/RestoredChoice, or the state came from a remote peer. This runs outside the sync guard so the result is written back.hostModelSelectionguard so the Agents window's host-owned selection isn't bypassed.Cloud delegation (from #341716, unchanged)
How to test
.github/agents/pinned.agent.mdwithmodel: [claude-sonnet-4.5, Claude Sonnet 4.5 (copilot)]andreasoning-effort: high.pinnedagent.events.jsonlshows the agent's model and effort onassistant.message.reasoning-effort. The effort returns to the conversation's own setting, and new sessions don't inherit High.reasoning-effort: high. Its effort applies to whichever model is selected, including after you switch models.model: Claude Haiku 4.5 (copilot).Validation
tsctype-check of all changedsrcfiles and tests: passed for workbench files. In agent-host files, the only errors are existing ones caused by the missing@github/copilot-sdktypes in the minimal toolchain (confirmed against an unmodified baseline). Ran with a minimal toolchain, because a fullnpm ciwasn't possible locally.chatInputPart.test.ts,chatModelConfigurationStore.test.ts,chatModel.test.ts,chatService.test.ts,agentHostChatContribution.test.ts,agentCustomizationItemProvider.test.ts,sessionCustomizationDiscovery.test.ts,copilotManagedModelConfiguration.test.ts,promptFileParser.test.ts,copilotCloudSessionsProvider.spec.ts): not run locally; relying on CI.SessionsListtests broken onmain.maincurrently fails Compile & Hygiene and twoSessions - SessionsListtests (QUICK_CHATS_SECTION_IDused without an import insessionsList.test.ts). CI merges this PR withmain, so those checks fail here untilmainis fixed.