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)
Description
A prompt that arrives without explicit
agent/modelfields — a background-subagent completion notification, or any injected/fire-and-forget prompt — makescreateUserMessagefall 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, increateUserMessage: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
agent/model(e.g. a background subagent completing, which re-prompts the parent).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 currentdev)