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

"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
This commit is contained in:
Ethan authored and GitHub committed 2026-11-09 15:55:16 +11:00
1 parent 5138fa300f
commit 63e08e231e
24 files changed
+667 -673

No files matched your search

+11 -12
View File
@@ -7669,18 +7669,6 @@ func (q *querier) ReorderChatQueuedMessageToFront(ctx context.Context, arg datab
return q.db.ReorderChatQueuedMessageToFront(ctx, arg)
}
func (q *querier) ReorderChatQueuedMessageToHead(ctx context.Context, arg database.ReorderChatQueuedMessageToHeadParams) (int64, error) {
chat, err := q.db.GetChatByID(ctx, arg.ChatID)
if err != nil {
return 0, err
}
if err := q.authorizeContext(ctx, policy.ActionUpdate, chat); err != nil {
return 0, err
}
_ = chat
return q.db.ReorderChatQueuedMessageToHead(ctx, arg)
}
func (q *querier) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string) error {
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceSystem); err != nil {
return err
@@ -7771,6 +7759,17 @@ func (q *querier) SoftDeleteWorkspaceAgentsByWorkspaceID(ctx context.Context, wo
return q.db.SoftDeleteWorkspaceAgentsByWorkspaceID(ctx, workspaceID)
}
func (q *querier) SteerChatQueuedMessage(ctx context.Context, arg database.SteerChatQueuedMessageParams) (int64, error) {
chat, err := q.db.GetChatByID(ctx, arg.ChatID)
if err != nil {
return 0, err
}
if err := q.authorizeContext(ctx, policy.ActionUpdate, chat); err != nil {
return 0, err
}
return q.db.SteerChatQueuedMessage(ctx, arg)
}
func (q *querier) SyncAgentChatsContextLiveResources(ctx context.Context, agentID uuid.UUID) ([]uuid.UUID, error) {
// The push can update multiple chats bound to the agent, so authorize the
// chat resource class.
+3 -3
View File
@@ -1775,11 +1775,11 @@ func (s *MethodTestSuite) TestChats() {
dbm.EXPECT().DeleteAllChatQueuedMessagesReturningCount(gomock.Any(), chat.ID).Return(int64(1), nil).AnyTimes()
check.Args(chat.ID).Asserts(chat, policy.ActionUpdate).Returns(int64(1))
}))
s.Run("ReorderChatQueuedMessageToHead", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
s.Run("SteerChatQueuedMessage", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
chat := testutil.Fake(s.T(), faker, database.Chat{})
arg := database.ReorderChatQueuedMessageToHeadParams{ChatID: chat.ID, ID: 1}
arg := database.SteerChatQueuedMessageParams{ChatID: chat.ID, ID: 1}
dbm.EXPECT().GetChatByID(gomock.Any(), chat.ID).Return(chat, nil).AnyTimes()
dbm.EXPECT().ReorderChatQueuedMessageToHead(gomock.Any(), arg).Return(int64(1), nil).AnyTimes()
dbm.EXPECT().SteerChatQueuedMessage(gomock.Any(), arg).Return(int64(1), nil).AnyTimes()
check.Args(arg).Asserts(chat, policy.ActionUpdate).Returns(int64(1))
}))
s.Run("UpdateChatQueuedMessageEditing", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
+8 -8
View File
@@ -5456,14 +5456,6 @@ func (m queryMetricsStore) ReorderChatQueuedMessageToFront(ctx context.Context,
return r0, r1
}
func (m queryMetricsStore) ReorderChatQueuedMessageToHead(ctx context.Context, arg database.ReorderChatQueuedMessageToHeadParams) (int64, error) {
start := time.Now()
r0, r1 := m.s.ReorderChatQueuedMessageToHead(ctx, arg)
m.queryLatencies.WithLabelValues("ReorderChatQueuedMessageToHead").Observe(time.Since(start).Seconds())
m.queryCounts.WithLabelValues(httpmw.ExtractHTTPRoute(ctx), httpmw.ExtractHTTPMethod(ctx), "ReorderChatQueuedMessageToHead").Inc()
return r0, r1
}
func (m queryMetricsStore) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string) error {
start := time.Now()
r0 := m.s.RevokeDBCryptKey(ctx, activeKeyDigest)
@@ -5536,6 +5528,14 @@ func (m queryMetricsStore) SoftDeleteWorkspaceAgentsByWorkspaceID(ctx context.Co
return r0
}
func (m queryMetricsStore) SteerChatQueuedMessage(ctx context.Context, arg database.SteerChatQueuedMessageParams) (int64, error) {
start := time.Now()
r0, r1 := m.s.SteerChatQueuedMessage(ctx, arg)
m.queryLatencies.WithLabelValues("SteerChatQueuedMessage").Observe(time.Since(start).Seconds())
m.queryCounts.WithLabelValues(httpmw.ExtractHTTPRoute(ctx), httpmw.ExtractHTTPMethod(ctx), "SteerChatQueuedMessage").Inc()
return r0, r1
}
func (m queryMetricsStore) SyncAgentChatsContextLiveResources(ctx context.Context, agentID uuid.UUID) ([]uuid.UUID, error) {
start := time.Now()
r0, r1 := m.s.SyncAgentChatsContextLiveResources(ctx, agentID)
+15 -15
View File
@@ -10366,21 +10366,6 @@ func (mr *MockStoreMockRecorder) ReorderChatQueuedMessageToFront(ctx, arg any) *
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReorderChatQueuedMessageToFront", reflect.TypeOf((*MockStore)(nil).ReorderChatQueuedMessageToFront), ctx, arg)
}
// ReorderChatQueuedMessageToHead mocks base method.
func (m *MockStore) ReorderChatQueuedMessageToHead(ctx context.Context, arg database.ReorderChatQueuedMessageToHeadParams) (int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ReorderChatQueuedMessageToHead", ctx, arg)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// ReorderChatQueuedMessageToHead indicates an expected call of ReorderChatQueuedMessageToHead.
func (mr *MockStoreMockRecorder) ReorderChatQueuedMessageToHead(ctx, arg any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ReorderChatQueuedMessageToHead", reflect.TypeOf((*MockStore)(nil).ReorderChatQueuedMessageToHead), ctx, arg)
}
// RevokeDBCryptKey mocks base method.
func (m *MockStore) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string) error {
m.ctrl.T.Helper()
@@ -10508,6 +10493,21 @@ func (mr *MockStoreMockRecorder) SoftDeleteWorkspaceAgentsByWorkspaceID(ctx, wor
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SoftDeleteWorkspaceAgentsByWorkspaceID", reflect.TypeOf((*MockStore)(nil).SoftDeleteWorkspaceAgentsByWorkspaceID), ctx, workspaceID)
}
// SteerChatQueuedMessage mocks base method.
func (m *MockStore) SteerChatQueuedMessage(ctx context.Context, arg database.SteerChatQueuedMessageParams) (int64, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SteerChatQueuedMessage", ctx, arg)
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// SteerChatQueuedMessage indicates an expected call of SteerChatQueuedMessage.
func (mr *MockStoreMockRecorder) SteerChatQueuedMessage(ctx, arg any) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SteerChatQueuedMessage", reflect.TypeOf((*MockStore)(nil).SteerChatQueuedMessage), ctx, arg)
}
// SyncAgentChatsContextLiveResources mocks base method.
func (m *MockStore) SyncAgentChatsContextLiveResources(ctx context.Context, agentID uuid.UUID) ([]uuid.UUID, error) {
m.ctrl.T.Helper()
+1 -3
View File
@@ -1510,9 +1510,6 @@ type sqlcQuerier interface {
// Mutates only created_at on the target row; ids are unchanged so
// consumers can keep tracking queued messages by id.
ReorderChatQueuedMessageToFront(ctx context.Context, arg ReorderChatQueuedMessageToFrontParams) (int64, error)
// Sets the target queued message's position to one less than the
// current minimum position for that chat, moving it to the head.
ReorderChatQueuedMessageToHead(ctx context.Context, arg ReorderChatQueuedMessageToHeadParams) (int64, error)
RevokeDBCryptKey(ctx context.Context, activeKeyDigest string) error
// Note that this selects from the CTE, not the original table. The CTE is named
// the same as the original table to trick sqlc into reusing the existing struct
@@ -1551,6 +1548,7 @@ type sqlcQuerier interface {
// Agent context rows are hard-deleted for the same reason as in
// SoftDeletePriorWorkspaceAgents.
SoftDeleteWorkspaceAgentsByWorkspaceID(ctx context.Context, workspaceID uuid.UUID) error
SteerChatQueuedMessage(ctx context.Context, arg SteerChatQueuedMessageParams) (int64, error)
// MCP and ACP resources bypass context drift and are live-synced on each push.
// Changed chats are locked in ID order so concurrent clear-then-copy re-pins
// cannot interleave with the replacement.
+21 -29
View File
@@ -13375,35 +13375,6 @@ func (q *sqlQuerier) ReorderChatQueuedMessageToFront(ctx context.Context, arg Re
return result.RowsAffected()
}
const reorderChatQueuedMessageToHead = `-- name: ReorderChatQueuedMessageToHead :execrows
UPDATE chat_queued_messages AS target
SET position = COALESCE(
(SELECT MIN(position) FROM chat_queued_messages WHERE chat_id = $1::uuid),
0
) - 1
WHERE target.id = $2::bigint
AND target.chat_id = $1::uuid
AND target.position > COALESCE(
(SELECT MIN(position) FROM chat_queued_messages WHERE chat_id = $1::uuid),
target.position
)
`
type ReorderChatQueuedMessageToHeadParams struct {
ChatID uuid.UUID `db:"chat_id" json:"chat_id"`
ID int64 `db:"id" json:"id"`
}
// Sets the target queued message's position to one less than the
// current minimum position for that chat, moving it to the head.
func (q *sqlQuerier) ReorderChatQueuedMessageToHead(ctx context.Context, arg ReorderChatQueuedMessageToHeadParams) (int64, error) {
result, err := q.db.ExecContext(ctx, reorderChatQueuedMessageToHead, arg.ChatID, arg.ID)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
const setChatContextSnapshot = `-- name: SetChatContextSnapshot :exec
UPDATE chats
SET
@@ -13474,6 +13445,27 @@ func (q *sqlQuerier) SoftDeleteContextFileMessages(ctx context.Context, chatID u
return err
}
const steerChatQueuedMessage = `-- name: SteerChatQueuedMessage :execrows
UPDATE chat_queued_messages
SET position = nextval('chat_queued_messages_position_seq'),
busy_behavior = 'steer'
WHERE id = $1::bigint
AND chat_id = $2::uuid
`
type SteerChatQueuedMessageParams struct {
ID int64 `db:"id" json:"id"`
ChatID uuid.UUID `db:"chat_id" json:"chat_id"`
}
func (q *sqlQuerier) SteerChatQueuedMessage(ctx context.Context, arg SteerChatQueuedMessageParams) (int64, error) {
result, err := q.db.ExecContext(ctx, steerChatQueuedMessage, arg.ID, arg.ChatID)
if err != nil {
return 0, err
}
return result.RowsAffected()
}
const syncAgentChatsContextLiveResources = `-- name: SyncAgentChatsContextLiveResources :many
WITH agent_live AS (
SELECT source, body_kind, body, content_hash, size_bytes, status, error, source_path
+6 -14
View File
@@ -3044,20 +3044,12 @@ SET content = @content::jsonb,
WHERE id = @id::bigint AND chat_id = @chat_id::uuid
RETURNING *;
-- name: ReorderChatQueuedMessageToHead :execrows
-- Sets the target queued message's position to one less than the
-- current minimum position for that chat, moving it to the head.
UPDATE chat_queued_messages AS target
SET position = COALESCE(
(SELECT MIN(position) FROM chat_queued_messages WHERE chat_id = @chat_id::uuid),
0
) - 1
WHERE target.id = @id::bigint
AND target.chat_id = @chat_id::uuid
AND target.position > COALESCE(
(SELECT MIN(position) FROM chat_queued_messages WHERE chat_id = @chat_id::uuid),
target.position
);
-- name: SteerChatQueuedMessage :execrows
UPDATE chat_queued_messages
SET position = nextval('chat_queued_messages_position_seq'),
busy_behavior = 'steer'
WHERE id = @id::bigint
AND chat_id = @chat_id::uuid;
-- name: UpsertChatHeartbeat :exec
-- Upserts a heartbeat row for the (chat_id, runner_id) lease. Uses