fix: queue user prompt as followUp when system turn is streaming

When the agent is already streaming (system-triggered turn, e.g. autonomous
dispatch at startup) and the user sends a message without an explicit
streamingBehavior, default to followUp instead of steer.

Steer injects mid-stream into the current turn. FollowUp queues the
message as a clean new turn after the system work finishes — which is
what the user expects when they type their first message at startup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Mikael Hugo 2026-05-09 22:17:09 +02:00
parent c391abe08d
commit 705f9e2ba1

View file

@ -1214,17 +1214,16 @@ export class AgentSession {
]);
}
// If streaming, queue via steer() or followUp() based on option
// If streaming, queue via steer() or followUp() based on option.
// Default to followUp when no streamingBehavior is given — this covers
// user prompts that arrive while a system-triggered turn (e.g. autonomous
// dispatch at startup) is already running. The user's message queues as
// a clean new turn after the current one finishes, not steered into it.
if (this.isStreaming) {
if (!options?.streamingBehavior) {
throw new Error(
"Agent is already processing. Please wait for it to finish before sending another message.",
);
}
if (options.streamingBehavior === "followUp") {
await this._queueFollowUp(expandedText, currentImages);
} else {
if (options?.streamingBehavior === "steer") {
await this._queueSteer(expandedText, currentImages);
} else {
await this._queueFollowUp(expandedText, currentImages);
}
return;
}