Description
Description
A prompt that arrives without explicit agent/model fields — a background-subagent completion notification, or any injected/fire-and-forget prompt — makes createUserMessage fall back to the default agent and that agent's configured model, silently switching the session's active agent and model. Provider prompt caching keys on the model, so the next turn also misses the cache prefix and re-uploads the context.
Root cause
packages/opencode/src/session/prompt.ts, in createUserMessage:
const agentName = input.agent
const ag = agentName ? yield* agents.get(agentName) : yield* agents.defaultInfo()
...
const model = input.model ?? ag.model ?? (yield* currentModel(input.sessionID))An omitted agent resolves to the default agent, and an omitted model to that agent's configured model. Neither consults the session's active agent/model, so any injected prompt without those fields redirects the session.
Steps to reproduce
- Set a session to a non-default agent and model.
- Deliver an injected prompt with no
agent/model(e.g. a background subagent completing, which re-prompts the parent). - The next assistant turn runs on the default agent's model, not the session's.
Impact
Agent-coordination and overnight sessions: completion notifications change the session's agent and model out from under it, causing unexpected model switches and cache-prefix busts (billed on both models across the switch).
Prior art
Reported before as #21728 (closed by the inactivity bot while assigned to a maintainer) and fixed in @sjawhar's #35195 (also bot-closed, unmerged). Filing a live tracking issue since both are closed. #46106 revives the fix, extended to preserve the session variant and to only adopt the new agent's model on a genuine agent switch.
OpenCode version
dev (reproduces on current dev)
Activity
github-actions commentedon Aug 29, 2026
This issue might be a duplicate of existing open issues. Please check:
model) clobber the session's stored model via the samecreateUserMessagepath inprompt.ts. That issue also analyzes theinput.model ?? ag.model ?? currentModelresolution chain and thesetAgentModeloverwrite problem.You already reference the closed issues #21728 and #35195; #42893 is the active open tracking issue for the same underlying bug and may be worth consolidating with or cross-referencing.
LordMike commentedon Sep 5, 2026
Im seeing this too - it sucks, because I may start in an advanced model, but subagents reporting back will downgrade my session :/
Hoping the prompt_async can be changed to just flat out not modify the sessions model, unless specified to do so.
jtoronto commentedon Sep 8, 2026
Same here. This issue has been driving me crazy.
neriousy commentedon Oct 20, 2026
Thanks for the report. V2 keeps agent and model selection separate from prompt submission, so injected prompts without those selections use the session's selected agent and model; I'm closing this as fixed. If it comes back on the latest v2, please open a new issue with your version and steps.