Skip to content

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

Closed

Description

@iceteaSA

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)

Activity

  1. github-actions commented on Aug 29, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing open issues. Please check:

    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.

  2. LordMike commented on Sep 5, 2026

    @LordMike

    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.

  3. jtoronto commented on Sep 8, 2026

    @jtoronto

    Same here. This issue has been driving me crazy.

  4. neriousy commented on Oct 20, 2026

    @neriousy
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions