From f549045ed2b46f7d31d5382e9344315a88c081d4 Mon Sep 17 00:00:00 2001 From: yuez Date: Tue, 27 Oct 2026 18:07:04 +0800 Subject: [PATCH] fix(web): degrade server status when the /health probe fails `resolveServerStatus` only degraded on `healthOk === false`, so a /health request that errored outright (network error, 5xx) left the console claiming "online" off a cached /info. Add `healthError` as its own step, ahead of the subsystem check, and feed `health.isError` from the shell, the status page and the workspaces page so all three derive a single verdict. --- web/src/components/app-shell.tsx | 3 ++- web/src/features/status/server.ts | 12 +++++++++--- web/src/pages/status.tsx | 8 +++++++- web/src/pages/workspaces.tsx | 15 ++++++++++++--- web/tests/server-status.test.ts | 22 ++++++++++++++++++++-- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/web/src/components/app-shell.tsx b/web/src/components/app-shell.tsx index 11d469c..a60ec07 100644 --- a/web/src/components/app-shell.tsx +++ b/web/src/components/app-shell.tsx @@ -132,10 +132,11 @@ export function AppShell() { paired, info: info.data, infoError: info.isError, + healthError: health.isError, healthOk, }), ); - }, [healthOk, info.data, info.isError, paired, setServerStatus]); + }, [health.isError, healthOk, info.data, info.isError, paired, setServerStatus]); useEffect(() => { document.body.dataset.page = page; diff --git a/web/src/features/status/server.ts b/web/src/features/status/server.ts index 79321ac..eed21e4 100644 --- a/web/src/features/status/server.ts +++ b/web/src/features/status/server.ts @@ -10,6 +10,8 @@ export interface ServerStatusInput { info?: InfoResponse | null; /** The /info query failed (network error or non-2xx). */ infoError?: boolean; + /** The /health query failed (network error or non-2xx) while the daemon responds. */ + healthError?: boolean; /** `GET /api/v1/health` → `ok`, `null`/`undefined` while unknown. */ healthOk?: boolean | null; } @@ -24,15 +26,19 @@ export function resolveServerStatus(input: ServerStatusInput): ServerStatusValue if (input.infoError) { return "offline"; } - // 3. /health reported a degraded subsystem while the daemon itself responds. + // 3. /health probe failed (network error or 5xx) while the daemon answers. + if (input.healthError) { + return "degraded"; + } + // 4. /health reported a degraded subsystem while the daemon itself responds. if (input.healthOk === false) { return "degraded"; } - // 4. Cached or freshly fetched /info payload is present and healthy. + // 5. Cached or freshly fetched /info payload is present and healthy. if (input.info != null) { return "online"; } - // 5. First probe is still in flight — do not flash offline. + // 6. First probe is still in flight — do not flash offline. return "unknown"; } diff --git a/web/src/pages/status.tsx b/web/src/pages/status.tsx index 5337882..1a16e72 100644 --- a/web/src/pages/status.tsx +++ b/web/src/pages/status.tsx @@ -91,7 +91,13 @@ export function StatusPage() { wsState, fetchedAt: info.dataUpdatedAt || null, nameFallback: storedServer?.name || meta?.server?.name, - status: resolveServerStatus({ paired, info: info.data, infoError: info.isError, healthOk }), + status: resolveServerStatus({ + paired, + info: info.data, + infoError: info.isError, + healthError: health.isError, + healthOk, + }), }); // Background tasks: the live store covers open sessions, the REST session diff --git a/web/src/pages/workspaces.tsx b/web/src/pages/workspaces.tsx index abad3b1..ca5a3f7 100644 --- a/web/src/pages/workspaces.tsx +++ b/web/src/pages/workspaces.tsx @@ -8,8 +8,8 @@ import { PageHeader } from "@/components/shared/page-header"; import { Button } from "@/components/ui/button"; import { Empty } from "@/components/ui/empty"; import { toast } from "@/components/ui/toast"; -import { deriveServerIdentity, type InfoExtras } from "@/features/status/server"; -import { useInfoQuery, useWorkspacesQuery } from "@/features/status/queries"; +import { deriveServerIdentity, resolveServerStatus, type InfoExtras } from "@/features/status/server"; +import { useHealthQuery, useInfoQuery, useWorkspacesQuery } from "@/features/status/queries"; import { ActivityColumn } from "@/features/workspaces/activity-column"; import { openWorkspace, workspaceSessionCount } from "@/features/workspaces/commands"; import { NewWorkspaceDialog, type NewWorkspaceInput } from "@/features/workspaces/new-workspace-dialog"; @@ -47,12 +47,14 @@ export function WorkspacesPage() { const queryClient = useQueryClient(); const [dialogOpen, setDialogOpen] = useState(false); + const paired = useConnectionStore((state) => state.paired); const endpoint = useConnectionStore((state) => state.endpoint); const wsState = useConnectionStore((state) => state.wsState); const storedServer = useConnectionStore((state) => state.server); const workspaces = useWorkspacesQuery(); const info = useInfoQuery(); + const health = useHealthQuery(paired); // Persisted "show N hidden" toggle (localStorage, default off): secondary // rows (hidden/ghost/temp/…) stay out of the list until asked for. @@ -76,13 +78,20 @@ export function WorkspacesPage() { ); const runningCount = useMemo(() => all.filter((workspace) => (workspace.liveCount || 0) > 0).length, [all]); + const healthOk = health.data?.ok ?? (health.data ? health.data.items.every((item) => item.ok) : undefined); const server = deriveServerIdentity({ info: info.data as InfoExtras | undefined, endpoint, wsState, fetchedAt: info.dataUpdatedAt || null, nameFallback: storedServer?.name, - status: info.isError ? "offline" : undefined, + status: resolveServerStatus({ + paired, + info: info.data, + infoError: info.isError, + healthError: health.isError, + healthOk, + }), }); async function createWorkspace(input: NewWorkspaceInput) { diff --git a/web/tests/server-status.test.ts b/web/tests/server-status.test.ts index 524e2cd..c3b48ee 100644 --- a/web/tests/server-status.test.ts +++ b/web/tests/server-status.test.ts @@ -19,7 +19,7 @@ const realisticInfo: InfoResponse = { }; describe("resolveServerStatus", () => { - it("resolves unpaired client to offline", () => { + it("resolves unpaired client to offline even when info is present", () => { const input: ServerStatusInput = { paired: false, info: realisticInfo, @@ -27,15 +27,33 @@ describe("resolveServerStatus", () => { }; expect(resolveServerStatus(input)).toBe("offline"); expect(resolveServerStatus({ paired: false })).toBe("offline"); + expect(resolveServerStatus({ paired: false, info: realisticInfo })).toBe("offline"); }); - it("resolves infoError to offline", () => { + it("resolves infoError to offline, even with stale cached info", () => { const input: ServerStatusInput = { paired: true, infoError: true, healthOk: true, }; expect(resolveServerStatus(input)).toBe("offline"); + expect( + resolveServerStatus({ + paired: true, + info: realisticInfo, + infoError: true, + }), + ).toBe("offline"); + }); + + it("resolves healthError to degraded even when info is present", () => { + expect( + resolveServerStatus({ + paired: true, + info: realisticInfo, + healthError: true, + }), + ).toBe("degraded"); }); it("resolves info present + healthOk === false to degraded", () => {