Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions apps/desktop-tauri/src-tauri/src/commands/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const LOCAL_USAGE_TTL: Duration = Duration::from_secs(30);
pub struct DailyCostPoint {
pub date: String,
pub value: Option<f64>,
/// Claude requests that only produced a preliminary proxy usage row that
/// day (upstream 0.60.5 #3688). Omitted when zero or not applicable.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub incomplete_request_count: Option<u32>,
}

/// A single (date, tokens) point for the Tokens chart mode (upstream 0.50.0
Expand Down Expand Up @@ -69,6 +73,10 @@ pub struct ProviderLocalUsageSummary {
pub top_model: Option<String>,
pub estimate_note: String,
pub token_cost_updated_at_ms: i64,
/// Incomplete Claude requests excluded from the 30-day totals. Omitted
/// when zero or not applicable.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub incomplete_request_count: Option<u32>,
}

/// One display-only quota-window history row. Completeness is tracked per
Expand Down Expand Up @@ -186,7 +194,18 @@ fn build_provider_chart_data_with_cancel(
.daily_cost
.iter()
.cloned()
.map(|(date, value)| DailyCostPoint { date, value })
.map(|(date, value)| {
let incomplete_request_count = snapshot
.daily_incomplete
.iter()
.find(|(day, _)| *day == date)
.map(|(_, count)| *count);
DailyCostPoint {
date,
value,
incomplete_request_count,
}
})
.collect();
let tokens_history = snapshot
.daily_tokens
Expand Down Expand Up @@ -233,7 +252,11 @@ fn build_provider_chart_data_with_cancel(
let raw_cost = get_daily_cost_history(&provider_id, 30);
let cost_history: Vec<DailyCostPoint> = raw_cost
.into_iter()
.map(|(date, value)| DailyCostPoint { date, value })
.map(|(date, value)| DailyCostPoint {
date,
value,
incomplete_request_count: None,
})
.collect();

let (raw_tokens, tokens_incomplete) = get_daily_token_history(&provider_id, 30);
Expand Down Expand Up @@ -336,7 +359,10 @@ fn local_usage_summary_from_cost_summary(
summary: &CostSummary,
) -> Option<ProviderLocalUsageSummary> {
let total_tokens = total_tokens(summary);
let has_usage = summary.sessions_count > 0 || summary.total_cost_usd > 0.0 || total_tokens > 0;
let has_usage = summary.sessions_count > 0
|| summary.total_cost_usd > 0.0
|| total_tokens > 0
|| summary.incomplete_request_count > 0;
has_usage.then(|| ProviderLocalUsageSummary {
today_cost: None,
thirty_day_cost: non_zero_f64(summary.total_cost_usd),
Expand All @@ -345,6 +371,7 @@ fn local_usage_summary_from_cost_summary(
top_model: top_model(summary),
estimate_note: localized_estimate_note(provider_id, locale::current_language()),
token_cost_updated_at_ms: current_unix_ms(),
incomplete_request_count: non_zero_u32(summary.incomplete_request_count),
})
}

Expand Down Expand Up @@ -412,8 +439,10 @@ fn load_local_usage_summary_with_unknown_models(

let thirty_day_tokens = total_tokens(&thirty_day);
let latest_tokens = total_tokens(&today);
let has_usage =
thirty_day.sessions_count > 0 || thirty_day.total_cost_usd > 0.0 || thirty_day_tokens > 0;
let has_usage = thirty_day.sessions_count > 0
|| thirty_day.total_cost_usd > 0.0
|| thirty_day_tokens > 0
|| thirty_day.incomplete_request_count > 0;
if !has_usage {
return (None, unknown_models);
}
Expand All @@ -428,6 +457,7 @@ fn load_local_usage_summary_with_unknown_models(
top_model: top_model(&thirty_day),
estimate_note: localized_estimate_note(provider_id, lang),
token_cost_updated_at_ms: current_unix_ms(),
incomplete_request_count: non_zero_u32(thirty_day.incomplete_request_count),
}),
unknown_models,
)
Expand All @@ -449,6 +479,7 @@ fn muse_local_usage_summary(
top_model: report.top_model.clone(),
estimate_note: locale::get_text(lang, LocaleKey::PanelEstimatedFromLocalLogsMuse),
token_cost_updated_at_ms: current_unix_ms(),
incomplete_request_count: None,
})
}

Expand Down Expand Up @@ -662,6 +693,10 @@ fn non_zero_u64(value: u64) -> Option<u64> {
(value > 0).then_some(value)
}

