ADR-0108: Mid-turn steering — queued input reaches the running turn¶
- Status: Accepted 2026-11-23
- Context: issue #441 — while a turn runs (most acutely during a long reasoning stretch), the only ways to add an element were Ctrl+C and re-send, or queue for the next turn; Claude Code's steering (type while it works, the agent picks it up mid-task) was the inspiration
- Amends: ADR-0083 — the queue's delivery timing (capture, review surface and escape hatch are unchanged)
Context¶
ADR-0083 built the busy-input queue losslessly but lazily: Enter-while-busy
captured the text and handleAgentDone flushed it as the next turn, one
per turn; Telegram input captured while busy sat in pendingRemoteInputs
until the turn ended; ACP prompts serialized behind turnMu. A user watching
their own carefully tuned prompt arrive mid-thought had no way to hand the
running turn a correction — cancel, retype, resend, lose the work in between.
Two realities shaped the design:
- A running HTTP stream cannot be appended to. While the model is reasoning or answering, the request is in flight — nothing can be injected. The earliest a running turn can see new input is the next request boundary: after a tool round executes, or — for a tool-less response — when the stream ends.
- Not every host has a boundary. milk's local provider (OpenAI-compat,
Bedrock, Responses — one shared
runToolLoop) builds its next request itself and can carry input into it. Subprocess agents (Claude CLI, aider, smolagent) are opaque processes — there is no channel to inject into.
Decision¶
Capture is unchanged; delivery moves to the boundary. One queue, two drain points, promotion as the universal fallback.
- The seam.
local.Agent.WithSteerDrain(fn)(wired throughlocalAgentWiring.steerDrain, filled per turn bybuildTUIAgentsoverinteractiveState) exposes the host's queues to the tool loop. The loop pops at exactly two moments: the top of every iteration (so input queued during a tool round rides the request that follows the tool results) and the no-tool-calls termination branch (so input queued during a tool-less stream continues the same turn: the answer-so-far is persisted as an assistant message, the input appends as a user message, the loop goes around again). This is the "as if it were a tool result" shape from the issue — a plain user message in the next round's payload, which is how steering reads to the model. - Never where the host doesn't own the queue. Background clones drop
steerDrain(cloneForBackground's explicit field list; jobs have their ownbgInboxfollow-up channel, issue #250), andbuildToolRunnerdeliberately does not select the field into agent-as-tool runners — a nested tool-agent call must never consume the session's queue. CLI-backed agents get no drain: their queue keeps flushing one per next turn (the honest degradation — no injection channel exists). - Steerable = what the flush path would send as a plain prompt.
Steering bypasses
submitInputentirely, so an entry may steer only whensubmitInputwould dispatch it as prompt text: no staged attachments (the flush must attach them), no slash command (the flush must execute it), no bang direct-exec, no direct-bash shell text (confirmation/PTY), and paste provenance honored exactly likesubmitInput's issue-#151 gate (a pasted slash-looking line is inert text and steers). The drain takes each queue's FIFO steerable prefix and stops at the first blocked entry — order cannot skip — and remote (Telegram) input drains only once the prompt queue is empty, preserving the flush chain's global order (queued prompts before remote inputs). - The echo is the flush's echo. Each drained item is rendered exactly
as its flush would have —
[queued]/[telegram]label + tokenized text, loop-detector user-turn feed, histories recorded once (queue-time recording, issue #368, owns queued entries; remote input records at delivery). The pop runs on the agent goroutine, so the echo rides the tea queue into Update, and both slices are guarded by a newsteerMu— agent-goroutine pop vs UI-goroutine queue/drop/review. - Promotion is the fallback, not a second mechanism. Whatever cannot
steer — or was queued before the turn ended (interrupt, deadline,
provider error) — flushes one per next turn through
handleAgentDoneexactly as ADR-0083 described. The iteration budget guards the termination drain: pastmaxIternothing is popped, so no entry is ever consumed by a continuation that cannot run.queue_while_busy: false, the two-step Enter confirm, Ctrl+C undo and/queueare untouched. - Observability: every delivered batch counts as
milk.steer.delivered(count, model, agent role).
Consequences¶
- The busy hint and the queue receipt now say "the agent picks it up on its
next step" instead of "for the next turn" (the phrase ADR-0083 quoted);
/queuehelp reads "queued while the agent works". The ADR-0083 body keeps its original quotes with an amendment note. - Telegram input captured while busy can now act on the live turn — it
previously waited for idle. ACP parity shipped as the follow-up half of
issue #441 (same day): a busy
session/promptis buffered in the session's own steer queue (cmd/milk/acp_steer.go) and pulled by the running turn'ssteerDrainat a model-request boundary — while the request itself keeps blocking onturnMu. Delivered, it returns the delivery echo'smessageIdand runs no second turn; undelivered (or non-steerable — slash command, media, a pending setup wizard, or the 20-entry cap) it dequeues itself and runs as the next turn exactly as the blocking path did.queue_while_busy: falsekeeps pure serialization; the prefix-stop and remote-after-prompts order rules mirror the TUI'spopSteer. - Queued input reaches the model even mid-reasoning — but only at the next boundary; the transcript shows the delivery line where the model's next round begins, which is the honest depiction of what happened.
- Delivered input is persisted like any other user message (the gap the
first live ACP test exposed): the drain queues each line on the session
(
Session.AddSteeredInput), and the turn'srecordUserTurnwrites it into history right after the prompt it rode —[prompt][steered…] [assistant], exactly once, across TUI, ACP and Telegram deliveries. Nothing enters the store mid-run, matching the prompt itself (also recorded at turn end), so the session-history tool's mid-run view stays consistent. Over ACP every disposition logs underacp steerinmilk.log(enqueue/deliver/resolved/serialize/refuse/stop), so a queued-while-busy message is attributable after the fact — no line at all means it arrived idle. - A steered message is not re-routed through command handling, PTY or attachment staging by construction; anything needing those paths can never be mis-delivered as model text.
Alternatives rejected¶
- Rewriting the in-flight request — impossible over one HTTP stream; providers expose no append.
- Waiting for turn end (status quo) — the cancel-and-resend problem the issue exists to remove.
- Delivering at queue time into the transcript only — an echo with no model delivery is the invisible-prompt bug ADR-0083 already forbade.
- A steering gesture separate from Enter — a third busy disposition to learn; the queue already exists and already confirms explicitly, so its delivery timing is the only thing that had to change.