Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(ai-gateway): stop the gateway banner from flickering on the organizations page (#19557)

Tobias Wochingerf015e23bea8d
diff --git a/web/src/features/ai-gateway/hooks/useGatewayLaunchEligibility.ts b/web/src/features/ai-gateway/hooks/useGatewayLaunchEligibility.ts
index fa8eb6a08c..289629a615 100644
--- a/web/src/features/ai-gateway/hooks/useGatewayLaunchEligibility.ts
+++ b/web/src/features/ai-gateway/hooks/useGatewayLaunchEligibility.ts
@@ -41,6 +41,7 @@ export function useGatewayLaunchTarget(
),
),
);
+ if (!isLaunchTargetSettled(candidates, statuses, ownKeys)) return null;
const unconfigured = candidates.filter(
(_, index) => statuses[index]?.data?.isConfigured === false,
);
@@ -72,3 +73,24 @@ export function useGatewayLaunchTarget(
setupOptions: [],
};
}
+
+/**
+ * A partial answer picks a different org or state than the final one, so the
+ * banner would swap while queries settle.
+ */
+function isLaunchTargetSettled(
+ candidates: ReadonlyArray<GatewayLaunchCandidate>,
+ statuses: ReadonlyArray<SettleQuery<{ isConfigured: boolean }>>,
+ ownKeys: ReadonlyArray<SettleQuery<unknown>>,
+) {
+ // `isFetched` rather than `isError`: refetching a failed query resets its
+ // error, which would hide the banner on every window focus.
+ return candidates.every((candidate, index) => {
+ const status = statuses[index];
+ if (status?.isFetched !== true) return false;
+ if (candidate.canManage || status.data?.isConfigured !== true) return true;
+ return ownKeys[index]?.isFetched === true;
+ });
+}
+
+type SettleQuery<TData> = { data?: TData; isFetched: boolean } | undefined;
diff --git a/web/src/features/organizations/components/OrganizationProjectOverview.tsx b/web/src/features/organizations/components/OrganizationProjectOverview.tsx
index 18eb95024f..ff98e28c17 100644
--- a/web/src/features/organizations/components/OrganizationProjectOverview.tsx
+++ b/web/src/features/organizations/components/OrganizationProjectOverview.tsx
@@ -609,6 +609,9 @@ const pageBanner = ({
/>
);
}
+ // The v4 banner takes precedence once its checks finish, so showing the
+ // gateway banner before then would flash it and swap it out.
+ if (v4UpgradeUiEnabled && v4MigrationBannerState.isChecking) return null;
if (gatewayBanner) return gatewayBanner;
return v4UpgradeUiEnabled ? null : <AgentToolsBanner />;
};
diff --git a/web/src/features/v4-migration/V4MigrationBanner.clienttest.tsx b/web/src/features/v4-migration/V4MigrationBanner.clienttest.tsx
index eb268261d0..fb9aa0de18 100644
--- a/web/src/features/v4-migration/V4MigrationBanner.clienttest.tsx
+++ b/web/src/features/v4-migration/V4MigrationBanner.clienttest.tsx
@@ -108,6 +108,7 @@ describe("V4MigrationBanner", () => {
expect(result.current).toEqual({
projectsNeedingMigration: 0,
totalProjects: 1,
+ isChecking: false,
});
});
@@ -120,6 +121,7 @@ describe("V4MigrationBanner", () => {
const { result } = renderHook(() => useV4MigrationBannerState(true));
expect(result.current.projectsNeedingMigration).toBe(0);
+ expect(result.current.isChecking).toBe(true);
});
it("excludes the demo org and deleted projects from the queried scope", () => {
diff --git a/web/src/features/v4-migration/V4MigrationBanner.tsx b/web/src/features/v4-migration/V4MigrationBanner.tsx
index 51b8019f9a..6c1150368b 100644
--- a/web/src/features/v4-migration/V4MigrationBanner.tsx
+++ b/web/src/features/v4-migration/V4MigrationBanner.tsx
@@ -30,13 +30,17 @@ export function useV4MigrationBannerState(enabled: boolean) {
organizations,
enabled: enabled && organizations.length > 0,
});
- const statuses = Array.from(migrationStatusByProjectId.values());
+ const readiness = Array.from(
+ migrationStatusByProjectId.values(),
+ getProjectMigrationReadiness,
+ );
return {
- projectsNeedingMigration: statuses.filter(
- (status) => getProjectMigrationReadiness(status) === "action-needed",
+ projectsNeedingMigration: readiness.filter(
+ (value) => value === "action-needed",
).length,
- totalProjects: statuses.length,
+ totalProjects: readiness.length,
+ isChecking: enabled && readiness.includes("checking"),
};
}