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(bots): 续接群任务时为新一轮发进行中卡

Chris14343add055c
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
index f404f4c711..911ed8547e 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts
@@ -4306,6 +4306,32 @@ describe('Bot Session task end-to-end runtime', () => {
} finally { release(); runtime.dispose(); }
});
+ it('posts a fresh in-progress card to the group for each continued run of a group task', async () => {
+ await seedPair(); seedGroupLane();
+ const release = registerGroupToolAuthority('group-lane', { botId: 'bot-a', mode: 'owner', isCurrent: () => true, validate: async () => {} });
+ const postGroupTaskMessage = vi.fn(async (input: { clientId: string }) => ({ ok: true as const, messageId: `posted:${input.clientId}` }));
+ const runtime = createDelegationRuntime({ postGroupTaskMessage });
+ try {
+ const task = await runtime.delegation.startSessionTask({ callerSessionId: 'group-lane', objective: 'First pass' });
+ if (!task.ok) throw new Error(task.message);
+ await runtime.runPendingTurns();
+ const id = task.delegationId;
+ expect(postGroupTaskMessage.mock.calls.map(([input]) => input.clientId))
+ .toEqual([`bot-delegation-task:${id}:started`, `bot-delegation-task:${id}:1:result`]);
+ expect(await runtime.delegation.messageSessionTask('group-lane', id, { kind: 'message', text: 'One more pass.' }))
+ .toMatchObject({ ok: true, resumed: true });
+ // The group no longer shows the first run's 「已完成」 while the second one runs.
+ await vi.waitFor(() => expect(postGroupTaskMessage).toHaveBeenLastCalledWith(expect.objectContaining({
+ clientId: `bot-delegation-task:${id}:2:started`, card: expect.objectContaining({ data: expect.objectContaining({ state: 'started' }) }),
+ })));
+ await runtime.runPendingTurns();
+ expect(postGroupTaskMessage.mock.calls.map(([input]) => input.clientId)).toEqual([
+ `bot-delegation-task:${id}:started`, `bot-delegation-task:${id}:1:result`,
+ `bot-delegation-task:${id}:2:started`, `bot-delegation-task:${id}:2:result`,
+ ]);
+ } finally { release(); runtime.dispose(); }
+ });
+
it('keeps the teammate\'s full objective out of the group task card that every member can read', async () => {
await seedPair(); seedGroupLane();
const release = registerGroupToolAuthority('group-lane', { botId: 'bot-a', mode: 'owner', isCurrent: () => true, validate: async () => {} });
diff --git a/apps/desktop/src/main/maker-ipc/botDelegationService.ts b/apps/desktop/src/main/maker-ipc/botDelegationService.ts
index a541641376..92e54f5447 100644
--- a/apps/desktop/src/main/maker-ipc/botDelegationService.ts
+++ b/apps/desktop/src/main/maker-ipc/botDelegationService.ts
@@ -817,7 +817,7 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
};
type GroupTaskRow = Pick<DelegationRow,
- 'id' | 'requestingBotId' | 'targetBotId' | 'objective' | 'parentSessionId' | 'childSessionId'
+ 'id' | 'requestingBotId' | 'targetBotId' | 'objective' | 'parentSessionId' | 'childSessionId' | 'runSequence'
>;
/** The card's fallback line, in this computer's UI language, for clients that do not know the card. */
@@ -875,18 +875,23 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
* The 「进行中」 card is posted with backoff for as long as the task runs (a group outage may
* outlast any fixed number of tries); `restore` posts it again after a restart. The post is
* idempotent by client id, so a card already in the group is never repeated, and a retry
- * after the task ended stays away. The result message carries the card again.
+ * after the task ended (or moved on to another run) stays away. The result message carries
+ * the card again. A continued task posts a fresh card for each run; the first run keeps the
+ * client id it always had.
*/
const postGroupTaskStart = (home: { groupId: string }, row: GroupTaskRow, attempt = 0): Promise<void> => {
const run = (async () => {
try {
if (attempt > 0) {
// A retry after the task already ended would put a stale 「进行中」 card under its result.
- const current = await getDbClient().drizzle.select({ status: botDelegations.status }).from(botDelegations)
- .where(eq(botDelegations.id, row.id)).get();
- if (!current || !isActiveDelegation(current.status as DelegationStatus)) return;
+ const current = await getDbClient().drizzle.select({ status: botDelegations.status, runSequence: botDelegations.runSequence })
+ .from(botDelegations).where(eq(botDelegations.id, row.id)).get();
+ if (!current || !isActiveDelegation(current.status as DelegationStatus) || current.runSequence !== row.runSequence) return;
}
- const posted = await postGroupTaskEvent(home, row, { clientId: `bot-delegation-task:${row.id}:started`, text: '', state: 'started' });
+ const clientId = row.runSequence > 1
+ ? `bot-delegation-task:${row.id}:${row.runSequence}:started`
+ : `bot-delegation-task:${row.id}:started`;
+ const posted = await postGroupTaskEvent(home, row, { clientId, text: '', state: 'started' });
if (posted.ok) return;
if (!posted.retryable) {
log.warn('group refused the task card', { delegationId: row.id, groupId: home.groupId, errorCode: posted.errorCode });
@@ -2537,6 +2542,7 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
childSessionId,
permissionSnapshotJson,
createdAt,
+ runSequence: 1,
};
// The requesting timeline is the user's only guaranteed place to find and
// control this task. Persist its card before starting the child Session;
@@ -3330,6 +3336,9 @@ export function createBotDelegationService(deps: BotDelegationServiceDeps) {
});
}
scheduleTimeout(row.id, deadlineAt);
+ // The group still shows the last run's end: tell it this run is under way.
+ const groupHome = groupHomeOf(nextSnapshot);
+ if (groupHome) void postGroupTaskStart(groupHome, { ...reopenedRow, runSequence: row.runSequence + 1 });
const dispatched = await attemptDispatch(row.id);
return {
ok: true,
diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.md
index 242b20edac..f87361c30c 100644
--- a/docs/product-rules/bot-group-chat.md
+++ b/docs/product-rules/bot-group-chat.md
@@ -350,7 +350,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授
群专线的 `role=group` 是来源身份,不等于只读历史任务,也不单独构成授权。读取自己的 Profile、能力与 Skill 目录时,必须核对活跃执行、伙伴归属、成员状态、授权版本及执行租约;只聊天的专线仍不可读取私人资料。群主身份不能替代伙伴主人身份。
-只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言;群里每位成员都读得到卡片数据,所以卡片只带任务标题,不带伙伴写下的完整任务目标)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么;从本机旧式群(没有服务器房间)启动时返回 `completion_destination=private`,伙伴告诉群里结果会私下交给主人,不承诺在群里更新。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。
+只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言;群里每位成员都读得到卡片数据,所以卡片只带任务标题,不带伙伴写下的完整任务目标)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;主人续接已结束的任务时,新一轮同样发一张「进行中」卡(幂等 ID 带轮次,首轮沿用原 ID),群里不再停在上一轮的终态;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么;从本机旧式群(没有服务器房间)启动时返回 `completion_destination=private`,伙伴告诉群里结果会私下交给主人,不承诺在群里更新。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。
非主人群工具授权仅允许读取伙伴自身资料、已选能力和自己的技能;应用级能力目录与默认模型查询仍须当前主人执行授权。