From 56b913d951ae0efb15dfd2e4b9d6317ce27e1ec7 Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Mon, 24 Nov 2025 15:35:45 -0800 Subject: [PATCH] fix: feature-flags cache persistence during auth transitions (#7652) * fix: feature-flags cache persistence during auth transitions Restructured feature flags polling and cache management to prevent empty cache states during authentication transitions: - Move cache timestamp update to after successful population in poll() method to ensure cache validity reflects actual data availability - Remove cache.clear() from reset() method to preserve existing flag values until new data is fetched - Split polling logic in AuthService to explicitly handle authenticated vs unauthenticated states - Poll feature flags immediately after reset for authenticated users to ensure cache is populated This prevents temporary cache misses when users log in/out while maintaining cache freshness guarantees. * remove reset method and usage in auth flow Remove the FeatureFlagsService.reset() method and its call during user authentication. The feature flags polling mechanism is sufficient to keep flags up-to-date for authenticated users without requiring an explicit cache reset on auth state changes. Changes: - Remove reset() method from FeatureFlagsService - Remove featureFlagsService.reset() call from AuthService after user identification - Rely solely on poll() to manage feature flags cache updates --- src/services/auth/AuthService.ts | 9 +++++---- .../feature-flags/FeatureFlagsService.ts | 17 +++-------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/services/auth/AuthService.ts b/src/services/auth/AuthService.ts index 25449595..69e20cc0 100644 --- a/src/services/auth/AuthService.ts +++ b/src/services/auth/AuthService.ts @@ -393,11 +393,12 @@ export class AuthService { // Identify the user in telemetry if available if (this._clineAuthInfo?.userInfo?.id) { telemetryService.identifyAccount(this._clineAuthInfo.userInfo) - // Reset feature flags to ensure they are fetched for the new/logged in user - featureFlagsService.reset(this._clineAuthInfo?.userInfo?.id) + // Poll feature flags immediately for authenticated users to ensure cache is populated + await featureFlagsService.poll(this._clineAuthInfo?.userInfo?.id) + } else { + // Poll feature flags for unauthenticated state + await featureFlagsService.poll(undefined) } - // Poll feature flags to ensure they are up to date for all users - await featureFlagsService.poll(this._clineAuthInfo?.userInfo?.id) // Update state in webviews once per unique controller await Promise.all(Array.from(uniqueControllers).map((c) => c.postStateToWebview())) diff --git a/src/services/feature-flags/FeatureFlagsService.ts b/src/services/feature-flags/FeatureFlagsService.ts index e4057157..819c09a9 100644 --- a/src/services/feature-flags/FeatureFlagsService.ts +++ b/src/services/feature-flags/FeatureFlagsService.ts @@ -38,13 +38,15 @@ export class FeatureFlagsService { return } } - this.cacheInfo = { updateTime: timesNow, userId: userId || null } for (const flag of FEATURE_FLAGS) { const payload = await this.getFeatureFlag(flag).catch(() => false) this.cache.set(flag, payload ?? false) } + // Only update timestamp after successfully populating cache + this.cacheInfo = { updateTime: timesNow, userId: userId || null } + getClineOnboardingModels() // Refresh onboarding models cache if relevant flag changed } @@ -149,19 +151,6 @@ export class FeatureFlagsService { return this.provider.getSettings() } - /** - * Reset the feature flags cache - * Should run on user auth state changes to ensure flags are up-to-date - */ - public reset(userId?: string): void { - // Skip known user ID to avoid redundant resets - if (userId && this.cacheInfo.userId === userId) { - return - } - this.cacheInfo = { updateTime: 0, userId: userId || null } - this.cache.clear() - } - /** * For testing: directly set a feature flag in the cache */