Description
Two different flows write to modelStore.model[agentName] (a per-agent, in-memory model override in the TUI):
- User manually selects a model via the model dialog (dialog-model.tsx calls local.model.set()).
- Session loads and restores the last user message model (prompt/index.tsx calls local.model.set(msg.model) when sessionID changes, line 401).
The second flow fires automatically when navigating into a session — no prompt submission needed. Once set, this override persists for the rest of the TUI process. /new does not clear it.
Scope issue: The session model restoration (per-session intent) writes to a global in-memory key (modelStore.model[agentName], keyed by agent name, not session ID). There is no cleanup path when the session ends.
This means that within one TUI process lifetime, after visiting a session:
- client.global.config.update() writes to opencode.json correctly
- But the model indicator continues to show the stale override
- Only a TUI restart restores the baseline (because modelStore.model is not persisted to disk — only recent/favorite/variant are saved in model.json)
Steps to reproduce
- Start TUI on home page.
- Call client.global.config.update() with a different model — model indicator updates correctly.
- Enter a session (messages load, override is set from the last user message's model).
- /new to return to home.
- Call client.global.config.update() again with a different model — opencode.json is written, model indicator unchanged.
- Restart the TUI — the change from step 5 is now visible.
Suggested fix
Clear modelStore.model[agentName] on /new or session navigation back to home. This lets the lookup chain fall through to the refreshed opencode.json baseline, which is necessary for client.global.config.update() (a public API) to always be effective.
Plugins
Custom TUI plugin calling client.global.config.update()
Description
Two different flows write to
modelStore.model[agentName](a per-agent, in-memory model override in the TUI):The second flow fires automatically when navigating into a session — no prompt submission needed. Once set, this override persists for the rest of the TUI process. /new does not clear it.
Scope issue: The session model restoration (per-session intent) writes to a global in-memory key (modelStore.model[agentName], keyed by agent name, not session ID). There is no cleanup path when the session ends.
This means that within one TUI process lifetime, after visiting a session:
Steps to reproduce
Suggested fix
Clear modelStore.model[agentName] on /new or session navigation back to home. This lets the lookup chain fall through to the refreshed opencode.json baseline, which is necessary for client.global.config.update() (a public API) to always be effective.
Plugins
Custom TUI plugin calling client.global.config.update()