SIGN IN SIGN UP

agentHost: surface steering messages as their own user turn (#318456)

* agentHost: surface steering messages as their own user turn

When a user sent a steering message mid-turn, the Copilot agent host folded the SDK's response into the in-flight turn instead of showing the steering as a separate user message in the chat UI. The pending steering bubble silently disappeared and the assistant's reply appeared as a continuation of the original turn.

Buffer accepted steering messages and, when the SDK echoes them back through a `user.message` event (matched by content, skipping synthetic `source != 'user'` injections), promote the steering to its own protocol turn: dispatch `SessionTurnComplete` for the in-flight turn, then `SessionTurnStarted` with the steering's userMessage and `queuedMessageId` so the reducer atomically clears the pending entry. `_turnId` is updated so subsequent SDK deltas land in the new turn. Cleanup paths (abort, dispose) drain any unflipped buffer entries via `steering_consumed` so the chat UI bubble still clears.

Fixes #318265

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* address PR review feedback

- Skip setTurnEventId for synthetic user.message injections (source != 'user') so the DB doesn't pin a turn boundary to a non-user-visible event id.

- Promote the steering turn BEFORE recording the SDK event id, so history.truncate / sessions.fork target the new steering turn rather than the preempted one.

- _beginSteeringTurn now uses resetTurnState() to also reset the usage counter and subagent agentId map (previously bled across the preempt).

- Update _pendingSteeringFlips / _takeMatchingPendingSteering JSDoc to match the user.message-driven implementation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
C
Connor Peet committed
20aaa24961d30467dbd4ac786489594a6d136474
Parent: f4e6219
Committed by GitHub <noreply@github.com> on 5/26/2026, 11:29:41 PM