Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): keep remote roster loading during cold start
MagicLizi2cad17ce9a63
diff --git a/apps/mobile/app/resources/[collectionId].tsx b/apps/mobile/app/resources/[collectionId].tsxindex 72764dfeb1..6b673bf176 100644--- a/apps/mobile/app/resources/[collectionId].tsx+++ b/apps/mobile/app/resources/[collectionId].tsx@@ -114,7 +114,7 @@ function RemoteCollectionScreenContent() {title={title || t('devices.resources.titleFallback')}titleTestID="remoteResources.title"/>- {loading && items.length === 0 ? (+ {loading ? (<View style={styles.center}><RemoteListSyncingPlaceholder testID="remoteResources.loading" /></View>diff --git a/apps/mobile/src/__tests__/remoteResourceAvailability.test.ts b/apps/mobile/src/__tests__/remoteResourceAvailability.test.tsindex 92a7f373d8..5af3d858b2 100644--- a/apps/mobile/src/__tests__/remoteResourceAvailability.test.ts+++ b/apps/mobile/src/__tests__/remoteResourceAvailability.test.ts@@ -33,5 +33,6 @@ it('connection color is independent of a successful list reply', () => {expect(remoteResourceConnectionState('online', false)).toBe(false);expect(remoteResourceConnectionState('online', null)).toBeNull();expect(remoteResourceConnectionState('reconnecting', true)).toBeNull();- expect(remoteResourceConnectionState('stopped', true)).toBe(false);+ expect(remoteResourceConnectionState('connecting', true)).toBeNull();+ expect(remoteResourceConnectionState('stopped', true)).toBeNull();});diff --git a/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx b/apps/mobile/src/__tests__/useRemoteResourceList.test.tsxindex a699adeeac..2a89f5faf0 100644--- a/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx+++ b/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx@@ -177,7 +177,7 @@ it('shows disk-cached rows during the first slow network read without claiming ah.list.mockReturnValue(new Promise(() => {}));await render();expect(result.items[0].item.ref.id).toBe('cached-visible');- expect(result.loading).toBe(false); expect(result.syncing).toBe(true);+ expect(result.loading).toBe(true); expect(result.syncing).toBe(true);expect(result.isOnline(targets[0])).toBe(false);});diff --git a/apps/mobile/src/__tests__/useTeammateRoster.test.tsx b/apps/mobile/src/__tests__/useTeammateRoster.test.tsxindex f3e12e5461..1b2991c695 100644--- a/apps/mobile/src/__tests__/useTeammateRoster.test.tsx+++ b/apps/mobile/src/__tests__/useTeammateRoster.test.tsx@@ -47,6 +47,21 @@ it('does not treat initial offline discovery as authoritative; recovers on conneh.link.status = 'online'; h.link.connectionEpoch++; await render();expect(result.authoritative).toBe(true); expect(result.createTargets[0].deviceId).toBe('new');});++it('keeps a cold launch loading while the relay is starting, without reporting cached hosts offline', async () => {+ const cached = { key: 'old:bot', host: { deviceId: 'old', deviceName: 'Old' }, item: {+ ref: { collectionId: 'teammates', kind: 'bot', id: 'bot' }, revision: '1', display: { title: 'Cached' }, links: [],+ } };+ h.link.status = 'stopped';+ h.list.items = [cached];+ h.snapshot.mockResolvedValue({ home: [], items: { teammates: [cached] }, read: {} });+ h.link.readDeviceList.mockRejectedValue(new Error('should wait for relay'));+ await render();+ expect(result.items).toEqual([cached]);+ expect(result.loading).toBe(true);+ expect(result.error).toBeNull();+ expect(h.link.readDeviceList).not.toHaveBeenCalled();+});it('drops old account discovery replies', async () => {let finish!: (value: unknown) => void;h.link.readDeviceList.mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }));@@ -88,7 +103,7 @@ it('shows cached teammates while host discovery is pending, then removes revokedh.snapshot.mockResolvedValue({ home: [], items: { teammates: h.list.items }, read: {} });h.list.isOnline.mockReturnValue(false);await render();- expect(result.items).toHaveLength(1); expect(result.loading).toBe(false);+ expect(result.items).toHaveLength(1); expect(result.loading).toBe(true);expect(result.authoritative).toBe(false); expect(result.isOnline(h.list.items[0].host)).toBe(false);h.revoked = new Set(['old']); await render();expect(result.items).toEqual([]);@@ -192,7 +207,7 @@ it('retains in-memory teammates if the disk capability read stalls', async () =>await act(async () => vi.advanceTimersByTimeAsync(2000));expect(result.targets.map(host => host.deviceId)).toEqual(['old']);expect(result.items).toEqual([cached]);- expect(result.loading).toBe(false);+ expect(result.loading).toBe(true);});it('keeps every cached roster host in the list targets while a partial home manifest catches up', async () => {diff --git a/apps/mobile/src/device-link/remoteResourceAvailability.ts b/apps/mobile/src/device-link/remoteResourceAvailability.tsindex 3c678245c6..7ad9cbaa7c 100644--- a/apps/mobile/src/device-link/remoteResourceAvailability.ts+++ b/apps/mobile/src/device-link/remoteResourceAvailability.ts@@ -30,6 +30,11 @@ export function writeRemoteCollectionCache(owner: string, collectionId: string,/** Connection evidence is independent of whether a resource/API request succeeded. */export function remoteResourceConnectionState(relayStatus: string, presence: boolean | null): boolean | null {- if (presence === false || relayStatus === 'stopped') return false;- return relayStatus === 'online' && presence === true ? true : null;+ // `stopped` / `connecting` are the relay startup window, not evidence that+ // the hosted computer is offline. Keep that distinction visible to list+ // consumers so a cold launch can stay in its loading state until the first+ // live reply establishes the host status.+ if (relayStatus !== 'online') return null;+ if (presence === false) return false;+ return presence === true ? true : null;}diff --git a/apps/mobile/src/session/TeammateHomeScreen.tsx b/apps/mobile/src/session/TeammateHomeScreen.tsxindex 6d31c45dc0..1ba9a983ff 100644--- a/apps/mobile/src/session/TeammateHomeScreen.tsx+++ b/apps/mobile/src/session/TeammateHomeScreen.tsx@@ -164,7 +164,7 @@ export function TeammateHomeScreen({ active = true }: { active?: boolean }) {quietPresence={quietPresence}topInset={nativeHeader ? headerHeight : undefined}notice={navigation.saveFailed ? <Text accessibilityRole="alert" style={styles.notice}>{t('devices.companions.preferenceSaveFailed')}</Text> : null} autoFocusSearch={searchEpoch > 0}- loading={roster.items.length + groups.items.length === 0 && (roster.loading || groups.loading)}+ loading={roster.loading || groups.loading}refreshing={roster.refreshing || groups.refreshing}error={groups.error ?? roster.error}onRefresh={() => { void roster.refresh(); void cloud.refresh(); if (groups.supported) void groups.refresh(); }}diff --git a/apps/mobile/src/session/useRemoteResourceList.ts b/apps/mobile/src/session/useRemoteResourceList.tsindex efdeb37474..1717e0992b 100644--- a/apps/mobile/src/session/useRemoteResourceList.ts+++ b/apps/mobile/src/session/useRemoteResourceList.ts@@ -37,6 +37,8 @@ export function useRemoteResourceList(collectionId: string, targets: readonly Reconst focusController = useRef(new AbortController());const recovery = useRef<ReturnType<typeof createRemoteReadRecovery> | null>(null);const failedHosts = useRef(new Set<string>());+ const settledRef = useRef(false);+ settledRef.current = state.binding === binding && state.settled;const presenceKey = targets.map((target) => `${target.deviceId}:${getPresenceAvailability(target.deviceId)}`).join('|');void presenceVersion;useEffect(() => {@@ -56,6 +58,10 @@ export function useRemoteResourceList(collectionId: string, targets: readonly Reconst read = useCallback(async (run: RemoteSyncRun) => {if (!enabled || !active.current || hydrated !== binding || !collectionId) return;+ // The relay starts as stopped/connecting during a cold launch. Do not+ // turn that transport startup window into a resource failure; the status+ // dependency will schedule the same read once the relay is online.+ if ((status === 'stopped' || status === 'connecting') && !settledRef.current) return;const expected = ++generation.current;const signal = focusController.current.signal;const current = () => !run.isStale() && !signal.aborted && generation.current === expected@@ -145,7 +151,10 @@ export function useRemoteResourceList(collectionId: string, targets: readonly Re), [connectionEpoch, getPresenceAvailability, ownState, presenceKey, state.replies, status]);return {items: ownState ? state.items : [],- loading: !ownState || (!state.settled && state.items.length === 0 && (state.loading || hydrated !== binding)),+ // A disk snapshot is still unverified on a cold mount. Keep the first+ // screen in its loading state until a live collection read settles; after+ // that, background refreshes continue to leave the current rows visible.+ loading: !ownState || (!state.settled && (state.loading || hydrated !== binding)),syncing: !ownState || state.loading || hydrated !== binding,refreshing: ownState && state.refreshing,error: ownState ? state.error : null,diff --git a/apps/mobile/src/session/useTeammateRoster.ts b/apps/mobile/src/session/useTeammateRoster.tsindex b44f9e0848..a84eb50d43 100644--- a/apps/mobile/src/session/useTeammateRoster.ts+++ b/apps/mobile/src/session/useTeammateRoster.ts@@ -39,9 +39,9 @@ export function useTeammateRoster(enabled = true) {// Hosts whose manifest advertises group chats (bot-group-chat.md §8); an older desktop never does.const lastGroupTargets = useRef<{ binding: string; targets: RemoteResourceHostTarget[] }>({ binding: '', targets: NO_TARGETS });const [discovery, setDiscovery] = useState<{- binding: string; ready: boolean; loading: boolean; targets: RemoteResourceHostTarget[]; createTargets: RemoteResourceHostTarget[];+ binding: string; ready: boolean; loading: boolean; settled: boolean; targets: RemoteResourceHostTarget[]; createTargets: RemoteResourceHostTarget[];groupTargets: RemoteResourceHostTarget[]; error: string | null;- }>({ binding: '', ready: false, loading: true, targets: NO_TARGETS, createTargets: NO_TARGETS, groupTargets: NO_TARGETS, error: null });+ }>({ binding: '', ready: false, loading: true, settled: false, targets: NO_TARGETS, createTargets: NO_TARGETS, groupTargets: NO_TARGETS, error: null });const discover = useCallback(async (run: RemoteSyncRun) => {const expected = ++generation.current;const signal = focusController.current.signal;@@ -68,13 +68,17 @@ export function useTeammateRoster(enabled = true) {const targets = home.find(collection => collection.id === TEAMMATE_COLLECTION_ID && collection.resourceKind === 'bot')?.targets ?? NO_TARGETS;lastCollections.current = { binding, home };const filtered = targets.filter(host => !revoked.has(host.deviceId));- setDiscovery(old => ({ ...old, binding, ready: true, loading,+ setDiscovery(old => ({ ...old, binding, ready: true, loading, settled: old.binding === binding && old.settled,createTargets: old.binding === binding ? old.createTargets : NO_TARGETS,groupTargets: old.binding === binding ? old.groupTargets : NO_TARGETS,targets: old.binding === binding && JSON.stringify(old.targets) === JSON.stringify(filtered) ? old.targets : filtered }));};// Cached capabilities are navigation hints; authorization stays at the host.publish(collections, true);+ // During relay startup the cached directory remains a navigation hint, but+ // the roster must stay in its loading state until a live directory read.+ // The status dependency reruns this coordinator after the relay is online.+ if (status === 'stopped' || status === 'connecting') return;const failures: unknown[] = [];let error: string | null = null;const createTargets: RemoteResourceHostTarget[] = [];@@ -149,7 +153,7 @@ export function useTeammateRoster(enabled = true) {lastGroupTargets.current = { binding, targets: groupTargets };lastCreateTargets.current = { binding, targets: createTargets };const filtered = targets.filter(host => !revoked.has(host.deviceId));- setDiscovery(old => ({ binding, ready: true, loading: false, createTargets,+ setDiscovery(old => ({ binding, ready: true, loading: false, settled: true, createTargets,targets: old.binding === binding && JSON.stringify(old.targets) === JSON.stringify(filtered) ? old.targets : filtered,groupTargets, error: error ?? (failures.length ? formatRemoteError(failures[0]) : null) }));}, [binding, i18n.language, invoke, openLink, readDeviceList, revoked, status, t, user?.id]);@@ -183,7 +187,7 @@ export function useTeammateRoster(enabled = true) {groupTargets: ready ? discovery.groupTargets : NO_TARGETS,createTargets: ready && status === 'online' ? discovery.createTargets.filter((host) => !revoked.has(host.deviceId) && list.isOnline(host)) : NO_TARGETS,authoritative: ready && !discovery.loading && !list.loading && !list.syncing && status === 'online' && !discovery.error && (!discovery.targets.length || !list.error),- loading: items.length === 0 && (!ready || list.loading),+ loading: !ready || !discovery.settled || list.loading,refreshing: list.refreshing,error: ready ? discovery.error ?? (discovery.targets.length ? list.error : null) : null, refresh };}diff --git a/docs/product-rules/cindy-bots-completion-matrix.md b/docs/product-rules/cindy-bots-completion-matrix.mdindex 118c7a4df1..ec071a67cd 100644--- a/docs/product-rules/cindy-bots-completion-matrix.md+++ b/docs/product-rules/cindy-bots-completion-matrix.md@@ -54,7 +54,7 @@## 2026-09-06 手机与另一台电脑的补齐范围-- 多设备名册:来源电脑与伙伴身份共同定位;保存账号隔离的名册缓存,冷启动缓存只按离线展示。单个来源失败只影响该来源,重新连接后重新读取,旧请求不能覆盖停连或换账号后的状态。+- 多设备名册:来源电脑与伙伴身份共同定位;保存账号隔离的名册缓存,冷启动先显示加载中,首轮权威同步完成后再显示最新名册;已完成首轮同步后断线才按缓存展示。单个来源失败只影响该来源,重新连接后重新读取,旧请求不能覆盖停连或换账号后的状态。- 后台任务:手机与另一台 Desktop 均可从伙伴时间线读取任务状态、打开来源电脑的子任务、停止任务;状态推送沿父任务订阅回流。远端只得到任务卡所需字段,不输出数据库行或冻结的权限配置。- 伙伴私聊:两端从原消息入口打开来源电脑的只读私聊,收到更新或重连时刷新;不会以控制端本机的同名伙伴替换远端身份。- 手机呈现:解析与 Desktop 共用的持久任务/私聊标记,显示预设和托管图片头像,恢复成果文件入口与运行模型展示。主任务记录发生恢复替换时,聚焦/重连/资源更新重新解析伙伴身份。