Skip to content

Commit f1775ba

Browse files
committed
Implement migration to clear old token-cache from global state
1 parent 03e5f23 commit f1775ba

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/vscode/src/extension.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
migrate_preset_is_default_to_is_selected,
88
migrate_api_providers_to_model_providers,
99
migrate_token_count_cache,
10-
migrate_saved_contexts_to_global_storage
10+
migrate_saved_contexts_to_global_storage,
11+
migrate_token_cache_cleanup
1112
} from './migrations'
1213
import {
1314
apply_chat_response_command,
@@ -56,6 +57,8 @@ export async function activate(context: vscode.ExtensionContext) {
5657
await migrate_token_count_cache(context)
5758
// 5 January 2026
5859
await migrate_saved_contexts_to_global_storage(context)
60+
// 12 January 2026
61+
await migrate_token_cache_cleanup(context)
5962
}
6063

6164
await migrations()

‎packages/vscode/src/migrations/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './migrate-preset-is-default-to-is-selected'
22
export * from './migrate-api-providers-to-model-providers'
33
export * from './migrate-token-count-cache'
44
export * from './migrate-saved-contexts-to-global-storage'
5+
export * from './migrate-token-cache-cleanup'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as vscode from 'vscode'
2+
import { Logger } from '@shared/utils/logger'
3+
4+
const MIGRATION_ID = 'token-cache-cleanup-20260112'
5+
const OLD_KEY = 'token-cache'
6+
7+
/**
8+
* Migration to clear the old 'token-cache' from global state.
9+
*/
10+
export async function migrate_token_cache_cleanup(
11+
context: vscode.ExtensionContext
12+
): Promise<void> {
13+
try {
14+
if (context.globalState.get(MIGRATION_ID)) {
15+
return
16+
}
17+
18+
const old_cache = context.globalState.get(OLD_KEY)
19+
20+
if (old_cache) {
21+
// Passing undefined removes the key from storage
22+
await context.globalState.update(OLD_KEY, undefined)
23+
24+
Logger.info({
25+
function_name: 'migrate_token_cache_cleanup',
26+
message: "Successfully cleared old 'token-cache' from global state"
27+
})
28+
}
29+
30+
await context.globalState.update(MIGRATION_ID, true)
31+
} catch (error) {
32+
Logger.error({
33+
function_name: 'migrate_token_cache_cleanup',
34+
message: "Error cleaning up old 'token-cache'",
35+
data: error instanceof Error ? error.message : String(error)
36+
})
37+
}
38+
}

0 commit comments

Comments
 (0)