Skip to content

feat(coderd)!: steer queued messages on Send now - #31156

Merged
ethanndickson merged 4 commits into
ethanndickson/chat-interrupt-send-steerfrom
ethanndickson/chat-send-now-steer
Nov 9, 2026
Merged

ethanndickson merged 4 commits into
ethanndickson/chat-interrupt-send-steerfrom
ethanndickson/chat-send-now-steer

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Breaking API Change for changelog:

POST /api/v2/chats/{chat}/queue/{queuedMessage}/promote (Send now) no longer interrupts a running chat or cancels the tool calls a requires_action chat is waiting on. It moves the message to the end of the steer lane instead, so the agent gets it before its next model call, or straight away if the chat has errored or is paused. Promoting or deleting a queued message that no longer exists now always returns a 404, where it used to return a 409 if the chat had nothing queued.

"Send now" on a queued message (POST /api/v2/chats/{chat}/queue/{queuedMessage}/promote) now just moves it to the end of the steer lane. It never interrupts the chat, so it can't cancel the step that would have answered it. The endpoint's request doesn't change. Before, it moved the message to the head of the queue with MIN(position) - 1, so if you pressed "Send now" on two messages, the second one went first. With a queue of Q1 Q2 Q3 S4, "Send now" on Q1 then Q3 now delivers S4 Q1 Q3, and Q2 keeps waiting.

If the chat has errored or is paused, the steer lane goes in straight away, like a send. Otherwise it goes in at the next delivery point: before the next model call, when the turn ends, or when an interrupt finishes. Stop is the only thing that interrupts.

"Send now" and "Remove" on a message that's already been delivered now return a 404 instead of a 409, the same as editing one, and "Remove" on an archived chat returns a 400.

In chatstate, SteerQueuedMessage replaces PromoteQueuedMessage. It moves the message to the end of the steer lane, and on an errored or paused chat it also delivers the steer lane and resumes the chat, like a send does. The SteerChatQueuedMessage query sets position = nextval(...) and replaces ReorderChatQueuedMessageToHead. Most of the diff is tests.

#31174 then makes steer the API default and removes interrupt as a busy behaviour, #31175 makes message_agent always steer, and #31173 updates the site.

Part of CODAGT-1140

@linear-code

linear-code Bot commented Oct 22, 2026

Copy link
Copy Markdown

CODAGT-1140

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T11:07:31.652403Z eb99e18 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30619339e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/chat_mutations.go Resolved
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

re: Cancel every outstanding call before resuming A1

Not valid. chatd never puts a chat in requires_action while a local tool call is outstanding: decideGenerationAction returns ExecuteLocalTools for any unanswered local call and only returns EnterRequiresAction once none remain, and its dynamic tool set is the chat's dynamic_tools minus built-in name collisions, so every call outstanding at EnterRequiresAction is dynamic to chatstate as well. The mixed A1 state only exists in a chatstate test seed. Even in that state, Interrupt leaves the chat in R1, the next decision runs the local tool, and DeliverSteerMessages only runs from generateAssistant, before the next model call, when no call is outstanding. The steered message is delivered and the turn does not fail.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 30619339e2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from 3061933 to f8d28a0 Compare October 22, 2026 08:49
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from f8d28a0 to 1d2e485 Compare October 22, 2026 09:11
@ethanndickson
ethanndickson marked this pull request as ready for review October 22, 2026 10:40
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from 1d2e485 to e110fd2 Compare October 22, 2026 10:57
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch 2 times, most recently from 40e674a to bcca889 Compare October 26, 2026 04:19
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from bcca889 to a6268d9 Compare October 27, 2026 00:46
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch 2 times, most recently from a9061b0 to 3677027 Compare November 2, 2026 04:44
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

re:
Comment on lines +1348 to +1349
if len(rows) == 0 {
return SteerQueuedMessageResult{}, nil

Badge Reconcile status when steering leaves the chat parked

Fixed in #31748, up in the stack.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: eb99e1874f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/exp_chats.go Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more comments above, but otherwise LGTM

@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from 0e3b3eb to f8f39e1 Compare November 5, 2026 06:41
Send now ends any edit on the queued message and moves it to the end of
the steer lane. In the same transaction, it interrupts the chat if the
chat is running or requires action, or is interrupting and no worker
owns it. From E1, E1P, or P, it delivers the steer lane into history,
up to the first message under edit.

SteerQueuedMessage replaces PromoteQueuedMessage in chatstate, and the
SteerChatQueuedMessage query replaces ReorderChatQueuedMessageToHead.
When chatstate refuses a delete, edit, or Send now on a queued message, it now looks up the message. A missing message returns ErrQueuedMessageNotFound (404). An existing message keeps ErrTransitionNotAllowed, which the handlers map to 409, as on main.
The test enables the chat worker. The worker can take over the unowned requires_action chat, and without requires_action_deadline_at it cancels the pending tool call at once, so SubmitToolResults got a 409.
@ethanndickson
ethanndickson force-pushed the ethanndickson/chat-send-now-steer branch from f8f39e1 to 7b15d15 Compare November 6, 2026 06:03
ibetitsmike added a commit to ibetitsmike/coder that referenced this pull request Nov 9, 2026
@ethanndickson
ethanndickson merged commit 63e08e2 into main Nov 9, 2026
57 of 84 checks passed
@ethanndickson
ethanndickson deleted the ethanndickson/chat-send-now-steer branch November 9, 2026 04:55
ethanndickson added a commit that referenced this pull request Nov 9, 2026
…1153)

