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:
1 parent
5139adf915
commit
f549045ed2
5 files changed
+50
-10
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in new issue
Block a user