The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): free-tier status doesn't race on profile change
ethernet05b9e9e38e5a
diff --git a/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts b/apps/desktop/src/app/shell/hooks/use-status-snapshot.tsindex 241c034d825..8665d25b04f 100644--- a/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts+++ b/apps/desktop/src/app/shell/hooks/use-status-snapshot.ts@@ -96,10 +96,13 @@ export function useStatusSnapshot(// The free-tier verdict is a local, zero-network read that writes// straight to its own store and swallows its failures — nothing here- // waits on it or reads the result.+ // waits on it or reads the result. Unlike the readiness publish below,+ // its write happens inside the store, so hand it this run's liveness: a+ // reply that lands after a source/profile switch must not repaint the+ // shared atom the new run already answered.const [inferenceResult] = await Promise.allSettled([evaluateRuntimeReadiness(requestGateway),- refreshFreeTierStatus(requestGateway)+ refreshFreeTierStatus(requestGateway, () => !cancelled)])if (cancelled || inferenceResult.status !== 'fulfilled') {diff --git a/apps/desktop/src/store/free-tier.ts b/apps/desktop/src/store/free-tier.tsindex 2256046a814..96d089f7ba4 100644--- a/apps/desktop/src/store/free-tier.ts+++ b/apps/desktop/src/store/free-tier.ts@@ -48,15 +48,23 @@ function isFreeTierStatus(value: unknown): value is FreeTierStatus {* cadence (the ambient status snapshot) or a seam that just changed the answer* (boot, a completed sign-in, an acknowledged notice).*+ * `isCurrent` lets a caller whose read belongs to one backend/profile drop a+ * reply that lands after that scope moved: the atom is single and shared, so an+ * in-flight read from the previous profile must not repaint the new one. Omit+ * it where the read cannot outlive its scope.+ ** A failed read leaves the last known answer in place rather than blanking the* chrome — an older backend without the method, or a gateway flap, is not* evidence that the free tier went away.*/-export async function refreshFreeTierStatus(requestGateway: FreeTierRequester): Promise<FreeTierStatus | null> {+export async function refreshFreeTierStatus(+ requestGateway: FreeTierRequester,+ isCurrent?: () => boolean+): Promise<FreeTierStatus | null> {try {const status = await requestGateway<FreeTierStatus>('free_tier.status')- if (!isFreeTierStatus(status)) {+ if (!isFreeTierStatus(status) || (isCurrent && !isCurrent())) {return $freeTierStatus.get()}