Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(archive): 手机批量归档沿用单条路径的已知无绑定快路径
Dashd55d1b37cfb4
diff --git a/apps/mobile/app/devices/[deviceId].tsx b/apps/mobile/app/devices/[deviceId].tsxindex eddb4cc9eb..817e92283d 100644--- a/apps/mobile/app/devices/[deviceId].tsx+++ b/apps/mobile/app/devices/[deviceId].tsx@@ -107,7 +107,7 @@ import {loadSharedSessionScheduleIndex,} from '@/session/scheduleIndex';import { shouldSuppressRemoteListEmptyState } from '@/session/sessionEmptyState';-import { countSessionsWithActiveBoundSchedules } from '@/session/archiveScheduleConfirm';+import { anyMayHaveBoundSchedules, countSessionsWithActiveBoundSchedules } from '@/session/archiveScheduleConfirm';import type { RemoteSession } from '@/session/types';import { useTheme, useThemedStyles, type ThemeColors } from '@/theme';import { fontWeight, lineHeight, radius, spacing, typeScale } from '@/theme/tokens';@@ -678,9 +678,11 @@ function DeviceDetailScreenContent() {}const scheduleRequest = ++bulkScheduleRequestRef.current;setBulkScheduleCount(0);- setBulkScheduleLoading(action === 'archive');- if (action === 'archive') {- void countSessionsWithActiveBoundSchedules(deviceId, invoke, summary.candidates.map((session) => session.id))+ // 全部已知无绑定时不查询、不禁用确认(与单条路径同一个快路径)。+ const needsLookup = action === 'archive' && anyMayHaveBoundSchedules(deviceId, summary.candidates);+ setBulkScheduleLoading(needsLookup);+ if (needsLookup) {+ void countSessionsWithActiveBoundSchedules(deviceId, invoke, summary.candidates).then((count) => {if (bulkScheduleRequestRef.current !== scheduleRequest) return;setBulkScheduleCount(count);diff --git a/apps/mobile/src/__tests__/archiveScheduleConfirm.test.ts b/apps/mobile/src/__tests__/archiveScheduleConfirm.test.tsindex 0f227dac0a..6dd7e32a66 100644--- a/apps/mobile/src/__tests__/archiveScheduleConfirm.test.ts+++ b/apps/mobile/src/__tests__/archiveScheduleConfirm.test.ts@@ -28,7 +28,7 @@ describe('archive schedule lookup deadline', () => {mocks.list.mockReturnValue(new Promise(() => {}));const single = loadActiveBoundScheduleNames(args);- const bulk = countSessionsWithActiveBoundSchedules('pc', mocks.list as never, ['task']);+ const bulk = countSessionsWithActiveBoundSchedules('pc', mocks.list as never, [{ id: 'task' }]);await vi.advanceTimersByTimeAsync(SCHEDULE_LOOKUP_WAIT_MS);await expect(single).resolves.toEqual([]);@@ -48,13 +48,32 @@ describe('archive schedule lookup deadline', () => {mocks.list.mockResolvedValue([]);await loadActiveBoundScheduleNames(args);- await countSessionsWithActiveBoundSchedules('pc', mocks.list as never, ['task']);+ await countSessionsWithActiveBoundSchedules('pc', mocks.list as never, [{ id: 'task' }]);for (const call of mocks.list.mock.calls) {expect(call).toEqual(['pc', 'maker:schedule:list', [null, { sessionBindings: true }]]);}});+ it('bulk archive skips the request when every candidate is known unbound', async () => {+ mocks.mayHave.mockReturnValue(false);++ await expect(+ countSessionsWithActiveBoundSchedules('pc', mocks.list as never, [{ id: 'a' }, { id: 'b' }]),+ ).resolves.toBe(0);+ expect(mocks.list).not.toHaveBeenCalled();+ });++ it('bulk archive still queries once when any candidate may be bound', async () => {+ mocks.mayHave.mockImplementation(((_d: string, id: string) => id === 'b') as never);+ mocks.list.mockResolvedValue([{ id: 's', name: 'Daily', status: 'active', targetSessionId: 'b' }]);++ await expect(+ countSessionsWithActiveBoundSchedules('pc', mocks.list as never, [{ id: 'a' }, { id: 'b' }]),+ ).resolves.toBe(1);+ expect(mocks.list).toHaveBeenCalledTimes(1);+ });+it('skips the request for tasks known to be unbound', async () => {mocks.mayHave.mockReturnValue(false);diff --git a/apps/mobile/src/session/archiveScheduleConfirm.ts b/apps/mobile/src/session/archiveScheduleConfirm.tsindex f937cb9f43..89f143fafe 100644--- a/apps/mobile/src/session/archiveScheduleConfirm.ts+++ b/apps/mobile/src/session/archiveScheduleConfirm.ts@@ -35,14 +35,28 @@ function stopsWhenTargetArchived(schedule: RemoteSchedule): boolean {return schedule.status === 'active' && !schedule.persistentSession && !!schedule.targetSessionId;}-/** 批量归档:所选任务里归档后会停掉自动化的任务数(一次列表请求;失败按 0)。 */+export interface BulkArchiveCandidate {+ id: string;+ source?: string | null;+}++/** 与单条路径同一个快路径:索引已确认无绑定的任务不必查询。 */+export function anyMayHaveBoundSchedules(+ deviceId: string,+ candidates: readonly BulkArchiveCandidate[],+): boolean {+ return candidates.some((c) => sessionMayHaveScheduleRuns(deviceId, c.id, c.source));+}++/** 批量归档:所选任务里归档后会停掉自动化的任务数(最多一次列表请求;全部已知无绑定则不请求;失败按 0)。 */export async function countSessionsWithActiveBoundSchedules(deviceId: string,invoke: RemoteInvoke,- sessionIds: readonly string[],+ candidates: readonly BulkArchiveCandidate[],): Promise<number> {+ if (!anyMayHaveBoundSchedules(deviceId, candidates)) return 0;try {- const ids = new Set(sessionIds);+ const ids = new Set(candidates.map((c) => c.id));const bound = new Set(normalizeScheduleList(await withLookupDeadline(listBindingSchedules(deviceId, invoke), [])).filter((schedule) => stopsWhenTargetArchived(schedule) && ids.has(schedule.targetSessionId!))