From 7f710c2bc8486d5e3b5e2d019f90b61deec49eb9 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 12:55:43 +0000 Subject: [PATCH] fix(usage): wait for initial connection attempt --- apps/mobile/src/state/usage.test.ts | 8 ++++++++ apps/mobile/src/state/usage.ts | 4 +++- apps/web/src/state/usage.test.ts | 8 ++++++++ apps/web/src/state/usage.ts | 4 +++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/state/usage.test.ts b/apps/mobile/src/state/usage.test.ts index 089f5712a9..7e2c66199e 100644 --- a/apps/mobile/src/state/usage.test.ts +++ b/apps/mobile/src/state/usage.test.ts @@ -43,6 +43,14 @@ describe("mobile usage environment scope", () => { ).toEqual({ isPending: true, isPartial: false }); }); + it("waits for the first connection attempt", () => { + expect( + getEnvironmentUsageLoadingState([ + { phase: "connecting", isPending: true, summary: null, error: null }, + ]), + ).toEqual({ isPending: true, isPartial: false }); + }); + it("isolates a selected environment and falls back when it disappears", () => { const options = [environment("healthy", "connected"), environment("down", "offline")]; diff --git a/apps/mobile/src/state/usage.ts b/apps/mobile/src/state/usage.ts index 7300747499..b53b182c29 100644 --- a/apps/mobile/src/state/usage.ts +++ b/apps/mobile/src/state/usage.ts @@ -69,13 +69,15 @@ const usageByWindowAtom = Atom.family((key: string) => const { environmentId } = option; const connectionResult = get(environmentCatalog.stateAtom(environmentId)); // Keep reading the environment-scoped atom while disconnected so a prior - // successful value remains visible. Only a connected query can keep the UI loading. + // successful value remains visible. Wait through the first connection attempt, + // then treat retries as terminal coverage so a down machine cannot block the UI. const result = get(serverEnvironment.usageSummary({ environmentId, input })); const failed = option.phase === "connected" && result._tag === "Failure"; environments.push({ ...option, isPending: (option.phase === "available" && connectionResult.waiting) || + option.phase === "connecting" || (option.phase === "connected" && result.waiting), error: failed ? "This environment could not report usage." : null, summary: Option.getOrNull(AsyncResult.value(result)), diff --git a/apps/web/src/state/usage.test.ts b/apps/web/src/state/usage.test.ts index 4bb40f8939..d78a0294ca 100644 --- a/apps/web/src/state/usage.test.ts +++ b/apps/web/src/state/usage.test.ts @@ -87,6 +87,14 @@ describe("usage environment scope", () => { ).toEqual({ isPending: true, isPartial: false }); }); + it("keeps the first connection attempt pending", () => { + expect( + getEnvironmentUsageLoadingState([ + { phase: "connecting", isPending: true, summary: null, error: null }, + ]), + ).toEqual({ isPending: true, isPartial: false }); + }); + it("keeps a selected offline environment terminal and isolated", () => { const scope = resolveEnvironmentUsageScope( [environment("healthy", "connected"), environment("down", "offline")], diff --git a/apps/web/src/state/usage.ts b/apps/web/src/state/usage.ts index 131ccaa39b..32703e01c3 100644 --- a/apps/web/src/state/usage.ts +++ b/apps/web/src/state/usage.ts @@ -67,13 +67,15 @@ const usageByWindowAtom = Atom.family((key: string) => const { environmentId } = option; const connectionResult = get(environmentCatalog.stateAtom(environmentId)); // Keep reading the environment-scoped atom while disconnected so a prior - // successful value remains visible. Only a connected query can keep the UI loading. + // successful value remains visible. Wait through the first connection attempt, + // then treat retries as terminal coverage so a down machine cannot block the UI. const result = get(serverEnvironment.usageSummary({ environmentId, input })); const failed = option.phase === "connected" && result._tag === "Failure"; environments.push({ ...option, isPending: (option.phase === "available" && connectionResult.waiting) || + option.phase === "connecting" || (option.phase === "connected" && result.waiting), error: failed ? "This environment could not report usage." : null, summary: Option.getOrNull(AsyncResult.value(result)),