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:
1 parent
5138fa300f
commit
63e08e231e
24 files changed
+667
-673
No files matched your search
Generated
+21
-29
@@ -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
|
||||
|
||||
Reference in new issue
Block a user