Skip to content

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

TypeScript

fix(desktop): keep transient team hops out of session generation (R13-M3)

Josué53159d8bfc5b
diff --git a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
index c99d1a7ae..75e87f3a2 100644
--- a/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
+++ b/desktop-app/src/__tests__/appService.teamTransitionOwnership.test.ts
@@ -129,6 +129,44 @@ describe('AppService deliberate team transition ownership', () => {
await expect(restore).resolves.toEqual({ authenticated: true, me })
})
+ it('keeps the public session generation stable through transient team hops', async () => {
+ const { service } = await createNativeCommitTestHarness()
+ const meA = {
+ id: 'user-a',
+ email: '[email protected]',
+ name: 'User A',
+ picture: null,
+ teamId: 'team-a',
+ teamName: 'Team A',
+ role: 'member',
+ }
+ const meB = { ...meA, teamId: 'team-b', teamName: 'Team B' }
+ const app = service as unknown as {
+ authClient: unknown
+ readWorkflow(ns: string, name: string): Promise<unknown>
+ workflowTeamByKey: Map<string, string>
+ workflowKey(ns: string, name: string): string
+ getSessionGeneration(): number
+ }
+ let currentTeamId = 'team-a'
+ app.authClient = {
+ googleLogin: vi.fn().mockResolvedValue({ token: 'session-a', me: meA }),
+ switchTeam: vi.fn(async (_token: string, teamId: string) => {
+ currentTeamId = teamId
+ return { token: `session-${teamId}`, team: { id: teamId, name: teamId, role: 'member' } }
+ }),
+ getMe: vi.fn(async () => (currentTeamId === 'team-a' ? meA : meB)),
+ readWorkflow: vi.fn().mockResolvedValue({ workflow: 'result' }),
+ }
+ await service.googleLogin('synthetic-google-token')
+ app.workflowTeamByKey.set(app.workflowKey('team-a', 'flow-a'), 'team-b')
+ const sessionGeneration = app.getSessionGeneration()
+
+ await expect(app.readWorkflow('team-a', 'flow-a')).resolves.toEqual({ workflow: 'result' })
+
+ expect(app.getSessionGeneration()).toBe(sessionGeneration)
+ })
+
it('rejects a stale handoff generation after a public login advances the session', async () => {
const { service, runtimeConfig, optionA } = await createNativeCommitTestHarness()
const app = service as unknown as {
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.ts
index 5b267fa6d..b00b434c7 100644
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@ -1131,10 +1131,12 @@ export class AppService {
private async commitSessionToken(
token: string,
- options: { refreshMe?: boolean } = {}
+ options: { advanceSessionGeneration?: boolean; refreshMe?: boolean } = {}
): Promise<void> {
const tokenChanged = token !== this.sessionToken
- if (tokenChanged) this.sessionGeneration += 1
+ if (tokenChanged && options.advanceSessionGeneration !== false) {
+ this.sessionGeneration += 1
+ }
this.sessionToken = token
if (tokenChanged) {
this.rpcTokenManager.clear()
@@ -1159,7 +1161,11 @@ export class AppService {
}
/** Caller must hold the native auth/environment commit owner. */
- private async switchSessionToTeam(teamId: string, token: string) {
+ private async switchSessionToTeam(
+ teamId: string,
+ token: string,
+ options: { advanceSessionGeneration?: boolean } = {}
+ ) {
const releaseTransientHop = this.enterGfsTransientTeamHop()
const targetTeamId = String(teamId || '').trim()
try {
@@ -1177,7 +1183,10 @@ export class AppService {
if (this.sessionGeneration !== switchGeneration || this.sessionToken !== token) {
throw new Error('stale_auth_epoch: authenticated team scope changed during switch')
}
- await this.commitSessionToken(switched.token, { refreshMe: true })
+ await this.commitSessionToken(switched.token, {
+ advanceSessionGeneration: options.advanceSessionGeneration,
+ refreshMe: true,
+ })
if (!this.me) throw new Error('Team switch ended without an authenticated session')
return switched.token
} catch (error) {
@@ -1341,7 +1350,9 @@ export class AppService {
if (shouldRestore) this.chatStoreHomeTeamId = originalTeamId
try {
- const activeToken = await this.switchSessionToTeam(targetTeamId, originalToken)
+ const activeToken = await this.switchSessionToTeam(targetTeamId, originalToken, {
+ advanceSessionGeneration: false,
+ })
try {
return await operation(activeToken)
@@ -1351,7 +1362,9 @@ export class AppService {
} finally {
if (shouldRestore) {
try {
- await this.switchSessionToTeam(originalTeamId, this.requireSessionToken())
+ await this.switchSessionToTeam(originalTeamId, this.requireSessionToken(), {
+ advanceSessionGeneration: false,
+ })
restoredOriginalTeam = true
} catch (restoreError) {
if (!operationError) throw restoreError