anomalyco / anomalyco/opencode

[BUG]: Injected prompts without agent/model silently switch the session's agent and model

Open
#46,111 3 comments 0 reactions 1 assignee View on GitHub

@neriousy is already working on this.

Since Aug 29, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
Avg merge
7h 2m
Merged PRs (30d)
384

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
  1. Set a session to a non-default agent and model.
  2. Deliver an injected prompt with no agent/model (e.g. a background subagent completing, which re-prompts the parent).
  3. 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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.