Skip to content

fix(tui): keep model selection owned by the tab - #54367

Closed
cleardevice wants to merge 2 commits into
anomalyco:devfrom
cleardevice:fix/tui-tab-model-selection
Closed

cleardevice wants to merge 2 commits into
anomalyco:devfrom
cleardevice:fix/tui-tab-model-selection

Conversation

@cleardevice

@cleardevice cleardevice commented Oct 10, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #54363

Type of change

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

What does this PR do?

  • On the new-session screen, the fallback model is stored in the draft once preferences, the model catalog and config are loaded, so later changes to the shared recent list and variant preferences only affect screens opened afterwards. Open sessions without a saved model are covered by fix(tui): keep session model stable when recents sync #52533.
  • The new-session draft keeps the variant, and changing the variant on the new-session screen updates the draft.
  • Leaving a session for the new-session screen carries the agent, model and variant of that session. This covers /new, /clear, the tab rail "+" and the open menu in one place. Agents with a configured model keep it.

How did you verify your code works?

Screenshots / recordings

Before / after recordings below.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cross-client case from #54363 is fixed. On the base, TUI A's footer switched to the model picked in TUI B; with this change it stays on its own model. I checked this with the issue's opencode-drive script on both checkouts. bun test test/context and bun run typecheck pass in packages/tui, and both new tests fail on the base.

Public API: unchanged. Only TUI-internal selection state is touched.

Concerns:

  • /new and /clear still lose the session's variant. The handlers in packages/tui/src/app.tsx still call local.model.set(model) (and local.agent.set) right after route.navigate({ type: "home" }). That goes through selectModel, which stores preferredSelection(model), so the variant carried over from the session is replaced by the shared per-model variant preference. In a quick test (session on third/high, shared preference third = low), going home and calling local.model.set(...) as /new does left the selection on low; without that call it stays on high. Since the description says the carry-over covers /new and /clear in one place, removing those re-sets in app.tsx looks like the simplest fix. A test of that flow with the shared variant preference set to something different would cover it.
  • Overlap with #52533. The new effect also writes a fallback into session tabs that have no stored model, which is what the open #52533 does. Whichever lands second will need to be reconciled so there is one mechanism.

Before

After

Comment thread packages/tui/src/context/local.tsx Outdated
const current = agent.current()
if (!current) return false
setSelectionState("newSessionModelByLocationAgent", locationAgentKey(current.id), model)
setSelectionState("newSessionModelByLocationAgent", locationAgentKey(current.id), preferredSelection(model))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the new-session screen, selectModel always stores preferredSelection(model), so the variant comes from the shared preference. The /new and /clear handlers in app.tsx call local.model.set(model) right after navigating home, so they overwrite the variant that the carry-over just set from the session. I confirmed this with a small test: session third/high, shared preference third = low, navigate home, then local.model.set(...) leaves the selection on low. Either drop those re-sets in app.tsx (the carry-over already handles them), or keep the existing draft's variant here when the model is unchanged, as the session branch above does.

@cleardevice
cleardevice force-pushed the fix/tui-tab-model-selection branch from 9798096 to 5bf057b Compare October 10, 2026 19:51
@cleardevice

Copy link
Copy Markdown
Author

Thanks, both points addressed:

  • /new and /clear: the new-session branch of selectModel now keeps the draft's variant when the model is unchanged, like the session branch does, so the re-set in app.tsx no longer replaces the carried variant. Added a test with the session on third/high and the shared preference third = low.
  • fix(tui): keep session model stable when recents sync #52533: I dropped the fallback capture for open sessions, so this PR only covers the new-session screen and the carry-over into a new tab. The two changes no longer overlap.

@cleardevice
cleardevice force-pushed the fix/tui-tab-model-selection branch from 5bf057b to 73f903d Compare November 3, 2026 18:15
@cleardevice

Copy link
Copy Markdown
Author

Rebased onto current dev, tests pass, still relevant.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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.

tui: tab model selection follows other tabs and clients

1 participant