mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
3011207519
## Problem Tasks currently only expose a machine-friendly name field (e.g. `task-python-debug-a1b2`), but this value is primarily an identifier rather than a clean, descriptive label. We need a separate display-friendly name for use in the UI. This PR introduces a new `display_name` field and updates the task-name generation flow. The Claude system prompt was updated to return valid JSON with both `name` and `display_name`. The name generation logic follows a fallback chain (Anthropic > prompt sanitization > random fallback). To make task names more closely resemble their display names, the legacy `task-` prefix has been removed. For context, PR https://github.com/coder/coder/pull/20834 introduced a small Task icon to the workspace list to help identify workspaces associated to tasks. ## Changes - Database migration: Added `display_name` column to tasks table - Updated system prompt to generate both task name and display name as valid JSON - Task name generation now follows a fallback chain: Anthropic > prompt sanitization > random fallback - Removed `task-` prefix from task names to allow more descriptive names - Note: PR https://github.com/coder/coder/pull/20834 adds a Task icon to workspaces in the workspace list to distinguish task-created workspaces **Note:** UI changes will be addressed in a follow-up PR Related to: https://github.com/coder/coder/issues/20801
88 lines
2.9 KiB
SQL
88 lines
2.9 KiB
SQL
-- Drop view first before removing the display_name column from tasks
|
|
DROP VIEW IF EXISTS tasks_with_status;
|
|
|
|
-- Remove display_name column from tasks
|
|
ALTER TABLE tasks DROP COLUMN display_name;
|
|
|
|
-- Recreate view without the display_name column.
|
|
-- This restores the view to its previous state after removing display_name from tasks.
|
|
CREATE VIEW
|
|
tasks_with_status
|
|
AS
|
|
SELECT
|
|
tasks.*,
|
|
CASE
|
|
WHEN tasks.workspace_id IS NULL OR latest_build.job_status IS NULL THEN 'pending'::task_status
|
|
|
|
WHEN latest_build.job_status = 'failed' THEN 'error'::task_status
|
|
|
|
WHEN latest_build.transition IN ('stop', 'delete')
|
|
AND latest_build.job_status = 'succeeded' THEN 'paused'::task_status
|
|
|
|
WHEN latest_build.transition = 'start'
|
|
AND latest_build.job_status = 'pending' THEN 'initializing'::task_status
|
|
|
|
WHEN latest_build.transition = 'start' AND latest_build.job_status IN ('running', 'succeeded') THEN
|
|
CASE
|
|
WHEN agent_status.none THEN 'initializing'::task_status
|
|
WHEN agent_status.connecting THEN 'initializing'::task_status
|
|
WHEN agent_status.connected THEN
|
|
CASE
|
|
WHEN app_status.any_unhealthy THEN 'error'::task_status
|
|
WHEN app_status.any_initializing THEN 'initializing'::task_status
|
|
WHEN app_status.all_healthy_or_disabled THEN 'active'::task_status
|
|
ELSE 'unknown'::task_status
|
|
END
|
|
ELSE 'unknown'::task_status
|
|
END
|
|
|
|
ELSE 'unknown'::task_status
|
|
END AS status,
|
|
task_app.*,
|
|
task_owner.*
|
|
FROM
|
|
tasks
|
|
CROSS JOIN LATERAL (
|
|
SELECT
|
|
vu.username AS owner_username,
|
|
vu.name AS owner_name,
|
|
vu.avatar_url AS owner_avatar_url
|
|
FROM visible_users vu
|
|
WHERE vu.id = tasks.owner_id
|
|
) task_owner
|
|
LEFT JOIN LATERAL (
|
|
SELECT workspace_build_number, workspace_agent_id, workspace_app_id
|
|
FROM task_workspace_apps task_app
|
|
WHERE task_id = tasks.id
|
|
ORDER BY workspace_build_number DESC
|
|
LIMIT 1
|
|
) task_app ON TRUE
|
|
LEFT JOIN LATERAL (
|
|
SELECT
|
|
workspace_build.transition,
|
|
provisioner_job.job_status,
|
|
workspace_build.job_id
|
|
FROM workspace_builds workspace_build
|
|
JOIN provisioner_jobs provisioner_job ON provisioner_job.id = workspace_build.job_id
|
|
WHERE workspace_build.workspace_id = tasks.workspace_id
|
|
AND workspace_build.build_number = task_app.workspace_build_number
|
|
) latest_build ON TRUE
|
|
CROSS JOIN LATERAL (
|
|
SELECT
|
|
COUNT(*) = 0 AS none,
|
|
bool_or(workspace_agent.lifecycle_state IN ('created', 'starting')) AS connecting,
|
|
bool_and(workspace_agent.lifecycle_state = 'ready') AS connected
|
|
FROM workspace_agents workspace_agent
|
|
WHERE workspace_agent.id = task_app.workspace_agent_id
|
|
) agent_status
|
|
CROSS JOIN LATERAL (
|
|
SELECT
|
|
bool_or(workspace_app.health = 'unhealthy') AS any_unhealthy,
|
|
bool_or(workspace_app.health = 'initializing') AS any_initializing,
|
|
bool_and(workspace_app.health IN ('healthy', 'disabled')) AS all_healthy_or_disabled
|
|
FROM workspace_apps workspace_app
|
|
WHERE workspace_app.id = task_app.workspace_app_id
|
|
) app_status
|
|
WHERE
|
|
tasks.deleted_at IS NULL;
|