Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 非当前群删除核验失败时有界重试
Dash7681eb297469
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.tsindex 9157583968..854e398f8d 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts@@ -8,6 +8,7 @@ import type {BotGroupSendResult,} from '../../../../shared/botGroupChat';import {+ BOT_GROUP_GONE_RETRY_MS,beginBotGroupTimelineRead,botGroupSendSignature,discardBotGroupOutbox,@@ -688,6 +689,54 @@ describe('botGroupOutbox', () => {expect(released()).toEqual(['drawn']);});+ describe('a read that is not definite', () => {+ const failOne = async () => {+ mocks.send.mockResolvedValueOnce({ ok: false, errorCode: 'INTERNAL', message: '' });+ enqueueBotGroupSend(draft({ groupId: 'g1', clientId: 'failed' }, { files: [staged('failed')] }));+ await flush();+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });+ };+ afterEach(() => vi.useRealTimers());++ it('is retried on its own and discards once a later read says NOT_FOUND', async () => {+ await failOne();+ mocks.getBotGroup.mockRejectedValueOnce(new Error('ipc'))+ .mockResolvedValueOnce({ ok: false, errorCode: 'INTERNAL', message: '' })+ .mockResolvedValueOnce({ ok: false, errorCode: 'NOT_FOUND', message: '' });+ listGroups([]);+ await vi.advanceTimersByTimeAsync(0);+ expect(mocks.getBotGroup).toHaveBeenCalledTimes(1);+ await vi.advanceTimersByTimeAsync(BOT_GROUP_GONE_RETRY_MS[0]);+ expect(mocks.getBotGroup).toHaveBeenCalledTimes(2);+ expect(getBotGroupOutbox('g1')).toHaveLength(1);+ await vi.advanceTimersByTimeAsync(BOT_GROUP_GONE_RETRY_MS[1]);+ expect(mocks.getBotGroup).toHaveBeenCalledTimes(3);+ expect(getBotGroupOutbox('g1')).toEqual([]);+ expect(released()).toEqual(['failed']);+ });++ it('gives up after the last retry, keeping the outbox', async () => {+ await failOne();+ mocks.getBotGroup.mockResolvedValue({ ok: false, errorCode: 'INTERNAL', message: '' });+ listGroups([]);+ await vi.advanceTimersByTimeAsync(10 * 60_000);+ expect(mocks.getBotGroup).toHaveBeenCalledTimes(1 + BOT_GROUP_GONE_RETRY_MS.length);+ expect(getBotGroupOutbox('g1')).toHaveLength(1);+ expect(mocks.cleanupStaged).not.toHaveBeenCalled();+ });++ it('stops once the group is listed again or reads fine', async () => {+ await failOne();+ mocks.getBotGroup.mockRejectedValueOnce(new Error('ipc'));+ listGroups([]);+ await vi.advanceTimersByTimeAsync(0);+ mocks.list = { groups: [{ id: 'g1' }], loaded: true };+ await vi.advanceTimersByTimeAsync(10 * 60_000);+ expect(mocks.getBotGroup).toHaveBeenCalledTimes(1);+ expect(getBotGroupOutbox('g1')).toHaveLength(1);+ });+ });+it('keeps a group that is only missing from the list when the read fails or is not definite', async () => {mocks.send.mockResolvedValueOnce({ ok: false, errorCode: 'INTERNAL', message: '' });enqueueBotGroupSend(draft({ groupId: 'g1', clientId: 'failed' }, { files: [staged('failed')] }));diff --git a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts b/apps/desktop/src/renderer/features/bots/botGroupOutbox.tsindex 555f500bcb..e3ed4cc3e8 100644--- a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts+++ b/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts@@ -468,36 +468,53 @@ export function discardBotGroupOutbox(groupId: string): void {let unwatchGroupList: (() => void) | null = null;const verifying = new Set<string>();+const retryTimers = new Set<ReturnType<typeof setTimeout>>();+/** A read that was not definite (thrown, or a failure other than NOT_FOUND) is tried again. */+export const BOT_GROUP_GONE_RETRY_MS = [5_000, 30_000, 120_000] as const;/*** Groups deleted while their page is closed (or from another device) send no event this* outbox sees. The group list does: a group that drops out of it is read once more, and only- * a definite NOT_FOUND discards its outbox (a legacy id still resolves, a failed read keeps it).+ * a definite NOT_FOUND discards its outbox (a legacy id still resolves). A read that fails is+ * retried a few times on its own: the event that dropped the group may never come again.*/function watchGroupList(): void {if (unwatchGroupList) return;unwatchGroupList = subscribeBotGroups(() => {- const list = getBotGroupListSnapshot();- if (!list.loaded) return;- const listed = new Set(list.groups.map((group) => group.id));- for (const [groupId, group] of groups) {- if (listed.has(groupId) || verifying.has(groupId)) continue;- if (group.entries.length === 0 && group.previews.size === 0) continue;- const api = botGroupApi();- if (!api) continue;- const requestGeneration = generation;- verifying.add(groupId);- void api- .getBotGroup(groupId)- .then((result) => {- if (requestGeneration === generation && !result.ok && result.errorCode === 'NOT_FOUND') discardBotGroupOutbox(groupId);- })- .catch(() => undefined)- .finally(() => verifying.delete(groupId));- }+ for (const groupId of groups.keys()) verifyGroupGone(groupId, 0);});}+function verifyGroupGone(groupId: string, attempt: number): void {+ if (verifying.has(groupId)) return;+ const group = groups.get(groupId);+ if (!group || (group.entries.length === 0 && group.previews.size === 0)) return;+ const list = getBotGroupListSnapshot();+ if (!list.loaded || list.groups.some((listed) => listed.id === groupId)) return;+ const api = botGroupApi();+ if (!api) return;+ const requestGeneration = generation;+ let definite = false;+ verifying.add(groupId);+ void api+ .getBotGroup(groupId)+ .then((result) => {+ definite = result.ok || result.errorCode === 'NOT_FOUND';+ if (requestGeneration === generation && !result.ok && result.errorCode === 'NOT_FOUND') discardBotGroupOutbox(groupId);+ })+ .catch(() => undefined)+ .finally(() => {+ verifying.delete(groupId);+ const delay = BOT_GROUP_GONE_RETRY_MS[attempt];+ if (definite || delay === undefined || requestGeneration !== generation) return;+ const timer = setTimeout(() => {+ retryTimers.delete(timer);+ if (requestGeneration === generation) verifyGroupGone(groupId, attempt + 1);+ }, delay);+ retryTimers.add(timer);+ });+}+/*** The group's composer is on screen. A message that failed while it was away (another group,* share mode) comes back into it now, the same way as a failure seen in place.@@ -594,6 +611,8 @@ export function resetBotGroupOutboxForTests(): void {preparing.clear();verifying.clear();submitting.clear();+ for (const timer of retryTimers) clearTimeout(timer);+ retryTimers.clear();unwatchGroupList?.();unwatchGroupList = null;composers.clear();diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 3e16e4d0f6..de2b48c364 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -351,7 +351,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授同一草稿的点名目标 ID、顺序或所有人标记变化,即使显示名字与正文没变,也必须使用新的 `clientId`。只有正文、点名目标、分工标记和附件均不变时,失败重试才复用原发送尝试。-Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序,旧版逐个列出时按顺序同名(烧录后的名字)配对,继续显示本地预览直到副本可用,不退成缺失、不重复、同名文件不互换。离开输入框的图片(含标注原图与本地预览)登记进存储清理的保护清单直到条目释放;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群)或切换账号时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」,可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。发件箱原样保存并发出完整发送输入(附件在提交时才烧录标注并序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换账号清空、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。+Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序,旧版逐个列出时按顺序同名(烧录后的名字)配对,继续显示本地预览直到副本可用,不退成缺失、不重复、同名文件不互换。离开输入框的图片(含标注原图与本地预览)登记进存储清理的保护清单直到条目释放;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群;读取不确定时在 5 秒、30 秒、2 分钟后各重试一次,群回到列表或读到仍存在即停止)或切换账号时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」,可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。发件箱原样保存并发出完整发送输入(附件在提交时才烧录标注并序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换账号清空、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。完成全部显式目标校验后,最终点名列表继续沿用排除当前用户自己的既有规则;主群、Thread 与手机直连均一致,不因显式列表或所有人标记改变。