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.
This commit is contained in:
yuez committed 2026-10-27 18:07:04 +08:00
1 parent 5139adf915
commit f549045ed2
5 files changed
+50 -10

No files matched your search

+2 -1
View File
@@ -132,10 +132,11 @@ export function AppShell() {
paired, paired,
info: info.data, info: info.data,
infoError: info.isError, infoError: info.isError,
healthError: health.isError,
healthOk, healthOk,
}), }),
); );
}, [healthOk, info.data, info.isError, paired, setServerStatus]); }, [health.isError, healthOk, info.data, info.isError, paired, setServerStatus]);
useEffect(() => { useEffect(() => {
document.body.dataset.page = page; document.body.dataset.page = page;
+9 -3
View File
@@ -10,6 +10,8 @@ export interface ServerStatusInput {
info?: InfoResponse | null; info?: InfoResponse | null;
/** The /info query failed (network error or non-2xx). */ /** The /info query failed (network error or non-2xx). */
infoError?: boolean; 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. */ /** `GET /api/v1/health` → `ok`, `null`/`undefined` while unknown. */
healthOk?: boolean | null; healthOk?: boolean | null;
} }
@@ -24,15 +26,19 @@ export function resolveServerStatus(input: ServerStatusInput): ServerStatusValue
if (input.infoError) { if (input.infoError) {
return "offline"; 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) { if (input.healthOk === false) {
return "degraded"; 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) { if (input.info != null) {
return "online"; 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"; return "unknown";
} }
+7 -1
View File
@@ -91,7 +91,13 @@ export function StatusPage() {
wsState, wsState,
fetchedAt: info.dataUpdatedAt || null, fetchedAt: info.dataUpdatedAt || null,
nameFallback: storedServer?.name || meta?.server?.name, 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 // Background tasks: the live store covers open sessions, the REST session
+12 -3
View File
@@ -8,8 +8,8 @@ import { PageHeader } from "@/components/shared/page-header";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Empty } from "@/components/ui/empty"; import { Empty } from "@/components/ui/empty";
import { toast } from "@/components/ui/toast"; import { toast } from "@/components/ui/toast";
import { deriveServerIdentity, type InfoExtras } from "@/features/status/server"; import { deriveServerIdentity, resolveServerStatus, type InfoExtras } from "@/features/status/server";
import { useInfoQuery, useWorkspacesQuery } from "@/features/status/queries"; import { useHealthQuery, useInfoQuery, useWorkspacesQuery } from "@/features/status/queries";
import { ActivityColumn } from "@/features/workspaces/activity-column"; import { ActivityColumn } from "@/features/workspaces/activity-column";
import { openWorkspace, workspaceSessionCount } from "@/features/workspaces/commands"; import { openWorkspace, workspaceSessionCount } from "@/features/workspaces/commands";
import { NewWorkspaceDialog, type NewWorkspaceInput } from "@/features/workspaces/new-workspace-dialog"; import { NewWorkspaceDialog, type NewWorkspaceInput } from "@/features/workspaces/new-workspace-dialog";
@@ -47,12 +47,14 @@ export function WorkspacesPage() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [dialogOpen, setDialogOpen] = useState(false); const [dialogOpen, setDialogOpen] = useState(false);
const paired = useConnectionStore((state) => state.paired);
const endpoint = useConnectionStore((state) => state.endpoint); const endpoint = useConnectionStore((state) => state.endpoint);
const wsState = useConnectionStore((state) => state.wsState); const wsState = useConnectionStore((state) => state.wsState);
const storedServer = useConnectionStore((state) => state.server); const storedServer = useConnectionStore((state) => state.server);
const workspaces = useWorkspacesQuery(); const workspaces = useWorkspacesQuery();
const info = useInfoQuery(); const info = useInfoQuery();
const health = useHealthQuery(paired);
// Persisted "show N hidden" toggle (localStorage, default off): secondary // Persisted "show N hidden" toggle (localStorage, default off): secondary
// rows (hidden/ghost/temp/…) stay out of the list until asked for. // 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 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({ const server = deriveServerIdentity({
info: info.data as InfoExtras | undefined, info: info.data as InfoExtras | undefined,
endpoint, endpoint,
wsState, wsState,
fetchedAt: info.dataUpdatedAt || null, fetchedAt: info.dataUpdatedAt || null,
nameFallback: storedServer?.name, 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) { async function createWorkspace(input: NewWorkspaceInput) {
+20 -2
View File
@@ -19,7 +19,7 @@ const realisticInfo: InfoResponse = {
}; };
describe("resolveServerStatus", () => { describe("resolveServerStatus", () => {
it("resolves unpaired client to offline", () => { it("resolves unpaired client to offline even when info is present", () => {
const input: ServerStatusInput = { const input: ServerStatusInput = {
paired: false, paired: false,
info: realisticInfo, info: realisticInfo,
@@ -27,15 +27,33 @@ describe("resolveServerStatus", () => {
}; };
expect(resolveServerStatus(input)).toBe("offline"); expect(resolveServerStatus(input)).toBe("offline");
expect(resolveServerStatus({ paired: false })).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 = { const input: ServerStatusInput = {
paired: true, paired: true,
infoError: true, infoError: true,
healthOk: true, healthOk: true,
}; };
expect(resolveServerStatus(input)).toBe("offline"); 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", () => { it("resolves info present + healthOk === false to degraded", () => {