Elffuss BraidHub

kikocis/continue public

Fix: Refactor dependency injection for settings and clients

This commit refactors how IdeSettings and ControlPlaneClient are accessed throughout
the configuration system to improve state management and reduce coupling.

Previously, ideSettingsPromise was passed down from the top-level ConfigHandler
through various profile loaders and clients. This created a rigid dependency chain
and required manual promise replacement when settings were updated. Similarly,
downstream components could hold onto stale instances of ControlPlaneClient after a
change in authentication state.

The key changes are:
  - Removed ideSettingsPromise prop drilling: Components that require IDE settings
    now fetch them directly from the IDE object (ide.getIdeSettings()) when
    needed.

  - Updated globalLocalProfileManager during every cascadeInit: This ensures it
    always holds the most recent ControlPlaneClient, preventing issues with stale
    client objects after re-authentication.

  - Simplified constructors: The constructors for ConfigHandler, ControlPlaneClient,
    and various loaders have been simplified to reflect these changes, primarily by
    passing the IDE object directly instead of its derived promises.
Changeset424fb7319bf7a85702469b26c9d0f2504fd4d43ab4c8e07c59660f8f9db3901a
AuthorJazzcort <jason101011113@gmail.com> · 2025-08-28 15:34 -04:00
CommitterJazzcort <jason101011113@gmail.com> · 2025-09-03 09:15 -04:00
Parents8aab215acf3c

Browse the files at this changeset

8 files changed

