Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): deduplicate channel-owned handoff notices
guyong2823d738c35e
diff --git a/apps/desktop/src/main/__tests__/notificationService.test.ts b/apps/desktop/src/main/__tests__/notificationService.test.tsindex 1f01fd0bd3..5a3313a774 100644--- a/apps/desktop/src/main/__tests__/notificationService.test.ts+++ b/apps/desktop/src/main/__tests__/notificationService.test.ts@@ -23,6 +23,7 @@*/import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import type { Session } from '@cindy/maker-core';type IpcHandler = (event: unknown, payload: unknown) => Promise<void> | void;@@ -102,6 +103,11 @@ vi.mock('../device-link', () => ({getMobileNotifyGeneration,}));+const pendingHandoffSessions = new Set<string>();+vi.mock('../input-handoff/service', () => ({+ getInputHandoffService: () => ({ hasPending: (id: string) => pendingHandoffSessions.has(id) }),+}));+// mobile 正文素材:最近一条 assistant 内容(真实实现走 localDb)。默认空 = 无摘要,// 既有用例的调用断言不带 detail;内容用例单独 mockResolvedValueOnce。const latestMessageText = vi.fn<@@ -155,6 +161,7 @@ async function freshService() {markSessionNeedsAttention.mockClear();sendMobileSessionNotify.mockReset().mockReturnValue(true);getMobileNotifyGeneration.mockClear();+ pendingHandoffSessions.clear();latestMessageText.mockClear();readSessionNotificationPreview.mockReset().mockImplementation(async (sessionId, includeReply = true) => {if (!includeReply) return {};@@ -198,6 +205,57 @@ describe('notificationService — channels 分发', () => {vi.useRealTimers();});+ // #6754 / input-handoff §2.4 / unit: the real notification IPC must not+ // duplicate Main's channel pointer on successive steps. Both bot tasks have+ // the same source; only the live route plus pending request distinguishes them.+ it('deduplicates channel-owned handoff steps while preserving desktop bot fallback and other notices', async () => {+ const { initNotificationService } = await freshService();+ const { bindInputHandoffChannelNotice, clearInputHandoffChannelNotices } =+ await import('../im/shared/inputHandoffChannelNotice');+ const feishuIm = makeFeishuIm('owner');+ initNotificationService(baseDeps(feishuIm));+ const statusListeners = new Set<(status: string) => void>();+ bindInputHandoffChannelNotice({+ id: 'im-bot',+ onStatusChange: (listener: (status: string) => void) => {+ statusListeners.add(listener);+ return () => statusListeners.delete(listener);+ },+ } as unknown as Session, async () => true);+ const notify = (sessionId: string, kind = 'needs-reply') => invokeHandler({+ sessionId, title: 'Bot', kind, channels: { desktop: true, feishu: true, mobile: false },+ });+ try {+ pendingHandoffSessions.add('im-bot');+ await notify('im-bot'); // first actionable step+ await notify('im-bot'); // next step of the same request+ expect(feishuIm.sendMarkdownText).not.toHaveBeenCalled();+ expect(notificationCtor).toHaveBeenCalledTimes(2);+ expect(markSessionNeedsAttention).toHaveBeenCalledWith('im-bot');+ expect(sendMobileSessionNotify).not.toHaveBeenCalled();++ pendingHandoffSessions.add('desktop-bot');+ await notify('desktop-bot'); // ordinary bot: no channel route+ expect(feishuIm.sendMarkdownText).toHaveBeenCalledOnce();++ pendingHandoffSessions.delete('im-bot');+ await notify('im-bot'); // channel route alone must not hide a question+ expect(feishuIm.sendMarkdownText).toHaveBeenCalledTimes(2);+ pendingHandoffSessions.add('im-bot'); // a new handoff request is also owned by Main+ await notify('im-bot');+ expect(feishuIm.sendMarkdownText).toHaveBeenCalledTimes(2);+ await notify('im-bot', 'error');+ await notify('im-bot', 'done');+ expect(feishuIm.sendMarkdownText).toHaveBeenCalledTimes(4);++ statusListeners.forEach(listener => listener('closed'));+ await notify('im-bot'); // a removed route cannot suppress a fallback+ expect(feishuIm.sendMarkdownText).toHaveBeenCalledTimes(5);+ } finally {+ clearInputHandoffChannelNotices();+ }+ });+it('hands off delegated completion on every external channel while preserving task attention and consuming retries', async () => {const { initNotificationService } = await freshService();const feishuIm = makeFeishuIm('owner');diff --git a/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts b/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.tsindex 94ab12870d..75a93f708a 100644--- a/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts+++ b/apps/desktop/src/main/im/shared/inputHandoffChannelNotice.ts@@ -16,6 +16,11 @@ interface Route {const routes = new Map<string, Route>();+/** Main-only routing truth; a bot's persisted source does not identify its active channel. */+export function hasInputHandoffChannelNotice(sessionId: string): boolean {+ return routes.has(sessionId);+}+export function bindInputHandoffChannelNotice(session: Session,deliver: (text: string) => Promise<unknown>,diff --git a/apps/desktop/src/main/notificationService.ts b/apps/desktop/src/main/notificationService.tsindex 7dd3bdb788..e5747c11f6 100644--- a/apps/desktop/src/main/notificationService.ts+++ b/apps/desktop/src/main/notificationService.ts@@ -34,6 +34,8 @@ import { drainSessionActiveTurnWrites, getSessionNotificationTurnSignal } from 'import { captureDataOwnerBroadcastScope, isDataOwnerBroadcastScopeCurrent } from './device-link/broadcast-tap';import { latestMessageText } from './localDb/latestMessageText';import { drainPersistQueue } from './messagePersistBroadcaster';+import { getInputHandoffService } from './input-handoff/service';+import { hasInputHandoffChannelNotice } from './im/shared/inputHandoffChannelNotice';import { createLogger } from './logger';import {getSessionExternalNotificationText,@@ -389,7 +391,13 @@ export function initNotificationService(deps: NotificationServiceDeps): void {}})().catch((err) => log.warn('[notification] reply notification failed (non-fatal)', err));- if (wantFeishu && kind !== 'done') {+ // Channel-driven handoffs already receive Main's fixed pointer once per+ // request. Bot tasks share source='bot' with ordinary Desktop bot tasks,+ // so decide from the live request and route instead of Renderer metadata.+ const channelOwnsHandoff = kind === 'needs-reply'+ && getInputHandoffService()?.hasPending(sessionId)+ && hasInputHandoffChannelNotice(sessionId);+ if (wantFeishu && kind !== 'done' && !channelOwnsHandoff) {await sendFeishuMessage(feishuIm, safeTitle, kind);}},