fn non_zero_u32(value: u32) -> Option<u32> {
(value > 0).then_some(value)
}

fn top_model(summary: &CostSummary) -> Option<String> {
summary
.by_model_tokens
Expand Down Expand Up @@ -712,6 +747,7 @@ fn load_openai_dashboard_chart_data(
.map(|d| DailyCostPoint {
date: d.day.clone(),
value: Some(d.total_credits_used),
incomplete_request_count: None,
})
.collect();

Expand Down Expand Up @@ -791,6 +827,7 @@ mod tests {
top_model: Some("gpt-5".to_string()),
estimate_note: "estimated".to_string(),
token_cost_updated_at_ms: 1234,
incomplete_request_count: None,
};

let json = serde_json::to_value(summary).expect("serialize summary");
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,15 +1595,18 @@ fn chart_data_serde_roundtrip_preserves_fields() {
DailyCostPoint {
date: "2025-01-01".into(),
value: Some(1.25),
incomplete_request_count: None,
},
DailyCostPoint {
date: "2025-01-02".into(),
value: Some(0.0),
incomplete_request_count: None,
},
],
credits_history: vec![DailyCostPoint {
date: "2025-01-01".into(),
value: Some(42.0),
incomplete_request_count: None,
}],
usage_breakdown: vec![DailyUsageBreakdown {
day: "2025-01-01".into(),
Expand Down
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/src/powertoys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ mod tests {
top_model: Some("gpt-5".to_string()),
estimate_note: "cached".to_string(),
token_cost_updated_at_ms: 1234,
incomplete_request_count: None,
}),
);

Expand Down
9 changes: 9 additions & 0 deletions apps/desktop-tauri/src/components/MenuCardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ function LocalUsageBlock({
</div>
)}

{summary.incompleteRequestCount != null && summary.incompleteRequestCount > 0 && (
<div className="menu-card__local-note">
<strong>{t("IncompleteRequestsLabel")}</strong>
<span>
{t("IncompleteRequestsDetail").replace("{}", String(summary.incompleteRequestCount))}
</span>
</div>
)}

<div className="menu-card__local-note">
{summary.topModel && <strong>{t("PanelTopModelPrefix")}: {summary.topModel}</strong>}
<span>
Expand Down
20 changes: 20 additions & 0 deletions apps/desktop-tauri/src/components/MiniBarChart.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ describe("MiniBarChart history axes", () => {
expect((labels[1] as HTMLElement).style.transform).toBe("");
});

it("marks days that only had incomplete requests without inventing a cost", () => {
const { container } = render(
<SimpleBarChart
points={[
{ date: "2026-09-01", value: null, incompleteRequestCount: 2 },
{ date: "2026-09-02", value: 1.5, incompleteRequestCount: 1 },
]}
t={t}
/>,
);

const titles = Array.from(container.querySelectorAll("rect title")).map(
(node) => node.textContent,
);
expect(titles[0]).toBe("2026-09-01 \u00b7 IncompleteRequestsLabel \u00b7 IncompleteRequestsDetail");
expect(titles[1]).toContain("2026-09-02: 1.50");
expect(titles[1]).toContain("IncompleteRequestsLabel");
expect(container.querySelectorAll("rect")[0]).toHaveAttribute("opacity", "0");
});

it("keeps full endpoint dates for usage breakdown history", () => {
const { container } = render(
<StackedBarChart
Expand Down
8 changes: 7 additions & 1 deletion apps/desktop-tauri/src/components/MiniBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import type { DailyCostPoint, DailyUsageBreakdown } from "../types/bridge";
import type { LocaleKey } from "../i18n/keys";
import { incompleteRequestsTooltip } from "../lib/incompleteRequests";
import {
WIDTH,
getBarCenter,
Expand Down Expand Up @@ -72,7 +73,12 @@ export function SimpleBarChart({
rx={1}
>
<title>
{p.value == null ? p.date : `${p.date}: ${fmt(p.value)}`}
{[
p.value == null ? p.date : `${p.date}: ${fmt(p.value)}`,
incompleteRequestsTooltip(t, p.incompleteRequestCount),
]
.filter(Boolean)
.join(" \u00b7 ")}
</title>
</rect>
);
Expand Down
12 changes: 11 additions & 1 deletion apps/desktop-tauri/src/components/charts/BarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
export interface BarChartPoint {
label: string;
value: number | null;
/** Localized marker for requests excluded from this slot's value. */
incompleteNote?: string;
}

export interface BarChartProps {
Expand Down Expand Up @@ -127,7 +129,12 @@ export function BarChart({
onMouseLeave={onLeave}
>
<title>
{p.value == null ? p.label : `${p.label}: ${fmt(p.value)}`}
{[
p.value == null ? p.label : `${p.label}: ${fmt(p.value)}`,
p.incompleteNote,
]
.filter(Boolean)
.join(" \u00b7 ")}
</title>
</rect>
{isPeak && (
Expand Down Expand Up @@ -165,6 +172,9 @@ export function BarChart({
>
<span className="chart__tooltip-label">{data[hover.i].label}</span>
<strong>{fmt(data[hover.i].value ?? 0)}</strong>
{data[hover.i].incompleteNote && (
<span className="chart__tooltip-label">{data[hover.i].incompleteNote}</span>
)}
</div>
)}
</div>
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop-tauri/src/i18n/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ export const ALL_LOCALE_KEYS = [
"UsageSpendHourlyActivity",
"UsageSpendRequests",
"UsageSpendTokens",
"IncompleteRequestsLabel",
"IncompleteRequestsDetail",
"UsageSpendAllTimeHistory",
"UsageSpendCustomPricing",
"OverviewSpendTitle",
Expand Down
16 changes: 16 additions & 0 deletions apps/desktop-tauri/src/lib/incompleteRequests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from "vitest";
import { incompleteRequestsTooltip } from "./incompleteRequests";

const t = (key: string) =>
key === "IncompleteRequestsDetail" ? "{} requests excluded" : "Incomplete";

describe("incompleteRequestsTooltip", () => {
it("returns null when nothing was excluded", () => {
expect(incompleteRequestsTooltip(t, undefined)).toBeNull();
expect(incompleteRequestsTooltip(t, 0)).toBeNull();
});

it("names the marker and the excluded request count", () => {
expect(incompleteRequestsTooltip(t, 3)).toBe("Incomplete · 3 requests excluded");
});
});
16 changes: 16 additions & 0 deletions apps/desktop-tauri/src/lib/incompleteRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { LocaleKey } from "../i18n/keys";

type Translate = (key: LocaleKey) => string;

/**
* Tooltip text for Claude requests that only produced a preliminary proxy
* usage row (upstream 0.60.5 #3688). Returns null when there is nothing to
* flag so callers can skip the marker.
*/
export function incompleteRequestsTooltip(
t: Translate,
count: number | null | undefined,
): string | null {
if (count == null || count <= 0) return null;
return `${t("IncompleteRequestsLabel")} \u00b7 ${t("IncompleteRequestsDetail").replace("{}", String(count))}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export function ChartsSection({ providerId, accountEmail, accentColor, t }: Prop
providerId={providerId}
animations={animations}
emptyMessage={emptyMsg}
t={t}
/>
)}
{current === "credits" && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { BarChart } from "../../../../../components/charts/BarChart";
import { providerCostColor } from "../../../../../components/charts/chartPalette";
import { incompleteRequestsTooltip } from "../../../../../lib/incompleteRequests";
import type { LocaleKey } from "../../../../../i18n/keys";
import type { DailyCostPoint } from "../../../../../types/bridge";

interface Props {
Expand All @@ -9,6 +11,7 @@ interface Props {
providerId: string;
animations: boolean;
emptyMessage: string;
t: (key: LocaleKey) => string;
}

/**
Expand All @@ -23,9 +26,14 @@ export function CostHistoryChart({
providerId,
animations,
emptyMessage,
t,
}: Props) {
const recent = data.slice(-30);
const points = recent.map((p) => ({ label: p.date, value: p.value }));
const points = recent.map((p) => ({
label: p.date,
value: p.value,
incompleteNote: incompleteRequestsTooltip(t, p.incompleteRequestCount) ?? undefined,
}));
return (
<div className="provider-detail-chart">
<div className="provider-detail-chart__title">{title}</div>
Expand Down
4 changes: 4 additions & 0 deletions apps/desktop-tauri/src/types/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@ export interface AppInfoBridge {
export interface DailyCostPoint {
date: string;
value: number | null;
/** Claude requests excluded from this day's totals (upstream 0.60.5 #3688). */
incompleteRequestCount?: number;
}

/** Exact local token totals per day (upstream 0.50.0 #2930). */
Expand Down Expand Up @@ -825,6 +827,8 @@ export interface ProviderLocalUsageSummary {
topModel: string | null;
estimateNote: string;
tokenCostUpdatedAtMs: number;
/** Claude requests excluded from the 30-day totals (upstream 0.60.5 #3688). */
incompleteRequestCount?: number;
}

export interface QuotaWindowHistoryPoint {
Expand Down
Loading