feat: add healthy filter for workspace queries (#21743)

Adds support for filtering workspaces by health status using
healthy:true or healthy:false in the search query.

This is done by changing `has-agent` to accept a list of statuses and
aliasing `health:true` to `has-agent:connected` and `healthy:false` to
`has-agent:timeout,disconnected`.

Fixes #21623
This commit is contained in:
Jon Ayers
2026-02-04 20:48:27 -06:00
committed by GitHub
parent 984e363180
commit 22ece10a4a
11 changed files with 209 additions and 19 deletions
+4 -3
View File
@@ -292,7 +292,7 @@ WHERE
-- Filter by agent status
-- has-agent: is only applicable for workspaces in "start" transition. Stopped and deleted workspaces don't have agents.
AND CASE
WHEN @has_agent :: text != '' THEN
WHEN array_length(@has_agent_statuses :: text[], 1) > 0 THEN
(
SELECT COUNT(*)
FROM
@@ -306,7 +306,7 @@ WHERE
latest_build.transition = 'start'::workspace_transition AND
-- Filter out deleted sub agents.
workspace_agents.deleted = FALSE AND
@has_agent = (
(
CASE
WHEN workspace_agents.first_connected_at IS NULL THEN
CASE
@@ -324,7 +324,7 @@ WHERE
ELSE
NULL
END
)
) = ANY(@has_agent_statuses :: text[])
) > 0
ELSE true
END
@@ -389,6 +389,7 @@ WHERE
workspaces.group_acl ? (@shared_with_group_id :: uuid) :: text
ELSE true
END
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
-- @authorize_filter
), filtered_workspaces_order AS (