Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor(desktop-app): remove redundant auth owner checks (R12-L5)

Josuéb22957ca1303
diff --git a/desktop-app/src/__tests__/appService.bootstrap.test.ts b/desktop-app/src/__tests__/appService.bootstrap.test.ts
index 8ef74355b..b4cff0f1c 100644
--- a/desktop-app/src/__tests__/appService.bootstrap.test.ts
+++ b/desktop-app/src/__tests__/appService.bootstrap.test.ts
@@ -421,8 +421,6 @@ describe('AppService invitation configuration lookup', () => {
expect(service.tokenStore.clearSessionToken).toHaveBeenCalledWith(getActiveEnvKey(), {
legacyEnvKeys: [getActiveLegacyRestOnlyEnvKey()],
})
- expect(service.logoutInProgress).toBe(false)
-
await expect(service.getSessionState()).resolves.toEqual({ authenticated: true, me })
expect(service.getCachedUserId()).toBe('user-1')
expect(getSessionToken).not.toHaveBeenCalled()
diff --git a/desktop-app/src/__tests__/appService.chatStoreTeamHop.test.ts b/desktop-app/src/__tests__/appService.chatStoreTeamHop.test.ts
index 7d933b994..3c17fceb8 100644
--- a/desktop-app/src/__tests__/appService.chatStoreTeamHop.test.ts
+++ b/desktop-app/src/__tests__/appService.chatStoreTeamHop.test.ts
@@ -108,10 +108,11 @@ describe('chat store scope across a transient team hop', () => {
const internals = service as unknown as {
bindCurrentChatStore(userId: string): Promise<void>
runWithTeamContext<T>(teamId: string, op: (token: string) => Promise<T>): Promise<T>
- switchSessionToTeam(teamId: string): Promise<string>
chatStoreTeamId(): string | null
me: { teamId: string }
+ suspendDesktopGfsUploadsForAuthBoundary(): Promise<void>
}
+ internals.suspendDesktopGfsUploadsForAuthBoundary = vi.fn().mockResolvedValue(undefined)
await internals.bindCurrentChatStore('user-1')
const during: { sessionTeam?: string; chatStoreTeam?: string | null } = {}
@@ -128,7 +129,7 @@ describe('chat store scope across a transient team hop', () => {
// A genuine team switch after the hop: the store team follows `me.teamId`, it
// is not stuck on the team the finished hop was pinned to.
- await internals.switchSessionToTeam('team-c')
+ await service.switchTeam('team-c')
expect(internals.me.teamId).toBe('team-c')
expect(internals.chatStoreTeamId()).toBe('team-c')
@@ -222,12 +223,13 @@ describe('chat store scope across a transient team hop', () => {
const service = signedInService(['team-b'])
const internals = service as unknown as {
bindCurrentChatStore(userId: string): Promise<void>
- switchSessionToTeam(teamId: string): Promise<string>
+ suspendDesktopGfsUploadsForAuthBoundary(): Promise<void>
}
+ internals.suspendDesktopGfsUploadsForAuthBoundary = vi.fn().mockResolvedValue(undefined)
await internals.bindCurrentChatStore('user-1')
expect(requireChatStore().getAuthorityScope()?.teamId).toBe('team-a')
- await internals.switchSessionToTeam('team-b')
+ await service.switchTeam('team-b')
expect(requireChatStore().getAuthorityScope()?.teamId).toBe('team-b')
expect(service.getChatDeletionFenceAuthority().authorityScope.teamId).toBe('team-b')
diff --git a/desktop-app/src/__tests__/appService.prewarm.test.ts b/desktop-app/src/__tests__/appService.prewarm.test.ts
index 0f8664bd6..dac10c9a1 100644
--- a/desktop-app/src/__tests__/appService.prewarm.test.ts
+++ b/desktop-app/src/__tests__/appService.prewarm.test.ts
@@ -402,9 +402,7 @@ describe('AppService.prewarmHost — bounded wake re-emission', () => {
return operation
})
await operationStarted
- expect(switchSessionToTeam).toHaveBeenCalledWith('team-2', expect.any(String), {
- commitOwnerHeld: true,
- })
+ expect(switchSessionToTeam).toHaveBeenCalledWith('team-2', expect.any(String))
expect(
(
svc as unknown as { prewarmAttemptAtByHostRef: Map<string, number> }
@@ -416,9 +414,7 @@ describe('AppService.prewarmHost — bounded wake re-emission', () => {
finishOperation()
await hop
- expect(switchSessionToTeam).toHaveBeenCalledWith('team-1', expect.any(String), {
- commitOwnerHeld: true,
- })
+ expect(switchSessionToTeam).toHaveBeenCalledWith('team-1', expect.any(String))
await expect(svc.prewarmHost('chatllm')).resolves.toEqual({
requested: false,
skipped: 'cooldown',
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index a3ee4e218..d9f18999c 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -895,7 +895,6 @@ export class AppService {
private savedSessionRestoreAttemptedEnvKey: string | null = null
private savedSessionRestoreAttemptedAtMs = 0
private interactiveLoginAttempts = 0
- private logoutInProgress = false
private nativeAuthEnvironmentCommitQueue: Promise<void> = Promise.resolve()
private gfsAuthEpoch = 0
private gfsDispatchBlocked = true
@@ -1160,17 +1159,8 @@ export class AppService {
return this.me.teamId || ''
}
- private switchSessionToTeam(
- teamId: string,
- token?: string,
- options: { commitOwnerHeld?: boolean } = {}
- ): Promise<string> {
- const run = () =>
- this.switchSessionToTeamWithCommitOwner(teamId, token ?? this.requireSessionToken())
- return options.commitOwnerHeld ? run() : this.withNativeAuthEnvironmentCommit(run)
- }
-
- private async switchSessionToTeamWithCommitOwner(teamId: string, token: string) {
+ /** Caller must hold the native auth/environment commit owner. */
+ private async switchSessionToTeam(teamId: string, token: string) {
const releaseTransientHop = this.enterGfsTransientTeamHop()
const targetTeamId = String(teamId || '').trim()
try {
@@ -1323,9 +1313,7 @@ export class AppService {
if (shouldRestore) this.chatStoreHomeTeamId = originalTeamId
try {
- const activeToken = await this.switchSessionToTeam(targetTeamId, originalToken, {
- commitOwnerHeld: true,
- })
+ const activeToken = await this.switchSessionToTeam(targetTeamId, originalToken)
try {
return await operation(activeToken)
@@ -1335,9 +1323,7 @@ export class AppService {
} finally {
if (shouldRestore) {
try {
- await this.switchSessionToTeam(originalTeamId, this.requireSessionToken(), {
- commitOwnerHeld: true,
- })
+ await this.switchSessionToTeam(originalTeamId, this.requireSessionToken())
restoredOriginalTeam = true
} catch (restoreError) {
if (!operationError) throw restoreError
@@ -1589,7 +1575,7 @@ export class AppService {
private async restoreSavedSessionOnce(options: { runLaunchMaintenance?: boolean } = {}) {
const reservation = await this.withNativeAuthEnvironmentCommit(async () => {
- if (this.logoutInProgress || this.interactiveLoginAttempts > 0) return null
+ if (this.interactiveLoginAttempts > 0) return null
hydrateDesktopRuntimeConfig()
const environment = this.captureAuthEnvironmentBinding()
const legacyEnvKeys = getActiveLegacyEnvKeys()
@@ -1623,7 +1609,6 @@ export class AppService {
const ownsRestore = () =>
this.sessionGeneration === reservation.sessionGeneration &&
- !this.logoutInProgress &&
this.interactiveLoginAttempts === 0 &&
getActiveEnvKey() === reservation.environment.environmentKey &&
normalizeDesktopUploadBaseUrl(config.externalRestApiBaseUrl) ===
@@ -1763,7 +1748,6 @@ export class AppService {
throw new Error('stale_auth_epoch: authenticated scope changed during login replacement')
}
}
- this.logoutInProgress = false
this.sessionGeneration += 1
this.sessionToken = result.token
this.me = result.me
@@ -2006,7 +1990,6 @@ export class AppService {
let registered = false
try {
const attempt = await this.withNativeAuthEnvironmentCommit(async () => {
- if (this.logoutInProgress) throw new Error('auth_transition_in_progress')
const sessionGeneration = ++this.sessionGeneration
const binding = this.captureAuthEnvironmentBinding()
loginRequest = this.authClient.googleLogin(idToken)
@@ -2200,7 +2183,6 @@ export class AppService {
let registered = false
try {
const loginGeneration = await this.withNativeAuthEnvironmentCommit(async () => {
- if (this.logoutInProgress) throw new Error('auth_transition_in_progress')
const generation = ++this.sessionGeneration
hydrateDesktopRuntimeConfig()
if (!isDesktopRuntimeConfigured()) {
@@ -2390,7 +2372,6 @@ export class AppService {
async logout(): Promise<number> {
return this.withNativeAuthEnvironmentCommit(async () => {
- this.logoutInProgress = true
this.sessionGeneration += 1
const logoutGeneration = this.sessionGeneration
const logoutToken = this.sessionToken
@@ -2425,7 +2406,6 @@ export class AppService {
return this.sessionGeneration
} finally {
releasePrewarm()
- this.logoutInProgress = false
}
})
}
@@ -3781,14 +3761,11 @@ export class AppService {
// GFS activation and stream/cache publication complete. Transient
// runWithTeamContext hops continue to reuse their existing owner and do
// not suspend uploads or stop streams.
- const switchedToken = await this.switchSessionToTeam(targetTeamId, undefined, {
- commitOwnerHeld: true,
- })
+ const switchedToken = await this.switchSessionToTeam(
+ targetTeamId,
+ this.requireSessionToken()
+ )
const switchedMe = this.me
- const switchedGeneration = this.sessionGeneration
- const switchedEnvironment = this.captureAuthEnvironmentBinding()
- this.assertSessionGeneration(switchedGeneration)
- this.assertAuthEnvironmentBinding(switchedEnvironment)
if (this.sessionToken !== switchedToken || !switchedMe || this.me !== switchedMe) {
throw new Error('stale_auth_epoch: authenticated team scope changed before activation')
}
diff --git a/desktop-app/ui/src/hooks/domain/useAuthController.ts b/desktop-app/ui/src/hooks/domain/useAuthController.ts
index 4b7094a42..45b08b9d1 100644
--- a/desktop-app/ui/src/hooks/domain/useAuthController.ts
+++ b/desktop-app/ui/src/hooks/domain/useAuthController.ts
@@ -474,7 +474,6 @@ export function useAuthController({
}, [
getDesktopEnvironmentHandoffAuthState,
getSessionGeneration,
- handleSelectRuntimeConfig,
handleSelectRuntimeConfigForHandoff,
logoutForEnvironmentMismatch,
onSessionNeedsLoad,