Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): r8-l13 rebind live owners after expiry
Josué4ee5f11f9d84
diff --git a/desktop-app/src/__tests__/appService.entityChanges.test.ts b/desktop-app/src/__tests__/appService.entityChanges.test.tsindex f99bdfa62..5ad0cded7 100644--- a/desktop-app/src/__tests__/appService.entityChanges.test.ts+++ b/desktop-app/src/__tests__/appService.entityChanges.test.ts@@ -29,7 +29,7 @@ function setSyntheticSessionToken(service: object, value: string): void {}describe('AppService entity-change fan-out', () => {- it('rebinds the stream through the public Google login session-install path', async () => {+ it('rebinds a live subscriber after expiry through public Google login', async () => {const service = new AppService() as anysetSyntheticSessionToken(service, 'old-committed-token')service.me = null@@ -38,14 +38,19 @@ describe('AppService entity-change fan-out', () => {service.activateGfsAuthScope = vi.fn()service.tokenStore = { setSessionToken: vi.fn().mockResolvedValue(undefined) }service.rpcTokenManager = { clear: vi.fn() }- const opened: Array<{ token: string; cursor: string | null; signal: AbortSignal }> = []+ const opened: Array<{+ token: string+ cursor: string | null+ onEvent: (event: EntityChangeStreamEvent) => void+ signal: AbortSignal+ }> = []service.authClient = {googleLogin: vi.fn().mockResolvedValue({token: 'new-committed-token',me: { id: 'user-1', teamId: 'team-1' },}),- openEntityChangeStream: vi.fn((token, cursor, _onEvent, signal) => {- opened.push({ token, cursor, signal })+ openEntityChangeStream: vi.fn((token, cursor, onEvent, signal) => {+ opened.push({ token, cursor, onEvent, signal })return new Promise<void>(resolve => {signal.addEventListener('abort', () => resolve(), { once: true })})@@ -56,6 +61,15 @@ describe('AppService entity-change fan-out', () => {await flushAsyncWork()expect(opened[0]?.token).toBe('old-committed-token')+ opened[0]?.onEvent({+ type: 'stream.closing',+ schemaVersion: 1,+ cursor: '00000000-0000-0000-0000-000000000001',+ reason: 'session_expired',+ })+ await flushAsyncWork()+ expect(service.entityChangeSubscribers.size).toBe(1)+await service.googleLogin('id-token')await flushAsyncWork()@@ -262,6 +276,7 @@ describe('AppService.startEntityChangeStream session expiry', () => {expect(events.map(event => event.type)).toEqual(['stream.closing'])expect(events[0]).toMatchObject({ reason: 'session_expired' })expect(service.authClient.openEntityChangeStream).toHaveBeenCalledOnce()+ expect(service.entityChangeSubscribers.size).toBe(1)service.stopEntityChangeStream('stream-1', 7)})@@ -296,7 +311,7 @@ describe('AppService.startEntityChangeStream session expiry', () => {}})- it('removes dead subscribers after the server announces session expiry', async () => {+ it('keeps a dormant renderer owner after expiry until it rebinds or tears down', async () => {const service = new AppService() as anysetSyntheticSessionToken(service, 'session-token')service.authClient = {@@ -319,8 +334,9 @@ describe('AppService.startEntityChangeStream session expiry', () => {expect(events.map(event => event.type)).toEqual(['open', 'stream.closing'])expect(service.authClient.openEntityChangeStream).toHaveBeenCalledOnce()- expect(service.entityChangeSubscribers.size).toBe(0)+ expect(service.entityChangeSubscribers.size).toBe(1)service.stopEntityChangeStream('stream-1', 7)+ expect(service.entityChangeSubscribers.size).toBe(0)})it('rebinds a stale expired connection once to the newer committed session', async () => {@@ -393,7 +409,8 @@ describe('AppService.startEntityChangeStream session expiry', () => {expect(service.entityChangeSubscribers.size).toBe(1)releaseTransientHop()expect(events.map(event => event.type)).toEqual(['stream.closing'])- expect(service.entityChangeSubscribers.size).toBe(0)+ expect(service.entityChangeSubscribers.size).toBe(1)+ service.stopEntityChangeStream('stream-1', 7)})})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex f21e933b0..f20d321c0 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2948,7 +2948,10 @@ export class AppService {cursor: this.entityChangeCursor ?? '00000000-0000-0000-0000-000000000000',reason: 'session_expired',})- this.entityChangeSubscribers.clear()+ // Keep renderer-owned subscriptions dormant so a newly committed session+ // can rebind the stream without requiring a renderer remount. The expired+ // connection itself is already stopped; logout and renderer teardown remove+ // these owners through stopAllStreams/stopEntityChangeStreamsForOwner.}private ensureEntityChangeConnection(): void {