Skip to content

fix(session): preserve agent and model on async prompt without explicit fields#29357

Open
sjawhar wants to merge 1 commit into
anomalyco:devfrom
sjawhar:feat/prompt-async-agent-preserve
Open

fix(session): preserve agent and model on async prompt without explicit fields#29357
sjawhar wants to merge 1 commit into
anomalyco:devfrom
sjawhar:feat/prompt-async-agent-preserve

Conversation

@sjawhar
Copy link
Copy Markdown

@sjawhar sjawhar commented May 26, 2026

Issue for this PR

Closes #21728

Re-submission of #21729 (closed by automated cleanup), rebased onto current dev. The previous PR could not be reopened because the branch has been force-pushed since closure. The Linux e2e failure analyzed previously was traced to a different spec and unrelated to this PR.

Type of change

  • Bug fix

What does this PR do?

When prompt_async is called without agent or model fields, the session previously fell back to the default agent's model — clobbering the active agent/model the user had selected. This is the bug in #21728.

Now createUserMessage looks at the most recent user message with an agent set and uses that as the fallback before falling back to defaults. Same fallback chain for the model.

How did you verify your code works?

New test in test/session/prompt.test.ts asserts that a no-agent/no-model prompt_async after an initial prompt-with-agent preserves the original agent and model on the new user message.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When a prompt comes in without explicit agent/model fields (the common
case for prompt_async), createUserMessage was falling back to the
config's default agent and that agent's default model. This caused the
session to silently switch agents/models mid-conversation.

Fix: read the most recent user message in the session and prefer its
agent and model as the fallback before going to defaults. Both fields
fall through together because the user's previous choice was a coherent
pairing.

Replaces the dropped fix/prompt-async-agent-preserve branch with a
minimal version. Loop continuation guard and 30-min timeout from the
original branch are intentionally omitted; can be added later if
needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant