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(scheduler): notify sessionless automation failures (#3722)

WEIWEICurry8b176831f82f
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
index c0a4ed8c8c..40f52687f0 100644
--- a/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
+++ b/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
@@ -37,6 +37,7 @@ function run(status: ScheduleRun['status']): ScheduleRun {
function createNotifier(opts?: {
sendMarkdownText?: ReturnType<typeof vi.fn>;
shouldNotifyDesktop?: () => boolean;
+ isAgentIslandEnabled?: () => boolean;
publishMarkdown?: ReturnType<typeof vi.fn>;
}): {
notifier: DesktopNotifier;
@@ -55,6 +56,7 @@ function createNotifier(opts?: {
} as unknown as FeishuIM,
logger: { warn },
shouldNotifyDesktop: opts?.shouldNotifyDesktop ?? (() => true),
+ isAgentIslandEnabled: opts?.isAgentIslandEnabled ?? (() => false),
wecomGroupPublisher: { publishMarkdown },
});
return { notifier, sendMarkdownText, warn, publishMarkdown };
@@ -116,6 +118,37 @@ describe('DesktopNotifier desktop status mapping', () => {
expect(sendMobileSessionNotify).not.toHaveBeenCalled();
});
+ it('lets Agent Island replace a desktop notification for a session-bound run', async () => {
+ const { notifier } = createNotifier({ isAgentIslandEnabled: () => true });
+
+ await notifier.notify(schedule, run('failed'));
+
+ expect(showDesktopSessionEvent).not.toHaveBeenCalled();
+ });
+
+ it('keeps a desktop error notification when Agent Island cannot represent the failed run', async () => {
+ const { notifier } = createNotifier({ isAgentIslandEnabled: () => true });
+
+ await notifier.notify(schedule, { ...run('failed'), sessionId: undefined });
+
+ expect(showDesktopSessionEvent).toHaveBeenCalledWith(expect.any(Function), {
+ sessionId: '',
+ title: '每日检查',
+ kind: 'error',
+ });
+ });
+
+ it.each(['success', 'aborted', 'interrupted'] as const)(
+ 'does not bypass Agent Island for a sessionless %s run',
+ async (status) => {
+ const { notifier } = createNotifier({ isAgentIslandEnabled: () => true });
+
+ await notifier.notify(schedule, { ...run(status), sessionId: undefined });
+
+ expect(showDesktopSessionEvent).not.toHaveBeenCalled();
+ },
+ );
+
it('mobile 正文带运行结果摘要:成功用 resultText,失败用 errorMsg', async () => {
const { notifier } = createNotifier();
diff --git a/apps/desktop/src/main/scheduler-host/index.ts b/apps/desktop/src/main/scheduler-host/index.ts
index 7f51478cab..b9ec8d0d22 100644
--- a/apps/desktop/src/main/scheduler-host/index.ts
+++ b/apps/desktop/src/main/scheduler-host/index.ts
@@ -96,8 +96,8 @@ async function startSchedulerInternal(deps: StartSchedulerDeps): Promise<Schedul
getMainWindow: deps.getMainWindow,
feishuIm: deps.feishuIm,
logger: deps.logger,
- shouldNotifyDesktop: () =>
- getDesktopNotificationsEnabled() && !(getAgentIslandService()?.isEnabled() ?? false),
+ shouldNotifyDesktop: getDesktopNotificationsEnabled,
+ isAgentIslandEnabled: () => getAgentIslandService()?.isEnabled() ?? false,
wecomGroupPublisher: wecomGroupNotificationService,
});
const promptRunner = new MakerScheduleRunner({
diff --git a/apps/desktop/src/main/scheduler-host/notifier.ts b/apps/desktop/src/main/scheduler-host/notifier.ts
index ff76483310..080178bbcc 100644
--- a/apps/desktop/src/main/scheduler-host/notifier.ts
+++ b/apps/desktop/src/main/scheduler-host/notifier.ts
@@ -25,8 +25,10 @@ export interface DesktopNotifierDeps {
getMainWindow: () => BrowserWindow | null;
feishuIm: FeishuIM;
logger: Logger;
- /** Global desktop preference and Agent Island arbitration, evaluated at send time. */
+ /** Global desktop preference, evaluated at send time. */
shouldNotifyDesktop: () => boolean;
+ /** Whether Agent Island should arbitrate routine scheduler desktop notifications. */
+ isAgentIslandEnabled: () => boolean;
wecomGroupPublisher?: WecomGroupNotificationPublisher;
}
@@ -37,7 +39,11 @@ export class DesktopNotifier implements Notifier {
// 链路代次在任何 await 之前捕获:飞书分支的 await 期间可能发生登出/换号,
// 发送侧按代次不一致丢弃,旧账号调度的通知不会进新账号的链路。
const generation = getMobileNotifyGeneration();
- if (schedule.notify.desktop && this.deps.shouldNotifyDesktop()) {
+ if (
+ schedule.notify.desktop &&
+ this.deps.shouldNotifyDesktop() &&
+ (!this.deps.isAgentIslandEnabled() || (run.status === 'failed' && !run.sessionId))
+ ) {
try {
this.notifyDesktop(schedule, run);
} catch (err) {