From ace0bcf316cbd1089d68071c52bbd2254423538e Mon Sep 17 00:00:00 2001
From: "Bingxi Zhao (Frank)" <13051345080@163.com>
Date: Tue, 1 Sep 2026 18:31:20 +0800
Subject: [PATCH] feat(web): expose safe multi-worker runtime health
---
web/app/(utility)/settings/network/page.tsx | 26 +++
.../settings/SettingsStatusPanel.tsx | 6 +
.../runtime-status/RuntimeHealthCard.tsx | 128 ++++++++++++++
.../TurnCoordinationSettings.tsx | 142 ++++++++++++++++
web/features/runtime-status/api.ts | 13 ++
web/features/runtime-status/index.ts | 16 ++
web/features/runtime-status/model.ts | 159 ++++++++++++++++++
.../runtime-status/useRuntimeStatus.ts | 98 +++++++++++
web/locales/en/app.json | 42 ++++-
web/locales/zh/app.json | 42 ++++-
web/tests/integration/runtime-health.spec.tsx | 82 +++++++++
web/tests/runtime-status.test.ts | 88 ++++++++++
12 files changed, 840 insertions(+), 2 deletions(-)
create mode 100644 web/features/runtime-status/RuntimeHealthCard.tsx
create mode 100644 web/features/runtime-status/TurnCoordinationSettings.tsx
create mode 100644 web/features/runtime-status/api.ts
create mode 100644 web/features/runtime-status/index.ts
create mode 100644 web/features/runtime-status/model.ts
create mode 100644 web/features/runtime-status/useRuntimeStatus.ts
create mode 100644 web/tests/integration/runtime-health.spec.tsx
create mode 100644 web/tests/runtime-status.test.ts
diff --git a/web/app/(utility)/settings/network/page.tsx b/web/app/(utility)/settings/network/page.tsx
index 84c805175..e62989be8 100644
--- a/web/app/(utility)/settings/network/page.tsx
+++ b/web/app/(utility)/settings/network/page.tsx
@@ -19,6 +19,11 @@ import {
writeStoredChatResponseTimeout,
} from "@/context/app-shell-storage";
import { apiFetch, apiUrl } from "@/lib/api";
+import {
+ RuntimeHealthCard,
+ TurnCoordinationSettings,
+ useRuntimeStatus,
+} from "@/features/runtime-status";
type NetworkSettings = {
backend_port: number;
@@ -210,6 +215,7 @@ function ChatResponseTimeoutSection() {
export default function NetworkSettingsPage() {
const { t } = useTranslation();
+ const runtime = useRuntimeStatus();
const { registerExtension, pendingExtensionPayload, draftRevision } =
useSettings();
const apiBasePlaceholder = "https://api.example.com";
@@ -328,6 +334,26 @@ export default function NetworkSettingsPage() {
{t("Network changes take effect after restart.")}
+
+
+ {runtime.data ? (
+
+ ) : null}
+
+
{loading && (
diff --git a/web/components/settings/SettingsStatusPanel.tsx b/web/components/settings/SettingsStatusPanel.tsx
index 9943fba61..603e5cedd 100644
--- a/web/components/settings/SettingsStatusPanel.tsx
+++ b/web/components/settings/SettingsStatusPanel.tsx
@@ -5,6 +5,10 @@ import { useTranslation } from "react-i18next";
import MemoryUsageItem from "@/components/settings/MemoryUsageItem";
import { useSettings } from "@/components/settings/SettingsContext";
import { statusDotClass } from "@/components/settings/shared";
+import {
+ RuntimeHealthCard,
+ useRuntimeStatus,
+} from "@/features/runtime-status";
/**
* Resident status module on the settings hub — the old `/settings/status` page
@@ -21,6 +25,7 @@ import { statusDotClass } from "@/components/settings/shared";
export default function SettingsStatusPanel() {
const { t } = useTranslation();
const { status } = useSettings();
+ const runtime = useRuntimeStatus();
const online = status?.backend.status === "online";
@@ -42,6 +47,7 @@ export default function SettingsStatusPanel() {
+
);
diff --git a/web/features/runtime-status/RuntimeHealthCard.tsx b/web/features/runtime-status/RuntimeHealthCard.tsx
new file mode 100644
index 000000000..afeacb546
--- /dev/null
+++ b/web/features/runtime-status/RuntimeHealthCard.tsx
@@ -0,0 +1,128 @@
+"use client";
+
+import { RefreshCw, ServerCog } from "lucide-react";
+import { useTranslation } from "react-i18next";
+import { Button, InlineAlert, Skeleton, StatusChip, type StatusTone } from "@/shared/ui";
+import type { RuntimeHealth, RuntimeStatusSnapshot } from "./model";
+
+export interface RuntimeHealthCardProps {
+ snapshot: RuntimeStatusSnapshot;
+ onRefresh?: () => void | Promise;
+ showDetails?: boolean;
+ compact?: boolean;
+}
+
+const tone: Record = {
+ healthy: "success",
+ degraded: "warning",
+ recovering: "warning",
+ unavailable: "danger",
+};
+
+export function RuntimeHealthCard({
+ snapshot,
+ onRefresh,
+ showDetails = false,
+ compact = false,
+}: RuntimeHealthCardProps) {
+ const { t } = useTranslation();
+ const label = {
+ healthy: t("Healthy"),
+ degraded: t("Degraded"),
+ recovering: t("Recovering"),
+ unavailable: t("Unavailable"),
+ }[snapshot.health];
+
+ if (snapshot.loading && !snapshot.data) {
+ return compact ? : ;
+ }
+
+ if (compact) {
+ return (
+
+ {t("Turn runtime")}
+ {label}
+
+ );
+ }
+
+ const status = snapshot.data;
+ return (
+
+
+
+
+
+
+
+
+
+ {t("Turn runtime")}
+
+ {label}
+
+
+ {healthDescription(snapshot.health, t)}
+
+
+
+ {onRefresh ? (
+
+ ) : null}
+
+
+ {snapshot.error ? (
+
+ {status
+ ? t("The latest refresh failed. Showing the last safe snapshot.")
+ : t("Runtime health could not be loaded.")}
+
+ ) : null}
+
+ {status && showDetails ? (
+
+
+
+
+
+
+
+
+
+
+ ) : null}
+
+ );
+}
+
+function Metric({ label, value }: { label: string; value: string }) {
+ return (
+
+
{label}
+
+ {value}
+
+
+ );
+}
+
+function redisLabel(status: "ok" | "unavailable" | "not_configured", t: (key: string) => string) {
+ if (status === "ok") return t("Connected");
+ if (status === "unavailable") return t("Unavailable");
+ return t("Not configured");
+}
+
+function healthDescription(health: RuntimeHealth, t: (key: string) => string) {
+ if (health === "healthy") return t("Turn ownership and recovery services are operating normally.");
+ if (health === "recovering") return t("The runtime is reconciling interrupted work.");
+ if (health === "degraded") return t("Turn coordination needs operator attention.");
+ return t("The runtime status endpoint is not available.");
+}
diff --git a/web/features/runtime-status/TurnCoordinationSettings.tsx b/web/features/runtime-status/TurnCoordinationSettings.tsx
new file mode 100644
index 000000000..9704ff74d
--- /dev/null
+++ b/web/features/runtime-status/TurnCoordinationSettings.tsx
@@ -0,0 +1,142 @@
+"use client";
+
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import { Button, Field, InlineAlert } from "@/shared/ui";
+import {
+ validateTurnCoordination,
+ type TurnCoordinationDraft,
+} from "./model";
+
+export interface TurnCoordinationSettingsProps {
+ value: TurnCoordinationDraft;
+ redisConfigured: boolean;
+ onChange?: (next: TurnCoordinationDraft) => void;
+ onSaveRedisUrl?: (url: string) => Promise;
+}
+
+const controlClass =
+ "min-h-10 w-full rounded-xl border border-border bg-background px-3 text-sm text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-60";
+
+export function TurnCoordinationSettings({
+ value,
+ redisConfigured,
+ onChange,
+ onSaveRedisUrl,
+}: TurnCoordinationSettingsProps) {
+ const { t } = useTranslation();
+ const [redisUrl, setRedisUrl] = useState("");
+ const [savingSecret, setSavingSecret] = useState(false);
+ const [secretError, setSecretError] = useState("");
+ const errors = validateTurnCoordination(value, redisConfigured);
+ const readOnly = !onChange;
+ const update = (patch: Partial) => onChange?.({ ...value, ...patch });
+
+ const saveSecret = async () => {
+ if (!onSaveRedisUrl || !redisUrl.trim()) return;
+ setSavingSecret(true);
+ setSecretError("");
+ try {
+ await onSaveRedisUrl(redisUrl.trim());
+ setRedisUrl("");
+ } catch (error) {
+ setSecretError(error instanceof Error ? error.message : t("Failed to save."));
+ } finally {
+ setSavingSecret(false);
+ }
+ };
+
+ return (
+
+ );
+}
diff --git a/web/features/runtime-status/api.ts b/web/features/runtime-status/api.ts
new file mode 100644
index 000000000..75852ce09
--- /dev/null
+++ b/web/features/runtime-status/api.ts
@@ -0,0 +1,13 @@
+import { requestJson } from "@/shared/api/client";
+import { parseRuntimeStatus, type RuntimeStatusModel } from "./model";
+
+export const RUNTIME_STATUS_PATH = "/api/v1/system/runtime";
+
+export async function fetchRuntimeStatus(signal?: AbortSignal): Promise {
+ const payload = await requestJson(RUNTIME_STATUS_PATH, {
+ cache: "no-store",
+ signal,
+ scope: "runtime",
+ });
+ return parseRuntimeStatus(payload);
+}
diff --git a/web/features/runtime-status/index.ts b/web/features/runtime-status/index.ts
new file mode 100644
index 000000000..7bff9de16
--- /dev/null
+++ b/web/features/runtime-status/index.ts
@@ -0,0 +1,16 @@
+export { fetchRuntimeStatus, RUNTIME_STATUS_PATH } from "./api";
+export {
+ parseRuntimeStatus,
+ runtimeHealth,
+ validateTurnCoordination,
+ UnsafeRuntimePayloadError,
+} from "./model";
+export type {
+ RuntimeHealth,
+ RuntimeStatusModel,
+ RuntimeStatusSnapshot,
+ TurnCoordinationDraft,
+} from "./model";
+export { RuntimeHealthCard } from "./RuntimeHealthCard";
+export { TurnCoordinationSettings } from "./TurnCoordinationSettings";
+export { refreshRuntimeStatus, useRuntimeStatus } from "./useRuntimeStatus";
diff --git a/web/features/runtime-status/model.ts b/web/features/runtime-status/model.ts
new file mode 100644
index 000000000..39f1e1ae5
--- /dev/null
+++ b/web/features/runtime-status/model.ts
@@ -0,0 +1,159 @@
+export type RuntimeHealth = "healthy" | "degraded" | "recovering" | "unavailable";
+
+export interface RuntimeStatusModel {
+ workerId: string;
+ workerCount: number;
+ coordinationMode: "memory" | "redis";
+ redisConfigured: boolean;
+ redisStatus: "ok" | "unavailable" | "not_configured";
+ leaderId: string | null;
+ leaderHealthy: boolean | null;
+ ownerTurnCount: number;
+ recoveryBacklog: number;
+ leaseTtlSeconds: number;
+ renewIntervalSeconds: number;
+ recoveryIntervalSeconds: number;
+ protocolVersion: string;
+ minimumWebProtocolVersion: string;
+}
+
+export interface RuntimeStatusSnapshot {
+ data: RuntimeStatusModel | null;
+ health: RuntimeHealth;
+ error: string | null;
+ loading: boolean;
+ lastUpdated: number | null;
+}
+
+const SECRET_KEY = /(?:password|passwd|secret|token|credential|api[_-]?key|redis[_-]?url|dsn)/i;
+
+export class UnsafeRuntimePayloadError extends Error {
+ constructor() {
+ super("Runtime status contained a credential-like field");
+ this.name = "UnsafeRuntimePayloadError";
+ }
+}
+
+function hasCredentialLikeKey(value: unknown, seen = new Set