Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(task-copy): 被控端全局上限覆盖动作级预算,统计逐个计数执行文件数上限
Dashf030aff8e3c2
diff --git a/apps/desktop/src/main/device-link/__tests__/dispatchWeakNetwork.test.ts b/apps/desktop/src/main/device-link/__tests__/dispatchWeakNetwork.test.tsindex ad8a90e4c3..b1aa5d5c20 100644--- a/apps/desktop/src/main/device-link/__tests__/dispatchWeakNetwork.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/dispatchWeakNetwork.test.ts@@ -22,6 +22,7 @@ import {PROTOCOL_VERSION,TASK_MIGRATION_CHANNEL,TASK_MIGRATION_ESTIMATE_TIMEOUT_MS,+ resolveRemoteInvokeTimeoutMs,type Envelope,} from '@cindy/device-link';@@ -689,6 +690,24 @@ describe('[5] orphan 截止时间按 channel 收窄', () => {expect(outbox('estimate')).toBe(TASK_MIGRATION_ESTIMATE_TIMEOUT_MS * 2);expect(outbox('status')).toBe(60_000);});++ it('被控端从不早于控制端放弃:orphan 与 outbox 覆盖每个通道与动作的等待预算', () => {+ const calls: Array<[string | undefined, unknown[] | undefined]> = [+ [undefined, undefined],+ ...Object.keys(INVOKE_TIMEOUT_OVERRIDES_MS).map(+ (channel) => [channel, undefined] as [string, undefined],+ ),+ ...['estimate', 'receive', 'status', 'start', 'caps'].map(+ (action) => [TASK_MIGRATION_CHANNEL, [{ action, sessionId: 's' }]] as [string, unknown[]],+ ),+ ];+ for (const [channel, args] of calls) {+ const budget =+ (channel && resolveRemoteInvokeTimeoutMs(channel, args, 'desktop')) || 30_000;+ expect(__testing.remoteInvokeOrphanTimeoutForChannelMs(channel, args)).toBeGreaterThanOrEqual(budget);+ expect(__testing.outboxEntryMaxAgeMs(channel, args)).toBeGreaterThanOrEqual(budget);+ }+ });});describe('[6] active controller 生命周期与故障半径', () => {diff --git a/apps/desktop/src/main/device-link/dispatch.ts b/apps/desktop/src/main/device-link/dispatch.tsindex 0f847d2682..42c6e32c96 100644--- a/apps/desktop/src/main/device-link/dispatch.ts+++ b/apps/desktop/src/main/device-link/dispatch.ts@@ -36,6 +36,7 @@ import {canCoalesceRemoteListing,isCompletedInvokeRetryableReadChannel,INVOKE_TIMEOUT_OVERRIDES_MS,+ ACTION_INVOKE_TIMEOUTS_MS,resolveRemoteInvokeTimeoutMs,MAX_FRAME_BYTES,PROTOCOL_VERSION,@@ -742,6 +743,7 @@ const DEFAULT_REMOTE_INVOKE_CLIENT_WAIT_MS = 30_000;const REMOTE_INVOKE_MAX_CLIENT_WAIT_MS = Math.max(DEFAULT_REMOTE_INVOKE_CLIENT_WAIT_MS,...Object.values(INVOKE_TIMEOUT_OVERRIDES_MS),+ ...ACTION_INVOKE_TIMEOUTS_MS,);/** 再保留一轮同等重连窗口后才放弃无人等待的回包(全局上限;逐条按 channel 收窄)。 */const REMOTE_INVOKE_RESULT_OUTBOX_MAX_AGE_MS = REMOTE_INVOKE_MAX_CLIENT_WAIT_MS * 2;diff --git a/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts b/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.tsindex 45769e39fc..56d03e26c4 100644--- a/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts+++ b/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts@@ -86,6 +86,35 @@ it('counts a wide, deep tree and stops once the file cap is exceeded', async ()}});+it('stops at the file cap even when every entry type is unknown', async () => {+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'copy-estimate-'));+ const readdir = fs.readdir.bind(fs);+ const unknown = vi.spyOn(fs, 'readdir').mockImplementation((async (+ directory: string,+ options: unknown,+ ) =>+ (await readdir(directory, options as { withFileTypes: true })).map((entry) => ({+ name: entry.name,+ isDirectory: () => false,+ isFile: () => false,+ isSymbolicLink: () => false,+ }))) as never);+ const lstat = vi.spyOn(fs, 'lstat');+ try {+ await Promise.all(+ Array.from({ length: 300 }, (_, i) => fs.writeFile(path.join(root, `f${i}`), '')),+ );+ lstat.mockClear();+ await expect(estimateWorkspace(root, () => {}, 10)).rejects.toThrow('MIGRATION_TOO_MANY_FILES');+ // Classifying the 11th file is the last per-file work; the other 289 are never statted.+ expect(lstat.mock.calls.length).toBeLessThanOrEqual(11);+ } finally {+ lstat.mockRestore();+ unknown.mockRestore();+ await fs.rm(root, { recursive: true, force: true });+ }+});+it('classifies entries of unknown type with lstat instead of rejecting them', async () => {const root = await fs.mkdtemp(path.join(os.tmpdir(), 'copy-estimate-'));const readdir = fs.readdir.bind(fs);diff --git a/apps/desktop/src/main/task-migration/workspace.ts b/apps/desktop/src/main/task-migration/workspace.tsindex 36cf791983..01f228c1df 100644--- a/apps/desktop/src/main/task-migration/workspace.ts+++ b/apps/desktop/src/main/task-migration/workspace.ts@@ -308,12 +308,12 @@ export async function estimateWorkspace(: await fs.lstat(file);if (kind.isDirectory()) {if (directory !== root || !excluded.includes(entry.name)) pending.push(file);- } else if (kind.isFile() || kind.isSymbolicLink()) files.push(file);- else throw new Error('MIGRATION_NONPORTABLE_PATH');+ } else if (kind.isFile() || kind.isSymbolicLink()) {+ // Count as each file is recognised, before any per-file work beyond the cap.+ if (++result.fileCount > maxFiles) throw new Error('MIGRATION_TOO_MANY_FILES');+ files.push(file);+ } else throw new Error('MIGRATION_NONPORTABLE_PATH');}- // Count before stat so an oversized directory stops without statting every entry.- result.fileCount += files.length;- if (result.fileCount > maxFiles) throw new Error('MIGRATION_TOO_MANY_FILES');for (let index = 0; index < files.length; index += STAT_BATCH) {check();const stats = await Promise.all(diff --git a/packages/device-link/src/invokePolicy.ts b/packages/device-link/src/invokePolicy.tsindex 875743426c..e20c05b58b 100644--- a/packages/device-link/src/invokePolicy.ts+++ b/packages/device-link/src/invokePolicy.ts@@ -1,5 +1,9 @@import { INVOKE_TIMEOUT_OVERRIDES_MS } from './allowlist.js';-import { TASK_MIGRATION_CHANNEL, TASK_MIGRATION_ESTIMATE_TIMEOUT_MS } from './taskMigration.js';+import {+ TASK_MIGRATION_CHANNEL,+ TASK_MIGRATION_ESTIMATE_TIMEOUT_MS,+ TASK_MIGRATION_RECEIVE_TIMEOUT_MS,+} from './taskMigration.js';import type { InvokePayload } from './protocol.js';/**@@ -81,6 +85,16 @@ export const MOBILE_INVOKE_TIMEOUT_OVERRIDES_MS: Record<string, number> = {export const MOBILE_SCHEDULE_CHANNEL_TIMEOUT_MS = 40_000;+/**+ * Every action-specific desktop budget `resolveRemoteInvokeTimeoutMs` can return beyond+ * INVOKE_TIMEOUT_OVERRIDES_MS. Hosts size their global orphan/outbox ceilings from both,+ * so a host never gives up before the controller stops waiting.+ */+export const ACTION_INVOKE_TIMEOUTS_MS: readonly number[] = [+ TASK_MIGRATION_ESTIMATE_TIMEOUT_MS,+ TASK_MIGRATION_RECEIVE_TIMEOUT_MS,+];+export function resolveRemoteInvokeTimeoutMs(channel: string,args?: unknown[],@@ -89,7 +103,7 @@ export function resolveRemoteInvokeTimeoutMs(if (channel === TASK_MIGRATION_CHANNEL) {const request = args?.[0];const action = request && typeof request === 'object' && 'action' in request ? request.action : undefined;- if (action === 'receive') return 30 * 60_000;+ if (action === 'receive') return TASK_MIGRATION_RECEIVE_TIMEOUT_MS;// Read-only inventory of a large project (dependencies included) can legitimately exceed 30s.if (action === 'estimate') return TASK_MIGRATION_ESTIMATE_TIMEOUT_MS;return 30_000;diff --git a/packages/device-link/src/taskMigration.ts b/packages/device-link/src/taskMigration.tsindex abe61d1080..41f55133c1 100644--- a/packages/device-link/src/taskMigration.ts+++ b/packages/device-link/src/taskMigration.ts@@ -4,6 +4,7 @@ export const TASK_MIGRATION_LOCAL_CHANNEL = "task-copy:request";/** `estimate` stops early with MIGRATION_TOO_MANY_FILES above this many project files. */export const TASK_MIGRATION_MAX_FILES = 500_000;export const TASK_MIGRATION_ESTIMATE_TIMEOUT_MS = 3 * 60_000;+export const TASK_MIGRATION_RECEIVE_TIMEOUT_MS = 30 * 60_000;export interface MigrationFileRef {ref: string;size: number;