fix(coding-agent): rebuild system prompt on model switch#41
Open
Adolanium wants to merge 1 commit into
Open
Conversation
setModel and cycleModel updated agent.state.model but never rebuilt the cached system prompt, so the # Environment block kept naming the model the session started on. After switching model the agent reported a stale id. Refresh the prompt on every switch so it names the active model.
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.
What
setModel and cycleModel update agent.state.model but do not rebuild the cached
base system prompt. The # Environment block (Active model, knowledge cutoff) is
only rebuilt at init, extension reload, and cave-mode changes, so after a model
switch it still names the model the session started on.
Effect
After switching model mid-session the modeline and the outgoing request use the
new model, but the system prompt the model reads still names the old one. The
assistant then reports a stale model id and a stale knowledge cutoff. Reproduced
by switching to gpt-5.5 on the openai-codex provider: the modeline showed
gpt-5.5 and the request used gpt-5.5, but the assistant kept answering gpt-5.4.
Fix
Add a private _refreshSystemPromptForModel() that rebuilds _baseSystemPrompt and
agent.state.systemPrompt from the current model, and call it from setModel,
_cycleScopedModel, and _cycleAvailableModel after agent.state.model is set. This
reuses the existing rebuild path already used at init and on cave-mode change.
Tests
Added a case to packages/coding-agent/test/suite/agent-session-model-extension.test.ts:
prompt once, switch model with setModel, prompt again, and assert the system
prompt the faux provider receives names the new model and no longer names the
old one. Passes.
Two other tests in that file (setModel saves the model and emits model_select;
allows extension context handlers to modify messages before the LLM call) fail
on main independent of this change, verified by stashing the change and
rerunning. They are unrelated.
Checks
biome check is clean on the changed files. tsgo --noEmit passes. No CHANGELOG
edit (maintainer-managed).