Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit f3d1c12

Browse files
committed
fix: remove codebaseIndexModels from globalState storage
EMBEDDING_MODEL_PROFILES was being stored in globalState on every ClineProvider initialization, but this is unnecessary - it's static reference data that should be passed directly to the webview. Changes: - Remove line that stored EMBEDDING_MODEL_PROFILES in globalState - The webview still receives the data via the ?? fallback in getState() - Add migration v3 to clean up existing codebaseIndexModels keys - Add tests for migration v3
1 parent c038fa5 commit f3d1c12

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/core/webview/ClineProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ export class ClineProvider
177177
ClineProvider.activeInstances.add(this)
178178

179179
this.mdmService = mdmService
180-
this.updateGlobalState("codebaseIndexModels", EMBEDDING_MODEL_PROFILES)
180+
// Note: EMBEDDING_MODEL_PROFILES is passed directly to webview via getStateToPostToWebview()
181+
// without persisting to globalState. The webview receives it via the ?? fallback.
181182

182183
// Start configuration loading (which might trigger indexing) in the background.
183184
// Don't await, allowing activation to continue immediately.

src/utils/__tests__/settingsMigrations.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ describe("settingsMigrations", () => {
213213
expect("customMigration" in migrations[2]).toBe(true)
214214
})
215215

216+
it("should have migration version 3 defined with customMigration", () => {
217+
expect(migrations[3]).toBeDefined()
218+
expect(migrations[3].description).toContain("codebaseIndexModels")
219+
expect("customMigration" in migrations[3]).toBe(true)
220+
})
221+
216222
it("CURRENT_MIGRATION_VERSION should be the max key in migrations", () => {
217223
const maxVersion = Math.max(...Object.keys(migrations).map(Number))
218224
expect(CURRENT_MIGRATION_VERSION).toBe(maxVersion)
@@ -304,6 +310,48 @@ describe("settingsMigrations", () => {
304310
})
305311
})
306312

313+
describe("migration v3 - remove codebaseIndexModels from globalState", () => {
314+
it("should remove codebaseIndexModels if it exists", async () => {
315+
const mockModels = { openai: { model: "text-embedding-3-small" } }
316+
317+
mockContextProxy.getGlobalState.mockImplementation((key: keyof GlobalState) => {
318+
if (key === "settingsMigrationVersion") return 2 // Already completed v1 and v2
319+
if (key === "codebaseIndexModels") return mockModels
320+
return undefined
321+
})
322+
323+
await runSettingsMigrations(mockContextProxy as unknown as ContextProxy)
324+
325+
// Should have removed codebaseIndexModels
326+
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith("codebaseIndexModels", undefined)
327+
328+
// Migration version should be updated
329+
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith(
330+
"settingsMigrationVersion",
331+
CURRENT_MIGRATION_VERSION,
332+
)
333+
})
334+
335+
it("should skip migration if codebaseIndexModels does not exist", async () => {
336+
mockContextProxy.getGlobalState.mockImplementation((key: keyof GlobalState) => {
337+
if (key === "settingsMigrationVersion") return 2 // Already completed v1 and v2
338+
if (key === "codebaseIndexModels") return undefined
339+
return undefined
340+
})
341+
342+
await runSettingsMigrations(mockContextProxy as unknown as ContextProxy)
343+
344+
// Should NOT have called updateGlobalState for codebaseIndexModels
345+
expect(mockContextProxy.updateGlobalState).not.toHaveBeenCalledWith("codebaseIndexModels", undefined)
346+
347+
// Should still update migration version
348+
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith(
349+
"settingsMigrationVersion",
350+
CURRENT_MIGRATION_VERSION,
351+
)
352+
})
353+
})
354+
307355
describe("clearDefaultSettings", () => {
308356
it("should clear settings that match current defaults", async () => {
309357
// Setup: user has settings that match current defaults

src/utils/settingsMigrations.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ export const migrations: Record<number, MigrationDefinition> = {
127127
logger.info(" Removed nested codebaseIndexConfig object")
128128
},
129129
},
130+
3: {
131+
description: "Remove codebaseIndexModels from globalState (now passed directly to webview)",
132+
customMigration: async (contextProxy: ContextProxy) => {
133+
// codebaseIndexModels was previously storing the static EMBEDDING_MODEL_PROFILES
134+
// object in globalState, but this is unnecessary - it's reference data that
135+
// should be passed directly to the webview without persisting.
136+
const stored = contextProxy.getGlobalState("codebaseIndexModels" as keyof GlobalState)
137+
if (stored !== undefined) {
138+
await contextProxy.updateGlobalState("codebaseIndexModels" as keyof GlobalState, undefined)
139+
logger.info(" Removed codebaseIndexModels from globalState")
140+
} else {
141+
logger.info(" codebaseIndexModels not found in globalState, skipping")
142+
}
143+
},
144+
},
130145
}
131146

132147
/**

0 commit comments

Comments
 (0)