Skip to content

New Session uses the wrong model when an agent is selected #38333

Closed

Description

@ValentinFrima

OpenCode Desktop 1.18.4

When creating a new session, selecting an agent that has a configured model does not apply that model. Instead, the session starts with the previously selected model. The correct model is only applied after reselecting the agent from within the active session.

Steps to reproduce

  • Configure two agents with different models.
  • Open the New Session dialog.
  • Select an agent with a custom model.
  • Start the session.
  • Send a prompt.

Expected

The session starts with the model configured for the selected agent.
The model selector reflects the agent's configured model.

Actual

The New Session dialog keeps the previously selected model.
The new session starts using that incorrect model.
The correct model is only applied after reselecting the agent from within the active session.

Activity

  1. github-actions commented on Jul 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your issue is specifically about the New Session dialog not applying the agent's configured model when first starting a session, it may be distinct enough to stand on its own — but it's worth checking those issues first to see if they cover the same root cause.

  2. LLawliet444 commented on Jul 22, 2026

    @LLawliet444

    I’d like to take this. I reproduced the likely state-priority issue in the new-session composer: the persisted prompt model is preferred over the newly selected agent’s configured model. I’ll add a regression test ensuring an agent selection initializes the new session with that agent’s model while preserving an explicit subsequent model choice.

  3. Dominic-Leidenfrost commented on Aug 5, 2026

    @Dominic-Leidenfrost

    Hit this on 1.18.13 and dug into it — posting the root cause, since it's a bit more specific than the title suggests and I don't think #38372 as it stands fully closes it.

    Two things combine.

    packages/app/src/pages/session/composer/prompt-model-selection.ts orders the persisted draft model ahead of the agent's:

    const key = [prompt.model.current(), input.agent()?.model, configured(), recent(), fallback()].find(
      (item): item is ModelKey => !!item && valid(item),
    )

    And openNewTab in packages/app/src/components/titlebar.tsx seeds a new draft with the previous tab's model:

    const model = tabs.stateValue<PromptSession>(sessionTab, "prompt")?.model.current()
    tabs.newDraft({ server: sessionTab.server, directory: activeSession.directory }, "", model)

    So the wrong model is already in the draft before the agent is ever consulted. #38372 hooks the agent select callback, which covers step 3 of the repro here — but a new tab opened without touching the agent picker still starts on the inherited model, because the select never fires.

    Worth flagging: #39319 is the same code path from the opposite side, where the agent's model overwriting a manual pick is the complaint. A fix that just makes the agent model win harder will reopen that one.

    What worked for me is scoping rather than reordering: tag the persisted selection with the agent it was made under, and only honour it while that agent is active. Values without a tag — pre-existing drafts, and models inherited via openNewTab — lose to a configured agent model, but are still honoured for agents that have no model configured, so the inheritance behaviour stays intact where it's unambiguous.

    That gives:

    I've been running this against 1.18.13 as a patched bundle rather than a source build. Happy to open a PR against dev if that direction looks right.

  4. fobiat commented on Sep 17, 2026

    @fobiat

    Reproduced against current app source using a production build, isolated --pure server, and a local fake provider. A draft copied Alpha/low from its source session; selecting Beta changed only the agent label, and the provider received model=alpha, reasoning_effort=low.

    I have a focused fix for deliberate agent selection and both cycling directions. It updates the draft model/variant together with the agent, retains draft settings for agents without defaults, and leaves later manual selections intact. Browser verification now captures beta/high after selecting Beta. New-tab inheritance without an agent-selection action is intentionally unchanged; changing that precedence needs a separate decision. The earlier #38372 and #40604 were closed without merging.

  5. papue commented on Sep 29, 2026

    @papue

    Confirming this is still reproducible on OpenCode Desktop 1.18.33 / Windows 11.

    What I observe:

    • New Session → agent and configured model switch correctly.
    • + new tab with no other tab open → agent and configured model switch correctly.
    • + new tab while another tab is already open → the model becomes sticky and does not follow the selected primary agent's configured model.
  6. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    V2 applies the selected agent's configured model when you change agents in the new-session composer, rather than keeping an inherited model from another agent. Explicit model choices are remembered per agent when switching back. To get v2: npm i -g @opencode/cli@latest or curl -fsSL https://opencode.ai/v2/install | bash (desktop: update the app). If you still see this on v2, please open a new issue with the details.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions