Skip to content

Commit 1a44c40

Browse files
M4NU5claude
andauthored
fix(client): usage limits skip disabled connections (pingdotgg#22936)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6de7da5 commit 1a44c40

4 files changed

Lines changed: 60 additions & 7 deletions

File tree

‎apps/web/src/components/usage/UsagePage.tsx‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ export function UsagePage() {
224224
const refreshingUsage = isRefreshing && !showingLimits;
225225
const showingKept = shown !== null && shown.window !== window;
226226
const presentations = useAtomValue(environmentPresentations.presentationsAtom);
227-
const providersByEnvironment = useAtomValue(environmentPresentations.providersByEnvironmentAtom);
227+
const presentationsWithProviders = useAtomValue(
228+
environmentPresentations.presentationsWithProvidersAtom,
229+
);
228230
const cursorAccessEnvironments = hiddenProviders.has("cursor")
229231
? []
230232
: cursorKeychainAccessEnvironments(selectedEnvironments);
@@ -351,10 +353,10 @@ export function UsagePage() {
351353
: enumerateHourStarts(shownWindow.sinceTime, shownWindow.untilTime);
352354
const showChatGptSharing =
353355
!hiddenProviders.has("codex") &&
354-
[...providersByEnvironment].some(
355-
([id, providers]) =>
356+
[...presentationsWithProviders].some(
357+
([id, presentation]) =>
356358
(selectedEnvironmentIds === null || selectedEnvironmentIds.has(id)) &&
357-
providers.some(usesChatGptSharing),
359+
(presentation.serverConfig?.providers ?? []).some(usesChatGptSharing),
358360
);
359361

360362
const windowLabel =

‎docs/user/usage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ the dialog.
7979
## Track subscription limits
8080

8181
**Usage → Limits** pools every subscription account it can see per provider, so with several Codex
82-
or Claude accounts across your environments and hubs you read one number per window rather than a
82+
or Claude accounts across your enabled environments and hubs you read one number per window rather than a
8383
list. Each window card shows how much of the pool is left and a bar with one segment per account,
8484
kept in the same column across windows. Accounts are ordered by their next 5-hour refill, soonest
8585
first. For an account with no weekly quota left, this is when its session becomes usable again.

‎packages/client-runtime/src/state/presentation.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
33
import * as Option from "effect/Option";
44
import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
55

6+
import type { ConnectionCatalogEntry } from "../connection/catalog.ts";
67
import { AVAILABLE_CONNECTION_STATE, PrimaryConnectionTarget } from "../connection/model.ts";
78
import {
89
createEnvironmentPresentationAtoms,
@@ -88,3 +89,49 @@ describe("environment summary subscriptions", () => {
8889
}
8990
});
9091
});
92+
93+
describe("presentations with providers", () => {
94+
it("leaves out disabled connections until they are re-enabled", () => {
95+
const h = harness();
96+
const atom = h.full.presentationsWithProvidersAtom;
97+
const withSecond = (enabled: boolean): EnvironmentCatalogState => ({
98+
isReady: true,
99+
entries: new Map([
100+
[FIRST, entry(FIRST)],
101+
[SECOND, { ...entry(SECOND), enabled }],
102+
]),
103+
});
104+
const stop = h.registry.subscribe(atom, () => {});
105+
try {
106+
h.registry.set(h.configs(SECOND), config(false, "/second"));
107+
h.registry.set(h.catalog, withSecond(false));
108+
expect([...h.registry.get(atom).keys()]).toEqual([FIRST]);
109+
expect(h.registry.get(h.full.presentationsAtom).has(SECOND)).toBe(true);
110+
h.registry.set(h.catalog, withSecond(true));
111+
expect([...h.registry.get(atom).keys()]).toEqual([FIRST, SECOND]);
112+
expect(h.registry.get(atom).get(SECOND)?.serverConfig?.cwd).toBe("/second");
113+
} finally {
114+
stop();
115+
h.registry.dispose();
116+
}
117+
});
118+
119+
it("leaves out unsupported environments", () => {
120+
const h = harness();
121+
const atom = h.full.presentationsWithProvidersAtom;
122+
const stop = h.registry.subscribe(atom, () => {});
123+
try {
124+
h.registry.set(h.catalog, {
125+
isReady: true,
126+
entries: new Map<EnvironmentId, ConnectionCatalogEntry>([
127+
[FIRST, entry(FIRST)],
128+
[SECOND, { ...entry(SECOND), unsupportedReason: "Server is too old." }],
129+
]),
130+
});
131+
expect([...h.registry.get(atom).keys()]).toEqual([FIRST]);
132+
} finally {
133+
stop();
134+
h.registry.dispose();
135+
}
136+
});
137+
});

‎packages/client-runtime/src/state/presentation.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,17 @@ export function createEnvironmentPresentationAtoms<E>(input: {
152152
return previous !== null && mapsEqual(previous, next) ? previous : next;
153153
}).pipe(Atom.withLabel("environment-providers"));
154154

155-
// Usage limits ride on provider statuses, so these surfaces rebuild on every push by design.
155+
// Enabled environments only, like serverConfigsAtom: a disabled connection keeps its cached
156+
// config, and its accounts would otherwise count in usage limits. Usage limits ride on provider
157+
// statuses, so these surfaces rebuild on every push by design.
156158
const presentationsWithProvidersAtom = Atom.make((get) => {
157159
const previous = Option.getOrNull(
158160
get.self<ReadonlyMap<EnvironmentId, EnvironmentPresentationWithProviders>>(),
159161
);
160162
const next = new Map<EnvironmentId, EnvironmentPresentationWithProviders>();
161-
for (const [environmentId, presentation] of get(presentationsAtom)) {
163+
for (const environmentId of enabledEnvironmentIds(get(input.catalogValueAtom))) {
164+
const presentation = get(presentationAtom(environmentId));
165+
if (presentation === null) continue;
162166
const serverConfig = get(input.serverConfigValueAtom(environmentId));
163167
const prior = previous?.get(environmentId);
164168
next.set(

0 commit comments

Comments
 (0)