Skip to content

Model router: keep a long context window across a restart after an unrouted turn - #347522

Merged
Bhavya U (bhavyaus) merged 2 commits into
mainfrom
bhavyaus/model-router-long-context-restore
Nov 11, 2026
Merged

Bhavya U (bhavyaus) merged 2 commits into
mainfrom
bhavyaus/model-router-long-context-restore

Conversation

@bhavyaus

@bhavyaus Bhavya U (bhavyaus) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to a review comment on #347474 (#347474 (comment)), for model routers (.model-router.yaml, behind chat.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

  • A turn that asks for a router and gets no pick now records the router's name in its usage metadata (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.
  • Reading a chat's long context window and its last pick treats a turn with that marker as a router turn, not as a hand-picked model.
  • The chat's own check for whether a first-turn router's pick is settled reads the marker the same way, so a restored chat does not show a "picking a model" row or a "stayed on" line for a router that is not picking again.

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-client and 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: long and 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.

…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]>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 01:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified in the router continuity and restoration changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@bhavyaus
Bhavya U (bhavyaus) enabled auto-merge (squash) November 11, 2026 01:41
@bhavyaus
Bhavya U (bhavyaus) merged commit 9e6a198 into main Nov 11, 2026
53 of 54 checks passed
@bhavyaus
Bhavya U (bhavyaus) deleted the bhavyaus/model-router-long-context-restore branch November 11, 2026 01:56
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 11, 2026
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.

4 participants