fix(app): scope manual model override to the selected agent by Dominic-Leidenfrost · Pull Request #40604 · anomalyco/opencode · GitHub
Skip to content

fix(app): scope manual model override to the selected agent - #40604

Closed
Dominic-Leidenfrost wants to merge 2 commits into
anomalyco:devfrom
Dominic-Leidenfrost:agent-model-default
Closed

Dominic-Leidenfrost wants to merge 2 commits into
anomalyco:devfrom
Dominic-Leidenfrost:agent-model-default

Conversation

@Dominic-Leidenfrost

Copy link
Copy Markdown

Issue for this PR

Closes #38333

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

In the v2 composer the persisted draft model is checked before the agent's configured model:

const key = [prompt.model.current(), input.agent()?.model, configured(), recent(), fallback()].find(...)

Nothing clears it on an agent switch, and openNewTab seeds a new draft with the previous tab's model — so the stale value is already in place before the agent is ever consulted.

Instead of reordering that list, this tags the persisted selection with the agent it was made under and only honours it while that agent is active. PromptModel gains an optional agent field; override() returns the persisted model only when the tag matches. Untagged values (pre-existing drafts, models inherited from another tab) lose to a configured agent model, but are still used for agents that have no model configured — so the openNewTab inheritance stays intact where it is unambiguous. set and variant.set write the tag, and variant.selected reads through override so a stale variant can't leak across a switch.

Result: new sessions and agent switches land on the agent's model, while a deliberate pick sticks for as long as you stay on that agent.

The field is optional and the undefined case is handled explicitly, so no migration is needed.

Note on the neighbouring PRs: #38372 fixes this from the agent select callback, which a new tab never fires. #39319 is the same code path from the other side, where the agent model overwriting a manual pick is the bug — scoping rather than reordering is what lets both hold at once. Happy to rework this if you would rather land one of those first.

How did you verify your code works?

Applied the equivalent transformation to the shipped 1.18.13 renderer bundle and ran the desktop app against agents with different configured models. Checked: new session, agent switch, manual pick surviving across turns on the same agent, switching away and back, and variant selection. Not yet exercised as a source build.

Screenshots / recordings

No visual change — the model picker shows a different value. Happy to add a recording if useful.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@Arekejoker

Copy link
Copy Markdown

Supporting feedback — Web UI (opencode serve), v1.18.18

This is exactly the semantics we need. Self-hosted Web UI with two primary agents bound to different-capability models:

  • plan → local multimodal model (vLLM, vision)
  • build → cloud text model (DeepSeek V4 Flash via OpenCode Go)

Scoping the persisted draft model to the agent it was chosen under (PromptModel.agent tag) matches the desired behaviour: a deliberate pick sticks while that agent is active and is restored on switch-back, while untouched agents still resolve to their configured model. The openNewTab inheritance remaining intact where unambiguous is also the right call.

One behavioural question for the Web flow, since this PR targets the app composer: does the same scoping apply when the model is switched through the composer dropdown in the Web UI (the persisted model-selection local-storage state in local.tsx, which currently writes a single State.model with no agent tag)? Happy to verify once this lands in a release.

Thank you for the detailed write-up — the optional-field/no-migration approach is clean.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Session uses the wrong model when an agent is selected

2 participants