Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): preserve connections on unknown network hints
DavidShen61a3cf4689b6
diff --git a/apps/mobile/src/__tests__/historyViewProvider.test.tsx b/apps/mobile/src/__tests__/historyViewProvider.test.tsxindex ee436741b2..77a55ca489 100644--- a/apps/mobile/src/__tests__/historyViewProvider.test.tsx+++ b/apps/mobile/src/__tests__/historyViewProvider.test.tsx@@ -24,7 +24,7 @@ vi.mock('@/auth/AuthContext', () => ({ useAuth: () => auth }));const networkEvents = vi.hoisted(() => ({state: 'active',app: (_next: string) => {},- network: (_next: { type: string; isConnected: boolean; isInternetReachable: boolean }) => {},+ network: (_next: { type?: string; isConnected?: boolean; isInternetReachable?: boolean }) => {},}));vi.mock('react-native', () => ({Platform: { OS: 'android' },@@ -164,6 +164,48 @@ describe('Provider network recovery priority', () => {]);});+ it.each(['UNKNOWN', undefined])('probes an unknown network (%s) without treating it as route loss', async type => {+ const client = transport.clients[0];+ await act(async () => {+ networkEvents.network(wifi);+ networkEvents.network({ type, isConnected: false, isInternetReachable: false });+ networkEvents.network(wifi);+ });+ expect(client.restartConnection).not.toHaveBeenCalled();+ expect(client.notifyNetworkChanged.mock.calls).toEqual([+ [{ urgent: false }], [{ urgent: true }], [{ urgent: true }],+ ]);+ });++ it.each([false, true])('keeps confirmed route loss pending across UNKNOWN (connected=%s)', async isConnected => {+ const client = transport.clients[0];+ await act(async () => {+ networkEvents.network(wifi);+ networkEvents.network({ type: 'NONE', isConnected: false, isInternetReachable: false });+ networkEvents.network({ type: 'UNKNOWN', isConnected, isInternetReachable: false });+ });+ expect(client.restartConnection).not.toHaveBeenCalled();+ await act(async () => networkEvents.network(wifi));+ expect(client.restartConnection).toHaveBeenCalledExactlyOnceWith('network-path-changed');+ });++ it('does not retain unknown background notifications as a lost route', async () => {+ const client = transport.clients[0];+ await act(async () => {+ networkEvents.network(wifi);+ client.notifyNetworkChanged.mockClear();+ networkEvents.state = 'background'; networkEvents.app('background');+ networkEvents.network({ type: 'UNKNOWN', isConnected: false, isInternetReachable: false });+ });+ expect(client.notifyNetworkChanged).not.toHaveBeenCalled();+ await act(async () => {+ networkEvents.state = 'active'; networkEvents.app('active');+ networkEvents.network(wifi);+ });+ expect(client.restartConnection).not.toHaveBeenCalled();+ expect(client.notifyNetworkChanged).toHaveBeenCalledWith({ urgent: true });+ });+it('remembers a lost route even when the replacement has the same network type', async () => {const client = transport.clients[0];await act(async () => {diff --git a/apps/mobile/src/device-link/DeviceLinkContext.tsx b/apps/mobile/src/device-link/DeviceLinkContext.tsxindex b0b93ed4c0..c1b5314fe8 100644--- a/apps/mobile/src/device-link/DeviceLinkContext.tsx+++ b/apps/mobile/src/device-link/DeviceLinkContext.tsx@@ -1306,17 +1306,22 @@ export function DeviceLinkProvider({ children }: { children: ReactNode }) {|| previousNetwork.isInternetReachable !== network.isInternetReachable);previousNetwork = network;+ mobileDebugLog('debug', 'device-link', 'network path notification', { type: network.type, connected: network.isConnected, reachable: network.isInternetReachable, appState: AppState.currentState, urgent });+ // Native lookup failures can report UNKNOWN with isConnected=false.+ // They neither prove route loss nor consume an earlier confirmed loss.+ if (!network.type || network.type === 'UNKNOWN') {+ if (AppState.currentState === 'active') client.notifyNetworkChanged({ urgent });+ return;+ }// Reachability/capability notifications alone are not route changes:// preserve the full weak-network probe budget for those hints.if (network.isConnected === false) networkPathChanged = true;- if (network.isConnected === true && network.type- && network.type !== 'NONE' && network.type !== 'UNKNOWN') {+ if (network.isConnected === true && network.type !== 'NONE') {if (lastConnectedNetworkType !== undefined && lastConnectedNetworkType !== network.type) {networkPathChanged = true;}lastConnectedNetworkType = network.type;}- mobileDebugLog('debug', 'device-link', 'network path notification', { type: network.type, connected: network.isConnected, reachable: network.isInternetReachable, appState: AppState.currentState, urgent });if (AppState.currentState !== 'active' || network.isConnected === false) return;recoverNetwork(urgent);});