Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(chat): invalidate room snapshots when realtime reconnects
Chris21023c9af89e
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.tsindex b0a9ff4c6e..c1fb217105 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts@@ -2071,6 +2071,50 @@ describe('Chat Server result delivery and refresh', () => {expect(pushes()).toBe(1);});+ it.each([false, true])('uses current members after reconnect before list sync or replay finishes (late snapshot: %s)', async (lateSnapshot) => {+ const base = fixture.handle.getMockImplementation()!;+ let holdList = false;+ let finishList!: () => void;+ let finishSnapshot!: () => void;+ let holdSnapshot = false;+ let newMembers = false;+ fixture.handle.mockImplementation((route, method, data) => {+ if (route === '/me') return { body: { actor: { id: selfId }, capabilities: { conversationListStateVersion: 1 } } };+ if (route.startsWith('/conversation-list-state?')) return holdList+ ? new Promise(resolve => { finishList = () => resolve({ body: [] }); }) : { body: [] };+ if (route.endsWith('/snapshot')) {+ if (holdSnapshot) {+ holdSnapshot = false;+ return new Promise(resolve => { finishSnapshot = () => resolve(snapshotOf()); });+ }+ if (newMembers) return { body: { ...snapshotOf().body,+ members: [selfMember, { ...botMember, id: peerId, name: 'New teammate' }] } };+ }+ return base(route, method, data);+ });+ const previous = await live();+ previous.emit('close');+ holdSnapshot = lateSnapshot;+ const oldRead = lateSnapshot ? service.getGroup(roomId) : undefined;+ await vi.advanceTimersByTimeAsync(500);+ holdList = true;+ newMembers = true;+ const socket = fixture.sockets.at(-1)!;+ Object.defineProperty(socket, 'readyState', { value: 1 });+ socket.emit('message', JSON.stringify({ type: 'ready' }));+ if (lateSnapshot) { finishSnapshot(); await oldRead; }+ deps.decidePlan = vi.fn(() => new Promise(() => {})) as typeof deps.decidePlan;+ const from = fixture.handle.mock.calls.length;+ expect(await send('reconnect-members')).toMatchObject({ ok: true });+ await vi.advanceTimersByTimeAsync(0);+ expect(routesSince(from)).toContain(`GET /conversations/${roomId}/snapshot`);+ expect(deps.decidePlan).toHaveBeenCalledWith(expect.objectContaining({+ organizerName: 'New teammate', members: [{ botId: peerId, name: 'New teammate', description: '' }],+ }), expect.any(AbortSignal));+ finishList();+ await vi.advanceTimersByTimeAsync(0);+ });+it('still pushes a send locally while the realtime connection is down', async () => {expect(await send('latency-send-5')).toMatchObject({ ok: true });expect(pushes()).toBe(0);diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex 95f8ea53b1..e5ade027b6 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -812,6 +812,9 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDmemberJoinedClaims = true;reconnectDelay = 500; connected = true;threads.reset();+ // Subscription replay and list sync may lag behind ready. Retire cached state+ // now; advancing the generation also fences reads started before this connection.+ for (const roomId of rooms.keys()) invalidate(roomId);ws.send(JSON.stringify({ type: 'subscribe', scope: `actor:${selfId}`, after: '0' }));for (const [roomId, cursor] of rooms) ws.send(JSON.stringify({ type: 'subscribe', scope: `conversation:${roomId}`, after: cursor }));void syncPersonalList(true).then(() => { if (current() && socket === ws) { for (const roomId of rooms.keys()) changed(roomId); changed(''); } }).catch(() => ws.close());