Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(archive): 远程绑定快照未就绪时有限等待直取,空快照也标记为已加载
Dashcfb3f8e93298
diff --git a/apps/desktop/src/renderer/__tests__/remoteScheduleBindings.test.tsx b/apps/desktop/src/renderer/__tests__/remoteScheduleBindings.test.tsxindex 3ae4857b52..08a0c36e34 100644--- a/apps/desktop/src/renderer/__tests__/remoteScheduleBindings.test.tsx+++ b/apps/desktop/src/renderer/__tests__/remoteScheduleBindings.test.tsx@@ -199,6 +199,13 @@ describe('remote schedule binding badges', () => {expect(() => parseScheduleBindings([{ ...binding(), recurring: 'false' }])).toThrow();});+ it('marks an empty first snapshot as loaded, distinguishing it from not-yet-loaded', () => {+ remoteProjectsStore.setDeviceSessions('A', 'Device A', []);+ expect(remoteProjectsStore.hasScheduleBindings('A')).toBe(false);+ remoteProjectsStore.setDeviceScheduleBindings('A', []);+ expect(remoteProjectsStore.hasScheduleBindings('A')).toBe(true);+ });+it('keeps the persistent-session flag only when true, so archive confirmation can skip it', () => {expect(parseScheduleBindings([{ ...binding(), persistentSession: true }])).toEqual([{ ...binding(), persistentSession: true },diff --git a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.tsindex 1f7f850084..3dd09fa596 100644--- a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts+++ b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts@@ -568,10 +568,15 @@ const actions = {const shard = shards.get(deviceId);if (!shard) return;const next = buildBindingMap(bindings);- if (JSON.stringify([...(shard.scheduleBindings ?? [])]) === JSON.stringify([...next])) return;+ // 首次快照即使为空也要落下:`undefined` 表示尚未加载,空 Map 才是权威的「没有绑定」。+ if (shard.scheduleBindings && JSON.stringify([...shard.scheduleBindings]) === JSON.stringify([...next])) return;shard.scheduleBindings = next;subs.forEach((fn) => fn());},+ /** 该设备的绑定快照是否已加载过(区分「尚未加载」与「确实没有绑定」)。 */+ hasScheduleBindings(deviceId: string): boolean {+ return shards.get(deviceId)?.scheduleBindings !== undefined;+ },getSessionScheduleBindings(deviceId: string, sessionId: string): readonly ScheduleBinding[] {return shards.get(deviceId)?.scheduleBindings?.get(sessionId) ?? EMPTY_SCHEDULE_BINDINGS;},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.tsindex 314ea0c2ff..2ad8c0c815 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@@ -12,13 +12,18 @@ const mocks = vi.hoisted(() => ({ensure: vi.fn(),getSnapshot: vi.fn(),getSessionScheduleBindings: vi.fn(),+ hasScheduleBindings: vi.fn(),+ invoke: vi.fn(),}));vi.mock('../schedulesStore', () => ({schedulesStore: { ensure: mocks.ensure, getSnapshot: mocks.getSnapshot },}));vi.mock('@/features/device-link/remoteProjectsStore', () => ({- remoteProjectsStore: { getSessionScheduleBindings: mocks.getSessionScheduleBindings },+ remoteProjectsStore: {+ getSessionScheduleBindings: mocks.getSessionScheduleBindings,+ hasScheduleBindings: mocks.hasScheduleBindings,+ },}));import {@@ -38,6 +43,9 @@ describe('loadActiveBoundScheduleNames', () => {mocks.ensure.mockReset();mocks.getSnapshot.mockReset();mocks.getSessionScheduleBindings.mockReset().mockReturnValue([]);+ mocks.hasScheduleBindings.mockReset().mockReturnValue(true);+ mocks.invoke.mockReset();+ vi.stubGlobal('window', { electronAPI: { deviceLink: { invoke: mocks.invoke } } });});it('只返回本机任务绑定的 active 自动化', async () => {@@ -52,6 +60,46 @@ describe('loadActiveBoundScheduleNames', () => {expect([...result]).toEqual([['task', ['Daily']]]);});+ it('远程绑定快照尚未加载时直取一次,而不是把空当作没有绑定', async () => {+ mocks.hasScheduleBindings.mockReturnValue(false);+ mocks.invoke.mockResolvedValue([+ { id: 'r', name: 'Remote', status: 'active', targetSessionId: 'a', cronExpr: '* * * * *' },+ ]);++ const result = await loadActiveBoundScheduleNames([+ { id: 'a', deviceLinkDeviceId: 'mac-2' },+ { id: 'b', deviceLinkDeviceId: 'mac-2' },+ ]);++ expect(mocks.invoke).toHaveBeenCalledTimes(1);+ expect(mocks.invoke).toHaveBeenCalledWith('mac-2', 'maker:schedule:list', [+ null,+ { sessionBindings: true },+ ]);+ expect([...result]).toEqual([['a', ['Remote']]]);+ });++ it('远程快照未加载且直取超时时按无绑定处理', async () => {+ vi.useFakeTimers();+ try {+ mocks.hasScheduleBindings.mockReturnValue(false);+ mocks.invoke.mockReturnValue(new Promise(() => {}));++ const pending = loadActiveBoundScheduleNames([{ id: 'a', deviceLinkDeviceId: 'mac-2' }]);+ await vi.advanceTimersByTimeAsync(COLD_SCHEDULE_LOAD_WAIT_MS);++ expect((await pending).size).toBe(0);+ } finally {+ vi.useRealTimers();+ }+ });++ it('远程快照已就绪时不再发请求', async () => {+ await loadActiveBoundScheduleNames([{ id: 'a', deviceLinkDeviceId: 'mac-2' }]);++ expect(mocks.invoke).not.toHaveBeenCalled();+ });+it('持续会话归档后会换绑新任务继续跑,不提示', async () => {mocks.ensure.mockResolvedValue([{diff --git a/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts b/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.tsindex c5461409b9..7fad2a9b99 100644--- a/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts+++ b/apps/desktop/src/renderer/features/scheduler/lib/archiveScheduleWarning.ts@@ -7,7 +7,11 @@ import type { TFunction } from 'i18next';import { remoteProjectsStore } from '@/features/device-link/remoteProjectsStore';-import { buildBindingMap, type ScheduleBinding } from './scheduleBindingIndex';+import {+ buildBindingMap,+ parseScheduleBindings,+ type ScheduleBinding,+} from './scheduleBindingIndex';import { schedulesStore } from './schedulesStore';export interface ArchiveTarget {@@ -28,6 +32,23 @@ async function readLocalSchedules() {return Promise.race([schedulesStore.ensure().catch(() => null), timeout]);}+/**+ * 远程设备的绑定快照尚未加载(刚连上或重连后首拉还在途)时,空结果不是权威的:+ * 直接取一次绑定列表,最多等 COLD_SCHEDULE_LOAD_WAIT_MS,失败或超时按「无绑定」处理。+ */+async function readRemoteBindingsOnce(+ deviceId: string,+): Promise<readonly ScheduleBinding[] | null> {+ const timeout = new Promise<null>((resolve) =>+ setTimeout(() => resolve(null), COLD_SCHEDULE_LOAD_WAIT_MS),+ );+ const load = window.electronAPI.deviceLink+ .invoke(deviceId, 'maker:schedule:list', [null, { sessionBindings: true }])+ .then(parseScheduleBindings)+ .catch(() => null);+ return Promise.race([load, timeout]);+}+/** 每个任务归档后会停掉的自动化名称(active、非持续会话);没有的任务不出现在结果里。 */export async function loadActiveBoundScheduleNames(targets: readonly ArchiveTarget[],@@ -37,11 +58,29 @@ export async function loadActiveBoundScheduleNames(const localMap: ReadonlyMap<string, readonly ScheduleBinding[]> = localSchedules? buildBindingMap(localSchedules): new Map();+ // 快照未就绪的远程设备,每台只直接取一次。+ const coldRemote = new Map<string, Promise<ReadonlyMap<string, ScheduleBinding[]> | null>>();+ for (const target of targets) {+ const deviceId = target.deviceLinkDeviceId;+ if (+ deviceId &&+ !remoteProjectsStore.hasScheduleBindings(deviceId) &&+ !coldRemote.has(deviceId)+ ) {+ coldRemote.set(+ deviceId,+ readRemoteBindingsOnce(deviceId).then((list) => (list ? buildBindingMap(list) : null)),+ );+ }+ }const result = new Map<string, string[]>();for (const target of targets) {- const bindings = target.deviceLinkDeviceId- ? remoteProjectsStore.getSessionScheduleBindings(target.deviceLinkDeviceId, target.id)- : (localMap.get(target.id) ?? []);+ const deviceId = target.deviceLinkDeviceId;+ let bindings: readonly ScheduleBinding[];+ if (!deviceId) bindings = localMap.get(target.id) ?? [];+ else if (remoteProjectsStore.hasScheduleBindings(deviceId))+ bindings = remoteProjectsStore.getSessionScheduleBindings(deviceId, target.id);+ else bindings = (await coldRemote.get(deviceId))?.get(target.id) ?? [];const names = bindings.filter((schedule) => schedule.status === 'active' && !schedule.persistentSession).map((schedule) => schedule.name);