Repository navigation
fix: build session prompt for the provider/model that actually runs - #1210
Merged
SamSaffron merged 1 commit intoOct 6, 2026
Merged
SamSaffron merged 1 commit into
SamSaffron merged 1 commit into
Conversation
The system prompt ({{provider}}, {{model}}, {{provider_model}} and
model-gated user AGENTS.md blocks) was resolved from the agent's
preferred provider/model, not the one the session runs on. The runner
overrode only the model, so a web session on claude-bin:opus for an agent
preferring chatgpt rendered "chatgpt:opus" and dropped [[[claude-bin]]]
gates. ask/serve/loop ignored --provider entirely.
Callers now report the provider/model they resolved into cfg via
CLIFlags.ActiveProvider/ActiveModel, which win over agent preferences.
loop applies provider overrides before resolving its prompt.
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.
Problem
The session system prompt is resolved from the agent's preferred provider/model, not the provider/model the session actually runs on. This affects
{{provider}},{{model}}and{{provider_model}}, and also the model gates ([[[claude-bin]]]…) in the user-levelAGENTS.md.Observed on Jarvis, an agent whose preference is
chatgpt:gpt-6.1-sol:claude-bin:opuschatgpt:opusask --agent jarvis --provider claude-bin:opusclaude-bin:opuschatgpt:gpt-6.1-solThe web case is a half-applied override.
prepareRunnerAgentcopies the agent and replacesModelwith the requested model, but keeps the agent'sProvider.ResolveSettingsInDir/resolveSessionPromptToolsthen template fromagent.Provider+agent.Model. The provider the session really uses is resolved separately intocfgbyapplyProviderOverridesWithAgent, and prompt resolution never reads it.ask,servestartup andloopdon't consult the provider flag at all.Practical impact: a
[[[claude-bin]]]block in~/.config/term-llm/AGENTS.mdnever reaches Claude CLI sessions started from the web UI, and the model is told the wrong identity.Fix
CLIFlagsgainsActiveProvider/ActiveModel: the pair the caller has already resolved intocfgafter the CLI, request, agent and config overrides. WhenActiveProvideris set, bothResolveSettingsInDirandresolveSessionPromptToolsuse the pair in place of the agent's preference. The model always comes with its own provider, so a preferred model is never paired with another provider.activeLLMFlags(cfg)returnscfg.DefaultProvider+activeModel(cfg).askand bothask --resumeprompt pathsservestartuplooploopresolved its prompt before applying provider overrides. Applying the overrides is now moved ahead of prompt resolution.resolveChatRuntimeSystemContextWithConfigalready sets the agent copy's provider and model to the ones the session runs on, and this PR applies that same idea to the other paths.When no active pair is supplied, behaviour is unchanged (agent preference > config).
Tests
TestCmdRunnerPreparePromptUsesSelectedProviderAndModel: an agent that preferspreferred:preferred-model, prepared through the runner with these requests:selected:big. Before the fix this renderedpreferred:big, the same shape aschatgpt:opus.selected:selected-default. Before the fix:preferred:preferred-model.provider:modelflag →selected:big. Before the fix:preferred:preferred-model.TestResolveSettingsActiveLLMWinsOverAgentPreference: the active pair wins for templating, and a[[[claude-bin]]]user AGENTS.md block is included only when the active provider isclaude-bin. Ungated content is always kept.go test ./...passes under an isolated HOME/XDG per AGENTS.md.go build ./...passes.ask --agent jarvis --provider debug "hi"with a throwawayXDG_DATA_HOME, reading the persisted system message:Current LLM: **chatgpt:gpt-6.1-sol**Current LLM: **debug**(the debug provider has no configured model)Not changed
From reading the code (not tested): when a web session already has selected prompt inputs, the runner reuses them (
cli.inputs), so a mid-conversation model switch most likely keeps the prompt resolved when the session started. That is the existing refreshable-inputs design and is out of scope here. Sessions already created with a wrong prompt keep it.