mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: remove unused chat statuses pending, paused, and completed (#27064)
The chatd state machine only recognizes `waiting`, `running`, `error`, `requires_action`, and `interrupting`. Remove the unused `pending`, `paused`, and `completed` values from the database enum, backend, SDK, frontend, generated queries, and API docs. Migration `000543_chat_status_remove_unused` remaps existing `pending` rows to `running`, remaps `paused` and `completed` rows to `waiting`, drops the obsolete `idx_chats_pending` index, and recreates `chats_expanded` around the enum swap. It also removes the dead `AcquireChats` query and all remaining query literals for the deleted statuses. **NOTE**: The enum swap can break chat queries from older replicas during a mixed-version rollout because they still reference `'pending'::chat_status`. Chats are experimental, so this PR accepts that limited rollout window instead of adding a two-release expand and contract sequence. > This PR was authored by Mux (AI agent) on Mike's behalf.
This commit is contained in:
@@ -1469,7 +1469,7 @@ UPDATE chats
|
||||
SET context_dirty_since = @dirty_since
|
||||
WHERE agent_id = @agent_id::uuid
|
||||
AND archived = false
|
||||
AND status IN ('waiting', 'running', 'paused', 'pending', 'requires_action')
|
||||
AND status IN ('waiting', 'running', 'requires_action')
|
||||
AND context_aggregate_hash IS NOT NULL
|
||||
AND context_aggregate_hash IS DISTINCT FROM @aggregate_hash
|
||||
AND context_dirty_since IS NULL
|
||||
@@ -1540,90 +1540,6 @@ SELECT
|
||||
(SELECT COUNT(*)::int FROM genuinely_new) -
|
||||
(SELECT COUNT(*)::int FROM inserted) AS rejected_new_files;
|
||||
|
||||
-- name: AcquireChats :many
|
||||
-- Acquires up to @num_chats pending chats for processing. Uses SKIP LOCKED
|
||||
-- to prevent multiple replicas from acquiring the same chat.
|
||||
WITH acquired_chats AS (
|
||||
UPDATE
|
||||
chats
|
||||
SET
|
||||
status = 'running'::chat_status,
|
||||
started_at = @started_at::timestamptz,
|
||||
heartbeat_at = @started_at::timestamptz,
|
||||
updated_at = @started_at::timestamptz,
|
||||
worker_id = @worker_id::uuid
|
||||
WHERE
|
||||
id = ANY(
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
chats
|
||||
WHERE
|
||||
status = 'pending'::chat_status
|
||||
AND archived = false
|
||||
ORDER BY
|
||||
updated_at ASC
|
||||
FOR UPDATE
|
||||
SKIP LOCKED
|
||||
LIMIT
|
||||
@num_chats::int
|
||||
)
|
||||
RETURNING *
|
||||
),
|
||||
chats_expanded AS (
|
||||
SELECT
|
||||
acquired_chats.id,
|
||||
acquired_chats.owner_id,
|
||||
acquired_chats.workspace_id,
|
||||
acquired_chats.title,
|
||||
acquired_chats.status,
|
||||
acquired_chats.worker_id,
|
||||
acquired_chats.started_at,
|
||||
acquired_chats.heartbeat_at,
|
||||
acquired_chats.created_at,
|
||||
acquired_chats.updated_at,
|
||||
acquired_chats.parent_chat_id,
|
||||
acquired_chats.root_chat_id,
|
||||
acquired_chats.last_model_config_id,
|
||||
acquired_chats.last_reasoning_effort,
|
||||
acquired_chats.archived,
|
||||
acquired_chats.last_error,
|
||||
acquired_chats.mode,
|
||||
acquired_chats.mcp_server_ids,
|
||||
acquired_chats.labels,
|
||||
acquired_chats.build_id,
|
||||
acquired_chats.agent_id,
|
||||
acquired_chats.pin_order,
|
||||
acquired_chats.last_read_message_id,
|
||||
acquired_chats.dynamic_tools,
|
||||
acquired_chats.organization_id,
|
||||
acquired_chats.plan_mode,
|
||||
acquired_chats.client_type,
|
||||
acquired_chats.last_turn_summary,
|
||||
acquired_chats.snapshot_version,
|
||||
acquired_chats.history_version,
|
||||
acquired_chats.queue_version,
|
||||
acquired_chats.generation_attempt,
|
||||
acquired_chats.retry_state,
|
||||
acquired_chats.retry_state_version,
|
||||
acquired_chats.runner_id,
|
||||
acquired_chats.requires_action_deadline_at,
|
||||
COALESCE(root.user_acl, acquired_chats.user_acl) AS user_acl,
|
||||
COALESCE(root.group_acl, acquired_chats.group_acl) AS group_acl,
|
||||
owner.username AS owner_username,
|
||||
owner.name AS owner_name,
|
||||
acquired_chats.context_aggregate_hash,
|
||||
acquired_chats.context_dirty_since,
|
||||
acquired_chats.context_dirty_resources,
|
||||
acquired_chats.context_error
|
||||
FROM
|
||||
acquired_chats
|
||||
LEFT JOIN chats root ON root.id = COALESCE(acquired_chats.root_chat_id, acquired_chats.parent_chat_id)
|
||||
JOIN visible_users owner ON owner.id = acquired_chats.owner_id
|
||||
)
|
||||
SELECT *
|
||||
FROM chats_expanded;
|
||||
|
||||
-- name: UpdateChatStatus :one
|
||||
WITH updated_chat AS (
|
||||
UPDATE
|
||||
@@ -2534,10 +2450,9 @@ SELECT *
|
||||
FROM chats_expanded
|
||||
WHERE agent_id = @agent_id::uuid
|
||||
AND archived = false
|
||||
-- Active statuses only: waiting, pending, running, paused,
|
||||
-- requires_action.
|
||||
-- Excludes completed and error (terminal states).
|
||||
AND status IN ('waiting', 'running', 'paused', 'pending', 'requires_action')
|
||||
-- Active statuses only: waiting, running, requires_action.
|
||||
-- Excludes error (terminal state) and interrupting.
|
||||
AND status IN ('waiting', 'running', 'requires_action')
|
||||
ORDER BY updated_at DESC;
|
||||
|
||||
-- name: SoftDeleteContextFileMessages :exec
|
||||
@@ -2630,8 +2545,6 @@ WHERE
|
||||
AND chats_expanded.status NOT IN (
|
||||
'running'::chat_status,
|
||||
'interrupting'::chat_status,
|
||||
'pending'::chat_status,
|
||||
'paused'::chat_status,
|
||||
'requires_action'::chat_status
|
||||
)
|
||||
AND COALESCE(activity.last_activity_at, chats_expanded.created_at) < @archive_cutoff::timestamptz
|
||||
@@ -2999,7 +2912,7 @@ WITH to_archive AS (
|
||||
-- Redundant filter helps the planner use the partial index on created_at.
|
||||
AND c.created_at < @archive_cutoff::timestamptz
|
||||
-- New active statuses must be added here to prevent archiving.
|
||||
AND c.status NOT IN ('running', 'pending', 'paused', 'requires_action')
|
||||
AND c.status NOT IN ('running', 'requires_action')
|
||||
AND COALESCE(activity.last_activity_at, c.created_at) < @archive_cutoff::timestamptz
|
||||
-- Sorting by created_at lets Postgres drive the scan from the
|
||||
-- partial index instead of evaluating every LATERAL subquery
|
||||
|
||||
Reference in New Issue
Block a user