@devries-cameron20 / t3code Mirror · read-only / commits / 1a44c40901
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 19:30 UTC

fix(client): usage limits skip disabled connections (#22936)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

M4NU5 committed Oct 21, 2026 at 23:13 UTC 1a44c40901a8a639d18947fcccf9707b9b9222d8
4 files changed +60 -7
apps/web/src/components/usage/UsagePage.tsx
+6 -4
@@ -224,7 +224,9 @@ export function UsagePage() {
224 const refreshingUsage = isRefreshing && !showingLimits;
225 const showingKept = shown !== null && shown.window !== window;
226 const presentations = useAtomValue(environmentPresentations.presentationsAtom);
227 - const providersByEnvironment = useAtomValue(environmentPresentations.providersByEnvironmentAtom);
227 + const presentationsWithProviders = useAtomValue(
228 + environmentPresentations.presentationsWithProvidersAtom,
229 + );
230 const cursorAccessEnvironments = hiddenProviders.has("cursor")
231 ? []
232 : cursorKeychainAccessEnvironments(selectedEnvironments);
@@ -351,10 +353,10 @@ export function UsagePage() {
353 : enumerateHourStarts(shownWindow.sinceTime, shownWindow.untilTime);
354 const showChatGptSharing =
355 !hiddenProviders.has("codex") &&
354 - [...providersByEnvironment].some(
355 - ([id, providers]) =>
356 + [...presentationsWithProviders].some(
357 + ([id, presentation]) =>
358 (selectedEnvironmentIds === null || selectedEnvironmentIds.has(id)) &&
357 - providers.some(usesChatGptSharing),
359 + (presentation.serverConfig?.providers ?? []).some(usesChatGptSharing),
360 );
361
362 const windowLabel =
docs/user/usage.md
+1 -1
@@ -79,7 +79,7 @@ the dialog.
79 ## Track subscription limits
80
81 **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
83 list. Each window card shows how much of the pool is left and a bar with one segment per account,
84 kept in the same column across windows. Accounts are ordered by their next 5-hour refill, soonest
85 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
+47
@@ -3,6 +3,7 @@ import { EnvironmentId, type ServerConfig } from "@t3tools/contracts";
3 import * as Option from "effect/Option";
4 import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity";
5
6 +import type { ConnectionCatalogEntry } from "../connection/catalog.ts";
7 import { AVAILABLE_CONNECTION_STATE, PrimaryConnectionTarget } from "../connection/model.ts";
8 import {
9 createEnvironmentPresentationAtoms,
@@ -88,3 +89,49 @@ describe("environment summary subscriptions", () => {
89 }
90 });
91 });
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
+6 -2
@@ -152,13 +152,17 @@ export function createEnvironmentPresentationAtoms<E>(input: {
152 return previous !== null && mapsEqual(previous, next) ? previous : next;
153 }).pipe(Atom.withLabel("environment-providers"));
154
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.
158 const presentationsWithProvidersAtom = Atom.make((get) => {
159 const previous = Option.getOrNull(
160 get.self<ReadonlyMap<EnvironmentId, EnvironmentPresentationWithProviders>>(),
161 );
162 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;
166 const serverConfig = get(input.serverConfigValueAtom(environmentId));
167 const prior = previous?.get(environmentId);
168 next.set(