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(desktop): 群聊发件箱对消息内容被拒的失败只提供编辑

Dash0ebe3ef69a66
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
index bfd98effbf..28a5b517a1 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx
@@ -1271,10 +1271,12 @@ function BotGroupOutboxItem({
>
{t('bots.groupChat.outbox.edit')}
</Button>
- <Button variant="secondary" size="sm" compact type="button" onClick={() => retryBotGroupSend(entry.input.groupId, entry.input.clientId)}>
- <RefreshCcw size={13} />
- {t('bots.retry')}
- </Button>
+ {entry.retryable !== false ? (
+ <Button variant="secondary" size="sm" compact type="button" onClick={() => retryBotGroupSend(entry.input.groupId, entry.input.clientId)}>
+ <RefreshCcw size={13} />
+ {t('bots.retry')}
+ </Button>
+ ) : null}
</div>
) : null}
</BotGroupSelfBubble>
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 066493db79..9114b463e6 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -1561,6 +1561,24 @@ describe('BotGroupChatView', () => {
expect(screen.queryByTestId('bot-group-quote-preview')).toBeNull();
});
+ it('keeps a message whose original became unavailable for 编辑 only, never 重试', async () => {
+ const user = userEvent.setup();
+ let refuse!: () => void;
+ mocks.sendBotGroupMessage.mockImplementation(() => new Promise((resolve) => {
+ refuse = () => resolve({ ok: false, errorCode: 'QUOTE_UNAVAILABLE' });
+ }));
+ renderView();
+ await user.click(await quoteButton());
+ await user.keyboard('就这班{Enter}');
+ await waitFor(() => expect(mocks.sendBotGroupMessage).toHaveBeenCalledOnce());
+ await user.type(screen.getByRole('textbox', { name: 'bots.groupChat.composer.label' }), '另一件事');
+ await act(async () => refuse());
+ const failed = await screen.findByTestId('bot-group-outbox');
+ await waitFor(() => expect(failed.getAttribute('data-status')).toBe('failed'));
+ expect(within(failed).getByRole('button', { name: 'bots.groupChat.outbox.edit' })).toBeTruthy();
+ expect(within(failed).queryByRole('button', { name: /bots\.retry/ })).toBeNull();
+ });
+
it('offers no 引用回复 on a local group, a notice or a round divider', async () => {
mocks.getBotGroup.mockResolvedValue({ ok: true, group: detail() });
renderView();
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts
index 1976ef58bb..eb600bc51d 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGroupOutbox.test.ts
@@ -280,6 +280,24 @@ describe('botGroupOutbox', () => {
expect(getBotGroupOutbox('g1').map((entry) => entry.input.clientId)).toEqual(['keep']);
});
+ it('offers no 重试 when main refused the message itself: only 编辑 can change it', async () => {
+ registerBotGroupComposer('g1', { restore: vi.fn(() => false), notifyFailed: vi.fn() });
+ for (const errorCode of ['QUOTE_UNAVAILABLE', 'MENTION_UNAVAILABLE', 'INVALID_PARAMS', 'INVALID_ATTACHMENT', 'ATTACHMENT_TOO_LARGE'] as const) {
+ mocks.send.mockReset().mockResolvedValueOnce({ ok: false, errorCode, message: '' });
+ enqueueBotGroupSend(draft({ clientId: errorCode }));
+ await flush();
+ expect(getBotGroupOutbox('g1').find((entry) => entry.input.clientId === errorCode)).toMatchObject({ status: 'failed', retryable: false });
+ retryBotGroupSend('g1', errorCode);
+ await flush();
+ expect(mocks.send).toHaveBeenCalledTimes(1);
+ }
+ // A failure that may pass later stays retryable.
+ mocks.send.mockReset().mockResolvedValueOnce({ ok: false, errorCode: 'SERVICE_ERROR', message: '' });
+ enqueueBotGroupSend(draft({ clientId: 'later' }));
+ await flush();
+ expect(getBotGroupOutbox('g1').find((entry) => entry.input.clientId === 'later')?.retryable).toBe(true);
+ });
+
it('edits a failed message only into a composer that accepts it', async () => {
const restore = vi.fn(() => false);
registerBotGroupComposer('g1', { restore, notifyFailed: vi.fn() });
diff --git a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts b/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts
index 09608b42d2..847b434ee7 100644
--- a/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts
+++ b/apps/desktop/src/renderer/features/bots/botGroupOutbox.ts
@@ -41,6 +41,7 @@ import { setBotGroupOutboxAttachmentUrls } from '@/lib/composerDraftStore';
import type { AttachedFile } from '@/lib/fileTypes';
import type {
BotGroupAttachment,
+ BotGroupErrorCode,
BotGroupMessageView,
BotGroupQuoteView,
BotGroupSendInput,
@@ -96,6 +97,8 @@ export interface BotGroupOutboxEntry extends BotGroupOutboxDraft {
baseline?: number;
/** i18n key explaining a failure. */
errorKey?: string;
+ /** False when main refused the message itself: resending it unchanged can only fail again. */
+ retryable?: boolean;
}
/** The mounted composer of a group: takes a failed message back into the input when it is empty. */
@@ -115,6 +118,17 @@ interface GroupOutbox {
}
const CLAIMED_LIMIT = 64;
+/**
+ * Refusals of the message's own content (a quoted original or a named teammate that is gone,
+ * invalid fields or files): only 编辑 can change the outcome, so 重试 is not offered.
+ */
+const CONTENT_REFUSALS: ReadonlySet<BotGroupErrorCode> = new Set([
+ 'QUOTE_UNAVAILABLE',
+ 'MENTION_UNAVAILABLE',
+ 'INVALID_PARAMS',
+ 'INVALID_ATTACHMENT',
+ 'ATTACHMENT_TOO_LARGE',
+]);
const NO_PREVIEWS: ReadonlyMap<string, readonly BotGroupAttachment[]> = new Map();
const EMPTY: readonly BotGroupOutboxEntry[] = [];
@@ -282,7 +296,7 @@ function prepare(groupId: string, clientId: string): Promise<readonly AttachedFi
export function retryBotGroupSend(groupId: string, clientId: string): void {
ensureOwner();
const entry = groups.get(groupId)?.entries.find((candidate) => candidate.input.clientId === clientId);
- if (!entry || entry.status !== 'failed') return;
+ if (!entry || entry.status !== 'failed' || entry.retryable === false) return;
update(groupId, clientId, { status: 'sending', errorKey: undefined });
schedule(groupId, clientId);
}
@@ -341,6 +355,7 @@ async function submitOwned(
update(groupId, clientId, { baseline: group.latestSequence });
const api = botGroupApi();
let errorKey = 'bots.groupChat.composer.sendFailed';
+ let retryable = true;
try {
if (!api) throw new Error('HOST_NOT_READY');
// Drawn annotations are burned in first, as in a task; a failure keeps everything for a retry.
@@ -367,6 +382,7 @@ async function submitOwned(
}
// An original that is no longer available is not put back with the draft.
if (result.errorCode === 'QUOTE_UNAVAILABLE') update(groupId, clientId, { quote: null });
+ retryable = !CONTENT_REFUSALS.has(result.errorCode);
errorKey =
result.errorCode === 'INVALID_PARAMS' && prepared.length > 0
? 'bots.groupChat.composer.attachmentsFailed'
@@ -379,7 +395,7 @@ async function submitOwned(
}
if (isAnnotationBurnInError(error)) errorKey = 'chat.media.annotateBurnFailedNotSent';
}
- const failed = update(groupId, clientId, { status: 'failed', errorKey, baseline: undefined });
+ const failed = update(groupId, clientId, { status: 'failed', errorKey, retryable, baseline: undefined });
if (!failed) return;
const composer = composers.get(groupId);
if (composer?.restore(failed)) remove(groupId, clientId);
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 44b253ccda..ec209a8304 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -352,7 +352,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授
同一草稿的点名目标 ID、顺序或所有人标记变化,即使显示名字与正文没变,也必须使用新的 `clientId`。只有正文、点名目标、分工标记和附件均不变时,失败重试才复用原发送尝试。
-Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序;副本按下载完成先后逐个列出、数量不一致时,只有名字(烧录后的名字)在这条消息里唯一的附件按名字配对,重名的附件分不出谁是谁,继续显示各自的本地预览、对应副本暂不单独显示,直到数量一致再按顺序替换;不退成缺失、不重复、同名文件不互换。离开输入框、尚未确认的图片(含标注原图与烧录副本)登记进存储清理的保护清单直到条目释放,已确认消息的本地预览不登记(发送时 main 已在群的 `bot-group-attachment` 引用下固定);本地预览按已加载的全部时间线(含更早的页)结算,不设条数上限;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群;读取不确定时在 5 秒、30 秒、2 分钟后各重试一次,群回到列表或读到仍存在即停止)时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。切换账号时发件箱同样发出回收,但 main 只删当前账号暂存目录里的副本,renderer 看到切换时 main 已在新账号(或边界)下,所以前一账号的暂存副本留在它自己的目录里,不在发件箱范围内。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」,可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `clientId`);失败放回时引用只随它自己的正文放回(期间已另选引用的以新选为准),原消息不可用(`QUOTE_UNAVAILABLE`)时只放回正文。发件箱原样保存并发出完整发送输入(附件入队即开始烧录标注,提交时序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换到另一个账号时清空(同账号的 generation 修复、认证边界短暂的 null 不清空)、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。
+Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时间线末尾,输入框与托盘马上空出,可以接着发下一条;同一个群的提交按发出顺序逐条交给 main,慢于 0.6 秒才在气泡下显示「发送中…」。回执的 `messageId` 是替换依据:时间线读到该消息即换成真实消息,回执之后开始的重读没读到也视为已进历史;推送重读先于回执到达时,只对正在提交的那一条按「基线之后、未被回执认领、正文与附件数一致的自己的消息」做显示去重,最终仍以 `messageId` 为准。附件按输入生成临时列表;带手绘标注的图片入队即烧录,完成后气泡改用烧录后的本地预览,提交与重试复用同一份烧录结果,放回输入框的仍是带笔迹的原件。真实消息到达而服务器副本尚未可用(无 url / path,或旧版尚未列出)时,在同一 `messageId` 内配对:数量一致按发送顺序;副本按下载完成先后逐个列出、数量不一致时,只有名字(烧录后的名字)在这条消息里唯一的附件按名字配对,重名的附件分不出谁是谁,继续显示各自的本地预览、对应副本暂不单独显示,直到数量一致再按顺序替换;不退成缺失、不重复、同名文件不互换。离开输入框、尚未确认的图片(含标注原图与烧录副本)登记进存储清理的保护清单直到条目释放,已确认消息的本地预览不登记(发送时 main 已在群的 `bot-group-attachment` 引用下固定);本地预览按已加载的全部时间线(含更早的页)结算,不设条数上限;尚未进入消息的暂存文件按归属回收:还没开始提交的条目(排队中、已失败)归发件箱,群被删除(包括不在当前页、从列表消失且读取确认 `NOT_FOUND` 的群;读取不确定时在 5 秒、30 秒、2 分钟后各重试一次,群回到列表或读到仍存在即停止)时立即回收;已开始提交的条目归它的那次请求——烧录期间被丢弃的不再发出并回收,已交给 main 的等 main 答复,成功(已进入消息)不回收,失败或调用异常才回收(main 在答复前读完本地文件,失败时不留引用暂存路径的本地记录)。切换账号时发件箱同样发出回收,但 main 只删当前账号暂存目录里的副本,renderer 看到切换时 main 已在新账号(或边界)下,所以前一账号的暂存副本留在它自己的目录里,不在发件箱范围内。发送失败绝不自动重发:输入框为空(无文字、附件、分工标签)时把正文、点名、标签与附件原样放回并提示原因,再发沿用原 `clientId`;输入框已有新内容时消息留在时间线上显示「没发出去」,可「重试」(同一 `clientId`)或在输入框清空后「编辑」放回;main 拒绝的是消息内容本身时(引用原消息或点名对象已不可用、字段或附件无效:`QUOTE_UNAVAILABLE` / `MENTION_UNAVAILABLE` / `INVALID_PARAMS` / `INVALID_ATTACHMENT` / `ATTACHMENT_TOO_LARGE`),原样重发只会再次失败,只提供「编辑」;失败时输入框不在(切到别的群、分享模式),回到该群时同样放回空输入框并提示原因。「引用回复」随消息进入发件箱:待发气泡上方显示同一个引用块,引用是发送输入的一部分(换引用即换 `clientId`);失败放回时引用只随它自己的正文放回(期间已另选引用的以新选为准),原消息不可用(`QUOTE_UNAVAILABLE`)时只放回正文。发件箱原样保存并发出完整发送输入(附件入队即开始烧录标注,提交时序列化),首发与重试不挑字段;除 `clientId` 外的全部字段与附件共同决定能否复用原 `clientId`,新增发送字段无需改动发件箱。发件箱只在 renderer 内存中保留,切群后仍按群隔离,切换到另一个账号时清空(同账号的 generation 修复、认证边界短暂的 null 不清空)、删群丢弃,不持久化。Thread 回复与手机端仍是等待回执后显示。实现见 `renderer/features/bots/botGroupOutbox.ts`,回归见 `botGroupOutbox.test.ts` 与 `BotGroupChatView.test.tsx`。
完成全部显式目标校验后,最终点名列表继续沿用排除当前用户自己的既有规则;主群、Thread 与手机直连均一致,不因显式列表或所有人标记改变。