Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(group-chat): recover list subscriptions and success navigation

zqchris3d60084d663c
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts
index 8ec40d6d3f..3888d6ff80 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts
@@ -137,6 +137,29 @@ describe('Chat Server membership notices', () => {
expect(fixture.handle.mock.calls.some(([route, method]) => method === 'POST' && route.includes('/messages'))).toBe(false);
});
+ it('resyncs personal state and resumes actor events at the reset head', async () => {
+ lifecycle();
+ let states: unknown[] = [];
+ const handle = fixture.handle.getMockImplementation()!;
+ fixture.handle.mockImplementation((route, ...args) => route.startsWith('/conversation-list-state?') ? { body: states } : handle(route, ...args));
+ await service.listGroups();
+ await vi.advanceTimersByTimeAsync(2000);
+ const socket = fixture.sockets[0]!;
+ Object.defineProperty(socket, 'readyState', { value: 1 });
+ socket.emit('message', JSON.stringify({ type: 'ready' }));
+ await vi.advanceTimersByTimeAsync(0);
+ states = [{ conversationId: roomId, hidden: true, revision: 1 }];
+ socket.emit('message', JSON.stringify({ type: 'scope_error', scope: `actor:${selfId}`, error: { code: 'RESET_REQUIRED', details: { head: '42' } } }));
+ await vi.advanceTimersByTimeAsync(0);
+ expect(socket.send).toHaveBeenCalledWith(JSON.stringify({ type: 'subscribe', scope: `actor:${selfId}`, after: '42' }));
+ expect(await service.listGroups()).toMatchObject({ ok: true, groups: [] });
+ expect(changed.mock.calls.map(([payload]) => payload)).toContainEqual(expect.objectContaining({ groupId: roomId, change: 'list', listState: expect.objectContaining({ hidden: true }) }));
+ socket.emit('message', JSON.stringify({ type: 'changes', scope: `actor:${selfId}`, cursor: '43', changes: [
+ { type: 'conversation.list.changed', data: { conversationId: roomId, hidden: false, revision: 2 } },
+ ] }));
+ expect((await service.getGroup(roomId)).ok).toBe(true);
+ });
+
it('never continues a discussion from an admission event', async () => {
expect((await service.continueRound(roomId)).ok).toBe(false);
expect(fixture.handle.mock.calls.some(([route]) => route.endsWith('/continue'))).toBe(false);
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 5b55358ba5..5441ace8b6 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -591,6 +591,16 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
changed('');
}
ws.send(JSON.stringify({ type: 'ack', scope: event.scope, cursor: event.cursor }));
+ } else if (event.type === 'scope_error' && event.scope === `actor:${selfId}`) {
+ const head = event.error?.details?.head;
+ if (event.error?.code !== 'RESET_REQUIRED' || typeof head !== 'string' || !/^\d+$/.test(head)) { ws.close(); return; }
+ void (async () => {
+ if (supportsListRemoval) await personalList.resync(api);
+ if (!current() || socket !== ws || ws.readyState !== WebSocket.OPEN) return;
+ for (const roomId of rooms.keys()) changed(roomId);
+ changed('');
+ ws.send(JSON.stringify({ type: 'subscribe', scope: event.scope, after: head }));
+ })().catch(() => ws.close());
} else if (event.type === 'scope_error' && event.scope.startsWith('conversation:')) {
const roomId = event.scope.slice(13);
if (event.error?.code === 'RESET_REQUIRED') {
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
index aaa85a45da..3d3def8502 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
@@ -304,12 +304,15 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
void load();
const unsubscribe =
botGroupApi()?.onBotGroupChanged?.((payload, ownerStamp) => {
- if (!isDataOwnerPushCurrent(ownerStamp) || payload.groupId !== groupId) return;
+ if (cancelled || !isDataOwnerPushCurrent(ownerStamp) || payload.groupId !== groupId) return;
if (payload.change === 'deleted' || (payload.change === 'list' && payload.listState?.hidden)) {
requestVersion += 1;
// Unsent attachments go with the group (staged copies included).
discardDraft(botGroupAttachmentScope(groupId));
setState({ kind: 'missing' });
+ // The authoritative hide can unmount the drawer before its IPC reply.
+ // This mounted page owns selection, so clear the route here as well.
+ if (payload.change === 'list') navigate('/bots');
return;
}
void load();
@@ -320,7 +323,7 @@ function BotGroupChatContent({ groupId }: { groupId: string }) {
loadRef.current = () => {};
unsubscribe();
};
- }, [groupId, reloadVersion]);
+ }, [groupId, reloadVersion, navigate]);
const group = state.kind === 'ready' ? state.group : null;
// Until the timeline arrives, the header comes from the group's sidebar row (same account).
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index d1a192e7ef..76c7a6203b 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -327,6 +327,14 @@ beforeEach(() => {
afterEach(() => { cleanup(); vi.unstubAllGlobals(); });
describe('BotGroupChatView', () => {
+ it('clears the selected route when an authoritative personal hide unmounts settings', async () => {
+ renderView();
+ await screen.findByRole('textbox');
+ act(() => mocks.pushes.forEach(push => push({ groupId: 'g1', change: 'list', listState: { hidden: true, revision: 1 } })));
+ expect(mocks.navigate).toHaveBeenCalledWith('/bots');
+ expect(screen.queryByRole('textbox')).toBeNull();
+ });
+
function mockThreadMotion(duration: string) {
const style = document.createElement('style');
style.textContent = `aside { --motion-base: ${duration}; --motion-ease-move: linear; }`;
diff --git a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
index 1e80fc5dba..43d5c1d9a7 100644
--- a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
+++ b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx
@@ -832,6 +832,36 @@ describe('group settings', () => {
expect(byId('botGroup.settings')).not.toBeNull();
}
+ it.each([true, false])('leaves after confirmed personal hide even when settings unmounts before the reply (direct=%s)', async direct => {
+ h.chat.server = direct;
+ let finish!: () => void;
+ h.chat.act.mockImplementationOnce(() => new Promise(resolve => { finish = () => resolve({ effects: [] }); }));
+ await openSettings(group({ serverBacked: true, supportsListRemoval: true }));
+ await click('botGroup.settings.hide');
+ expect(h.chat.act).toHaveBeenLastCalledWith('hide', undefined);
+ await render(null, 'missing');
+ expect(byId('botGroup.settings')).toBeNull();
+ expect(h.leave).not.toHaveBeenCalled();
+ await act(async () => { finish(); });
+ expect(h.leave).toHaveBeenCalledOnce();
+ });
+
+ it('navigates only once when a personal hide completes before the list rerenders', async () => {
+ await openSettings(group({ serverBacked: true, supportsListRemoval: true }));
+ await click('botGroup.settings.hide');
+ expect(h.leave).toHaveBeenCalledOnce();
+ });
+
+ it('does not navigate from an old hide acknowledgement after leaving the screen', async () => {
+ let finish!: () => void;
+ h.chat.act.mockImplementationOnce(() => new Promise(resolve => { finish = () => resolve({ effects: [] }); }));
+ await openSettings(group({ serverBacked: true, supportsListRemoval: true }));
+ await click('botGroup.settings.hide');
+ await act(async () => root.render(el('div')));
+ await act(async () => { finish(); });
+ expect(h.leave).not.toHaveBeenCalled();
+ });
+
it('follows a remote rename on blur without saving an untouched name', async () => {
await openSettings();
await act(async () => { h.inputs['botGroup.settings.name'].onFocus(); });
@@ -890,8 +920,9 @@ describe('group settings', () => {
expect(byId('botGroup.settings.addable')).toBeNull();
await click('botGroup.settings.retry'); expect(refresh).toHaveBeenCalledOnce();
expect(h.chat.act).not.toHaveBeenCalled();
- expect(byId('botGroup.settings.delete')?.textContent).toContain('groupChat.settings.archive');
- expect(byId('botGroup.settings')?.textContent).toContain('groupChat.settings.archiveNote');
+ expect(byId('botGroup.settings.delete')).toBeNull();
+ expect(byId('botGroup.settings.hide')?.disabled).toBe(true);
+ expect(byId('botGroup.settings')?.textContent).toContain('groupChat.lifecycle.unavailable');
expect(byId('botGroup.settings')?.textContent).not.toContain('groupChat.settings.deleteNote');
});
@@ -956,26 +987,27 @@ describe('group settings', () => {
expect(byId('botGroup.settings.memberMenu.abu.action.remove:abu')?.disabled).toBe(true);
});
- it.each(['member', 'admin'] as const)('retains compatibility-entry leave for a server %s without granting archive', async (role) => {
- const data = group({ serverBacked: true, supportsSettingsManagement: true, revision: 5 });
- data.members[0] = { ...data.members[0], isOwned: true, role };
+ it.each(['member', 'admin'] as const)('uses explicit leave for a server %s without granting archive or compatibility delete', async (role) => {
+ const data = group({ serverBacked: true, supportsSettingsManagement: true, supportsGroupLeave: true, revision: 5 });
+ data.members[0] = { ...data.members[0], actorId: 'human', isSelf: true, isOwned: true, role };
await openSettings(data);
expect(h.inputs['botGroup.settings.name'].editable).toBe(role === 'admin');
expect(byId('botGroup.settings.add')?.disabled).toBe(role !== 'admin');
- expect(byId('botGroup.settings.delete')?.disabled).toBe(false);
- expect(byId('botGroup.settings.delete')?.textContent).toContain('groupChat.settings.delete');
- await click('botGroup.settings.delete');
- expect(h.chat.act).toHaveBeenCalledWith('delete', {});
+ expect(byId('botGroup.settings.delete')).toBeNull();
+ expect(byId('botGroup.settings.leave')?.disabled).toBe(false);
+ await click('botGroup.settings.leave');
+ expect(h.chat.act).toHaveBeenCalledWith('leave', undefined);
expect(h.leave).toHaveBeenCalledOnce();
});
- it('keeps compatibility leave disabled when the computer is offline', async () => {
- const data = group({ serverBacked: true, supportsSettingsManagement: true, revision: 5 });
- data.members[0] = { ...data.members[0], isOwned: true, role: 'member' };
+ it('keeps explicit leave disabled when the computer is offline', async () => {
+ const data = group({ serverBacked: true, supportsSettingsManagement: true, supportsGroupLeave: true, revision: 5 });
+ data.members[0] = { ...data.members[0], actorId: 'human', isSelf: true, isOwned: true, role: 'member' };
h.chat.online = false;
await openSettings(data);
- expect(byId('botGroup.settings.delete')?.disabled).toBe(true);
- await click('botGroup.settings.delete');
+ expect(byId('botGroup.settings.delete')).toBeNull();
+ expect(byId('botGroup.settings.leave')?.disabled).toBe(true);
+ await click('botGroup.settings.leave');
expect(h.chat.act).not.toHaveBeenCalled();
});
diff --git a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
index 16b5580d0a..984b76bc99 100644
--- a/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
+++ b/apps/mobile/src/__tests__/chatServerMobileEntry.test.tsx
@@ -5,7 +5,7 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest';
const h = vi.hoisted(() => ({
auth: { user: { id: 'owner' }, accountGeneration: 1, apiFetch: vi.fn(), getAccessToken: vi.fn(async () => 'fixture') },
link: { status: 'offline', connectionEpoch: 1, presenceVersion: 1, invoke: vi.fn(), openLink: vi.fn(),
- getPresenceAvailability: () => false, onRemoteResourceChanged: () => () => {}, subscribe: vi.fn(), unsubscribe: vi.fn() },
+ getPresenceAvailability: (): boolean => false, onRemoteResourceChanged: () => () => {}, subscribe: vi.fn(), unsubscribe: vi.fn() },
legacy: { items: [] as any[], loading: false, refreshing: false, error: null as string | null, isOnline: vi.fn(() => false), refresh: vi.fn() },
targets: [] as { deviceId: string; deviceName: string }[],
foreground: new Set<(state: string) => void>(),
diff --git a/apps/mobile/src/__tests__/chatServerSubscription.test.ts b/apps/mobile/src/__tests__/chatServerSubscription.test.ts
index 095232f2a6..483bb7cbf4 100644
--- a/apps/mobile/src/__tests__/chatServerSubscription.test.ts
+++ b/apps/mobile/src/__tests__/chatServerSubscription.test.ts
@@ -10,6 +10,19 @@ function socket(): MockSocket {
}
const receive = async (ws: ChatSocket, data: unknown) => { ws.onmessage?.({ data: JSON.stringify(data) } as MessageEvent); await Promise.resolve(); await Promise.resolve(); };
let stop = () => {};
+it('waits for reset state before resubscribing and ignores completion after disposal', async () => {
+ let finish!: () => void;
+ const reset = vi.fn(() => new Promise<void>(resolve => { finish = resolve; }));
+ stop = subscribeChatServer({ baseUrl: 'https://chat.example.invalid', token: async () => 'fixture', current: () => true,
+ socket, ready: async () => ({ scope: `actor:${actorId}`, cursor: '0' }), changed: vi.fn(), unavailable: vi.fn(), reset });
+ await Promise.resolve(); const ws = sockets[0];
+ await receive(ws, { type: 'ready', actorId });
+ await receive(ws, { type: 'scope_error', scope: `actor:${actorId}`, error: { code: 'RESET_REQUIRED', details: { head: '50' } } });
+ expect(reset).toHaveBeenCalledOnce();
+ expect(ws.send).not.toHaveBeenCalledWith(JSON.stringify({ type: 'subscribe', scope: `actor:${actorId}`, after: '50' }));
+ stop(); finish(); await Promise.resolve(); await Promise.resolve();
+ expect(ws.send).not.toHaveBeenCalledWith(JSON.stringify({ type: 'subscribe', scope: `actor:${actorId}`, after: '50' }));
+});
afterEach(() => { stop(); sockets.length = 0; vi.useRealTimers(); });
it('authenticates inside the socket, acknowledges string cursors and reconnects without replaying writes', async () => {
vi.useFakeTimers(); const changed = vi.fn(); const token = vi.fn(async () => 'fixture-token');
diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.ts
index 42b01f99f5..f2e8a7c954 100644
--- a/apps/mobile/src/chat/chatServerClient.ts
+++ b/apps/mobile/src/chat/chatServerClient.ts
@@ -216,6 +216,7 @@ export function createChatServerClient(request: ChatRequest, personalList = crea
await identity();
if (supportsListRemoval) await (force ? personalList.sync(request) : personalList.ensureSynced(request));
},
+ async resyncListState() { await identity(); if (supportsListRemoval) await personalList.resync(request); },
async hide(roomId: string, operationId: string) {
await identity();
if (!supportsListRemoval) throw new Error('LIFECYCLE_UNAVAILABLE');
diff --git a/apps/mobile/src/chat/chatServerSubscription.ts b/apps/mobile/src/chat/chatServerSubscription.ts
index 89a0344a36..9ccc48114b 100644
--- a/apps/mobile/src/chat/chatServerSubscription.ts
+++ b/apps/mobile/src/chat/chatServerSubscription.ts
@@ -15,6 +15,7 @@ export function subscribeChatServer(options: {
socket(url: string): ChatSocket;
ready(actorId: string): Promise<{ scope: string; cursor: string } | Array<{ scope: string; cursor: string }>>;
changed(changes?: Array<{ type: string; data: unknown }>): void; unavailable(): void; available?(): void;
+ reset?(): Promise<void>;
}) {
let stopped = false;
let socket: ChatSocket | undefined;
@@ -55,7 +56,9 @@ export function subscribeChatServer(options: {
// A full authenticated reload clears removed membership and resets expired cursors.
options.changed(value.changes);
if (value.error?.code === 'RESET_REQUIRED' && value.error?.details?.head) {
- ws.send(JSON.stringify({ type: 'subscribe', scope: value.scope, after: chatCursor(value.error.details.head) }));
+ const head = chatCursor(value.error.details.head);
+ await options.reset?.();
+ if (current(ws) && ws.readyState === 1) ws.send(JSON.stringify({ type: 'subscribe', scope: value.scope, after: head }));
} else { stopped = true; options.unavailable(); ws.close(); }
} else if (value.type === 'error') ws.close();
})().catch(() => { if (current(ws)) ws.close(); });
diff --git a/apps/mobile/src/chat/useChatServer.ts b/apps/mobile/src/chat/useChatServer.ts
index f098f4af72..d1b8408c28 100644
--- a/apps/mobile/src/chat/useChatServer.ts
+++ b/apps/mobile/src/chat/useChatServer.ts
@@ -138,7 +138,7 @@ export function useChatServerRoster(enabled: boolean) {
}
await read({ reason: 'connected' });
return { scope: `actor:${actorId}`, cursor };
- }, changed: changes => { for (const change of changes ?? []) if (change.type === 'conversation.list.changed') api.client.personalList.merge(change.data); void read({ reason: 'changed' }); }, available: () => { subscribed = true; }, unavailable: () => { subscribed = false; } });
+ }, reset: () => api.client.resyncListState(), changed: changes => { for (const change of changes ?? []) if (change.type === 'conversation.list.changed') api.client.personalList.merge(change.data); void read({ reason: 'changed' }); }, available: () => { subscribed = true; }, unavailable: () => { subscribed = false; } });
}).catch(() => {}); // HTTP read presents endpoint errors.
};
start();
@@ -220,7 +220,7 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {
if (!freshRead.current || !latest || latest.identity !== identity) throw new Error('CHAT_READ_FAILED');
return head === null ? { scope: `conversation:${groupId}`, cursor: latest.page.snapshot.cursor }
: [{ scope: `conversation:${groupId}`, cursor: latest.page.snapshot.cursor }, { scope: `actor:${actorId}`, cursor: head }];
- }, changed: changes => { for (const change of changes ?? []) if (change.type === 'conversation.list.changed') api.client.personalList.merge(change.data); reload(); }, available: () => { subscribed = true; }, unavailable: () => { subscribed = false; freshRead.current = false; } });
+ }, reset: () => api.client.resyncListState(), changed: changes => { for (const change of changes ?? []) if (change.type === 'conversation.list.changed') api.client.personalList.merge(change.data); reload(); }, available: () => { subscribed = true; }, unavailable: () => { subscribed = false; freshRead.current = false; } });
}).catch(() => {}); // Read presents endpoint errors.
};
start();
diff --git a/apps/mobile/src/session/BotGroupChatScreen.tsx b/apps/mobile/src/session/BotGroupChatScreen.tsx
index dccf60a864..824bab1337 100644
--- a/apps/mobile/src/session/BotGroupChatScreen.tsx
+++ b/apps/mobile/src/session/BotGroupChatScreen.tsx
@@ -198,6 +198,14 @@ export function BotGroupChatScreen({ deviceId, deviceName, groupId }: { deviceId
const currentHideScope = `${groupId}:${deviceId}:${accountGeneration}`;
hideScope.current = currentHideScope;
useEffect(() => () => { hideScope.current = ''; }, []);
+ const actFromSettings: typeof chat.act = async (action, input) => {
+ const captured = currentHideScope;
+ const receipt = await chat.act(action, input);
+ // The list listener may already have unmounted settings; the screen still
+ // owns this route and can complete navigation after the acknowledgement.
+ if ((action === 'hide' || action === 'leave') && hideScope.current === captured) leave();
+ return receipt;
+ };
const removeFromList = async () => {
if (hidePending.current) return;
hidePending.current = true;
@@ -371,7 +379,7 @@ export function BotGroupChatScreen({ deviceId, deviceName, groupId }: { deviceId
{body}
</>}
{group ? <BotGroupSettingsSheet readOnly={chat.server} visible={settings} group={group} host={host} identityFor={identityFor} online={chat.online}
- act={chat.act} onClose={() => setSettings(false)}
+ act={actFromSettings} onClose={() => setSettings(false)}
onRefresh={chat.reload}
onClosed={() => { if (leaveAfterSettings.current) { leaveAfterSettings.current = false; leave(); } }}
onDeleted={onGroupDeleted} /> : null}
diff --git a/apps/mobile/src/session/BotGroupSettingsSheet.tsx b/apps/mobile/src/session/BotGroupSettingsSheet.tsx
index 51307ffcc1..5fca7132f7 100644
--- a/apps/mobile/src/session/BotGroupSettingsSheet.tsx
+++ b/apps/mobile/src/session/BotGroupSettingsSheet.tsx
@@ -166,8 +166,7 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, ac
if (!await showConfirm({ title: t(`groupChat.lifecycle.${action}`), message: t(`groupChat.lifecycle.${action}Note`),
cancelLabel: t('devices.common.cancel'), confirmLabel: t(`groupChat.lifecycle.${action}`), destructive: true }) || active.current !== captured) return;
await lifecycleProps.act(action, action === 'dissolve' ? { expectedRevision: lifecycleGroup.revision } : undefined);
- if (active.current !== captured) return;
- if (action === 'hide') onDeleted();
+ // The owning screen completes hide/leave navigation even if this sheet unmounted.
} catch (error) {
if (active.current === captured) setErrors(current => ({ ...current, lifecycle: botGroupActionErrorText(t, error, 'groupChat.lifecycle.failed') }));
} finally { busyRef.current = null; if (active.current === captured) setBusy(null); }
@@ -347,7 +346,7 @@ function BotGroupSettingsContent({ visible, group, host, identityFor, online, ac
</View>
</View>
- {(!group.serverBacked || (canManageBotGroup(group) && !group.dissolvedAt)) && <View style={[styles.section, (readOnly || !online) && styles.inheritedInactive]}>
+ {(!group.serverBacked || (canManageBotGroup(group) && !leavesGroup && !group.dissolvedAt)) && <View style={[styles.section, (readOnly || !online) && styles.inheritedInactive]}>
<Pressable accessibilityRole="button" accessibilityLabel={t(archivesGroup ? 'groupChat.settings.archive' : 'groupChat.settings.delete')} disabled={deleteLocked}
onPress={() => void remove()}
style={({ pressed }) => [styles.group, styles.memberRow, pressed && mobileInteractionStyles.pressed, !readOnly && online && deleteLocked && styles.inactive]}
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 41f4784d58..fcc9c4f2c2 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -42,6 +42,9 @@ Desktop 收到终态后还会中止本机未完成的规划,沿原 lease 链
列表、选择与未读镜像,失败保留列表。手机同时订阅群和本人 human scope,代演不替换账号订阅。
同账号并发全量同步共用一次请求;普通聊天刷新复用已同步状态与事件,启动、重连及手机主动刷新重新读取。
同步失败不把缓存标记为已就绪。手机列表重新挂载时先纳入已有个人状态,直连离线也不恢复旧电脑回包。
+actor scope 遇到 RESET_REQUIRED 时,在在途读取完成后重新读取个人状态,再按服务端 head 续订;
+Desktop 与 Mobile 均受当前账号、socket 身份保护。个人移除成功时由仍挂载的聊天页完成返回列表,
+设置面板因列表更新先卸载不会吞掉成功导航,离开页面后的旧回包也不能改变新页面。
现有 `bot-group-chat` 投影可选追加 supportsDissolve、supportsListRemoval、supportsGroupLeave、dissolvedAt;远程资源
动作 `dissolve` / `leave` / `hide` 分别转发相同的服务端动作。hide 的 opaque result 返回
diff --git a/packages/maker-shared/src/__tests__/chatConversationList.test.ts b/packages/maker-shared/src/__tests__/chatConversationList.test.ts
index 60b5d5ea6d..388ec04389 100644
--- a/packages/maker-shared/src/__tests__/chatConversationList.test.ts
+++ b/packages/maker-shared/src/__tests__/chatConversationList.test.ts
@@ -2,6 +2,19 @@ import { expect, it, vi } from 'vitest';
import { createConversationListState } from '../chatConversationList';
const id = '00000000-0000-4000-8000-000000000001';
+it('starts a fresh scan after an older in-flight read when an event cursor resets', async () => {
+ const list = createConversationListState();
+ let finish!: (value: unknown) => void;
+ const request = vi.fn().mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }))
+ .mockResolvedValue([{ conversationId: id, hidden: true, revision: 2 }]);
+ const initial = list.sync(request);
+ const reset = list.resync(request);
+ finish([{ conversationId: id, hidden: false, revision: 1 }]);
+ await Promise.all([initial, reset]);
+ expect(request).toHaveBeenCalledTimes(2);
+ expect(list.hidden(id)).toBe(true);
+});
+
it('shares concurrent reads and avoids full-page downloads until an explicit reconnect', async () => {
const list = createConversationListState();
let resolve!: (value: unknown) => void;
diff --git a/packages/maker-shared/src/chatConversationList.ts b/packages/maker-shared/src/chatConversationList.ts
index 241519a8ab..86fa887afe 100644
--- a/packages/maker-shared/src/chatConversationList.ts
+++ b/packages/maker-shared/src/chatConversationList.ts
@@ -50,6 +50,9 @@ export function createConversationListState() {
subscribe(notify: (row: ConversationListState) => void) { listeners.add(notify); return () => { listeners.delete(notify); }; },
sync,
ensureSynced: (request: Request) => sync(request, false),
+ // A reset's head may be newer than the start of an existing scan. Finish that
+ // scan first, then read again so resubscribing at the supplied head loses no gap.
+ async resync(request: Request) { if (syncing) await syncing; await sync(request); },
async setHidden(request: Request, id: string, hidden: boolean, operationId: string) {
if (!uuid.test(id)) throw new Error('INVALID_CHAT_ID');
// Read first, including after leaving. A lost acknowledgement is safe to retry.