`FinishTurn`, `FinishInterruption` and a send to an errored chat with a
queue each had their own code for moving a queued message into history.
They now share `deliverQueuedRows`, which takes a list of queued rows,
so the next PR can deliver the whole steer lane at once instead of just
the queue head. Delivery still only takes the queue head here, so this
doesn't change behaviour. `PromotedMessages` on the turn and
interruption results is now a slice to match.

"Send now" on an errored chat, or one waiting on tool results, still has
its own copy of that code in `PromoteQueuedMessage` for now. #31156
replaces it with a move into the steer lane, which then goes through
`deliverQueuedRows` like everything else.

I've also deleted `GetChatQueuedMessagesByPosition` and
`GetChatQueuedMessageHead`, as `GetChatQueuedMessages` already returns
the queue in delivery order.

Part of CODAGT-1140
ethanndickson added a commit that referenced this pull request Nov 9, 2026
As suggested on #30074, steer messages are now their own lane, rather
than queue rows that jump ahead with a lower position. chatstate uses a
queued message's `busy_behavior` as its lane, and the steer lane always
goes first. `GetChatQueuedMessages` lists the steer lane first, so the
queue is shown in the order it'll actually be delivered.

At turn end, when an interruption finishes, and on a send to an errored
chat, the whole steer lane goes in. If there aren't any steer messages,
the queue head goes in like it does today. So with a queue of `Q1 S1 Q2
S2`, turn end delivers `S1 S2`, and `Q1` waits for the next turn end.

chatstate accepts `steer` here, but nothing sends it yet, so users won't
see a change. Until later in the stack, a few things still ignore the
steer lane:

- An interrupt send goes to the head of the queue lane, so it waits
behind any steer messages. #31155 moves it to the end of the steer lane.
- "Send now" on a running or interrupting chat only moves the message to
the head of its own lane, so when the interruption finishes, the steer
lane goes in instead of it.
- "Send now" on an errored chat, or one waiting on tool results, puts
the message into history straight away, ahead of any queued steer
messages.

#31156 fixes both "Send now" cases by making it steer. None of these can
happen yet, as there are no steer messages to get in the way.

I've added a "Queued message lanes" section to the chatd architecture
doc. Most of the diff is new cases in the transition matrix tests.

Since the first review, lane rule 3 in the architecture doc also says
that delivery stops at a message under edit, and which model and
reasoning effort a batch of delivered messages uses.

Part of CODAGT-1140
ethanndickson added a commit that referenced this pull request Nov 9, 2026
…30074)

This is where the steer lane gets delivered mid-turn. Before each
assistant model call, the generation task now runs
`DeliverSteerMessages`. If there are steer messages queued, they go into
history and the task returns without calling the model, and the history
change starts a new generation task that sends them to the model. It
never cancels anything, it just waits for the in-flight call and that
step's tool calls to finish. Queue messages still wait for turn end, and
compaction calls don't deliver steer messages, as they don't answer the
user.

A delivered steer message is a new prompt, so tracing treats it like any
other newer prompt: a new `chat_turn` span starts at it, and the span
before it ends as `abandoned`.

`chatd.SendMessage` now accepts `steer`, but the HTTP handler and
`message_agent` still only pass `queue` or `interrupt`, so the API
doesn't change in this PR. #31174 makes `steer` the API default. Outside
of tests, nothing creates steer messages until #31155 stores interrupt
sends in the steer lane, so this PR doesn't change behaviour for users
on its own.

I've split the earlier version of this PR up, so some of the review
comments are now addressed elsewhere in the stack. #31153 moves queue
delivery into one helper, #31154 adds the two lanes, #31155 stores
interrupt sends in the steer lane, and #31156 makes "Send now" steer,
which also fixes two presses being delivered in reverse order.

This supersedes #29784.

Since the first review, a steer message delivered before a model call
also records `queue_wait`, like the other delivery points.

Part of CODAGT-1140
ethanndickson added a commit that referenced this pull request Nov 9, 2026
An interrupt send to a running or interrupting chat now goes to the end
of the steer lane, and the whole steer lane goes in once the
interruption finishes. Before, it went to the head of the queue lane if
it started the interruption, or the tail if the chat was already
interrupting, and only the head went in. So if you sent two messages
with interrupt whilst the agent was stopping, the second one went to the
back of the queue. Now both go in once it stops, in the order you sent
them.

