feat(steering): settle a steered turn at idle, not at the interrupt (#958)

Steering is delivered at priority `now`, which makes the CLI **abort**
the running cycle instead of folding the message into it. The aborted
cycle ends with an ordinary human-origin `result`, so we answered
`session/prompt` with `end_turn` while the steered work was still going
— its remaining tool calls, its answer, and its file edits then streamed
with no turn in flight.

A steered turn's results now only record their outcome, and the turn
settles at the SDK's `idle` — the only signal spanning both the
interrupted and the steered cycle. The injected message's replay tells
them apart: an idle arriving before it means the steered cycle hasn't
started, so it is swallowed. `session/cancel` and the next prompt still
settle the turn early, with the recorded stop reason.

Four steering tests cover the interrupt, an early idle, the next-prompt
hand-off, and cancel.
This commit is contained in:
Andrey Bragin
2026-08-05 18:41:00 +02:00
committed by GitHub
parent b965dd2191
commit a84b81080a
3 changed files with 396 additions and 8 deletions

View File

@@ -29,9 +29,11 @@
* !steer <text> `_session/steering` — injected into the turn that is
* already running, so it can change course between tool
* calls. Answers "injected", or "startedNewTurn" if the turn
* beat us to the finish. Either way the reply arrives as
* `session/update` notifications that can outlast the
* `stopReason` of the turn you steered. See ./steering.ts.
* beat us to the finish. An injected reply streams as
* `session/update` notifications inside that turn, whose
* `stopReason` waits for it. "startedNewTurn" output belongs
* to a detached turn no `session/prompt` of ours tracks.
* See ./steering.ts.
* !queue <text> `session/prompt` sent mid-turn anyway. The agent advertises
* `promptQueueing`, so it takes the backlog instead of us —
* same ordering, different owner.
@@ -564,8 +566,8 @@ async function main() {
try {
const result = await agent.request<SteeringResponse>(STEERING_METHOD, params);
// Either way the steered message's own output arrives as `session/update`
// notifications, not in this response — and it may well keep streaming
// after the turn we steered has already answered with its stopReason.
// notifications, not in this response. When injected, it lands inside the
// turn we steered, whose `stopReason` waits for it.
log(
result.outcome === "injected"
? "steer outcome: injected into the running turn"