Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): scope legacy environment migration
Josuéb5b84cd6a27a
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.tsindex 95c535fa3..c256fa57e 100644--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts@@ -61,8 +61,10 @@ describe('AppService invitation configuration lookup', () => {delete process.env.PROFILE_UI_BASE_URLvi.resetModules()- const [{ AppService }, { config, isDesktopRuntimeConfigured, resolveEnvKey }] =- await Promise.all([import('../appService.js'), import('../config.js')])+ const [+ { AppService },+ { config, getActiveLegacyRestOnlyEnvKey, isDesktopRuntimeConfigured, resolveEnvKey },+ ] = await Promise.all([import('../appService.js'), import('../config.js')])const { bindChatStoreForUser } = await import('../chatStoreBinding.js')const service = new AppService() as unknown as {@@ -129,7 +131,8 @@ describe('AppService invitation configuration lookup', () => {// chat:* IPC throws "Not authenticated" until something else re-binds.expect(bindChatStoreForUser).toHaveBeenCalledWith('user-1',- resolveEnvKey('https://api.example.com', 'https://rpc.example.com')+ resolveEnvKey('https://api.example.com', 'https://rpc.example.com'),+ { legacyEnvKeys: [getActiveLegacyRestOnlyEnvKey()] })expect(config.externalRestApiBaseUrl).toBe('https://api.example.com')expect(config.rpcProxyBaseUrl).toBe('https://rpc.example.com')diff --git a/desktop-app/src/__tests__/config.runtimeConfig.test.ts b/desktop-app/src/__tests__/config.runtimeConfig.test.tsindex c7b835971..7e3f5f9c5 100644--- a/desktop-app/src/__tests__/config.runtimeConfig.test.ts+++ b/desktop-app/src/__tests__/config.runtimeConfig.test.ts@@ -300,6 +300,13 @@ describe('desktop runtime config', () => {createdAt: '2026-01-01T00:00:00.000Z',updatedAt: '2026-01-01T00:00:00.000Z',},+ {+ id: 'remote-other-rpc',+ appName: 'Remote Other RPC',+ fileName: 'runtime-config-remote-other-rpc.json',+ createdAt: '2026-01-01T00:00:00.000Z',+ updatedAt: '2026-01-01T00:00:00.000Z',+ },],}))@@ -311,6 +318,14 @@ describe('desktop runtime config', () => {appName: 'Remote',}))+ await fsp.writeFile(+ path.join(runtimeConfigDir, 'runtime-config-remote-other-rpc.json'),+ JSON.stringify({+ externalRestApiBaseUrl: 'https://api.remote.example.com',+ rpcProxyBaseUrl: 'https://rpc-alt.remote.example.com',+ appName: 'Remote Other RPC',+ })+ )delete process.env.CLERUM_DESKTOP_CONFIG_PATHdelete process.env.EVENFIRE_RENDERER_URLprocess.env.EXTERNAL_REST_API_BASE_URL = 'http://127.0.0.1:8091'@@ -328,10 +343,12 @@ describe('desktop runtime config', () => {},}))- const { config, getDesktopRuntimeConfigState } = await import('../config.js')+ const { config, getActiveLegacyEnvKeys, getDesktopRuntimeConfigState } =+ await import('../config.js')expect(config.externalRestApiBaseUrl).toBe('https://api.remote.example.com')expect(config.rpcProxyBaseUrl).toBe('https://rpc.remote.example.com')expect(getDesktopRuntimeConfigState().activeOptionId).toBe('remote')+ expect(getActiveLegacyEnvKeys()).toEqual([])})})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 3dd1a7cb1..41a8ff22e 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -7,7 +7,7 @@ import {config,deleteDesktopRuntimeConfigOption,getActiveEnvKey,- getActiveLegacyRestOnlyEnvKey,+ getActiveLegacyEnvKeys,getDesktopRuntimeConfigState,hydrateDesktopRuntimeConfig,isDesktopRuntimeConfigured,@@ -384,6 +384,12 @@ export class AppService {}}+ private async bindCurrentChatStore(userId: string): Promise<void> {+ await bindChatStoreForUser(userId, getActiveEnvKey(), {+ legacyEnvKeys: getActiveLegacyEnvKeys(),+ })+ }+private async commitSessionToken(token: string,options: { refreshMe?: boolean } = {}@@ -403,7 +409,7 @@ export class AppService {unbindChatStore()throw error}- await bindChatStoreForUser(this.me.id, getActiveEnvKey())+ await this.bindCurrentChatStore(this.me.id)this.updateCachedCurrentTeam(this.me.teamId)}}@@ -411,7 +417,7 @@ export class AppService {private async getCurrentSessionTeamId(token: string): Promise<string> {if (this.me?.teamId) return this.me.teamIdthis.me = await this.authClient.getMe(token)- await bindChatStoreForUser(this.me.id, getActiveEnvKey())+ await this.bindCurrentChatStore(this.me.id)this.updateCachedCurrentTeam(this.me.teamId)return this.me.teamId || ''}@@ -558,8 +564,7 @@ export class AppService {const restoreGeneration = this.sessionGenerationhydrateDesktopRuntimeConfig()const envKey = getActiveEnvKey()- const legacyEnvKey = getActiveLegacyRestOnlyEnvKey()- const legacyEnvKeys = legacyEnvKey !== envKey ? [legacyEnvKey] : []+ const legacyEnvKeys = getActiveLegacyEnvKeys()this.savedSessionRestoreAttemptedEnvKey = envKeylet token: string | nulltry {@@ -591,7 +596,7 @@ export class AppService {await bindChatStoreForUser(restoredMe.id, envKey, { legacyEnvKeys })if (this.sessionGeneration !== restoreGeneration || this.sessionToken !== token) {if (this.me) {- await bindChatStoreForUser(this.me.id, getActiveEnvKey(), { legacyEnvKeys })+ await this.bindCurrentChatStore(this.me.id)} else {unbindChatStore()}@@ -653,7 +658,7 @@ export class AppService {this.sessionGeneration += 1this.sessionToken = result.tokenthis.me = result.me- await bindChatStoreForUser(result.me.id, getActiveEnvKey())+ await this.bindCurrentChatStore(result.me.id)this.accessCatalog = nullthis.teamDirectoryCache = nullthis.workflowApprovalTeamById.clear()@@ -724,7 +729,7 @@ export class AppService {this.sessionGeneration += 1this.sessionToken = result.tokenthis.me = result.me- await bindChatStoreForUser(result.me.id, getActiveEnvKey())+ await this.bindCurrentChatStore(result.me.id)this.accessCatalog = nullthis.teamDirectoryCache = nullthis.workflowApprovalTeamById.clear()@@ -909,8 +914,7 @@ export class AppService {this.logoutInProgress = truetry {const envKey = getActiveEnvKey()- const legacyEnvKey = getActiveLegacyRestOnlyEnvKey()- const legacyEnvKeys = legacyEnvKey !== envKey ? [legacyEnvKey] : []+ const legacyEnvKeys = getActiveLegacyEnvKeys()this.clearAuthenticatedSessionState()await this.tokenStore.clearSessionToken(envKey, { legacyEnvKeys })} finally {@@ -1507,7 +1511,7 @@ export class AppService {const token = this.requireSessionToken()const me = this.me ?? (await this.authClient.getMe(token))this.me = me- await bindChatStoreForUser(me.id, getActiveEnvKey())+ await this.bindCurrentChatStore(me.id)const currentTeamId = String(me.teamId || '').trim()const [userContexts, userAgents, teamContexts, teamAgents] = await Promise.all([diff --git a/desktop-app/src/config.ts b/desktop-app/src/config.tsindex 15e5e658b..46f5224da 100644--- a/desktop-app/src/config.ts+++ b/desktop-app/src/config.ts@@ -722,6 +722,25 @@ export function getActiveLegacyRestOnlyEnvKey(): string {return resolveEnvKey(config.externalRestApiBaseUrl)}+/**+ * Return the pre-RPC-origin namespace only when it maps to one configured+ * environment. Two profiles sharing REST but using different RPC origins+ * cannot safely claim the same legacy token or chat tree.+ */+export function getActiveLegacyEnvKeys(): string[] {+ hydrateDesktopRuntimeConfig()+ const envKey = getActiveEnvKey()+ const legacyEnvKey = getActiveLegacyRestOnlyEnvKey()+ if (legacyEnvKey === envKey) return []++ const matchingEnvironmentKeys = new Set(+ buildRuntimeConfigOptions(storedProfiles, localhostRuntimeConfig, true)+ .filter(option => resolveEnvKey(option.externalRestApiBaseUrl) === legacyEnvKey)+ .map(option => resolveEnvKey(option.externalRestApiBaseUrl, option.rpcProxyBaseUrl))+ )+ return matchingEnvironmentKeys.size > 1 ? [] : [legacyEnvKey]+}+export function getDesktopRuntimeConfigState(): DesktopRuntimeConfigState {hydrateDesktopRuntimeConfig()const current = currentRuntimeConfig()