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 */