Skip to content

Commit ec229db

Browse files
agentHitsclaude
andcommitted
fix(gui): clear React Doctor findings in the accounts workspace
`[email protected] --scope changed --base upstream/dev` reported 11 issues, which the blocking CI job would have failed on once it is allowed to run: - `poolStateFrom` was rebuilt on every render and missing from two `useCallback` dependency lists (react-compiler MemoDependencies). It reads no component state, so it moves to module scope with a named state type. - The token-estimate effect set state after an `await` behind a combined condition; the cancellation check is now its own early return. - The estimate loops read `analyzed.<window>.percent` three or four times per iteration; each window's percentage is read once at the top of the loop. - The estimate's link to the Logs page was a literal `#logs`, which reads as an in-page anchor with no target. It is a hash route, so it is now built from the `Page` route name. No behaviour change. React Doctor reports no issues on the changed scope. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 66f3514 commit ec229db

3 files changed

Lines changed: 55 additions & 37 deletions

File tree

‎gui/src/components/provider-workspace/ProviderAccountsToolbar.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import type {
1616
AccountViewModeKey,
1717
AnalyzedAccountQuota,
1818
} from "./account-quota-analysis";
19+
import type { Page } from "../../app-routing";
20+
21+
/** The estimate's source link is a hash route to the Logs page, not an in-page anchor. */
22+
const LOGS_PAGE: Page = "logs";
1923