Interrupt is still a send option here, it just means "interrupt, then
steer" now. #31174 removes it from the API and #31175 from
`message_agent`, so you call the interrupt endpoint first, then send.

There's one gap until #31156. "Send now" still only moves a message to
the head of its own lane, so if you send with interrupt and then press
"Send now" on a queued message before the agent stops, only the steer
lane goes in when it stops, and the "Send now" message waits for the
next turn end. #31156 makes "Send now" steer too, so both go in.

The `codersdk` change is just the doc comment on
`ChatBusyBehaviorInterrupt`.

Part of CODAGT-1140
ethanndickson added a commit that referenced this pull request Nov 9, 2026
The site has never sent a `busy_behavior`, so since #31174 a message
sent whilst the agent is working already steers. This catches the UI up.
The send button now just says "Send" whilst the agent is busy, instead
of "Queue", and the queued messages list groups rows by lane, "Next
step" for steer messages and "After turn" for queue messages, in the
order they'll be delivered. Queue messages can still come from the API
or MCP, there's just no way to make one from the site.

"Send now" moves a row to the end of the "Next step" group instead of
hiding it, and the row leaves the list once the server delivers it. That
gets rid of the separate set of hidden "Send now" rows in the chat
store. When a send delivers queued messages, e.g. on an errored chat,
reconciliation now removes the rows named by `queued_message_id` on the
inserted messages, instead of assuming it was the queue head. The store
also compares queued rows by ID and lane, so a row that only moves to
the other lane still re-renders.

Removing a queued message now ignores a 404, as the message may have
been delivered or removed in the meantime.

Since #31156, "Send now" doesn't interrupt, so on a running chat it no
longer clears the live stream or sets the status. Whilst the agent is
working, a "Next step" row already goes in before the next model call,
so we hide its "Send now", and Enter on an empty composer doesn't send a
steer head either. The docs now describe the two groups and "Send now".

Part of CODAGT-1140
@ethanndickson ethanndickson added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label Nov 9, 2026
@github-actions github-actions Bot changed the title feat(coderd): steer queued messages on Send now feat(coderd)!: steer queued messages on Send now Nov 9, 2026
@coderagents

coderagents Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Blocking

  • docs/coder-agents/index.md (open) - The "Message queuing" section teaches the edit control for queued messages but never mentions the Send now (promote) control this PR changes. Send now moves a queued message to the end of the steer lane and no longer interrupts the agent, but no page tells a reader that. Add a sentence: "You can also select Send now on a queued message to deliver it before the messages queued behind it, without interrupting the agent's current work."
  • docs/coder-agents/architecture.md (open) - The "Message queuing" section describes deliver-on-turn-completion but never introduces the steer lane or the Send now (promote) action that sends a message ahead of the queue without interrupting. Add a note after describing queued delivery that a queued message can be promoted ("Send now") to be delivered before the messages behind it, without interrupting the agent.
Findings for agents
- id: doc-check-learner-001
  persona: learner
  class: missing
  blocking: true
  file: docs/coder-agents/index.md
  line: 127
  quote: "Users can edit a queued message before it is delivered."
  evidence:
    - coderd/x/chatd/chat_mutations.go:736 (PromoteQueued calls tx.SteerQueuedMessage)
    - coderd/x/chatd/chatstate/transitions.go:1286 (SteerQueuedMessage moves the target behind existing steer rows and never sets the chat interrupting)
    - git diff f5ab996dfd..7b15d1581a -- coderd/x/chatd/chat_mutations.go (PromoteQueued switched from tx.PromoteQueuedMessage, which set ChatStatusInterrupting, to tx.SteerQueuedMessage, which never interrupts)
  rule: null
  problem: A reader learning the queue-control section can discover they can edit a queued message but cannot discover the "Send now" (promote) control, or that Send now no longer interrupts the agent's current work.
  fix: "You can also select **Send now** on a queued message to deliver it before the messages queued behind it, without interrupting the agent's current work."
  verified: true
- id: doc-check-learner-002
  persona: learner
  class: missing
  blocking: true
  file: docs/coder-agents/architecture.md
  line: 95
  quote: "Messages are queued in the database and delivered when the agent completes its current turn (the full sequence of steps until the model stops calling tools)."
  evidence:
    - coderd/x/chatd/chatstate/transitions.go:1286 (SteerQueuedMessage)
  rule: null
  problem: The architecture page explains the delivery model for queued messages on turn completion but never introduces the steer lane or the Send now (promote) control that sends a message ahead of the waiting queue without interrupting the agent.
  fix: "After describing queued delivery, note that a queued message can be promoted (\"Send now\") to be delivered before the messages behind it, and that this does not interrupt the agent."
  verified: true

Automated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release/breaking This label is applied to PRs to detect breaking changes as part of the release process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants