Skip to content

fix: keep manually selected model across turns - #39322

Open
tbartik wants to merge 1 commit into
anomalyco:devfrom
tbartik:keep-model-selection
Open

fix: keep manually selected model across turns#39322
tbartik wants to merge 1 commit into
anomalyco:devfrom
tbartik:keep-model-selection

Conversation

@tbartik

Copy link
Copy Markdown

Issue for this PR

Closes#39319

Type of change

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

What does this PR do?

If your agent has a model configured, picking a different model in the picker doesn't stick. The prompt runs on your pick, then it snaps back to the agent's model for the next turn.

Two separate causes, one per UI:

TUIPrompt restored the model from the last user message whenever a session hydrated, which overwrote the pick. I removed that. The model is now seeded from durable session state in context/local.tsx, but only when the agent has no local override, so reopening a session still restores its model.

App/desktop — the agent Select calls agents.select(value) even when the value hasn't changed, and agent.set always rewrote state with model: item.model ?? prev?.model. Because the agent has a configured model, item.model is always set and always won. Now re-applying the already-persisted agent is skipped.

The guard compares against persisted state rather than agent.current() on purpose: store.current is initialised to the first agent in the list, so comparing against the resolved current agent would make the first genuine agent.set a no-op and never persist anything.

Switching agents still applies that agent's configured model — only redundant re-application is skipped.

How did you verify your code works?

Built a local binary (script/build.ts --single) and ran the desktop app (bun run --cwd packages/desktop dev), with a build agent pinned to one model:

  1. Confirm the session shows the agent's model
  2. Pick a different model
  3. Send two prompts — model stays on the pick (it reverted before this change)
  4. Switch agent away and back — model follows the agent's config, as expected

Also added unit tests for both guards, and bun test passes in packages/tui (193) and packages/app (548), with typecheck clean in both.

Screenshots / recordings

The change is behavioural, not visual: the model label in the composer stops reverting between turns.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title fix(tui,app): keep manually selected model across turns doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@tbartiktbartik changed the title fix(tui,app): keep manually selected model across turnsfix: keep manually selected model across turnsJul 28, 2026
A selected model was overwritten by the agent's configured model after every
turn, so staying on a non-default model was impossible.
TUI: Prompt restored the model from the last user message on session
hydration. Drop that, and instead seed the model from durable session state
only when the agent has no local override.
App: the agent Select calls agents.select even when the value is unchanged,
and agent.set always rewrote the model as `item.model ?? prev?.model`. Skip
re-applying the already-persisted agent so an explicit pick survives.
Switching agents still applies that agent's model.
Closesanomalyco#39319
Sign up for freeto 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.

Manually selected model reverts to the agent's configured model after every turn

1 participant

@tbartik