The best way to control Claude Code, Codex and more from any computer or phone
fix(usage): identify client version mismatches (#8208)
Tristan Knight committed
Sep 26, 2026 at 20:58 UTC
3dae78f33b1e3c7534feb51ca41a407ab2536b83
5 files changed
+92
-25
apps/mobile/src/features/usage/UsageRouteScreen.tsx
+7
-1
@@ -15,6 +15,7 @@ import {
15
formatHourShort,
16
formatPercent,
17
formatTokens,
18
+ formatUsageContractMismatch,
19
formatUsd,
20
makeWindow,
21
} from "@t3tools/shared/usageFormat";
@@ -753,7 +754,12 @@ function usageEnvironmentStatus(environment: EnvironmentUsageStatus): string {
754
environment.summary &&
755
!isCompatibleUsageContractVersion(environment.summary.contractVersion, USAGE_CONTRACT_VERSION)
756
) {
756
- return "Older server · excluded from usage totals";
757
+ return formatUsageContractMismatch(environment.label, {
758
+ direction:
759
+ environment.summary.contractVersion < USAGE_CONTRACT_VERSION
760
+ ? "serverBehind"
761
+ : "clientBehind",
762
+ });
763
}
764
if (!environment.isConnected)
765
return environment.summary ? "Disconnected · showing saved usage" : "Waiting for connection…";
apps/web/src/components/usage/UsagePage.tsx
+19
-13
@@ -20,6 +20,7 @@ import {
20
isModelCostUnknown,
21
type DailyTotals,
22
type HourlyTotals,
23
+ type MergedUsage,
24
} from "@t3tools/shared/usageMerge";
25
26
import { isElectron } from "../../env";
@@ -40,6 +41,7 @@ import {
41
formatHourShort,
42
formatPercent,
43
formatTokens,
44
+ formatUsageContractMismatch,
45
formatUsd,
46
makeWindow,
47
} from "@t3tools/shared/usageFormat";
@@ -314,7 +316,7 @@ export function UsagePage() {
316
showUsageStatus={!showingLimits}
317
isPartial={isPartial}
318
duplicateSources={merged.duplicateSources}
317
- staleEnvironments={merged.staleEnvironments}
319
+ contractMismatches={merged.contractMismatches}
320
/>
321
</WorkspaceBreadcrumbItem>
322
</WorkspaceBreadcrumb>
@@ -899,17 +901,21 @@ function Metric({ label, value }: { readonly label: string; readonly value: stri
901
function UsageCoverageNotice({
902
environments,
903
duplicateSources,
902
- staleEnvironments,
904
+ contractMismatches,
905
}: {
906
readonly environments: readonly EnvironmentUsageStatus[];
907
readonly duplicateSources: readonly string[];
906
- readonly staleEnvironments: readonly string[];
908
+ readonly contractMismatches: MergedUsage["contractMismatches"];
909
}) {
910
const failed = environments.filter((environment) => environment.error !== null);
909
- const stale = environments.filter((environment) =>
910
- staleEnvironments.includes(environment.environmentId),
911
+ const mismatchByEnvironment = new Map(
912
+ contractMismatches.map((mismatch) => [mismatch.environmentId, mismatch]),
913
);
912
- if (failed.length === 0 && stale.length === 0 && duplicateSources.length === 0) {
914
+ const incompatible = environments.flatMap((environment) => {
915
+ const mismatch = mismatchByEnvironment.get(environment.environmentId);
916
+ return mismatch === undefined ? [] : [{ environment, mismatch }];
917
+ });
918
+ if (failed.length === 0 && incompatible.length === 0 && duplicateSources.length === 0) {
919
return null;
920
}
921
@@ -918,9 +924,9 @@ function UsageCoverageNotice({
924
{failed.map((environment) => (
925
<span key={environment.label}>{environment.label} could not report usage.</span>
926
))}
921
- {stale.map((environment) => (
922
- <span key={environment.label}>
923
- {environment.label} runs an older server version and is excluded from totals.
927
+ {incompatible.map(({ environment, mismatch }) => (
928
+ <span key={environment.environmentId}>
929
+ {formatUsageContractMismatch(environment.label, mismatch)}
930
</span>
931
))}
932
{duplicateSources.length > 0 ? (
@@ -942,7 +948,7 @@ function UsageEnvironmentFilter({
948
showUsageStatus,
949
isPartial,
950
duplicateSources,
945
- staleEnvironments,
951
+ contractMismatches,
952
}: {
953
readonly environments: readonly EnvironmentUsageStatus[];
954
readonly selectedEnvironments: readonly EnvironmentUsageStatus[];
@@ -951,7 +957,7 @@ function UsageEnvironmentFilter({
957
readonly showUsageStatus: boolean;
958
readonly isPartial: boolean;
959
readonly duplicateSources: readonly string[];
954
- readonly staleEnvironments: readonly string[];
960
+ readonly contractMismatches: MergedUsage["contractMismatches"];
961
}) {
962
const [modelPricesOpen, setModelPricesOpen] = useState(false);
963
const allSelected = selectedEnvironmentIds === null;
@@ -966,7 +972,7 @@ function UsageEnvironmentFilter({
972
).length;
973
const hasIssue =
974
selectedEnvironments.some((environment) => environment.error !== null) ||
969
- staleEnvironments.length > 0;
975
+ contractMismatches.length > 0;
976
977
return (
978
<>
@@ -1066,7 +1072,7 @@ function UsageEnvironmentFilter({
1072
<UsageCoverageNotice
1073
environments={selectedEnvironments}
1074
duplicateSources={duplicateSources}
1069
- staleEnvironments={staleEnvironments}
1075
+ contractMismatches={contractMismatches}
1076
/>
1077
) : null}
1078
<MenuSeparator />
packages/shared/src/usageFormat.ts
+11
@@ -6,6 +6,8 @@
6
*/
7
import { UsageDay, type UsageResolution, type UsageSummaryInput } from "@t3tools/contracts";
8
9
+import type { UsageContractMismatch } from "./usageMerge.ts";
10
+
11
const CURRENCY = new Intl.NumberFormat("en-US", {
12
style: "currency",
13
currency: "USD",
@@ -49,6 +51,15 @@ export function formatPercent(share: number, digits = 1): string {
51
return `${percent.toFixed(digits)}%`;
52
}
53
54
+export function formatUsageContractMismatch(
55
+ environmentLabel: string,
56
+ mismatch: Pick<UsageContractMismatch, "direction">,
57
+): string {
58
+ return mismatch.direction === "serverBehind"
59
+ ? `${environmentLabel} runs an older server version and is excluded from totals.`
60
+ : `This client is older than the server on ${environmentLabel}; its usage is excluded from totals.`;
61
+}
62
+
63
/** `2026-08-07` to `Aug 7`. */
64
export function formatDayShort(day: string): string {
65
const [year, month, dayOfMonth] = day.split("-").map((part) => Number(part));
packages/shared/src/usageMerge.test.ts
+34
-3
@@ -329,7 +329,7 @@ describe("mergeUsage", () => {
329
expect(merged.contributingEnvironments).toEqual(["old"]);
330
});
331
332
- it("excludes an environment reporting an older contract version", () => {
332
+ it("identifies an environment reporting an older contract version", () => {
333
const merged = mergeUsage(
334
[
335
environment(
@@ -349,7 +349,38 @@ describe("mergeUsage", () => {
349
);
350
351
expect(merged.costUsd).toBe(10);
352
- expect(merged.staleEnvironments).toEqual(["env-b"]);
352
+ expect(merged.contractMismatches).toEqual([
353
+ {
354
+ environmentId: "env-b",
355
+ direction: "serverBehind",
356
+ contractVersion: USAGE_MERGE_COMPATIBLE_SINCE - 1,
357
+ },
358
+ ]);
359
+ });
360
+
361
+ it("identifies an environment reporting a newer contract version", () => {
362
+ const merged = mergeUsage(
363
+ [
364
+ environment(
365
+ "env-a",
366
+ summary(
367
+ [bucket()],
368
+ [{ provider: "claude", hostId: "mac", homePath: "/a" }],
369
+ USAGE_CONTRACT_VERSION + 1,
370
+ ),
371
+ ),
372
+ ],
373
+ USAGE_CONTRACT_VERSION,
374
+ );
375
+
376
+ expect(merged.costUsd).toBe(0);
377
+ expect(merged.contractMismatches).toEqual([
378
+ {
379
+ environmentId: "env-a",
380
+ direction: "clientBehind",
381
+ contractVersion: USAGE_CONTRACT_VERSION + 1,
382
+ },
383
+ ]);
384
});
385
386
it("keeps the previous compatible contract version so additive provider expansions still merge", () => {
@@ -375,7 +406,7 @@ describe("mergeUsage", () => {
406
);
407
408
expect(merged.costUsd).toBe(14);
378
- expect(merged.staleEnvironments).toEqual([]);
409
+ expect(merged.contractMismatches).toEqual([]);
410
});
411
412
it("keeps known usage when newer providers and bucket variants cannot be decoded", () => {
packages/shared/src/usageMerge.ts
+21
-8
@@ -76,6 +76,12 @@ export interface CostQuality {
76
readonly cacheSavingsUsd: number;
77
}
78
79
+export interface UsageContractMismatch {
80
+ readonly environmentId: EnvironmentId;
81
+ readonly direction: "serverBehind" | "clientBehind";
82
+ readonly contractVersion: number;
83
+}
84
+
85
export interface MergedUsage {
86
readonly costUsd: number;
87
readonly uncachedInputTokens: number;
@@ -94,7 +100,7 @@ export interface MergedUsage {
100
/** Environments whose data was dropped as a duplicate of another's. */
101
readonly duplicateSources: readonly string[];
102
readonly contributingEnvironments: readonly EnvironmentId[];
97
- readonly staleEnvironments: readonly EnvironmentId[];
103
+ readonly contractMismatches: readonly UsageContractMismatch[];
104
}
105
106
/**
@@ -303,15 +309,15 @@ const EMPTY_MERGED: MergedUsage = {
309
},
310
duplicateSources: [],
311
contributingEnvironments: [],
306
- staleEnvironments: [],
312
+ contractMismatches: [],
313
};
314
315
/**
316
* Merges every connected environment's summary.
317
*
312
- * `expectedContractVersion` guards against an environment running older server
313
- * code: rather than blocking the page, incompatible data is excluded and its
314
- * id is reported so the UI can say coverage is partial. Versions in
318
+ * `expectedContractVersion` guards against incompatible server code: rather
319
+ * than blocking the page, its data is excluded and the mismatch direction is
320
+ * reported so the UI can identify which side needs updating. Versions in
321
* [{@link USAGE_MERGE_COMPATIBLE_SINCE}, expected] still merge, so an additive
322
* provider expansion does not drop Claude/Codex totals from older servers.
323
*/
@@ -322,14 +328,21 @@ export function mergeUsage(
328
if (environments.length === 0) return EMPTY_MERGED;
329
330
const current: EnvironmentUsage[] = [];
325
- const staleEnvironments: EnvironmentId[] = [];
331
+ const contractMismatches: UsageContractMismatch[] = [];
332
for (const environment of environments) {
333
if (
334
isCompatibleUsageContractVersion(environment.summary.contractVersion, expectedContractVersion)
335
) {
336
current.push(environment);
337
} else {
332
- staleEnvironments.push(environment.environmentId);
338
+ contractMismatches.push({
339
+ environmentId: environment.environmentId,
340
+ direction:
341
+ environment.summary.contractVersion < expectedContractVersion
342
+ ? "serverBehind"
343
+ : "clientBehind",
344
+ contractVersion: environment.summary.contractVersion,
345
+ });
346
}
347
}
348
@@ -544,6 +557,6 @@ export function mergeUsage(
557
},
558
duplicateSources: duplicates,
559
contributingEnvironments,
547
- staleEnvironments,
560
+ contractMismatches,
561
};
562
}