Skip to content

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

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

fix(app): scope manual model override to the selected agent#40604
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

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found related PRs that are addressing similar model selection issues, though they are not exact duplicates:

Related PRs:

  1. fix(app): apply agent model to new sessions #38372 - fix(app): apply agent model to new sessions

    • Mentioned in the current PR description as fixing the issue from the agent select callback side
    • Related because it addresses the same underlying problem with agent model selection on new tabs
  2. fix: keep manually selected model across turns #39322 - fix: keep manually selected model across turns

Note: The PR description explicitly acknowledges these neighboring PRs (#38372 and #39319) as alternative approaches to the same issue, with this PR (#40604) taking a different approach by scoping the persisted selection with an agent field rather than reordering. The author notes that the scoping approach allows both concerns to be addressed simultaneously.

These are closely related but complementary solutions rather than duplicates of the current PR.

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

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.

New Session uses the wrong model when an agent is selected

2 participants