Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): retry transient saved-session restores
Josuéa98732595e52
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.tsindex c256fa57e..ba2eb86c8 100644--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts@@ -211,6 +211,8 @@ describe('AppService invitation configuration lookup', () => {delete process.env.PROFILE_UI_BASE_URLvi.resetModules()+ let now = 1_000+ const nowSpy = vi.spyOn(Date, 'now').mockImplementation(() => now)const { AppService } = await import('../appService.js')const getSessionToken = vi.fn().mockResolvedValue('stored-token')const clearSessionToken = vi.fn().mockResolvedValue(undefined)@@ -226,7 +228,15 @@ describe('AppService invitation configuration lookup', () => {}service.authClient = {- getMe: vi.fn().mockRejectedValue(new Error('fetch failed')),+ getMe: vi.fn().mockRejectedValueOnce(new Error('fetch failed')).mockResolvedValue({+ id: 'user-1',+ email: '[email protected]',+ name: null,+ picture: null,+ teamId: null,+ teamName: null,+ role: null,+ }),} as neverservice.tokenStore = {getSessionToken,@@ -248,8 +258,17 @@ describe('AppService invitation configuration lookup', () => {})expect(getSessionToken).toHaveBeenCalledTimes(1)expect(service.authClient.getMe).toHaveBeenCalledTimes(1)++ now += 5_001+ await expect(service.getSessionState()).resolves.toMatchObject({+ authenticated: true,+ me: { id: 'user-1' },+ })+ expect(getSessionToken).toHaveBeenCalledTimes(2)+ expect(service.authClient.getMe).toHaveBeenCalledTimes(2)} finally {warn.mockRestore()+ nowSpy.mockRestore()}})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 41a8ff22e..fe58e00c5 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -244,6 +244,7 @@ const RECONNECT_ATTEMPT_TIMEOUT_MS = 8000// post-`waiting` connection is still caught here (and by the renderer's 30s// watchdog).const RECONNECT_WAITING_FOR_OPEN_TIMEOUT_MS = 195_000+const SAVED_SESSION_RESTORE_RETRY_DELAY_MS = 5_000export class AppService {private readonly authClient = new AuthClient()@@ -272,6 +273,7 @@ export class AppService {private teamContextQueue: Promise<void> = Promise.resolve()private restoreSavedSessionInFlight: Promise<SessionState> | null = nullprivate savedSessionRestoreAttemptedEnvKey: string | null = null+ private savedSessionRestoreAttemptedAtMs = 0private logoutInProgress = falseprivate sessionGeneration = 0private workflowApprovalTeamById = new Map<string, string>()@@ -566,6 +568,7 @@ export class AppService {const envKey = getActiveEnvKey()const legacyEnvKeys = getActiveLegacyEnvKeys()this.savedSessionRestoreAttemptedEnvKey = envKey+ this.savedSessionRestoreAttemptedAtMs = Date.now()let token: string | nulltry {token = await this.tokenStore.getSessionToken(envKey, { legacyEnvKeys })@@ -1068,7 +1071,10 @@ export class AppService {// the renderer. Do not immediately repeat a failed 60-second network// attempt from the renderer bootstrap; a new app launch or environment// selection gets a fresh attempt because its service/env key is new.- if (this.savedSessionRestoreAttemptedEnvKey === getActiveEnvKey()) {+ if (+ this.savedSessionRestoreAttemptedEnvKey === getActiveEnvKey() &&+ Date.now() - this.savedSessionRestoreAttemptedAtMs < SAVED_SESSION_RESTORE_RETRY_DELAY_MS+ ) {return { authenticated: false, me: null }}return this.restoreSavedSession()