Repository navigation
feat(coderd)!: steer queued messages on Send now - #31156
ethanndickson merged 4 commits into
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
|
@codex review re: Cancel every outstanding call before resuming A1 Not valid. chatd never puts a chat in |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
3061933 to
f8d28a0
Compare
f8d28a0 to
1d2e485
Compare
1d2e485 to
e110fd2
Compare
40e674a to
bcca889
Compare
bcca889 to
a6268d9
Compare
a9061b0 to
3677027
Compare
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
mafredri
left a comment
There was a problem hiding this comment.
A couple more comments above, but otherwise LGTM
0e3b3eb to
f8f39e1
Compare
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.
…ed queued messages
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.
f8f39e1 to
7b15d15
Compare
…ueue-stack chore: merge upstream queue stack (coder#31156)
…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
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
…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
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
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
Documentation CheckBlocking
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: trueAutomated review via Coder Agents. Reply to a finding's thread with the reason if the finding is wrong. |
Breaking API Change for changelog:
"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 withMIN(position) - 1, so if you pressed "Send now" on two messages, the second one went first. With a queue ofQ1 Q2 Q3 S4, "Send now" onQ1thenQ3now deliversS4 Q1 Q3, andQ2keeps 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,
SteerQueuedMessagereplacesPromoteQueuedMessage. 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. TheSteerChatQueuedMessagequery setsposition = nextval(...)and replacesReorderChatQueuedMessageToHead. Most of the diff is tests.#31174 then makes
steerthe API default and removesinterruptas a busy behaviour, #31175 makesmessage_agentalways steer, and #31173 updates the site.Part of CODAGT-1140