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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agent-accounts): hide the usage block on a backend that has no usage route
rubenluetke10-beep33c628b60c82
diff --git a/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.tsx b/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.tsxindex 8a1984b622..39932fd7bd 100644--- a/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.tsx+++ b/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.tsx@@ -93,6 +93,9 @@ export function AgentAccountsPanel({ onActivate, note }: AgentAccountsPanelPropsconst [usage, setUsage] = useState<Record<string, AccountUsage>>({});const [usageTtl, setUsageTtl] = useState(60);const [refreshing, setRefreshing] = useState(false);+ // Assumed true until a 404 proves otherwise, so the meters appear on the+ // first successful read instead of after a round trip spent proving support.+ const [usageAvailable, setUsageAvailable] = useState(true);// One clock for every countdown on screen. Per-meter timers would drift// against each other and a card with four seats would run a dozen intervals// to render the same minute.@@ -120,6 +123,16 @@ export function AgentAccountsPanel({ onActivate, note }: AgentAccountsPanelPropsconst loadUsage = useCallback(async (force = false) => {try {const body = await fetchAgentUsage(force);+ if (body === null) {+ // This backend predates the usage route — the app's server does not+ // pick up new routes while it is running, so this is the ordinary state+ // between an update and the next restart. Hide the block entirely+ // rather than offering a control that cannot work.+ setUsageAvailable(false);+ setUsage({});+ return;+ }+ setUsageAvailable(true);const next: Record<string, AccountUsage> = {};for (const entry of body.accounts ?? []) next[entry.account_id] = entry;setUsage(next);@@ -145,10 +158,13 @@ export function AgentAccountsPanel({ onActivate, note }: AgentAccountsPanelProps// kept in step by hand. Floored so a short server TTL cannot turn this into// a request loop.useEffect(() => {+ // Polling a route that answered 404 would be a request a minute, forever,+ // for an answer that cannot change without a server restart.+ if (!usageAvailable) return;const period = Math.max(30, usageTtl) * 1000;const timer = setInterval(() => void loadUsage(), period);return () => clearInterval(timer);- }, [loadUsage, usageTtl]);+ }, [loadUsage, usageTtl, usageAvailable]);useEffect(() => {const timer = setInterval(() => setNow(Date.now()), 30_000);@@ -192,17 +208,19 @@ export function AgentAccountsPanel({ onActivate, note }: AgentAccountsPanelProps<span className="text-[11px] text-muted-foreground">· {t("agent_accounts.hint")}</span>- <button- type="button"- onClick={() => void refreshUsage()}- disabled={refreshing}- aria-label={t("agent_accounts.usage.refresh")}- title={t("agent_accounts.usage.refresh")}- className="ml-auto inline-flex shrink-0 items-center gap-1 rounded-lg border border-border px-2 py-1 text-[10px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground disabled:opacity-50"- >- <RefreshCw className={cn("h-3 w-3", refreshing && "animate-spin")} />- {t("agent_accounts.usage.refresh")}- </button>+ {usageAvailable && (+ <button+ type="button"+ onClick={() => void refreshUsage()}+ disabled={refreshing}+ aria-label={t("agent_accounts.usage.refresh")}+ title={t("agent_accounts.usage.refresh")}+ className="ml-auto inline-flex shrink-0 items-center gap-1 rounded-lg border border-border px-2 py-1 text-[10px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground disabled:opacity-50"+ >+ <RefreshCw className={cn("h-3 w-3", refreshing && "animate-spin")} />+ {t("agent_accounts.usage.refresh")}+ </button>+ )}</div><p className="px-1 text-[11px] leading-relaxed text-muted-foreground">{t("agent_accounts.description")}diff --git a/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.usage.test.tsx b/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.usage.test.tsxnew file mode 100644index 0000000000..d71fa9cd97--- /dev/null+++ b/jarvis/ui/web/frontend/src/components/AgentAccountsPanel.usage.test.tsx@@ -0,0 +1,134 @@+/**+ * The switcher's behaviour around plan usage, including the awkward middle state.+ *+ * The app's Python server does not pick up a new route while it is running, so+ * there is a real window — between updating and the next restart — where this+ * panel's new code talks to a backend that has never heard of usage and every+ * call 404s. That was observed live on 2026-08-13, and the first version made it+ * look broken: a Refresh button sat in the header doing nothing, forever, once a+ * minute. So "no usage route here" is treated as a capability answer, not an+ * error, and the whole block disappears instead.+ */+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";++import { AgentAccountsPanel } from "@/components/AgentAccountsPanel";+import { fetchAgentAccounts, fetchAgentUsage } from "@/lib/agentAccountsApi";++vi.mock("@/lib/agentAccountsApi", async () => {+ const actual = await vi.importActual<typeof import("@/lib/agentAccountsApi")>(+ "@/lib/agentAccountsApi",+ );+ return {+ ...actual,+ fetchAgentAccounts: vi.fn(),+ fetchAgentUsage: vi.fn(),+ };+});++const ACCOUNTS = {+ platforms: [+ {+ platform: "claude" as const,+ display_name: "Claude Code",+ active_account: "claude:default",+ accounts: [+ {+ id: "claude:default",+ platform: "claude" as const,+ label: "Default Claude Code login",+ config_dir: "/home/u/.claude",+ builtin: true,+ connected: true,+ mode: "subscription",+ message: "Signed in via Claude Max ([email protected]).",+ email: "[email protected]",+ tier: "max",+ },+ ],+ },+ ],+};++const USAGE = {+ accounts: [+ {+ account_id: "claude:default",+ platform: "claude" as const,+ status: "ok",+ windows: [+ {+ kind: "session",+ percent: 12,+ severity: "normal",+ resets_at: null,+ window_minutes: 300,+ scope_label: null,+ raw_label: null,+ },+ {+ kind: "weekly",+ percent: 74,+ severity: "normal",+ resets_at: null,+ window_minutes: 10080,+ scope_label: null,+ raw_label: null,+ },+ ],+ source: "live",+ as_of: Date.now() / 1000,+ message: "",+ plan: "Max 20x",+ },+ ],+ ttl_seconds: 60,+ generated_at: Date.now() / 1000,+};++beforeEach(() => {+ vi.mocked(fetchAgentAccounts).mockResolvedValue(ACCOUNTS as never);+});++afterEach(() => {+ cleanup();+ vi.clearAllMocks();+});++describe("AgentAccountsPanel — plan usage", () => {+ it("draws the meters and offers a refresh once the backend answers", async () => {+ vi.mocked(fetchAgentUsage).mockResolvedValue(USAGE as never);+ render(<AgentAccountsPanel />);++ await waitFor(() => expect(screen.getAllByRole("progressbar")).toHaveLength(2));+ expect(screen.getByText("Max 20x")).toBeTruthy();++ const refresh = screen.getByRole("button", { name: /refresh/i });+ fireEvent.click(refresh);+ // The manual button must BYPASS the server cache, otherwise it hands back+ // the same minute-old number and reads as a button that does nothing.+ await waitFor(() => expect(fetchAgentUsage).toHaveBeenCalledWith(true));+ });++ it("hides the whole block on a backend that has no usage route", async () => {+ // What a 404 becomes after the api client translates it.+ vi.mocked(fetchAgentUsage).mockResolvedValue(null as never);+ render(<AgentAccountsPanel />);++ await waitFor(() => expect(screen.getByText(/Default Claude Code login/)).toBeTruthy());+ expect(screen.queryAllByRole("progressbar")).toHaveLength(0);+ // The button is the point: offering a control that cannot work is worse+ // than offering nothing, because it reads as a broken feature.+ expect(screen.queryByRole("button", { name: /refresh/i })).toBeNull();+ });++ it("keeps the account list working when the usage read fails outright", async () => {+ vi.mocked(fetchAgentUsage).mockRejectedValue(new Error("network is down"));+ render(<AgentAccountsPanel />);++ // Usage sits on top of the switcher. A failed read must never cost the+ // rows the user actually came here to operate.+ await waitFor(() => expect(screen.getByText(/Default Claude Code login/)).toBeTruthy());+ expect(screen.queryAllByRole("progressbar")).toHaveLength(0);+ });+});diff --git a/jarvis/ui/web/frontend/src/lib/agentAccountsApi.ts b/jarvis/ui/web/frontend/src/lib/agentAccountsApi.tsindex 6ed40ac09a..1175fc5f0b 100644--- a/jarvis/ui/web/frontend/src/lib/agentAccountsApi.ts+++ b/jarvis/ui/web/frontend/src/lib/agentAccountsApi.ts@@ -114,16 +114,25 @@ export interface AgentUsageResponse {}/**- * Plan usage for every registered subscription.+ * Plan usage for every registered subscription, or `null` on a backend that+ * has no usage route at all.+ *+ * The `null` is the interesting part. The app's Python server does not pick up+ * a new route while it is running, so between updating and restarting there is+ * a real window where the new panel talks to an old backend and every call 404s.+ * Treating that as an ERROR put a Refresh button on screen that could not+ * possibly work; treating it as "not available here" lets the panel hide the+ * whole block and look finished rather than broken.** `refresh` bypasses the server's short cache; it backs the manual refresh* button, so a user who just closed a heavy session can see the new number* without waiting out the interval.*/-export async function fetchAgentUsage(refresh = false): Promise<AgentUsageResponse> {+export async function fetchAgentUsage(refresh = false): Promise<AgentUsageResponse | null> {const res = await fetch(`/api/agent-accounts/usage${refresh ? "?refresh=true" : ""}`, {cache: "no-store",});+ if (res.status === 404) return null;if (!res.ok) throw new Error(await detail(res));return (await res.json()) as AgentUsageResponse;}