Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-desktop): cover cold capture startup in negotiation budget
Dashaf028cc1d257
diff --git a/apps/desktop/src/main/remote-desktop/captureWindow.ts b/apps/desktop/src/main/remote-desktop/captureWindow.tsindex 4a829fdd4c..73b3d50692 100644--- a/apps/desktop/src/main/remote-desktop/captureWindow.ts+++ b/apps/desktop/src/main/remote-desktop/captureWindow.ts@@ -1,5 +1,6 @@import { BrowserWindow, session, type IpcMainInvokeEvent, type Session } from 'electron';import path from 'node:path';+import { REMOTE_DESKTOP_OFFER_BUDGET } from '@cindy/device-link';import { readFile } from 'node:fs/promises';import { installContentSecurityPolicy, parseOrigin } from '../security/csp';import { throwIpcError } from '../utils/ipcValidate';@@ -161,7 +162,7 @@ export class DesktopCaptureWindow {win.webContents.on('render-process-gone', failed);win.webContents.on('destroyed', failed);await new Promise<void>((resolve, reject) => {- const timer = setTimeout(failed, 10_000);+ const timer = setTimeout(failed, REMOTE_DESKTOP_OFFER_BUDGET.captureReadyMs);this.ready = { resolve, reject, timer };void win.loadURL(this.url).catch(failed);});diff --git a/apps/desktop/src/main/remote-desktop/index.ts b/apps/desktop/src/main/remote-desktop/index.tsindex 810bb23e7c..f52e6997cc 100644--- a/apps/desktop/src/main/remote-desktop/index.ts+++ b/apps/desktop/src/main/remote-desktop/index.ts@@ -15,6 +15,7 @@ import {import { randomUUID } from 'node:crypto';import {isDesktopPermission,+ REMOTE_DESKTOP_OFFER_BUDGET,parseDesktopIceReply,type RemoteDesktopIceRequest,type RemoteDesktopIceReply,@@ -132,7 +133,7 @@ function stopVideo(): void {pending = null;}}-async function sources(thumbnail = false, timeoutMs = 5000) {+async function sources(thumbnail = false, timeoutMs = REMOTE_DESKTOP_OFFER_BUDGET.sourcesMs) {if (process.platform === 'darwin' &&systemPreferences.getMediaAccessStatus('screen') !== 'granted'@@ -173,7 +174,7 @@ async function offer(nativeAvailable ||=process.platform === 'win32' && (await readWindowsDesktopSupport()) === 'ready';try {- const available = await sources(false, nativeAvailable ? 2000 : 5000);+ const available = await sources(false, nativeAvailable ? 2000 : REMOTE_DESKTOP_OFFER_BUDGET.sourcesMs);source = desktopCaptureSource(available, lease.display.id, screen.getAllDisplays());} catch (error) {// A locked macOS session can reject Chromium's source enumeration even@@ -213,7 +214,7 @@ async function offer(settings,attemptId,},- 18_000,+ REMOTE_DESKTOP_OFFER_BUDGET.hostMs,);if (typeof result !== 'string') throw new Error('DESKTOP_VIDEO_UNAVAILABLE');return result;diff --git a/apps/desktop/src/main/remote-desktop/windowsHost.ts b/apps/desktop/src/main/remote-desktop/windowsHost.tsindex fe8fe95336..436cd7b5e9 100644--- a/apps/desktop/src/main/remote-desktop/windowsHost.ts+++ b/apps/desktop/src/main/remote-desktop/windowsHost.ts@@ -1,4 +1,5 @@import { app } from 'electron';+import { REMOTE_DESKTOP_OFFER_BUDGET } from '@cindy/device-link';import { execFile } from 'node:child_process';import { createRequire } from 'node:module';import path from 'node:path';@@ -18,7 +19,7 @@ export async function readWindowsDesktopSupport(): Promise<WindowsDesktopSupportif (!app.isPackaged) return 'installRequired';try {const { stdout } = await exec(binary(), ['--status'], {- timeout: 8000,+ timeout: REMOTE_DESKTOP_OFFER_BUDGET.platformStatusMs,maxBuffer: 1024,windowsHide: true,});diff --git a/apps/mobile/src/__tests__/invokeTimeouts.test.ts b/apps/mobile/src/__tests__/invokeTimeouts.test.tsindex 2a23c4644b..cb0bb631d4 100644--- a/apps/mobile/src/__tests__/invokeTimeouts.test.ts+++ b/apps/mobile/src/__tests__/invokeTimeouts.test.ts@@ -9,7 +9,7 @@ import {describe("resolveMobileInvokeTimeoutMs", () => {it("allows remote desktop capture and ICE to finish without widening other device reads", () => {expect(resolveMobileInvokeTimeoutMs("device-link:remote-desktop:v1")).toBe(- 30_000,+ 59_000,);expect(resolveMobileInvokeTimeoutMs("device-link:state")).toBeUndefined();});diff --git a/apps/mobile/src/remote-desktop/__tests__/viewerRtc.test.ts b/apps/mobile/src/remote-desktop/__tests__/viewerRtc.test.tsindex fa8d78086c..7b0b515eeb 100644--- a/apps/mobile/src/remote-desktop/__tests__/viewerRtc.test.ts+++ b/apps/mobile/src/remote-desktop/__tests__/viewerRtc.test.ts@@ -176,6 +176,18 @@ it("does not replenish retry budget from a brief connection", async () => {h.api.stop();});+it("accepts a cold-host answer after readiness, Windows probe, sources and offer", async () => {+ const h = viewer();+ await h.api.start();+ await vi.advanceTimersByTimeAsync(10_000 + 21_000 + 5_000 + 18_000);+ expect(h.peers[0].close).not.toHaveBeenCalled();+ await h.answer();+ expect(h.peers[0].setRemoteDescription).toHaveBeenCalled();+ expect(h.peers).toHaveLength(1);+ h.api.stop();+ expect(vi.getTimerCount()).toBe(0);+});+it("separates answer wait from connection checks and drops the previous attempt answer", async () => {const h = viewer();await h.api.start();diff --git a/packages/device-link/src/allowlist.ts b/packages/device-link/src/allowlist.tsindex f3ec1aa7cf..de2651de26 100644--- a/packages/device-link/src/allowlist.ts+++ b/packages/device-link/src/allowlist.ts@@ -24,6 +24,7 @@* Renderer 可调用。它由业务 dispatch 拦截,绝不放行通用 UI / shell IPC。*/import { SESSION_ACTIVITY_CHANNEL, SESSION_SYNC_CHANNEL } from './topics.js';+import { REMOTE_DESKTOP_INVOKE_MS } from './remoteDesktopIce.js';import {REMOTE_RESOURCE_CHANGED_CHANNEL,REMOTE_RESOURCE_CHANNELS,@@ -652,9 +653,8 @@ export const PUSH_FORWARD_ALLOWLIST: ReadonlySet<string> = new Set([* client-agnostic:mobile/web 控制端应使用同一映射(与 allowlist 同为协议契约)。*/export const INVOKE_TIMEOUT_OVERRIDES_MS: Readonly<Record<string, number>> = {- // Source enumeration (<=5s), capture/legacy ICE (<=18s), plus reply delivery.- // Keep mobile's shorter 15s default from prematurely aborting negotiation.- "device-link:remote-desktop:v1": 30_000,+ // Capture renderer readiness + source enumeration + offer, then reply delivery.+ "device-link:remote-desktop:v1": REMOTE_DESKTOP_INVOKE_MS,// 被控端 CMD_TIMEOUT_MS(30s)+ CMD_KILL_GRACE_MS(5s)+ 5s 回程余量'desktop-cmd:run': 40_000,// 被控端 worktree:create 含 git worktree add(--no-checkout)+ 白名单文件选择性diff --git a/packages/device-link/src/remoteDesktopIce.ts b/packages/device-link/src/remoteDesktopIce.tsindex 248f304af0..92d33f9166 100644--- a/packages/device-link/src/remoteDesktopIce.ts+++ b/packages/device-link/src/remoteDesktopIce.ts@@ -23,13 +23,29 @@ export const REMOTE_DESKTOP_ICE_SERVERS = [{ urls: "stun:stun.cloudflare.com:3478" },{ urls: "stun:stun.l.google.com:19302" },];+// Sequential host stages, followed by transport and WebView delivery headroom.+// Keep the outer waits derived from these limits so a valid cold start is not discarded.+export const REMOTE_DESKTOP_OFFER_BUDGET = {+ captureReadyMs: 10_000,+ platformStatusMs: 8_000,+ // Windows Node-API probe: pipe open 3s, write 5s, and ready read 5s.+ platformHandshakeMs: 13_000,+ sourcesMs: 5_000,+ hostMs: 18_000,+};+export const REMOTE_DESKTOP_INVOKE_MS =+ REMOTE_DESKTOP_OFFER_BUDGET.captureReadyMs ++ REMOTE_DESKTOP_OFFER_BUDGET.platformStatusMs ++ REMOTE_DESKTOP_OFFER_BUDGET.platformHandshakeMs ++ REMOTE_DESKTOP_OFFER_BUDGET.sourcesMs ++ REMOTE_DESKTOP_OFFER_BUDGET.hostMs + 5_000;export const REMOTE_DESKTOP_NETWORK = {maxCandidates: 128,batchSize: 16,pollMs: 250,exchangeMs: 30_000,disconnectedMs: 5_000,- answerMs: 25_000,+ answerMs: REMOTE_DESKTOP_INVOKE_MS + 2_000,connectMs: 15_000,legacyGatherMs: 5_000,stableMs: 30_000,