Skip to content

Bug: prompt_async notifications override session's active agent and model #21728

@sjawhar

Description

@sjawhar

Bug Description

When a prompt_async request arrives without explicit agent or model fields (e.g., from Envoy notifications, Legion worker coordination, or any fire-and-forget prompt injection), the session's active agent and model are silently overridden by the default agent's configured defaults.

Steps to Reproduce

  1. Start a session and set it to a non-default agent and model (e.g., agent=hephaestus, model=opencode/kimi-k2.5-free)
  2. Send a POST /session/:id/prompt_async with only parts (no agent, no model)
  3. Observe the next assistant turn uses the default agent's configured model, not the session's active model

Expected Behavior

When prompt_async omits agent and model, the session should preserve whatever agent and model were active from the last user message.

Actual Behavior

The session's agent falls back to the default agent config, and the model falls back to that agent's configured model — discarding whatever the user had actively selected.

Root Cause

In packages/opencode/src/session/prompt.ts, createUserMessage() defaulted omitted agent/model from the default agent configuration instead of reading the current session prompt state (most recent user/assistant message). The synthesized user message then became the new source of truth for ACP session replay, silently redirecting the session.

Impact

This actively affects overnight agent coordination: Envoy notifications delivered to sessions via prompt_async can change the session's agent and model, causing unexpected model switches and errors.

Environment

  • OpenCode version: 1.4.0-sami
  • Affected endpoint: POST /session/:id/prompt_async
  • Also affects: command() (which reuses prompt())

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions