Update the remote config when the user logs in (#7025)

* Update the remote config when the user logs in

Subscribe to changes in the auth state, and fetch the remote config when the user logs in.

Move the error handling into `fetchRemoteConfig` to remove duplication.

* Update src/core/storage/remote-config/fetch.ts

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

---------

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
Sarah Fortuneandellipsis-dev[bot] authored and GitHub committed 2025-10-22 09:31:15 -06:00
1 parent 65a0c35163
commit ba6a72cf15
3 files changed
+22 -26

No files matched your search

@@ -14,17 +14,10 @@ export async function setUserOrganization(controller: Controller, request: UserO
if (!controller.accountService) {
throw new Error("Account service not available")
}
// Switch to the specified organization using the account service
await controller.accountService.switchAccount(request.organizationId)
try {
await fetchRemoteConfig(controller)
} catch (error) {
console.error("Failed to fetch remote config after org switch:", error)
}
return Empty.create({})
await fetchRemoteConfig(controller)
return {}
} catch (error) {
throw error
}
+12 -14
View File
@@ -34,6 +34,7 @@ import { featureFlagsService } from "@/services/feature-flags"
import { getDistinctId } from "@/services/logging/distinctId"
import { telemetryService } from "@/services/telemetry"
import { ShowMessageType } from "@/shared/proto/host/window"
import { AuthState } from "@/shared/proto/index.cline"
import { getLatestAnnouncementId } from "@/utils/announcements"
import { getCwd, getDesktopDir } from "@/utils/path"
import { PromptRegistry } from "../prompts/system-prompt"
@@ -47,6 +48,7 @@ import {
import { fetchRemoteConfig } from "../storage/remote-config/fetch"
import { PersistenceErrorEvent, StateManager } from "../storage/StateManager"
import { Task } from "../task"
import { StreamingResponseHandler } from "./grpc-handler"
import { sendMcpMarketplaceCatalogEvent } from "./mcp/subscribeToMcpMarketplaceCatalog"
import { appendClineStealthModels } from "./models/refreshOpenRouterModels"
import { checkCliInstallation } from "./state/checkCliInstallation"
@@ -108,16 +110,9 @@ export class Controller {
*/
private startRemoteConfigTimer() {
// Initial fetch
fetchRemoteConfig(this).catch((error) => {
console.error("Failed to fetch remote config:", error)
})
fetchRemoteConfig(this)
// Set up 30-second interval
this.remoteConfigTimer = setInterval(() => {
fetchRemoteConfig(this).catch((error) => {
console.error("Failed to fetch remote config:", error)
})
}, 30000) // 30 seconds
this.remoteConfigTimer = setInterval(() => fetchRemoteConfig(this), 30000) // 30 seconds
}
constructor(readonly context: vscode.ExtensionContext) {
@@ -150,6 +145,13 @@ export class Controller {
this.ocaAuthService = OcaAuthService.initialize(this)
this.accountService = ClineAccountService.getInstance()
const authStatusHandler: StreamingResponseHandler<AuthState> = async (response, _isLast, _seqNumber): Promise<void> => {
if (response.user) {
fetchRemoteConfig(this)
}
}
this.authService.subscribeToAuthStatusUpdate(this, {}, authStatusHandler, undefined)
this.authService.restoreRefreshTokenAndRetrieveAuthInfo().then(() => {
this.startRemoteConfigTimer()
})
@@ -244,11 +246,7 @@ export class Controller {
historyItem?: HistoryItem,
taskSettings?: Partial<Settings>,
) {
try {
await fetchRemoteConfig(this)
} catch (error) {
console.error("Failed to fetch remote config on task init:", error)
}
await fetchRemoteConfig(this)
await this.clearTask() // ensures that an existing task doesn't exist before starting a new one, although this shouldn't be possible since user must clear task before starting a new one
+8 -3
View File
@@ -177,12 +177,17 @@ async function ensureUserInOrgWithRemoteConfig(controller: Controller): Promise<
* Scans all user organizations, switches to the one with remote config if found,
* and applies the configuration.
*
* It catches any exceptions, logs them and does not propagate them to the caller.
*
* This function is called periodically to ensure users stay in
* organizations with remote configuration enabled.
*
* @param controller The controller instance
* @returns Promise resolving to the RemoteConfig object, or undefined if no organization has remote config
*/
export async function fetchRemoteConfig(controller: Controller): Promise<RemoteConfig | undefined> {
return ensureUserInOrgWithRemoteConfig(controller)
export async function fetchRemoteConfig(controller: Controller) {
try {
await ensureUserInOrgWithRemoteConfig(controller)
} catch (error) {
console.error("Failed to fetch remote config", error)
}
}