Skip to content

fix(coding-agent): rebuild system prompt on model switch#41

Open
Adolanium wants to merge 1 commit into
JuliusBrussee:mainfrom
Adolanium:fix/model-switch-system-prompt-refresh
Open

fix(coding-agent): rebuild system prompt on model switch#41
Adolanium wants to merge 1 commit into
JuliusBrussee:mainfrom
Adolanium:fix/model-switch-system-prompt-refresh

Conversation

@Adolanium

Copy link
Copy Markdown

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).

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.
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.

1 participant