2024
export interface ProviderAccountsToolbarProps {
2125
apiBase?: string;
@@ -395,7 +399,7 @@ export default function ProviderAccountsToolbar({
395399
<div className="pwi-tokens-header-bar">
396400
<span className="pwi-stat-lbl">{t("pws.tokensEstimateTitle")}</span>
397401
<a
398-
href="#logs"
402+
href={`#${LOGS_PAGE}`}
399403
className="pwi-stat-hint-link"
400404
title={t("pws.tokensCalibratedTooltip")}
401405
>

‎gui/src/components/provider-workspace/ProviderAuthPanel.tsx‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,25 @@ const EMPTY_API_KEYS: ApiKeyRow[] = [];
5959
* the badge must agree: a row fetched here and hidden there is a billing RPC
6060
* spent on a 401.
6161
*/
62+
interface GenericPoolState {
63+
scope: string;
64+
enabled: boolean;
65+
strategy: AccountPoolStrategy;
66+
inert: boolean;
67+
/** A stored strategy this dashboard does not model (Kiro's CLI-only least-loaded). */
68+
unmodeledStrategy: string | null;
69+
}
70+
71+
function poolStateFrom(scope: string, res: PoolSettings): GenericPoolState {
72+
return {
73+
scope,
74+
enabled: res.enabled === true || res.enabledEffective === true,
75+
strategy: res.strategy,
76+
inert: res.inert,
77+
unmodeledStrategy: res.storedStrategy !== null && res.storedStrategy !== res.strategy ? res.storedStrategy : null,
78+
};
79+
}
80+
6281
function accountShowsReauth(account: OAuthAccountRow): boolean {
6382
return Boolean(account.needsReauth) || oauthHealthShowsReauth(account.health?.status);
6483
}
@@ -273,18 +292,7 @@ export default function ProviderAuthPanel({
273292
// Pool settings belong to the provider and server they were read for. The panel is not
274293
// remounted per provider, so a value from another scope is hidden during render: it is
275294
// never shown, and the toggle can never persist it, under the provider now on screen.
276-
const [genericPoolState, setGenericPool] = useState<{
277-
scope: string; enabled: boolean; strategy: AccountPoolStrategy; inert: boolean;
278-
/** A stored strategy this dashboard does not model (Kiro's CLI-only least-loaded). */
279-
unmodeledStrategy: string | null;
280-
} | null>(null);
281-
const poolStateFrom = (scope: string, res: PoolSettings) => ({
282-
scope,
283-
enabled: res.enabled === true || res.enabledEffective === true,
284-
strategy: res.strategy,
285-
inert: res.inert,
286-
unmodeledStrategy: res.storedStrategy !== null && res.storedStrategy !== res.strategy ? res.storedStrategy : null,
287-
});
295+
const [genericPoolState, setGenericPool] = useState<GenericPoolState | null>(null);
288296
const genericPool = genericPoolState?.scope === grantScope ? genericPoolState : null;
289297

290298
const [poolSaveError, setPoolSaveError] = useState<string | null>(null);

‎gui/src/components/provider-workspace/account-tokens-estimate.ts‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -321,28 +321,31 @@ export function calculatePoolTokensEstimate(
321321
for (const analyzed of analyzedList) {
322322
const label = analyzed.account.logLabel || computeOAuthAccountLogLabel(analyzed.account.id, providerName);
323323
if (!label) continue;
324+
const gemini5h = analyzed.gemini5h?.percent;
325+
const claude5h = analyzed.claude5h?.percent;
326+
const generic5h = analyzed.generic5h?.percent;
324327

325-
if (analyzed.gemini5h && analyzed.gemini5h.percent > 0 && analyzed.gemini5h.percent < 99.5) {
328+
if (gemini5h !== undefined && gemini5h > 0 && gemini5h < 99.5) {
326329
const tok = tokens5hByLabelAndFamily.get(label + ":gemini") ?? 0;
327330
if (tok > 0) {
328331
gemUsedTokens5h += tok;
329-
gemUsedPercent5h += analyzed.gemini5h.percent;
332+
gemUsedPercent5h += gemini5h;
330333
}
331334
}
332335

333-
if (analyzed.claude5h && analyzed.claude5h.percent > 0 && analyzed.claude5h.percent < 99.5) {
336+
if (claude5h !== undefined && claude5h > 0 && claude5h < 99.5) {
334337
const tok = tokens5hByLabelAndFamily.get(label + ":claude") ?? 0;
335338
if (tok > 0) {
336339
claUsedTokens5h += tok;
337-
claUsedPercent5h += analyzed.claude5h.percent;
340+
claUsedPercent5h += claude5h;
338341
}
339342
}
340343

341-
if (analyzed.generic5h && analyzed.generic5h.percent > 0 && analyzed.generic5h.percent < 99.5) {
344+
if (generic5h !== undefined && generic5h > 0 && generic5h < 99.5) {
342345
const tok = tokens5hByLabelAndFamily.get(label + ":generic") ?? 0;
343346
if (tok > 0) {
344347
genericUsedTokens5h += tok;
345-
genericUsedPercent5h += analyzed.generic5h.percent;
348+
genericUsedPercent5h += generic5h;
346349
}
347350
}
348351
}
@@ -408,46 +411,49 @@ export function calculatePoolTokensEstimate(
408411
const acc = analyzed.account;
409412
if (acc.health?.status === "reauth_required") continue;
410413
if (acc.quotaUnavailable || !acc.quota) continue;
414+
const gemini5h = analyzed.gemini5h?.percent;
415+
const claude5h = analyzed.claude5h?.percent;
416+
const generic5h = analyzed.generic5h?.percent;
411417

412418
if (showModelFamilies || isAntigravity) {
413419
// Gemini 5h
414-
if (analyzed.gemini5h && !analyzed.geminiExhausted && analyzed.gemini5h.percent < 99.5) {
415-
const free = Math.max(0, 100 - analyzed.gemini5h.percent);
420+
if (gemini5h !== undefined && !analyzed.geminiExhausted && gemini5h < 99.5) {
421+
const free = Math.max(0, 100 - gemini5h);
416422
gemini5hRem += gemini5hCapacity * (free / 100);
417423
}
418424
// Gemini Weekly
419425
if (analyzed.geminiWeekly && analyzed.geminiWeekly.percent < 99.5) {
420426
const free = Math.max(0, 100 - analyzed.geminiWeekly.percent);
421427
geminiWeeklyRem += geminiWeeklyCapacity * (free / 100);
422-
} else if (analyzed.gemini5h && !analyzed.geminiExhausted) {
423-
const impliedUsed = Math.min(99, analyzed.gemini5h.percent * 0.35);
428+
} else if (gemini5h !== undefined && !analyzed.geminiExhausted) {
429+
const impliedUsed = Math.min(99, gemini5h * 0.35);
424430
geminiWeeklyRem += geminiWeeklyCapacity * (Math.max(0, 100 - impliedUsed) / 100);
425431
}
426432

427433
// Claude 5h
428-
if (analyzed.claude5h && !analyzed.claudeExhausted && analyzed.claude5h.percent < 99.5) {
429-
const free = Math.max(0, 100 - analyzed.claude5h.percent);
434+
if (claude5h !== undefined && !analyzed.claudeExhausted && claude5h < 99.5) {
435+
const free = Math.max(0, 100 - claude5h);
430436
claude5hRem += claude5hCapacity * (free / 100);
431437
}
432438
// Claude Weekly
433439
if (analyzed.claudeWeekly && analyzed.claudeWeekly.percent < 99.5) {
434440
const free = Math.max(0, 100 - analyzed.claudeWeekly.percent);
435441
claudeWeeklyRem += claudeWeeklyCapacity * (free / 100);
436-
} else if (analyzed.claude5h && !analyzed.claudeExhausted) {
437-
const impliedUsed = Math.min(99, analyzed.claude5h.percent * 0.35);
442+
} else if (claude5h !== undefined && !analyzed.claudeExhausted) {
443+
const impliedUsed = Math.min(99, claude5h * 0.35);
438444
claudeWeeklyRem += claudeWeeklyCapacity * (Math.max(0, 100 - impliedUsed) / 100);
439445
}
440446
} else {
441447
// Generic OAuth provider (Anthropic, OpenAI, etc.)
442-
if (analyzed.generic5h && analyzed.generic5h.percent < 99.5) {
443-
const free = Math.max(0, 100 - analyzed.generic5h.percent);
448+
if (generic5h !== undefined && generic5h < 99.5) {
449+
const free = Math.max(0, 100 - generic5h);
444450
generic5hRem += generic5hCapacity * (free / 100);
445451
}
446452
if (analyzed.genericWeekly && analyzed.genericWeekly.percent < 99.5) {
447453
const free = Math.max(0, 100 - analyzed.genericWeekly.percent);
448454
genericWeeklyRem += genericWeeklyCapacity * (free / 100);
449-
} else if (analyzed.generic5h && analyzed.generic5h.percent < 99.5) {
450-
const impliedUsed = Math.min(99, analyzed.generic5h.percent * 0.35);
455+
} else if (generic5h !== undefined && generic5h < 99.5) {
456+
const impliedUsed = Math.min(99, generic5h * 0.35);
451457
genericWeeklyRem += genericWeeklyCapacity * (Math.max(0, 100 - impliedUsed) / 100);
452458
}
453459
}
@@ -493,7 +499,7 @@ export function usePoolTokensEstimate({
493499
const [lastFetchedAt, setLastFetchedAt] = useState<number>(() => 0);
494500

495501
useEffect(() => {
496-
let unmounted = false;
502+
let cancelled = false;
497503
const controller = new AbortController();
498504
const loadLogs = async () => {
499505
// A hidden tab needs no fresh estimate; the next visible load refreshes.
@@ -503,10 +509,10 @@ export function usePoolTokensEstimate({
503509
const res = await fetch(url, { signal: controller.signal });
504510
if (!res.ok) return;
505511
const data = await res.json() as { logs?: MinimalLogEntry[] };
506-
if (!unmounted && Array.isArray(data.logs)) {
507-
setLogs(data.logs);
508-
setLastFetchedAt(Date.now());
509-
}
512+
if (cancelled) return;
513+
if (!Array.isArray(data.logs)) return;
514+
setLogs(data.logs);
515+
setLastFetchedAt(Date.now());
510516
} catch (err) {
511517
if (err instanceof DOMException && err.name === "AbortError") return;
512518
// Soft fallback to baseline
@@ -521,7 +527,7 @@ export function usePoolTokensEstimate({
521527
}, 45_000);
522528

523529
return () => {
524-
unmounted = true;
530+
cancelled = true;
525531
controller.abort();
526532
window.clearInterval(timer);
527533
};

0 commit comments

Comments
 (0)