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(archive): 桌面本机优先用自动化缓存,冷启动最多等 1.5 秒

Dasha3a7ee3337c7
diff --git a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/archiveScheduleWarning.test.ts b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/archiveScheduleWarning.test.ts
index c10eb57e57..314ea0c2ff 100644
--- a/apps/desktop/src/renderer/features/scheduler/lib/__tests__/archiveScheduleWarning.test.ts
+++ b/apps/desktop/src/renderer/features/scheduler/lib/__tests__/archiveScheduleWarning.test.ts
@@ -24,6 +24,7 @@ vi.mock('@/features/device-link/remoteProjectsStore', () => ({
import {
archiveConfirmDescription,
archiveScheduleWarningMany,
+ COLD_SCHEDULE_LOAD_WAIT_MS,
loadActiveBoundScheduleNames,
} from '../archiveScheduleWarning';
import { __resetBindingMemoForTest } from '../scheduleBindingIndex';
@@ -82,15 +83,31 @@ describe('loadActiveBoundScheduleNames', () => {
expect(result.get('task')).toEqual(['Remote']);
});
- it('本机列表加载失败时退回已有快照', async () => {
- mocks.ensure.mockRejectedValue(new Error('offline'));
+ it('有缓存时直接使用,不等列表请求', async () => {
mocks.getSnapshot.mockReturnValue([
{ id: 'a', name: 'Cached', status: 'active', targetSessionId: 'task' },
]);
+ mocks.ensure.mockReturnValue(new Promise(() => {}));
const result = await loadActiveBoundScheduleNames([{ id: 'task' }]);
expect(result.get('task')).toEqual(['Cached']);
+ expect(mocks.ensure).not.toHaveBeenCalled();
+ });
+
+ it('冷启动时最多等待一小段时间,超时按无绑定处理', async () => {
+ vi.useFakeTimers();
+ try {
+ mocks.getSnapshot.mockReturnValue(null);
+ mocks.ensure.mockReturnValue(new Promise(() => {}));
+
+ const pending = loadActiveBoundScheduleNames([{ id: 'task' }]);
+ await vi.advanceTimersByTimeAsync(COLD_SCHEDULE_LOAD_WAIT_MS);
+
+ expect((await pending).size).toBe(0);
+ } finally {
+ vi.useRealTimers();
+ }
});
it('批量提示按绑定了自动化的任务数计数', async () => {
diff --git a/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts b/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts
index f4ffa589e7..c5461409b9 100644
--- a/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts
+++ b/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts
@@ -15,14 +15,25 @@ export interface ArchiveTarget {
deviceLinkDeviceId?: string | null;
}
+/** 冷启动且缓存未就绪时,最多等这么久;超时按「无绑定」处理,不让普通任务的归档卡在列表请求上。 */
+export const COLD_SCHEDULE_LOAD_WAIT_MS = 1500;
+
+/** 有缓存直接用(侧栏行常驻订阅,通常已就绪);没有缓存才有限等待一次加载。 */
+async function readLocalSchedules() {
+ const cached = schedulesStore.getSnapshot();
+ if (cached) return cached;
+ const timeout = new Promise<null>((resolve) =>
+ setTimeout(() => resolve(null), COLD_SCHEDULE_LOAD_WAIT_MS),
+ );
+ return Promise.race([schedulesStore.ensure().catch(() => null), timeout]);
+}
+
/** 每个任务归档后会停掉的自动化名称(active、非持续会话);没有的任务不出现在结果里。 */
export async function loadActiveBoundScheduleNames(
targets: readonly ArchiveTarget[],
): Promise<Map<string, string[]>> {
const needsLocal = targets.some((target) => !target.deviceLinkDeviceId);
- const localSchedules = needsLocal
- ? await schedulesStore.ensure().catch(() => schedulesStore.getSnapshot())
- : null;
+ const localSchedules = needsLocal ? await readLocalSchedules() : null;
const localMap: ReadonlyMap<string, readonly ScheduleBinding[]> = localSchedules
? buildBindingMap(localSchedules)
: new Map();
diff --git a/docs/product-rules/archive-pauses-automations.md b/docs/product-rules/archive-pauses-automations.md
index b9102f330a..26e652a2e6 100644
--- a/docs/product-rules/archive-pauses-automations.md
+++ b/docs/product-rules/archive-pauses-automations.md
@@ -31,4 +31,5 @@
## 允许的例外
- 绑定信息读取失败(如远程电脑暂时不可达)时,入口按「无绑定」直接归档,不阻塞归档。
+- 桌面本机优先使用已有的自动化缓存;冷启动缓存未就绪时最多等待约 1.5 秒,超时按「无绑定」处理,普通任务的归档不会卡在自动化列表请求上。
- Agent 工具(`archive_sessions`)与 IM 渠道的归档没有确认界面,不在本规则范围内。