modified core/config/ConfigHandler.ts +13 −19
@@ -59,27 +59,17 @@
5959
6060 constructor(
6161 private readonly ide: IDE,
62- private ideSettingsPromise: Promise<IdeSettings>,
6362 private llmLogger: ILLMLogger,
64- sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
63+ initialSessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
6564 ) {
66- this.ide = ide;
67- this.ideSettingsPromise = ideSettingsPromise;
68-
6965 this.controlPlaneClient = new ControlPlaneClient(
70- sessionInfoPromise,
71- ideSettingsPromise,
72- this.ide.getIdeInfo(),
66+ initialSessionInfoPromise,
67+ this.ide,
7368 );
7469
7570 // This profile manager will always be available
7671 this.globalLocalProfileManager = new ProfileLifecycleManager(
77- new LocalProfileLoader(
78- ide,
79- ideSettingsPromise,
80- this.controlPlaneClient,
81- this.llmLogger,
82- ),
72+ new LocalProfileLoader(ide, this.controlPlaneClient, this.llmLogger),
8373 this.ide,
8474 );
8575
@@ -97,6 +87,7 @@
9787 }
9888
9989 private workspaceDirs: string[] | null = null;
90+
10091 async getWorkspaceId() {
10192 if (!this.workspaceDirs) {
10293 this.workspaceDirs = await this.ide.getWorkspaceDirs();
@@ -113,6 +104,13 @@
113104 const signal = this.cascadeAbortController.signal;
114105 this.workspaceDirs = null; // forces workspace dirs reload
115106
107+ // Always update globalLocalProfileManager before recreating all the loaders
108+ // during every cascadeInit so it holds the most recent controlPlaneClient.
109+ this.globalLocalProfileManager = new ProfileLifecycleManager(
110+ new LocalProfileLoader(this.ide, this.controlPlaneClient, this.llmLogger),
111+ this.ide,
112+ );
113+
116114 try {
117115 const { orgs, errors } = await this.getOrgs();
118116
@@ -246,7 +244,6 @@
246244 versionSlug: assistant.configResult.config?.version ?? "latest",
247245 controlPlaneClient: this.controlPlaneClient,
248246 ide: this.ide,
249- ideSettingsPromise: this.ideSettingsPromise,
250247 llmLogger: this.llmLogger,
251248 rawYaml: assistant.rawYaml,
252249 orgScopeId: orgScopeId,
@@ -367,7 +364,6 @@
367364 const profiles = [...assistantFiles, ...agentFiles].map((assistant) => {
368365 return new LocalProfileLoader(
369366 this.ide,
370- this.ideSettingsPromise,
371367 this.controlPlaneClient,
372368 this.llmLogger,
373369 assistant,
@@ -392,7 +388,6 @@
392388
393389 // Ide settings change: refresh session and cascade refresh from the top
394390 async updateIdeSettings(ideSettings: IdeSettings) {
395- this.ideSettingsPromise = Promise.resolve(ideSettings);
396391 this.abortCascade();
397392 await this.cascadeInit("IDE settings update");
398393 }
@@ -430,8 +425,7 @@
430425 if (reload) {
431426 this.controlPlaneClient = new ControlPlaneClient(
432427 Promise.resolve(sessionInfo),
433- this.ideSettingsPromise,
434- this.ide.getIdeInfo(),
428+ this.ide,
435429 );
436430 this.abortCascade();
437431 await this.cascadeInit("Control plane session info update");
modified core/config/profile/LocalProfileLoader.ts +1 −3
@@ -1,7 +1,7 @@
11 import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
22
33 import { ControlPlaneClient } from "../../control-plane/client.js";
4-import { ContinueConfig, IDE, IdeSettings, ILLMLogger } from "../../index.js";
4+import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
55 import { ProfileDescription } from "../ProfileLifecycleManager.js";
66
77 import { getPrimaryConfigFilePath } from "../../util/paths.js";
@@ -15,7 +15,6 @@
1515
1616 constructor(
1717 private ide: IDE,
18- private ideSettingsPromise: Promise<IdeSettings>,
1918 private controlPlaneClient: ControlPlaneClient,
2019 private llmLogger: ILLMLogger,
2120 private overrideAssistantFile?:
@@ -57,7 +56,6 @@
5756 async doLoadConfig(): Promise<ConfigResult<ContinueConfig>> {
5857 const result = await doLoadConfig({
5958 ide: this.ide,
60- ideSettingsPromise: this.ideSettingsPromise,
6159 controlPlaneClient: this.controlPlaneClient,
6260 llmLogger: this.llmLogger,
6361 profileId: this.description.id,
modified core/config/profile/PlatformProfileLoader.ts +2 −10
@@ -2,7 +2,7 @@
22
33 import { ControlPlaneClient } from "../../control-plane/client.js";
44 import { getControlPlaneEnv } from "../../control-plane/env.js";
5-import { ContinueConfig, IDE, IdeSettings, ILLMLogger } from "../../index.js";
5+import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
66 import { ProfileDescription } from "../ProfileLifecycleManager.js";
77
88 import doLoadConfig from "./doLoadConfig.js";
@@ -28,7 +28,6 @@
2828 private readonly versionSlug: string;
2929 private readonly controlPlaneClient: ControlPlaneClient;
3030 private readonly ide: IDE;
31- private ideSettingsPromise: Promise<IdeSettings>;
3231 private llmLogger: ILLMLogger;
3332 readonly description: ProfileDescription;
3433 private readonly orgScopeId: string | null;
@@ -41,7 +40,6 @@
4140 versionSlug,
4241 controlPlaneClient,
4342 ide,
44- ideSettingsPromise,
4543 llmLogger,
4644 description,
4745 orgScopeId,
@@ -53,7 +51,6 @@
5351 versionSlug: string;
5452 controlPlaneClient: ControlPlaneClient;
5553 ide: IDE;
56- ideSettingsPromise: Promise<IdeSettings>;
5754 llmLogger: ILLMLogger;
5855 description: ProfileDescription;
5956 orgScopeId: string | null;
@@ -65,7 +62,6 @@
6562 this.versionSlug = versionSlug;
6663 this.controlPlaneClient = controlPlaneClient;
6764 this.ide = ide;
68- this.ideSettingsPromise = ideSettingsPromise;
6965 this.llmLogger = llmLogger;
7066 this.description = description;
7167 this.orgScopeId = orgScopeId;
@@ -79,7 +75,6 @@
7975 versionSlug,
8076 controlPlaneClient,
8177 ide,
82- ideSettingsPromise,
8378 llmLogger,
8479 rawYaml,
8580 orgScopeId,
@@ -91,12 +86,11 @@
9186 versionSlug: string;
9287 controlPlaneClient: ControlPlaneClient;
9388 ide: IDE;
94- ideSettingsPromise: Promise<IdeSettings>;
9589 llmLogger: ILLMLogger;
9690 rawYaml: string;
9791 orgScopeId: string | null;
9892 }): Promise<PlatformProfileLoader> {
99- const controlPlaneEnv = await getControlPlaneEnv(ideSettingsPromise);
93+ const controlPlaneEnv = await getControlPlaneEnv(ide.getIdeSettings());
10094
10195 const description: ProfileDescription = {
10296 id: `${ownerSlug}/${packageSlug}`,
@@ -121,7 +115,6 @@
121115 versionSlug,
122116 controlPlaneClient,
123117 ide,
124- ideSettingsPromise,
125118 llmLogger,
126119 description,
127120 orgScopeId,
@@ -139,7 +132,6 @@
139132
140133 const results = await doLoadConfig({
141134 ide: this.ide,
142- ideSettingsPromise: this.ideSettingsPromise,
143135 controlPlaneClient: this.controlPlaneClient,
144136 llmLogger: this.llmLogger,
145137 overrideConfigYaml: this.configResult.config,
modified core/config/profile/doLoadConfig.ts +2 −5
@@ -11,7 +11,6 @@
1111 import {
1212 ContinueConfig,
1313 IDE,
14- IdeSettings,
1514 ILLMLogger,
1615 RuleWithSource,
1716 SerializedContinueConfig,
@@ -70,7 +69,6 @@
7069 }
7170 export default async function doLoadConfig(options: {
7271 ide: IDE;
73- ideSettingsPromise: Promise<IdeSettings>;
7472 controlPlaneClient: ControlPlaneClient;
7573 llmLogger: ILLMLogger;
7674 overrideConfigJson?: SerializedContinueConfig;
@@ -82,7 +80,6 @@
8280 }): Promise<ConfigResult<ContinueConfig>> {
8381 const {
8482 ide,
85- ideSettingsPromise,
8683 controlPlaneClient,
8784 llmLogger,
8885 overrideConfigJson,
@@ -95,7 +92,7 @@
9592
9693 const ideInfo = await ide.getIdeInfo();
9794 const uniqueId = await ide.getUniqueId();
98- const ideSettings = await ideSettingsPromise;
95+ const ideSettings = await ide.getIdeSettings();
9996 const workOsAccessToken = await controlPlaneClient.getAccessToken();
10097 const isSignedIn = await controlPlaneClient.isSignedIn();
10198
@@ -370,7 +367,7 @@
370367 const useOnPremProxy =
371368 controlPlane?.useContinueForTeamsProxy === false && controlPlane?.proxyUrl;
372369
373- const env = await getControlPlaneEnv(ideSettingsPromise);
370+ const env = await getControlPlaneEnv(Promise.resolve(ideSettings));
374371 let controlPlaneProxyUrl: string = useOnPremProxy
375372 ? controlPlane?.proxyUrl
376373 : env.DEFAULT_CONTROL_PLANE_PROXY_URL;
modified core/context/providers/_context-providers.vitest.ts +0 −2
@@ -28,11 +28,9 @@
2828 ): Promise<ContextProviderExtras> {
2929 setUpTestDir();
3030 const ide = new FileSystemIde(TEST_DIR);
31- const ideSettingsPromise = ide.getIdeSettings();
3231 const llmLogger = new LLMLogger();
3332 const configHandler = new ConfigHandler(
3433 ide,
35- ideSettingsPromise,
3634 llmLogger,
3735 Promise.resolve(undefined),
3836 );
modified core/control-plane/client.ts +4 −5
@@ -11,7 +11,7 @@
1111 import fetch, { RequestInit, Response } from "node-fetch";
1212
1313 import { OrganizationDescription } from "../config/ProfileLifecycleManager.js";
14-import { IdeInfo, IdeSettings, ModelDescription } from "../index.js";
14+import { IDE, ModelDescription } from "../index.js";
1515 import { Logger } from "../util/Logger.js";
1616
1717 import { ControlPlaneSessionInfo, isOnPremSession } from "./AuthTypes.js";
@@ -44,8 +44,7 @@
4444 export class ControlPlaneClient {
4545 constructor(
4646 readonly sessionInfoPromise: Promise<ControlPlaneSessionInfo | undefined>,
47- private readonly ideSettingsPromise: Promise<IdeSettings>,
48- private readonly ideInfoPromise: Promise<IdeInfo>,
47+ private readonly ide: IDE,
4948 ) {}
5049
5150 async resolveFQSNs(
@@ -90,9 +89,9 @@
9089 throw new Error("No access token");
9190 }
9291
93- const env = await getControlPlaneEnv(this.ideSettingsPromise);
92+ const env = await getControlPlaneEnv(this.ide.getIdeSettings());
9493 const url = new URL(path, env.CONTROL_PLANE_URL).toString();
95- const ideInfo = await this.ideInfoPromise;
94+ const ideInfo = await this.ide.getIdeInfo();
9695
9796 const resp = await fetch(url, {
9897 ...init,
modified core/core.ts +2 −3
@@ -138,7 +138,7 @@
138138
139139 const ideInfoPromise = messenger.request("getIdeInfo", undefined);
140140 const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
141- const sessionInfoPromise = messenger.request(
141+ const initialSessionInfoPromise = messenger.request(
142142 "getControlPlaneSessionInfo",
143143 {
144144 silent: true,
@@ -148,9 +148,8 @@
148148
149149 this.configHandler = new ConfigHandler(
150150 this.ide,
151- ideSettingsPromise,
152151 this.llmLogger,
153- sessionInfoPromise,
152+ initialSessionInfoPromise,
154153 );
155154
156155 this.docsService = DocsService.createSingleton(
modified core/test/fixtures.ts +1 −3
@@ -12,13 +12,11 @@
1212
1313 export const testControlPlaneClient = new ControlPlaneClient(
1414 Promise.resolve(undefined),
15- ideSettingsPromise,
16- testIde.getIdeInfo(),
15+ testIde,
1716 );
1817
1918 export const testConfigHandler = new ConfigHandler(
2019 testIde,
21- ideSettingsPromise,
2220 new LLMLogger(),
2321 Promise.resolve(undefined),
2422 );