Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(runtimes): show online machine count in sidebar (#9943)
Bohan Jiang2ae2f08005f0
diff --git a/packages/views/layout/panels/team-panel.test.tsx b/packages/views/layout/panels/team-panel.test.tsxnew file mode 100644index 0000000000..45cd628b2e--- /dev/null+++ b/packages/views/layout/panels/team-panel.test.tsx@@ -0,0 +1,182 @@+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { act, screen, waitFor, within } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { agentTaskSnapshotOptions } from "@multica/core/agents";+import { api } from "@multica/core/api";+import { createAuthStore, registerAuthStore } from "@multica/core/auth";+import { WorkspaceSlugProvider } from "@multica/core/paths";+import { runtimeListOptions } from "@multica/core/runtimes/queries";+import type { AgentRuntime } from "@multica/core/types";+import {+ agentListOptions,+ memberListOptions,+ skillListOptions,+ squadListOptions,+ workspaceListOptions,+} from "@multica/core/workspace/queries";+import { NavigationProvider, type NavigationAdapter } from "../../navigation";+import { renderWithI18n } from "../../test/i18n";+import { TeamPanel } from "./team-panel";++const WS = "ws-test";+const NOW = Date.parse("2026-11-04T08:00:00Z");+const adapter: NavigationAdapter = {+ push: vi.fn(),+ replace: vi.fn(),+ back: vi.fn(),+ pathname: "/acme/runtimes",+ searchParams: new URLSearchParams(),+ hash: "",+ getShareableUrl: (path) => path,+};++function runtime(overrides: Partial<AgentRuntime> = {}): AgentRuntime {+ return {+ id: "rt-online",+ workspace_id: WS,+ daemon_id: "daemon-1",+ name: "Claude (dev.local)",+ runtime_mode: "local",+ provider: "claude",+ launch_header: "",+ status: "online",+ device_info: "dev.local",+ metadata: {},+ owner_id: "user-1",+ visibility: "private",+ last_seen_at: new Date(NOW - 42 * 60_000).toISOString(),+ created_at: new Date(NOW - 60 * 60_000).toISOString(),+ updated_at: new Date(NOW - 60 * 60_000).toISOString(),+ ...overrides,+ };+}++let qc: QueryClient;++beforeEach(() => {+ vi.spyOn(Date, "now").mockReturnValue(NOW);+ registerAuthStore(+ createAuthStore({+ api,+ storage: { getItem: () => null, setItem: () => {}, removeItem: () => {} },+ }),+ );+ qc = new QueryClient({+ defaultOptions: { queries: { retry: false, staleTime: Infinity } },+ });+ qc.setQueryData(workspaceListOptions().queryKey, [{+ id: WS,+ name: "Acme",+ slug: "acme",+ description: null,+ context: null,+ settings: {},+ repos: [],+ issue_prefix: "ACM",+ avatar_url: null,+ created_at: new Date(NOW).toISOString(),+ updated_at: new Date(NOW).toISOString(),+ }]);+ for (const options of [+ agentListOptions(WS),+ agentTaskSnapshotOptions(WS),+ memberListOptions(WS),+ skillListOptions(WS),+ squadListOptions(WS),+ ]) {+ qc.setQueryData(options.queryKey, []);+ }+});++afterEach(() => {+ qc.clear();+ vi.restoreAllMocks();+});++function renderPanel(runtimes: AgentRuntime[]) {+ qc.setQueryData(runtimeListOptions(WS).queryKey, runtimes);+ renderWithI18n(+ <QueryClientProvider client={qc}>+ <WorkspaceSlugProvider slug="acme">+ <NavigationProvider value={adapter}>+ <TeamPanel />+ </NavigationProvider>+ </WorkspaceSlugProvider>+ </QueryClientProvider>,+ );+}++describe("TeamPanel runtime badge", () => {+ it("shows a green online machine count without a total or duplicate providers", () => {+ renderPanel([+ ...Array.from({ length: 4 }, (_, index) => [+ runtime({ id: `online-${index}`, daemon_id: `daemon-${index}` }),+ runtime({ id: `online-codex-${index}`, daemon_id: `daemon-${index}`, provider: "codex" }),+ ]).flat(),+ ...Array.from({ length: 4 }, (_, index) =>+ runtime({+ id: `stale-${index}`,+ daemon_id: `daemon-${index}`,+ provider: "copilot",+ status: "offline",+ }),+ ),+ runtime({ id: "offline-claude", daemon_id: "daemon-offline", status: "offline" }),+ runtime({+ id: "offline-codex",+ daemon_id: "daemon-offline",+ provider: "codex",+ status: "offline",+ }),+ ]);++ const link = screen.getByRole("link", { name: /^Runtimes/ });+ expect(within(link).getByText("4 online")).toHaveClass("text-success");+ expect(link).not.toHaveTextContent(/offline|\//);+ });++ it("updates the count and warning when the last online provider disconnects and reconnects", async () => {+ const online = runtime();+ const stale = runtime({ id: "rt-stale", provider: "codex", status: "offline" });+ renderPanel([online, stale]);+ const link = screen.getByRole("link", { name: /^Runtimes/ });++ expect(within(link).getByText("1 online")).toHaveClass("text-success");++ act(() => {+ qc.setQueryData(runtimeListOptions(WS).queryKey, [{ ...online, status: "offline" }, stale]);+ });+ await waitFor(() => {+ expect(within(link).getByText("0 online")).toHaveClass("text-warning");+ });++ act(() => {+ qc.setQueryData(runtimeListOptions(WS).queryKey, [online, stale]);+ });+ await waitFor(() => {+ expect(within(link).getByText("1 online")).toHaveClass("text-success");+ });+ });++ it("does not count Qoder cloud services as machines", () => {+ renderPanel([+ runtime(),+ runtime({+ id: "rt-qoder-cloud",+ daemon_id: "qoder-daemon",+ provider: "qoder_cloud",+ runtime_mode: "cloud",+ }),+ ]);++ const link = screen.getByRole("link", { name: /^Runtimes/ });+ expect(within(link).getByText("1 online")).toHaveClass("text-success");+ });++ it("hides the badge when there are no machines", () => {+ renderPanel([]);++ expect(screen.getByRole("link", { name: "Runtimes" })).toBeInTheDocument();+ expect(screen.queryByText(/online|offline/)).not.toBeInTheDocument();+ });+});diff --git a/packages/views/layout/panels/team-panel.tsx b/packages/views/layout/panels/team-panel.tsxindex 745b7d0637..b6b02f0772 100644--- a/packages/views/layout/panels/team-panel.tsx+++ b/packages/views/layout/panels/team-panel.tsx@@ -11,7 +11,6 @@ import { useAgentsViewStore } from "@multica/core/agents/stores";import { useAuthStore } from "@multica/core/auth";import { issueDetailOptions } from "@multica/core/issues/queries";import { useCurrentWorkspace, useWorkspacePaths } from "@multica/core/paths";-import { deriveRuntimeHealth } from "@multica/core/runtimes";import { runtimeListOptions } from "@multica/core/runtimes/queries";import { memberListOptions, skillListOptions, squadListOptions } from "@multica/core/workspace/queries";import { resolvePublicFileUrl } from "@multica/core/workspace/avatar-url";@@ -19,6 +18,7 @@ import type { Agent, AgentTask } from "@multica/core/types";import { useNavigation } from "../../navigation";import { availabilityConfig } from "../../agents/presence";import { useT } from "../../i18n";+import { buildRuntimeMachines, runtimeMachineCounts } from "../../runtimes/components/runtime-machines";import {PanelBody,PanelCount,@@ -119,12 +119,11 @@ export function TeamPanel() {const { data: members = [] } = useQuery({ ...memberListOptions(wsId), enabled: !!wsId });const { data: skills = [] } = useQuery({ ...skillListOptions(wsId), enabled: !!wsId });const { data: runtimes = [] } = useQuery({ ...runtimeListOptions(wsId), enabled: !!wsId });- const offlineRuntimes = useMemo(() => {- const now = Date.now();- return runtimes.filter((runtime) => {- const health = deriveRuntimeHealth(runtime, now);- return health === "offline" || health === "long_offline";- }).length;+ const machineCounts = useMemo(() => {+ const machines = buildRuntimeMachines(runtimes, { now: Date.now() }).filter(+ (machine) => !machine.runtimes.every((runtime) => runtime.provider === "qoder_cloud"),+ );+ return runtimeMachineCounts(machines);}, [runtimes]);const mineCount = userId ? agents.filter((agent) => agent.owner_id === userId).length : 0;@@ -284,9 +283,12 @@ export function TeamPanel() {label={t(($) => $.nav.runtimes)}active={isPathWithin(pathname, p.runtimes())}trailing={- offlineRuntimes > 0 ? (- <span className="shrink-0 text-caption text-warning">- {t(($) => $.panels.team.runtimes_offline, { count: offlineRuntimes })}+ machineCounts.all > 0 ? (+ <span className={cn(+ "shrink-0 text-caption",+ machineCounts.online > 0 ? "text-success" : "text-warning",+ )}>+ {t(($) => $.panels.team.runtimes_online, { count: machineCounts.online })}</span>) : undefined}diff --git a/packages/views/locales/en/layout.json b/packages/views/locales/en/layout.jsonindex 79d30a7dd2..1169bc3126 100644--- a/packages/views/locales/en/layout.json+++ b/packages/views/locales/en/layout.json@@ -162,8 +162,8 @@"members_one": "{{count}} member","members_other": "{{count}} members","resources": "Resources",- "runtimes_offline_one": "{{count}} offline",- "runtimes_offline_other": "{{count}} offline",+ "runtimes_online_one": "{{count}} online",+ "runtimes_online_other": "{{count}} online","invite_member": "Invite member"},"autopilots": {diff --git a/packages/views/locales/fr/layout.json b/packages/views/locales/fr/layout.jsonindex e5d7a23edb..2fb9573b12 100644--- a/packages/views/locales/fr/layout.json+++ b/packages/views/locales/fr/layout.json@@ -162,8 +162,8 @@"members_one": "{{count}} membre","members_other": "{{count}} membres","resources": "Ressources",- "runtimes_offline_one": "{{count}} hors ligne",- "runtimes_offline_other": "{{count}} hors ligne",+ "runtimes_online_one": "{{count}} en ligne",+ "runtimes_online_other": "{{count}} en ligne","invite_member": "Inviter un membre"},"autopilots": {diff --git a/packages/views/locales/ja/layout.json b/packages/views/locales/ja/layout.jsonindex 4dd12a2751..9bf7625aef 100644--- a/packages/views/locales/ja/layout.json+++ b/packages/views/locales/ja/layout.json@@ -157,7 +157,7 @@"squads_and_members": "スクワッドとメンバー","members_other": "メンバー {{count}} 人","resources": "リソース",- "runtimes_offline_other": "{{count}} 件オフライン",+ "runtimes_online_other": "{{count}} 台オンライン","invite_member": "メンバーを招待"},"autopilots": {diff --git a/packages/views/locales/ko/layout.json b/packages/views/locales/ko/layout.jsonindex 5bbadfd9be..e21b53caf1 100644--- a/packages/views/locales/ko/layout.json+++ b/packages/views/locales/ko/layout.json@@ -157,7 +157,7 @@"squads_and_members": "스쿼드 및 멤버","members_other": "멤버 {{count}}명","resources": "리소스",- "runtimes_offline_other": "{{count}}개 오프라인",+ "runtimes_online_other": "{{count}}대 온라인","invite_member": "멤버 초대"},"autopilots": {diff --git a/packages/views/locales/zh-Hans/layout.json b/packages/views/locales/zh-Hans/layout.jsonindex 138ca56243..50937a8536 100644--- a/packages/views/locales/zh-Hans/layout.json+++ b/packages/views/locales/zh-Hans/layout.json@@ -157,7 +157,7 @@"squads_and_members": "小队与成员","members_other": "{{count}} 位成员","resources": "资源",- "runtimes_offline_other": "{{count}} 个离线",+ "runtimes_online_other": "{{count}} 台在线","invite_member": "邀请成员"},"autopilots": {diff --git a/packages/views/locales/zh-Hant/layout.json b/packages/views/locales/zh-Hant/layout.jsonindex 4b8a9fa6d3..859892dec1 100644--- a/packages/views/locales/zh-Hant/layout.json+++ b/packages/views/locales/zh-Hant/layout.json@@ -157,7 +157,7 @@"squads_and_members": "小隊與成員","members_other": "{{count}} 位成員","resources": "資源",- "runtimes_offline_other": "{{count}} 個離線",+ "runtimes_online_other": "{{count}} 台線上","invite_member": "邀請成員"},"autopilots": {