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
This commit is contained in:
2 files changed
+8
-18
No files matched your search
@@ -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()))
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user