Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 限制首次远程发现的入口等待时间
DavidShen2d77d784be6b
diff --git a/apps/desktop/src/renderer/__tests__/remoteProjectsStartup.test.tsx b/apps/desktop/src/renderer/__tests__/remoteProjectsStartup.test.tsxindex 15393acbfb..0c029f012c 100644--- a/apps/desktop/src/renderer/__tests__/remoteProjectsStartup.test.tsx+++ b/apps/desktop/src/renderer/__tests__/remoteProjectsStartup.test.tsx@@ -72,7 +72,7 @@ afterEach(() => {// #7437 / unit: real startup hook + redirect + mirror. Earlier tests seeded// bootstrap before mount, missing local-B arriving before cache/device discovery.// Deferred IPC replies verify the visible route without network or real waits.-// Standalone on Windows: 5.51s wall / 3.74s Vitest / 61ms tests (18 cases, one worker).+// Standalone on Windows: 5.01s wall / 3.38s Vitest / 62ms tests (21 cases, one worker).function deferred<T>() {let resolve!: (value: T) => void;let reject!: (reason: Error) => void;@@ -184,14 +184,55 @@ it('releases the initial wait when Device Link stops, ignoring late completion',expect(state.navigate).toHaveBeenCalledTimes(1);});+// PR #7453 / unit: the real directory IPC has no default network timeout.+// Earlier failure cases rejected; an unresolved read must also release routing+// without clearing other peers or navigating again when the late cache arrives.+it.each(['cache', 'state', 'directory'] as const)('bounds initial discovery when %s never settles', async (pending) => {+ const { cache, link, directory } = setupStartup();+ await act(async () => {+ render(<StartupRoute />);+ remoteProjectsStore.setDeviceSessions('healthy', 'Healthy', [+ { id: 'healthy-task', status: 'active', source: 'desktop' } as import('@/lib/ccAgent.types').Session,+ ]);+ if (pending !== 'cache') cache.resolve([]);+ if (pending !== 'state') link.resolve({ linkStatus: 'connecting' });+ if (pending !== 'directory') directory.resolve({ devices: [+ { deviceId: 'healthy', name: 'Healthy', online: false, remoteControlEnabled: false, isSelf: false },+ { deviceId: 'late', name: 'Late', online: false, remoteControlEnabled: false, isSelf: false },+ ] });+ });+ const peers = remoteProjectsStore.getDeviceList();+ await act(async () => { await vi.advanceTimersByTimeAsync(9_999); });+ expect(state.navigate).not.toHaveBeenCalled();+ await act(async () => { await vi.advanceTimersByTimeAsync(1); });+ expect(state.navigate).toHaveBeenCalledExactlyOnceWith('/cc-agent/local-B', { replace: true });+ expect(remoteProjectsStore.getDeviceList()).toEqual(peers);+ expect(remoteProjectsStore.getSessionDeviceId('healthy-task')).toBe('healthy');+ await act(async () => {+ cache.resolve([{ deviceId: 'late', deviceName: 'Late', sessions: [+ { id: 'remote-A', status: 'active', source: 'desktop' } as import('@/lib/ccAgent.types').Session,+ ] }]);+ link.resolve({ linkStatus: 'connecting' });+ directory.resolve({ devices: [+ { deviceId: 'healthy', name: 'Healthy', online: false, remoteControlEnabled: false, isSelf: false },+ { deviceId: 'late', name: 'Late', online: false, remoteControlEnabled: false, isSelf: false },+ ] });+ });+ expect(state.navigate).toHaveBeenCalledTimes(1);+ if (pending === 'cache') expect(remoteProjectsStore.getSessionDeviceId('remote-A')).toBe('late');+});+it('does not let cancelled initialization settle a newly mounted synchronizer', async () => {const old = setupStartup();let view!: ReturnType<typeof render>;await act(async () => { view = render(<StartupRoute />); });+ await act(async () => { await vi.advanceTimersByTimeAsync(5_000); });view.unmount();expect(remoteProjectsStore.getInitialDiscoverySettled()).toBe(true);const current = setupStartup();await act(async () => { render(<StartupRoute />); });+ await act(async () => { await vi.advanceTimersByTimeAsync(5_000); });+ expect(state.navigate).not.toHaveBeenCalled();await act(async () => {old.cache.resolve([]);old.link.resolve({ linkStatus: 'connecting' });diff --git a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.tsindex 3ca7cf9014..39ac11401f 100644--- a/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts+++ b/apps/desktop/src/renderer/features/device-link/remoteProjectsStore.ts@@ -1436,7 +1436,7 @@ export function useRemoteProjectSessions(): Session[] {return useSyncExternalStore(subscribe, actions.getVisibleMergedRemoteSessions);}-/** Both initial cache hydration and device discovery have settled (including failure/cancellation). */+/** Initial discovery settled, was cancelled, or exceeded the startup route's wait budget. */export function useRemoteInitialDiscoverySettled(): boolean {return useSyncExternalStore(subscribe, actions.getInitialDiscoverySettled);}diff --git a/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts b/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.tsindex 3662d58742..f9ec962b93 100644--- a/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts+++ b/apps/desktop/src/renderer/features/device-link/useDeviceLinkRemoteProjects.ts@@ -133,6 +133,9 @@ export function startSessionListTokenRefresh(/** sessions:created reseed 防抖(被控端短时间多次创建会话 / orca 起多 worker 时合并重拉)。 */const RESEED_DEBOUNCE_MS = 300;+// Limit only the startup route's discovery wait, not the request or peer lifetime.+// Matches the background device directory's 10s budget; late results still apply.+const INITIAL_DISCOVERY_WAIT_MS = 10_000;/*** best-effort push 的窗口内 anti-entropy 周期。列表、置顶、归档/删除走 sessions:patched /@@ -424,6 +427,7 @@ export function useDeviceLinkRemoteProjects(let disposed = false;const finishInitialDiscovery = remoteProjectsStore.beginInitialDiscovery();+ const initialDiscoveryTimer = setTimeout(finishInitialDiscovery, INITIAL_DISCOVERY_WAIT_MS);/*** 「已明确离场、不许被冷缓存种回来」的设备 id。删除 / 撤销访问 / 关闭被控 / 本机停用控制* 路径都会往里加 —— 它们清盘是异步的,而 mount 时那次 readCachedSessionList 可能早已@@ -909,7 +913,10 @@ export function useDeviceLinkRemoteProjects(// Neither an empty bootstrap set nor the first completed read alone proves// the remembered remote task is absent. Per-device loading takes over once// discovery starts bootstrap; failures and cleanup must release this gate.- void Promise.allSettled([initialCacheRead, initialDirectoryRead]).then(finishInitialDiscovery);+ void Promise.allSettled([initialCacheRead, initialDirectoryRead]).then(() => {+ clearTimeout(initialDiscoveryTimer);+ finishInitialDiscovery();+ });const offPresence = window.electronAPI.deviceLink.onPresenceChanged((snap) => {applyDevice({@@ -984,6 +991,7 @@ export function useDeviceLinkRemoteProjects(// 已空,整份快照被写成 [],main 侧据此把 session-list.json 删掉。于是「relay 停服// (非登出)」会在约 1.2s 后抹掉侧边栏冷缓存 —— 而「停服后重启、relay 仍未恢复」// 正是这份缓存要解决的场景(review: P2)。整体删除只归 owner 边界的 clearAll。+ clearTimeout(initialDiscoveryTimer);remoteProjectsStore.clear();remoteProjectAliases.clear();cancelSessionListPersist();@@ -1076,6 +1084,7 @@ export function useDeviceLinkRemoteProjects(return () => {disposed = true;+ clearTimeout(initialDiscoveryTimer);setRemoteReseedImpl(null);setRemoteSessionBootstrapRetryImpl(null);wakeRemoteReconcileRef.current = () => undefined;