Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 共用单设备与全连接的索引恢复规则
Dashc1d697148072
diff --git a/apps/mobile/src/__tests__/scheduleIndex.test.ts b/apps/mobile/src/__tests__/scheduleIndex.test.tsindex eb41f360a8..b91699464c 100644--- a/apps/mobile/src/__tests__/scheduleIndex.test.ts+++ b/apps/mobile/src/__tests__/scheduleIndex.test.ts@@ -7,7 +7,6 @@ import {invalidateOfflineScheduleIndexFailureFor,invalidateRunningSessionScheduleEntries,invalidateScheduleIndexForDevice,- invalidateTransientScheduleIndexFailureFor,invalidateScheduleIndexesAfterLinkRecovery,loadLightweightSessionScheduleIndex,loadSessionScheduleIndex,@@ -36,6 +35,23 @@ function makerWithSchedules(}describe('scheduleIndex', () => {+ it.each([false, true])('peer recovery invalidates only its success or pending snapshot (pending=%s)', async (pending) => {+ resetScheduleIndexThrottleForTesting();+ let finish!: (value: Map<string, RemoteSessionScheduleInfo>) => void;+ const fresh = new Map<string, RemoteSessionScheduleInfo>();+ const loadA = vi.fn(async () => new Map<string, RemoteSessionScheduleInfo>());+ const loadB = vi.fn().mockImplementationOnce(() => new Promise((resolve) => { finish = resolve; })).mockResolvedValue(fresh);+ const a = await loadSessionScheduleIndexThrottled('a', loadA);+ const old = loadSessionScheduleIndexThrottled('b', loadB);+ if (!pending) { finish(new Map()); await old; }+ invalidateScheduleIndexesAfterLinkRecovery('b');+ const next = loadSessionScheduleIndexThrottled('b', loadB);+ if (pending) { expect(loadB).toHaveBeenCalledTimes(1); finish(new Map()); await old; }+ expect(await next).toBe(fresh);+ expect(loadB).toHaveBeenCalledTimes(2);+ expect(await loadSessionScheduleIndexThrottled('a', loadA)).toBe(a);+ expect(loadA).toHaveBeenCalledTimes(1);+ });it.each([false, true])('restores older running ownership from the same snapshot (lightweight=%s)', async (lightweight) => {const schedules = [{ id: 'sched', name: 'run', status: 'active', targetSessionId: 'task' }];const row = { scheduleId: 'sched', scheduleName: 'run', scheduleStatus: 'active', readAt: 1 };@@ -624,7 +640,7 @@ describe('loadSessionScheduleIndexThrottled (单飞 + TTL 节流)', () => {});await Promise.resolve();- invalidateTransientScheduleIndexFailureFor('dev-b');+ invalidateScheduleIndexesAfterLinkRecovery('dev-b');await expect(loadSessionScheduleIndexThrottled('dev-a', loadA, { now })).rejects.toMatchObject({code: 'NOT_CONNECTED',});diff --git a/apps/mobile/src/device-link/DeviceLinkContext.tsx b/apps/mobile/src/device-link/DeviceLinkContext.tsxindex ef2f6561a2..617e0e36c9 100644--- a/apps/mobile/src/device-link/DeviceLinkContext.tsx+++ b/apps/mobile/src/device-link/DeviceLinkContext.tsx@@ -77,7 +77,6 @@ import {clearSessionScheduleIndexCache,invalidateOfflineScheduleIndexFailureFor,invalidateScheduleIndexForDevice,- invalidateTransientScheduleIndexFailureFor,invalidateScheduleIndexesAfterLinkRecovery,} from '@/session/scheduleIndex';import { isTransientRemoteError } from '@/device-link/remoteRetry';@@ -588,8 +587,8 @@ export function DeviceLinkProvider({ children }: { children: ReactNode }) {);if (!plan) return { retry: false };- // 只清当前 peer 在断线窗口留下的瞬时负缓存,避免 A 的恢复改变 B 的节流状态。- invalidateTransientScheduleIndexFailureFor(targetDeviceId);+ // 只失效当前 peer 的旧成功快照和瞬时链路失败,避免 A 的恢复改变 B 的节流状态。+ invalidateScheduleIndexesAfterLinkRecovery(targetDeviceId);const result = await rehydrateDeviceLinkPeer(plan, {isCancelled: () => (backgroundReleaseInFlightRef.currentdiff --git a/apps/mobile/src/session/scheduleIndex.ts b/apps/mobile/src/session/scheduleIndex.tsindex f9057cb5f5..23d4b60e0f 100644--- a/apps/mobile/src/session/scheduleIndex.ts+++ b/apps/mobile/src/session/scheduleIndex.ts@@ -218,22 +218,16 @@ export function loadSessionScheduleIndexThrottled(* 由共享恢复入口统一失效,在途扫描仍先结束再合并重拉。普通本机断线负缓存* 同时清除;设备离线、熔断和请求超时的负缓存继续走各自的恢复旁路。*/-export function invalidateScheduleIndexesAfterLinkRecovery(): void {- for (const [key, entry] of scheduleIndexThrottleEntries) {- if (entry.failedAt === null || entry.failedTransient) {+export function invalidateScheduleIndexesAfterLinkRecovery(deviceId?: string): void {+ const keys = deviceId === undefined ? scheduleIndexThrottleEntries.keys() : [deviceId];+ for (const key of keys) {+ const entry = scheduleIndexThrottleEntries.get(key);+ if (entry && (entry.failedAt === null || entry.failedTransient)) {invalidateScheduleIndexForDevice(key);}}}-/** Per-peer variant used by independent Mobile recovery lifecycles. */-export function invalidateTransientScheduleIndexFailureFor(deviceId: string): void {- const entry = scheduleIndexThrottleEntries.get(deviceId);- if (entry?.failedAt !== null && entry?.failedTransient) {- scheduleIndexThrottleEntries.delete(deviceId);- }-}-/*** 逐设备失效钩子(review P1):DEVICE_OFFLINE 的负缓存只在该设备 presence* 恢复时清除(DeviceLinkContext 的 presence.recovered 分支调用,key 即