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(costs): the Spend section says "loading" instead of showing zeros

rubenluetke10-beep4174e3c9a629
diff --git a/jarvis/ui/web/frontend/src/components/costs/CostTrendChart.tsx b/jarvis/ui/web/frontend/src/components/costs/CostTrendChart.tsx
index d1459980b6..e40b1affd1 100644
--- a/jarvis/ui/web/frontend/src/components/costs/CostTrendChart.tsx
+++ b/jarvis/ui/web/frontend/src/components/costs/CostTrendChart.tsx
@@ -39,6 +39,12 @@ interface Props {
eurPerUsd: number;
/** Bar the pointer selects; clicking it filters the section to that bucket. */
onSelect?: (key: string) => void;
+ /**
+ * No answer has arrived yet. Without this the chart cannot tell "nothing was
+ * spent" from "nobody has told me yet", and it announced the first as the
+ * second for as long as the read took.
+ */
+ loading?: boolean;
}
interface Point {
@@ -57,6 +63,13 @@ const TOKEN_COLORS = {
tokens_cached: "hsl(268 72% 68%)",
} as const;
+/**
+ * Heights of the waiting chart's bars, as percentages. Fixed rather than
+ * random so the skeleton does not reshuffle on every render, and uneven so it
+ * reads as a chart rather than a progress bar.
+ */
+const SKELETON_BARS = [38, 52, 30, 61, 44, 72, 35, 58, 47, 66, 29, 55, 40, 63, 33] as const;
+
export function CostTrendChart({
series,
bucket,
@@ -64,6 +77,7 @@ export function CostTrendChart({
currency,
eurPerUsd,
onSelect,
+ loading = false,
}: Props) {
const t = useT();
@@ -92,6 +106,25 @@ export function CostTrendChart({
);
if (data.length === 0) {
+ // A chart-shaped wait, so the panel keeps its height and the eye has
+ // somewhere to rest — rather than a sentence claiming a result.
+ if (loading) {
+ return (
+ <div
+ className="flex h-full min-h-[180px] items-end gap-1.5 px-2 pb-6"
+ role="status"
+ aria-label={t("costs_view.chart_loading")}
+ >
+ {SKELETON_BARS.map((height, i) => (
+ <div
+ key={i}
+ className="flex-1 animate-pulse rounded-sm bg-foreground/10"
+ style={{ height: `${height}%` }}
+ />
+ ))}
+ </div>
+ );
+ }
return (
<div className="flex h-full min-h-[180px] items-center justify-center text-xs text-muted-foreground">
{t("costs_view.chart_empty")}
diff --git a/jarvis/ui/web/frontend/src/components/extensions/StatTile.loading.test.tsx b/jarvis/ui/web/frontend/src/components/extensions/StatTile.loading.test.tsx
new file mode 100644
index 0000000000..0094276a7f
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/components/extensions/StatTile.loading.test.tsx
@@ -0,0 +1,49 @@
+import { render, screen } from "@testing-library/react";
+import { describe, expect, it } from "vitest";
+
+import { StatTile } from "./primitives";
+
+/**
+ * A tile that is still waiting must not show the number its caller invented.
+ *
+ * Every caller passes React Query's `isLoading`, which is true only while NO
+ * answer has arrived, and passes a fallback like `totals?.cost_usd ?? 0` for
+ * the value. Rendering that fallback — even faded — states a result: the Spend
+ * section showed "$0.00", "0 tokens" and "Nothing recorded yet" for the whole
+ * first read and was reported as a broken, empty section (2026-08-28). A
+ * placeholder bar says "not yet" instead, which is the truth.
+ */
+describe("StatTile while it is waiting", () => {
+ it("shows a placeholder instead of the caller's fallback number", () => {
+ render(<StatTile label="Total spend" value="$0.00" hint="$0.00 per day" loading />);
+
+ expect(screen.queryByText("$0.00")).toBeNull();
+ expect(screen.queryByText("$0.00 per day")).toBeNull();
+ // The label stays, so the row still reads as four named tiles.
+ expect(screen.getByText("Total spend")).toBeTruthy();
+ expect(screen.getByRole("status")).toBeTruthy();
+ });
+
+ it("shows the number as soon as one has arrived", () => {
+ render(<StatTile label="Total spend" value="$17,002" hint="$563 per day" />);
+
+ expect(screen.getByText("$17,002")).toBeTruthy();
+ expect(screen.getByText("$563 per day")).toBeTruthy();
+ expect(screen.queryByRole("status")).toBeNull();
+ });
+
+ it("keeps the placeholder visible against the surface it sits on", () => {
+ // `bg-muted` is ~3% lightness from `bg-card`, so a skeleton painted with it
+ // is invisible and the tile just looks blank — which is the same defect in
+ // a different costume. A fraction of the foreground contrasts by
+ // construction, in light mode and dark mode alike.
+ const { container } = render(<StatTile label="Tokens" value="0" loading />);
+ const bars = container.querySelectorAll(".animate-pulse");
+
+ expect(bars.length).toBeGreaterThan(0);
+ for (const bar of bars) {
+ expect(bar.className).toContain("bg-foreground/");
+ expect(bar.className).not.toContain("bg-muted");
+ }
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/components/extensions/primitives.tsx b/jarvis/ui/web/frontend/src/components/extensions/primitives.tsx
index e2e1ae9700..75854ece68 100644
--- a/jarvis/ui/web/frontend/src/components/extensions/primitives.tsx
+++ b/jarvis/ui/web/frontend/src/components/extensions/primitives.tsx
@@ -705,16 +705,37 @@ export function StatTile({
) : null}
<span className="truncate">{label}</span>
</div>
- <div
- className={cn(
- "mt-1.5 truncate font-display text-[22px] font-semibold tabular-nums tracking-tight text-foreground",
- loading && "opacity-40",
- )}
- title={typeof value === "string" ? value : undefined}
- >
- {value}
- </div>
- {hint ? (
+ {/*
+ A tile with nothing to show yet shows nothing — never a dimmed zero.
+ `loading` here means "no answer has arrived", so the number underneath
+ it is a placeholder the caller had to invent, and a faded "$0.00" reads
+ as a total, not as a wait. The skeleton is the same height as the
+ number so the row does not jump when it lands.
+ */}
+ {loading ? (
+ <div
+ className="mt-1.5 h-[26px] py-1"
+ role="status"
+ aria-label={`${label}: …`}
+ >
+ <div className="h-[18px] w-20 animate-pulse rounded bg-foreground/15" />
+ </div>
+ ) : (
+ <div
+ className={cn(
+ "mt-1.5 truncate font-display text-[22px] font-semibold tabular-nums",
+ "tracking-tight text-foreground",
+ )}
+ title={typeof value === "string" ? value : undefined}
+ >
+ {value}
+ </div>
+ )}
+ {loading ? (
+ <div className="mt-0.5 h-[15px] py-[3px]">
+ <div className="h-[9px] w-28 animate-pulse rounded bg-foreground/10" />
+ </div>
+ ) : hint ? (
<div
className="mt-0.5 truncate text-[11px] text-muted-foreground"
title={typeof hint === "string" ? hint : undefined}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index a560b7041f..4e5b6f6869 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -4928,6 +4928,7 @@
"metric_cost": "Kosten",
"metric_tokens": "Tokens",
"chart_empty": "In diesem Zeitraum wurde nichts ausgegeben.",
+ "chart_loading": "Das Buch wird gelesen…",
"total": "Gesamt",
"tokens_in": "Rein",
"tokens_out": "Raus",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index b4a844e6af..b49cb8390d 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -4928,6 +4928,7 @@
"metric_cost": "Cost",
"metric_tokens": "Tokens",
"chart_empty": "Nothing spent in this range.",
+ "chart_loading": "Reading the ledger…",
"total": "Total",
"tokens_in": "In",
"tokens_out": "Out",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index ef7c34deb1..cc38c82d0e 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -4928,6 +4928,7 @@
"metric_cost": "Coste",
"metric_tokens": "Tokens",
"chart_empty": "No hubo gasto en este periodo.",
+ "chart_loading": "Leyendo el registro…",
"total": "Total",
"tokens_in": "Entrada",
"tokens_out": "Salida",
diff --git a/jarvis/ui/web/frontend/src/views/CostsView.tsx b/jarvis/ui/web/frontend/src/views/CostsView.tsx
index 38f96a3bea..4c2e63cb3b 100644
--- a/jarvis/ui/web/frontend/src/views/CostsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/CostsView.tsx
@@ -459,6 +459,7 @@ export function CostsView() {
metric={metric}
currency={currency}
eurPerUsd={eurPerUsd}
+ loading={summary.isLoading}
/>
</div>
</Panel>
@@ -583,18 +584,26 @@ export function CostsView() {
) : null}
</Panel>
- <p className="px-1 pb-2 text-[11px] leading-relaxed text-muted-foreground">
- {fill(t("costs_view.footnote"), {
- sources: (data?.sources_present ?? []).join(", ") || "—",
- rate: eurPerUsd.toFixed(2),
- rateSource: t(
- data?.currency.source === "config"
- ? "costs_view.rate_from_config"
- : "costs_view.rate_default",
- ),
- estimated: money(totals?.estimated_usd ?? 0),
- })}
- </p>
+ {/*
+ Held back until there is an answer. Rendered against no data it read
+ "Read from —. $0.00 of the total was priced here…", which names the
+ stores as missing and the estimate as nil — two claims the section
+ cannot make yet.
+ */}
+ {data ? (
+ <p className="px-1 pb-2 text-[11px] leading-relaxed text-muted-foreground">
+ {fill(t("costs_view.footnote"), {
+ sources: data.sources_present.join(", ") || "—",
+ rate: eurPerUsd.toFixed(2),
+ rateSource: t(
+ data.currency.source === "config"
+ ? "costs_view.rate_from_config"
+ : "costs_view.rate_default",
+ ),
+ estimated: money(totals?.estimated_usd ?? 0),
+ })}
+ </p>
+ ) : null}
</div>
</ScrollArea>
);
@@ -658,7 +667,7 @@ function AreaSwitch({
"flex flex-1 items-center justify-center gap-1.5 rounded-[10px] px-3 py-1.5 text-xs font-medium transition-colors sm:flex-none",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
active
- ? "bg-card text-foreground shadow-sm"
+ ? "bg-card text-foreground"
: "text-muted-foreground hover:text-foreground",
)}
>
@@ -1299,7 +1308,7 @@ function RatesTable({
<Hash className="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
<span className="truncate text-foreground">{rate.model}</span>
{!rate.known ? (
- <span className="shrink-0 rounded border border-amber-500/40 px-1.5 py-0.5 text-[10px] text-amber-500">
+ <span className="shrink-0 rounded border border-foreground/40 px-1.5 py-0.5 text-[10px] text-foreground">
{t("costs_view.rate_unknown")}
</span>
) : null}
@@ -1626,6 +1635,7 @@ function DayReport({
metric={metric}
currency={currency}
eurPerUsd={eurPerUsd}
+ loading={summary.isLoading}
/>
</div>
</Panel>
@@ -1881,7 +1891,7 @@ function TokenSplitBar({
const parts = [
{ id: "tokens_in", value: tokensIn, color: "hsl(199 90% 62%)" },
{ id: "tokens_cached", value: tokensCached, color: "hsl(268 72% 68%)" },
- { id: "tokens_out", value: tokensOut, color: "hsl(50 100% 52%)" },
+ { id: "tokens_out", value: tokensOut, color: "hsl(var(--primary))" },
];
const total = parts.reduce((sum, p) => sum + p.value, 0);