TUI: User selected agent/model is overwritten by server defaults when creating a new session
Description
Title: TUI: User selected agent/model is overwritten by server defaults when creating a new session Description: When creating a new session in the TUI (via the Home screen), the user's manually selected Agent (e.g., "Plan") or Model is unexpectedly reset to the server's default configuration (e.g., "Build" / "Google") immediately after sending the first message. This regression appears to be introduced in v1.1.13.
What happened?
- On the TUI Home screen, I manually selected the "Plan" agent (or a specific model like Claude).
- I typed a prompt and pressed Enter to start the session.
- The TUI navigated to the new session view.
- Immediately upon loading the session view, the Agent/Model indicator switched back to the default "Build" (and often "Google" as the provider), ignoring my initial selection.
Root Cause Analysis:
The issue is caused by a race condition in packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx.
A createEffect hook monitors sessionID changes and attempts to restore the state (Agent/Model) from the last user message of the session:
// packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
createEffect(() => {
const sessionID = props.sessionID
// ...
const msg = lastUserMessage() // Fetches the last message with role="user"
if (sessionID !== syncedSessionID) {
// ...
// PROBLEM: This logic aggressively overwrites local state with message metadata
if (msg.agent) local.agent.set(msg.agent)
if (msg.model) local.model.set(msg.model)
}
})
In v1.1.13, changes to the component's lifecycle (moving ref initialization to onMount) seemingly altered the timing of rendering vs. data synchronization. When navigating to a newly created session:
- The first message is synced from the server.
- Since it's a new session, the server metadata for this message might still reflect default values (or be initialized with defaults like "Build").
- The createEffect triggers, sees this "default" metadata on the message, and forcefully resets the local TUI state, overwriting the user's manual selection.
Expected behavior: When creating a new session from the Home screen, the TUI should respect the Agent/Model selected by the user during creation and not overwrite it with the server's initial default state.
Suggested Fix: Modify the navigation logic to pass a flag (e.g., created: true) when transitioning from Home to Session. The Prompt component should check this flag and skip the state restoration logic for newly created sessions.
Plugins
"[email protected]", "@franlol/[email protected]"
OpenCode version
1.1.13
Steps to reproduce
- Start OpenCode TUI (
opencode). - On the Home screen, use
Ctrl+x ato switch the agent to "Plan" (or any non-default agent). - Type a message and submit.
- Observe that as soon as the session view loads, the agent reverts to "Build".
Screenshot and/or share link
Operating System
macOS
Terminal
iTerm2