Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(agents): open the Agents section with roster and teams already loaded (#642)

Ruben Lütke31e516d4ffc5
diff --git a/jarvis/ui/web/frontend/src/App.detached.test.tsx b/jarvis/ui/web/frontend/src/App.detached.test.tsx
index f906f2cb97..25edb0ff48 100644
--- a/jarvis/ui/web/frontend/src/App.detached.test.tsx
+++ b/jarvis/ui/web/frontend/src/App.detached.test.tsx
@@ -11,6 +11,7 @@ vi.mock("@/hooks/useAssistantNameSeed", () => ({
useAssistantNameSeed: () => undefined,
}));
vi.mock("@/hooks/useCodingMode", () => ({ useCodingMode: () => undefined }));
+vi.mock("@/hooks/useSocietyWarmup", () => ({ useSocietyWarmup: () => undefined }));
vi.mock("@/hooks/useResizablePane", () => ({
useResizablePane: () => ({
size: 280,
diff --git a/jarvis/ui/web/frontend/src/App.tsx b/jarvis/ui/web/frontend/src/App.tsx
index 3e62c077b1..43576e3fb4 100644
--- a/jarvis/ui/web/frontend/src/App.tsx
+++ b/jarvis/ui/web/frontend/src/App.tsx
@@ -9,6 +9,7 @@ import { useAssistantNameSeed } from "@/hooks/useAssistantNameSeed";
import { useCodingMode } from "@/hooks/useCodingMode";
import { useFileDropGuard } from "@/hooks/useFileDropGuard";
import { useSectionUrlMemory } from "@/hooks/useSectionUrlMemory";
+import { useSocietyWarmup } from "@/hooks/useSocietyWarmup";
import {
Sidebar,
SIDEBAR_DEFAULT_WIDTH,
@@ -186,6 +187,8 @@ export default function App() {
* reload carries over. See hooks/useSectionUrlMemory.
*/
useSectionUrlMemory();
+ // The Agents section opens with its roster and teams already loaded.
+ useSocietyWarmup();
/*
* Remember which field the user is typing in, app-wide.
diff --git a/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx b/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
index afe11f206c..4bbd307d99 100644
--- a/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/card/AgentCardOverlay.tsx
@@ -30,6 +30,8 @@ export interface AgentCardOverlayProps {
onAddAgentToGroup?: (agentId: string, groupId: string) => void;
/** True while the roster is still loading; the rail says so. */
rosterLoading?: boolean;
+ /** True until the teams have answered; the rail holds its list back until then. */
+ teamsPending?: boolean;
/** True while rows come from the sample roster rather than society.db. */
sample?: boolean;
/** A row in the rail was clicked: the card swaps to that agent. */
@@ -51,6 +53,7 @@ export function AgentCardOverlay({
onGroupAgents,
onAddAgentToGroup,
rosterLoading = false,
+ teamsPending = false,
sample = false,
onSelectAgent,
onCreate,
@@ -99,6 +102,7 @@ export function AgentCardOverlay({
onGroupAgents={onGroupAgents}
onAddAgentToGroup={onAddAgentToGroup}
loading={rosterLoading}
+ teamsPending={teamsPending}
sample={sample}
activeAgentId={agent.agentId}
onOpen={(id) => { if (id !== agent.agentId) onSelectAgent?.(id); }}
diff --git a/jarvis/ui/web/frontend/src/components/society/data.ts b/jarvis/ui/web/frontend/src/components/society/data.ts
index a72f1d2c75..2afa9fe533 100644
--- a/jarvis/ui/web/frontend/src/components/society/data.ts
+++ b/jarvis/ui/web/frontend/src/components/society/data.ts
@@ -21,6 +21,7 @@ import type { CompanionAppearance } from "./companion/appearance";
import { useCreateAgentDialog } from "./create/createAgentStore";
import { NEUTRAL_ASSISTANT_NAME } from "@/lib/assistantNameCache";
+import { societyChatGroupsQuery } from "@/lib/societyChatGroups";
import { useEventStore } from "@/store/events";
import { translate } from "@/i18n";
@@ -332,6 +333,33 @@ function patchRoster(
void client.invalidateQueries({ queryKey: ROSTER_QUERY_KEY });
}
+/** A list this fresh is not asked for again by `warmSocietyLists`. */
+const WARM_FRESH_MS = 2_000;
+
+/**
+ * Load the roster and the teams ahead of the views that show them.
+ *
+ * The Agents section starts some twenty requests when it mounts and a browser
+ * sends six at a time to one host, so the two lists, asked last, waited over a
+ * second for answers that take milliseconds: new agents were missing and every
+ * team member stood alone until then. Asked here (at app start and on the
+ * switch to the section, before it renders) both are there for its first paint.
+ */
+export async function warmSocietyLists(client: QueryClient): Promise<void> {
+ // A refetch mid-ceremony would delete the figure being carried to the mine.
+ if (retirementRunning()) return;
+ const rosterQuery = { queryKey: ROSTER_QUERY_KEY, queryFn: fetchSocietyRoster, staleTime: WARM_FRESH_MS };
+ const teams = () => client.prefetchQuery({ ...societyChatGroupsQuery, staleTime: WARM_FRESH_MS });
+ // The sample roster has no teams; a roster known to be real asks for both at once.
+ const known = client.getQueryData<RosterData>(ROSTER_QUERY_KEY);
+ if (known && !known.sample) {
+ await Promise.all([client.prefetchQuery(rosterQuery), teams()]);
+ return;
+ }
+ const roster = await client.fetchQuery(rosterQuery);
+ if (!roster.sample) await teams();
+}
+
/**
* The lead is the assistant itself, so it wears the name the user gave it
* through the wake phrase ("George"), not the roster row's seeded name. The
diff --git a/jarvis/ui/web/frontend/src/components/society/office/MissionScreens.tsx b/jarvis/ui/web/frontend/src/components/society/office/MissionScreens.tsx
index 1a23a3aeeb..c1019bd226 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/MissionScreens.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/MissionScreens.tsx
@@ -30,7 +30,7 @@ import { WorkspaceTerminalHeader } from "@/components/agentic/WorkspaceTerminalH
import type { PaneEdgeState } from "@/components/agentic/terminalThemes";
import { RosterRail } from "@/components/society/roster/RosterRail";
import { useSocietyRoster, type SocietyAgent } from "../data";
-import { useSocietyChatGroups } from "@/lib/societyChatGroups";
+import { chatGroupsKnown, useSocietyChatGroups } from "@/lib/societyChatGroups";
import { paneLabel, paneOccupants, type PaneOccupant } from "./codingFloor";
import { PaneScreenView } from "./PaneLiveScreen";
import { screenChanged } from "./terminalScreen";
@@ -79,7 +79,8 @@ function AgentsScreen() {
const roster = useSocietyRoster();
const agents = useMemo(() => roster.data?.agents ?? [], [roster.data]);
const sample = roster.data?.sample ?? true;
- const groups = useSocietyChatGroups(!sample).data ?? [];
+ const groupsQuery = useSocietyChatGroups(!sample);
+ const groups = groupsQuery.data ?? [];
const shown = pickShownAgent(agents);
const shownId = shown?.agentId ?? null;
const store = useMemo(() => (shownId ? createAgentChatStore("society", `office-mission:${shownId}`) : null), [shownId]);
@@ -87,7 +88,7 @@ function AgentsScreen() {
useEffect(() => () => store?.getState().disconnect(), [store]);
return (
<div className="grid h-full min-h-0 grid-cols-[300px_minmax(0,1fr)] bg-card">
- <RosterRail agents={agents} groups={groups} loading={roster.isLoading} sample={sample}
+ <RosterRail agents={agents} groups={groups} loading={roster.isLoading} teamsPending={!sample && !chatGroupsKnown(groupsQuery)} sample={sample}
activeAgentId={shownId} onOpen={() => undefined} onCreate={() => undefined}
side="left" className="w-full border-0 jarvis-nav-surface" />
<section className="flex min-h-0 flex-col overflow-hidden rounded-tl-[12px] border-l border-border bg-background">
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.lifecycle.test.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.lifecycle.test.tsx
index 8e83ad13ed..d603e6e3cf 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.lifecycle.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.lifecycle.test.tsx
@@ -33,7 +33,7 @@ vi.mock("./useDeskChats", () => ({
}));
vi.mock("./useDprBudget", () => ({ useDprBudget: () => 1 }));
// The agents floor is built from the teams; the stage waits for the first answer about them.
-vi.mock("@/lib/societyChatGroups", () => ({ useSocietyChatGroups: () => ({ data: [], isSuccess: true, isError: false }) }));
+vi.mock("@/lib/societyChatGroups", async (importOriginal) => ({ ...(await importOriginal<typeof import("@/lib/societyChatGroups")>()), useSocietyChatGroups: () => ({ data: [], isSuccess: true, isError: false, failureCount: 0 }) }));
vi.mock("@react-three/fiber", () => ({
advance: () => undefined,
Canvas: ({ children, frameloop }: { children: ReactNode; frameloop: string }) => {
diff --git a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
index 792db5ca29..485e681ff5 100644
--- a/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/office/OfficeStage.tsx
@@ -23,7 +23,7 @@ import { isCreateCancelled } from "../create/createAgentStore";
import { OfficeScene } from "./OfficeScene";
import { allDesks, buildOfficeLayout, countStates, seatedCount, type OfficeTeamInput } from "./officeLayout";
import { buildHallLayout } from "./hallFloorLayout";
-import { useSocietyChatGroups } from "@/lib/societyChatGroups";
+import { chatGroupsKnown, useSocietyChatGroups } from "@/lib/societyChatGroups";
import { buildNavGrid } from "./officeNav";
import { SpotBook } from "./officeBehavior";
import { CAMERA_FOV } from "./officeCamera";
@@ -206,8 +206,7 @@ export function OfficeStage({ onOpenLedger, onSelectAgent, onCreateAgent, onOpen
// The agents floor is built from the teams (society chat groups): every team has its studio. The roster waits
// for the first answer about them, so nobody is seated in the pool and then sent across the floor.
const chatGroups = useSocietyChatGroups(awake && floor === "agents");
- // A first failed read counts as an answer too: the floor opens without teams and rebuilds if a retry brings them.
- const teamsKnown = chatGroups.isSuccess || chatGroups.isError || chatGroups.failureCount > 0;
+ const teamsKnown = chatGroupsKnown(chatGroups);
const teams = useMemo<OfficeTeamInput[]>(() => (chatGroups.data ?? []).map((group) => ({
id: group.group_id, name: group.name, members: group.members, createdMs: group.created_ms, leadId: group.lead_agent_id ?? null,
})), [chatGroups.data]);
diff --git a/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.test.tsx b/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.test.tsx
index 38081b72b6..725b1cd010 100644
--- a/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.test.tsx
@@ -69,6 +69,21 @@ describe("RosterRail status", () => {
fireEvent.click(screen.getByTestId("society-group-team"));
expect(openGroup).toHaveBeenCalledWith("team");
});
+ it("lists nobody on their own until the teams have answered", () => {
+ const agents = [agent({ agentId: "scout", name: "Scout" }), agent({ agentId: "writer", name: "Writer" }), agent({ agentId: "solo", name: "Solo" })];
+ const view = render(<RosterRail {...baseProps} activeAgentId={null} agents={agents} teamsPending />);
+ // Not one frame shows a team member as a loose agent.
+ expect(screen.queryByText("Scout")).toBeNull();
+ expect(screen.queryByText("Solo")).toBeNull();
+ expect(screen.getByText("society.roster.loading")).toBeTruthy();
+
+ view.rerender(<RosterRail {...baseProps} activeAgentId={null} agents={agents} onOpenGroup={() => undefined}
+ groups={[{ group_id: "team", name: "Launch team", members: ["scout", "writer"], created_ms: 1, updated_ms: 1 }]} />);
+ expect(screen.getByTestId("society-group-team")).toBeTruthy();
+ expect(screen.queryByText("Scout")).toBeNull();
+ expect(screen.getByText("Solo")).toBeTruthy();
+ expect(screen.queryByText("society.roster.loading")).toBeNull();
+ });
it("opens team actions on right-click and only ungroups after confirmation", async () => {
const request = vi.fn(async () => ({ ok: true, json: async () => ({}) }));
vi.stubGlobal("fetch", request);
diff --git a/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.tsx b/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.tsx
index 185709cf77..92b1c79daa 100644
--- a/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.tsx
+++ b/jarvis/ui/web/frontend/src/components/society/roster/RosterRail.tsx
@@ -88,6 +88,8 @@ export interface RosterRailProps {
onGroupAgents?: (sourceId: string, targetId: string) => void;
onAddAgentToGroup?: (agentId: string, groupId: string) => void;
loading: boolean;
+ /** True until the teams have answered: who stands alone in the list is not known before. */
+ teamsPending?: boolean;
/** True while rows come from the sample roster rather than society.db. */
sample: boolean;
activeAgentId: string | null;
@@ -111,6 +113,7 @@ export function RosterRail({
onGroupAgents,
onAddAgentToGroup,
loading,
+ teamsPending = false,
sample,
activeAgentId,
onOpen,
@@ -183,7 +186,9 @@ export function RosterRail({
// Orchestrators, then specialists; stable within a tier. The lead lives
// in its own centered hero above and never repeats in the list.
const rank = { lead: 0, orchestrator: 1, specialist: 2 } as const;
- const rest = filtered
+ // Until the teams have answered, a member would be listed on its own and
+ // jump into its team a moment later; the list waits for the answer instead.
+ const rest = teamsPending ? [] : filtered
.filter((a) => a.agentId !== lead?.agentId && !groupedIds.has(a.agentId));
// A drag persists the full visible order, so from then on the person's
// own arrangement wins over the tier grouping. Agents the list never saw
@@ -202,7 +207,7 @@ export function RosterRail({
return rank[a.tier] - rank[b.tier];
});
return { leadVisible: masterVisible, rows: rest };
- }, [agents, assistantName, groupedIds, hiddenIds, lead, orderIds, query, showHidden]);
+ }, [agents, assistantName, groupedIds, hiddenIds, lead, orderIds, query, showHidden, teamsPending]);
// While searching, the list is a filtered excerpt — dragging there would
// file agents by where they happen to sit in the excerpt, so rows stay put.
@@ -600,10 +605,10 @@ export function RosterRail({
</li>)}
</ul>}
<ul ref={listRef} className="flex flex-col gap-0.5 px-2 pb-3">
- {loading && !leadVisible && rows.length === 0 ? (
+ {(teamsPending || (loading && !leadVisible)) && rows.length === 0 ? (
<li className="px-2 py-3 text-xs text-muted-foreground">{t("society.roster.loading")}</li>
) : null}
- {!loading && !leadVisible && rows.length === 0 && visibleGroups.length === 0 ? (
+ {!loading && !teamsPending && !leadVisible && rows.length === 0 && visibleGroups.length === 0 ? (
<li className="px-2 py-3 text-xs text-muted-foreground">{t("society.roster.empty")}</li>
) : null}
{rows.map((agent) => {
diff --git a/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.test.tsx b/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.test.tsx
new file mode 100644
index 0000000000..c2b22422dd
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.test.tsx
@@ -0,0 +1,100 @@
+import type { ReactNode } from "react";
+import { act, cleanup, renderHook, waitFor } from "@testing-library/react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import type { RosterData } from "@/components/society/data";
+import type { SocietyChatGroup } from "@/lib/societyChatGroups";
+import { useEventStore } from "@/store/events";
+import { useSocietyWarmup } from "./useSocietyWarmup";
+
+const ROSTER_URL = "/api/society/agents";
+const TEAMS_URL = "/api/society/chat-groups";
+const ROSTER_KEY = ["society", "roster"];
+const TEAMS_KEY = ["society", "chat-groups"];
+
+const TEAM: SocietyChatGroup = { group_id: "team", name: "Launch team", members: ["scout", "writer"], created_ms: 1, updated_ms: 1 };
+
+function row(id: string) {
+ return {
+ agent_id: id, name: id, title: "", description: "", tier: "specialist", parent_agent_id: null, state: "active",
+ avatar: null, checkpoint: "home", provider: "openai", model: "", effort: "", grant_mode: "all", grants: [],
+ focus: [], denies: [], permission_ceiling: "ask", approval_rules: { require_approval: [], always_allow: [] },
+ daily_budget_usd: 0, max_concurrent_runs: 1, session_id: `society:${id}`, created_ms: 0, updated_ms: 0,
+ stats: { runs: 0, total_cost_usd: 0, last_active_ms: null },
+ };
+}
+
+describe("useSocietyWarmup", () => {
+ let client: QueryClient;
+ let agents: string[];
+ const calls: string[] = [];
+ const wrapper = ({ children }: { children: ReactNode }) => <QueryClientProvider client={client}>{children}</QueryClientProvider>;
+ const count = (url: string) => calls.filter((call) => call === url).length;
+
+ beforeEach(() => {
+ calls.length = 0;
+ agents = ["scout", "writer"];
+ client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+ vi.stubGlobal("fetch", async (url: string) => {
+ calls.push(url);
+ return new Response(JSON.stringify(url === ROSTER_URL ? { agents: agents.map(row) } : { groups: [TEAM] }));
+ });
+ useEventStore.setState({ activeSection: "chats", solo: false });
+ });
+ afterEach(() => {
+ cleanup();
+ client.clear();
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+ useEventStore.setState({ activeSection: "chats", solo: false });
+ });
+
+ it("has the roster and the teams loaded before anyone opens the Agents section", async () => {
+ renderHook(() => useSocietyWarmup(), { wrapper });
+
+ await waitFor(() => expect(client.getQueryData(TEAMS_KEY)).toEqual([TEAM]));
+ expect(client.getQueryData<RosterData>(ROSTER_KEY)?.agents.map((agent) => agent.agentId)).toEqual(["scout", "writer"]);
+ });
+
+ it("reads both again on the switch to the section, so a new agent is there on arrival", async () => {
+ vi.useFakeTimers({ toFake: ["Date"] });
+ renderHook(() => useSocietyWarmup(), { wrapper });
+ await waitFor(() => expect(count(TEAMS_URL)).toBe(1));
+
+ agents = ["scout", "writer", "newcomer"];
+ vi.setSystemTime(Date.now() + 60_000);
+ act(() => useEventStore.getState().setActiveSection("agents"));
+
+ await waitFor(() => expect(client.getQueryData<RosterData>(ROSTER_KEY)?.agents).toHaveLength(3));
+ await waitFor(() => expect(count(TEAMS_URL)).toBe(2));
+ });
+
+ it("asks nothing twice when the lists were read a moment ago", async () => {
+ renderHook(() => useSocietyWarmup(), { wrapper });
+ await waitFor(() => expect(count(TEAMS_URL)).toBe(1));
+
+ act(() => useEventStore.getState().setActiveSection("agents"));
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });
+
+ expect(count(ROSTER_URL)).toBe(1);
+ expect(count(TEAMS_URL)).toBe(1);
+ });
+
+ it("leaves the teams alone while only the sample roster is known", async () => {
+ agents = [];
+ renderHook(() => useSocietyWarmup(), { wrapper });
+
+ await waitFor(() => expect(client.getQueryData<RosterData>(ROSTER_KEY)?.sample).toBe(true));
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });
+ expect(count(TEAMS_URL)).toBe(0);
+ });
+
+ it("stays quiet in a detached window of another section", async () => {
+ useEventStore.setState({ activeSection: "agentic-ide", solo: true });
+ renderHook(() => useSocietyWarmup(), { wrapper });
+
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 20)); });
+ expect(calls).toEqual([]);
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.ts b/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.ts
new file mode 100644
index 0000000000..85ccd6277c
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/hooks/useSocietyWarmup.ts
@@ -0,0 +1,40 @@
+import { useEffect } from "react";
+import { useQueryClient } from "@tanstack/react-query";
+
+import { useEventStore } from "@/store/events";
+
+/**
+ * Keeps the agent roster and the teams loaded before the Agents section asks.
+ *
+ * Mounted once at the shell. The lists are read at app start and again on
+ * every switch to the section: the store reports the switch before React
+ * renders the section, so the requests leave ahead of everything the section
+ * itself starts (see `warmSocietyLists`). A detached window of another section
+ * never shows them and stays quiet.
+ */
+export function useSocietyWarmup(): void {
+ const client = useQueryClient();
+ useEffect(() => {
+ const failed = (error: unknown) => console.debug("Agent lists not warmed", error);
+ // The society data module stays out of the entry bundle. Once loaded it is called directly, with no
+ // promise in between: the requests then leave inside the store update, before React mounts the section.
+ let lists: ((queryClient: typeof client) => Promise<void>) | null = null;
+ const warm = () => {
+ if (lists) {
+ void lists(client).catch(failed);
+ return;
+ }
+ void import("@/components/society/data")
+ .then((module) => {
+ lists = module.warmSocietyLists;
+ return lists(client);
+ })
+ .catch(failed);
+ };
+ const { solo, activeSection } = useEventStore.getState();
+ if (!solo || activeSection === "agents") warm();
+ return useEventStore.subscribe((state, previous) => {
+ if (state.activeSection === "agents" && previous.activeSection !== "agents") warm();
+ });
+ }, [client]);
+}
diff --git a/jarvis/ui/web/frontend/src/lib/societyChatGroups.ts b/jarvis/ui/web/frontend/src/lib/societyChatGroups.ts
index fee11e3a1d..68ead821d1 100644
--- a/jarvis/ui/web/frontend/src/lib/societyChatGroups.ts
+++ b/jarvis/ui/web/frontend/src/lib/societyChatGroups.ts
@@ -57,10 +57,25 @@ const POLL_FLOOR_MS = 250;
const GROUPS_POLL_MS = 10_000;
const ROUND_POLL_MS = 2_000;
+/** The teams query itself, for a caller that loads it ahead of the views (`warmSocietyLists`). */
+export const societyChatGroupsQuery = {
+ queryKey: ["society", "chat-groups"] as const,
+ queryFn: async () => (await json<{ groups: SocietyChatGroup[] }>("/api/society/chat-groups")).groups,
+};
+
+/**
+ * Whether the teams have answered at all. Until then nobody knows who belongs
+ * to which team, and a view that lists agents by team must wait instead of
+ * showing every member on its own first. A first failed read counts as an
+ * answer too: the view opens without teams and regroups if a retry brings them.
+ */
+export function chatGroupsKnown(query: { isSuccess: boolean; isError: boolean; failureCount: number }): boolean {
+ return query.isSuccess || query.isError || query.failureCount > 0;
+}
+
export function useSocietyChatGroups(enabled = true) {
return useQuery({
- queryKey: ["society", "chat-groups"],
- queryFn: async () => (await json<{ groups: SocietyChatGroup[] }>("/api/society/chat-groups")).groups,
+ ...societyChatGroupsQuery,
enabled,
staleTime: 15_000,
// Jittered (AP-33), and not tied to `document.visibilityState`: the desktop WebView reports a visible
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.deferred.test.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.deferred.test.tsx
index 5e64037848..92d5cd5d9f 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.deferred.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.deferred.test.tsx
@@ -8,7 +8,7 @@ const quick = vi.hoisted(() => ({ create: vi.fn(async () => ({ agentId: "lead" }
vi.mock("@/i18n", () => ({ useT: () => (key: string) => key, useLocaleChunk: () => true }));
vi.mock("@/lib/mapFullscreen", () => ({ setMapFullscreen: async () => undefined }));
vi.mock("@/components/society/chat/useModelMenuData", () => ({ useModelMenuData: () => undefined }));
-vi.mock("@/lib/societyChatGroups", () => ({ useSocietyChatGroups: () => ({ data: [] }) }));
+vi.mock("@/lib/societyChatGroups", async (importOriginal) => ({ ...(await importOriginal<typeof import("@/lib/societyChatGroups")>()), useSocietyChatGroups: () => ({ data: [], isSuccess: true, isError: false, failureCount: 0 }) }));
vi.mock("@/components/society/chat/ChatGroupPanel", () => ({ ChatGroupPanel: () => null }));
vi.mock("@/components/society/chat/AgentChatPanel", () => ({ useSocietyChatStore: { getState: () => ({ disconnect: () => undefined }) } }));
vi.mock("@/components/society/data", () => ({ useQuickCreateAgent: () => quick.create,
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
index 7e2363d505..d075115883 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.test.tsx
@@ -20,7 +20,7 @@ vi.mock("@tanstack/react-query", async (importOriginal) => ({
}));
vi.mock("@/i18n", () => ({ useT: () => (key: string) => key, useLocaleChunk: () => true }));
vi.mock("@/components/society/chat/useModelMenuData", () => ({ useModelMenuData: () => undefined }));
-vi.mock("@/lib/societyChatGroups", () => ({ useSocietyChatGroups: () => ({ data: groupsState.groups }) }));
+vi.mock("@/lib/societyChatGroups", async (importOriginal) => ({ ...(await importOriginal<typeof import("@/lib/societyChatGroups")>()), useSocietyChatGroups: () => ({ data: groupsState.groups, isSuccess: true, isError: false, failureCount: 0 }) }));
vi.mock("@/components/society/chat/ChatGroupPanel", () => ({ ChatGroupPanel: ({ group, onOpenAgent }: any) => <div data-testid="group-workspace">{group.name}<button onClick={() => onOpenAgent("specialist")}>Open member</button></div> }));
vi.mock("@/components/society/data", () => ({ useQuickCreateAgent: () => quick.create, useSocietyRoster: () => ({ data: { sample: false, agents: [
{ agentId: "lead", name: "Lead", tier: "lead", state: "idle" },
diff --git a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
index 997705c06d..417368557a 100644
--- a/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
+++ b/jarvis/ui/web/frontend/src/views/society/SocietyView.tsx
@@ -22,7 +22,7 @@ import { RosterRail } from "@/components/society/roster/RosterRail";
import { useModelMenuData } from "@/components/society/chat/useModelMenuData";
import { ChatGroupPanel } from "@/components/society/chat/ChatGroupPanel";
import { useSocietyChatStore } from "@/components/society/chat/AgentChatPanel";
-import { createSocietyChatGroup, updateSocietyChatGroup, useSocietyChatGroups } from "@/lib/societyChatGroups";
+import { chatGroupsKnown, createSocietyChatGroup, updateSocietyChatGroup, useSocietyChatGroups } from "@/lib/societyChatGroups";
import { CanvasActivity } from "@/hooks/useCanvasAwake";
import { forgetLastAgentId, rememberLastAgentId, storedLastAgentId } from "./lastAgent";
@@ -57,6 +57,7 @@ export function SocietyView() {
const sample = roster.data?.sample ?? true;
const groupsQuery = useSocietyChatGroups(!sample);
const groups = useMemo(() => groupsQuery.data ?? [], [groupsQuery.data]);
+ const teamsPending = !sample && !chatGroupsKnown(groupsQuery);
const [openGroupId, setOpenGroupId] = useState<string | null>(null);
const openGroup = groups.find((group) => group.group_id === openGroupId) ?? null;
const [openAgentId, setOpenAgentId] = useState<string | null>(storedLastAgentId);
@@ -238,13 +239,13 @@ export function SocietyView() {
onCreateAgent={createAgent} onDeleted={() => setOpenGroupId(null)}
onGroupAgents={groupAgents} onAddAgentToGroup={addAgentToGroup} />
) : openAgent ? (
- <AgentCardOverlay embedded agent={openAgent} roster={agents} rosterLoading={roster.isLoading}
+ <AgentCardOverlay embedded agent={openAgent} roster={agents} rosterLoading={roster.isLoading} teamsPending={teamsPending}
groups={groups} onSelectGroup={selectGroup}
onGroupAgents={sample ? undefined : groupAgents} onAddAgentToGroup={sample ? undefined : addAgentToGroup}
sample={sample} onSelectAgent={selectAgent} onCreate={createAgent}
onClose={() => setOpenAgentId(null)} />
) : (
- <RosterRail agents={agents} loading={roster.isLoading} sample={sample}
+ <RosterRail agents={agents} loading={roster.isLoading} teamsPending={teamsPending} sample={sample}
groups={groups} onOpenGroup={selectGroup}
onGroupAgents={sample ? undefined : groupAgents} onAddAgentToGroup={sample ? undefined : addAgentToGroup}
activeAgentId={null} onOpen={selectAgent} onCreate={createAgent} side="left"