Repository navigation
Model router: keep a long context window across a restart after an unrouted turn - #347522
Merged
Bhavya U (bhavyaus) merged 2 commits intoNov 11, 2026
Merged
Conversation
…routed turn A turn sent on a model router that makes no pick (an invalid or missing file, no available models, a failed routing call) runs on the chat's current model. While the host is running, the turn's selection is still the router, so the chat's long context window and the router's last pick both hold. After a host restart the provider restores the turn with the model it ran on as its selection, which read as a model the user picked by hand: the next routed turn could shrink the window and route afresh. The turn's usage now records the router it asked for, the same way a routed turn's usage records the pick, so it is saved with the turn and restored with it. Reading a chat's long window and its last pick treats such a turn as a router turn. Follow-up to a review comment on #347474. Co-authored-by: Copilot <[email protected]>
Dmitriy Vasyura (dmitrivMS)
previously approved these changes
Nov 11, 2026
This was referenced Nov 11, 2026
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Restored unrouted turns are still misclassified as manual selections by the client, causing misleading model-picking status rows; the marker fallback and restored-history test coverage are missing.
1 open issue
What changed in this PR
This follow-up to #347474 preserves a model router’s long context window and last pick across an Agent Host restart when an intervening turn could not be routed.
Changes:
- Records the requested router in usage metadata when routing fails or makes no pick.
- Uses that metadata to distinguish restored router turns from manually selected models.
- Adds regression tests for restored history and repeated usage reports.
| File | Description |
|---|---|
src/vs/platform/agentHost/test/node/copilotModelRouter.test.ts |
Tests preservation of the long window and last pick after restoration. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Tests marker retention on every usage report. |
src/vs/platform/agentHost/node/copilot/copilotModelRouter.ts |
Recognizes restored unrouted turns when reading routing history. |
src/vs/platform/agentHost/node/agentSideEffects.ts |
Records and carries unrouted-router metadata. |
src/vs/platform/agentHost/common/meta/vscode/agentUsageMeta.ts |
Defines and validates the new usage marker. |
src/vs/platform/agentHost/common/meta/agentUsageMeta.ts |
Recognizes the marker as VS Code usage metadata. |
Review effort: Balanced
The chat decides whether a first-turn router's pick is settled the way the host does. After a restart, a turn that asked for the router and got no pick has the model it ran on as its selection, so the chat read it as a model picked by hand and could show a "picking a model" row and a "stayed on" line for a router that was not picking again. It now reads the router from the turn's usage, as the host does. Co-authored-by: Copilot <[email protected]>
Bhavya U (bhavyaus)
enabled auto-merge (squash)
November 11, 2026 01:41
Vijay Upadya (vijayupadya)
approved these changes
Nov 11, 2026
Bhavya U (bhavyaus)
deleted the
bhavyaus/model-router-long-context-restore
branch
November 11, 2026 01:56
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.

Follow-up to a review comment on #347474 (#347474 (comment)), for model routers (
.model-router.yaml, behindchat.copilot.modelRouter.enabled).Problem
A turn sent on a model router that makes no pick runs on the chat's current model. That happens when the router file is invalid or missing, when none of its models are available, or when the routing call fails.
While the host is running, such a turn's selection is still the router, so the chat's long context window and the router's last pick both hold. After a host restart the provider restores the turn with the model it ran on as its selection. That read as a model the user had picked by hand, so the next routed turn could shrink the context window and route the chat afresh.
Change
modelRouterUnrouted). It is re-added on every usage report, the same way a routed turn's pick is, so it is saved with the turn and restored with it.How to test
./scripts/test.sh --run src/vs/platform/agentHost/test/node/copilotModelRouter.test.ts --run src/vs/platform/agentHost/test/node/agentSideEffects.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts: 1,635 passing.pnpm run typecheck-clientand eslint on the changed files: clean.Three tests cover the sequence in the comment:
copilotModelRouter.test.ts: a long-window pick, then a turn restored the way the provider restores it (selection is the model it ran on, usage applied from storage). With the marker the next route keeps the pick and the long window; without it the turn is a hand-picked model and the window resets.agentSideEffects.test.ts: a turn whose router made no pick, or whose routing call failed, carries the marker on every usage report.stateToProgressAdapter.test.ts: a restored unrouted turn of the same router leaves the pick settled; one of another router does not.By hand: pick a router with
context-size: longand send a message; break the router file and send another; restart VS Code; fix the file and send a third. The chat stays on the long window.