Skip to content

fix(tui): respect current model config when continuing a session#26355

Closed
st3fk3 wants to merge 1 commit into
anomalyco:devfrom
st3fk3:fix/session-restore-stale-model
Closed

fix(tui): respect current model config when continuing a session#26355
st3fk3 wants to merge 1 commit into
anomalyco:devfrom
st3fk3:fix/session-restore-stale-model

Conversation

@st3fk3

@st3fk3 st3fk3 commented May 8, 2026

Copy link
Copy Markdown

Issue for this PR

Type of change

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

What does this PR do?

Continuing an old session restores the model from the last user message, overriding the current agent config. After changing models between sessions, the old model is still sent to the API.

This removes the model/variant restoration from the session-switch effect. After the fix:

  • the config model is always used when continuing a session
  • the agent is still restored from session history (intentional)
  • /models manual picks still work (they write directly to the model store)

How did you verify your code works?

  • built from source and confirmed the correct model is used after changing config and continuing a session
  • verified /models picks still override correctly
  • checked that subagents are unaffected (they read from agent state, not the model store)

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally, see: #comment-4407725787
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

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

Based on my search, I found one potentially related PR:

Related PR:

Note: The search results show PR #26355 (the current PR) in multiple results, which is expected. The related PR #24508 appears relevant as it deals with the same concern of model/agent state during session transitions.

No exact duplicate PRs found. The issue #26351 (mentioned in the PR description as "Closes") is the specific bug being addressed by this PR.

@st3fk3

st3fk3 commented May 8, 2026

Copy link
Copy Markdown
Author

How the fix was verified

Tested by adding a temporary log at the patch site, running against an isolated opencode instance.

Debug snippet:

if (msg.model) {
  Bun.write("/tmp/opencode-session-restore-test.log",
    `[session-restore] skipping model restore: ${JSON.stringify(msg.model)}\n`
  ).catch(() => {})
  // local.model.set(msg.model)
  // local.model.variant.set(msg.model.variant)
}

Before (original code -- restores model from session):

  1. Started session with deepseek-chat, sent a message, quit
  2. Changed config to deepseek-reasoner
  3. Continued session -- old model (deepseek-chat) was restored, config change ignored

After (patched code -- skips model restore):

Same steps. Log confirmed the skip:

[session-restore] skipping model restore: {"providerID":"deepseek","modelID":"deepseek-chat"}

Config model (deepseek-reasoner) correctly took precedence over session history.

Prevents session history model from overriding the agent
config on session continue.
@st3fk3 st3fk3 force-pushed the fix/session-restore-stale-model branch from 7bef60d to 7f1c891 Compare May 8, 2026 15:50
@github-actions

github-actions Bot commented Jun 8, 2026

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.

[BUG]: Model from previous session overrides current config when continuing a session

1 participant