Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(task-copy): 统计在任务所在电脑上按 3 分钟截止

Dash250ad30cb064
diff --git a/apps/desktop/src/main/task-migration/__tests__/service.test.ts b/apps/desktop/src/main/task-migration/__tests__/service.test.ts
index a6dcaeb254..b48f6ff2d7 100644
--- a/apps/desktop/src/main/task-migration/__tests__/service.test.ts
+++ b/apps/desktop/src/main/task-migration/__tests__/service.test.ts
@@ -9,6 +9,7 @@ import { createHash } from 'node:crypto';
import { AsyncLocalStorage } from 'node:async_hooks';
import {
parseAttachmentOssRef,
+ TASK_MIGRATION_ESTIMATE_TIMEOUT_MS,
TASK_MIGRATION_LOCAL_CHANNEL,
TASK_MIGRATION_MAX_FILES,
} from '@cindy/device-link';
@@ -210,8 +211,9 @@ vi.mock('../workspace', async (original) => ({
.isExcludedFromWorkspace,
managedWorktreeExclusions: (await original<typeof import('../workspace')>())
.managedWorktreeExclusions,
- estimateWorkspace: async (_root: string, _check: () => void, maxFiles: number) => {
+ estimateWorkspace: async (_root: string, check: () => void, maxFiles: number) => {
state.estimateLimits.push(maxFiles);
+ check();
return { fileCount: 1, bytes: 8 };
},
snapshotWorkspace: async (source: string, directory: string) => {
@@ -502,6 +504,20 @@ describe('resumable cross-computer copy', () => {
expect(state.exported).not.toHaveBeenCalled();
expect(state.files.size).toBe(0);
});
+ it('stops a local estimate at the same budget the remote wait uses', async () => {
+ const start = Date.now();
+ const now = vi
+ .spyOn(Date, 'now')
+ .mockReturnValueOnce(start)
+ .mockReturnValue(start + TASK_MIGRATION_ESTIMATE_TIMEOUT_MS + 1);
+ try {
+ await expect(requestTaskMigration({ action: 'estimate', sessionId: 'fork' })).rejects.toThrow(
+ 'MIGRATION_TIMEOUT',
+ );
+ } finally {
+ now.mockRestore();
+ }
+ });
it('reports a timed-out remote request as MIGRATION_TIMEOUT instead of a generic failure', async () => {
const { ipcMain } = await import('electron');
const handler = vi
diff --git a/apps/desktop/src/main/task-migration/service.ts b/apps/desktop/src/main/task-migration/service.ts
index 150075b2a9..104fdeb5d0 100644
--- a/apps/desktop/src/main/task-migration/service.ts
+++ b/apps/desktop/src/main/task-migration/service.ts
@@ -6,6 +6,7 @@ import {
TASK_MIGRATION_CHANNEL,
TASK_MIGRATION_LOCAL_CHANNEL,
TASK_MIGRATION_MAX_FILES,
+ TASK_MIGRATION_ESTIMATE_TIMEOUT_MS,
DeviceLinkError,
parseTaskMigrationRequest,
buildAttachmentOssRef,
@@ -923,11 +924,17 @@ export async function requestTaskMigration(raw: unknown): Promise<TaskMigrationV
await Promise.all(members.map((member) => physicalWorktreeKey(member.workingDir))),
);
const estimate = { fileCount: 0, bytes: 0 };
+ // Same budget as the remote wait, enforced here so a local or orphaned scan also stops.
+ const deadline = Date.now() + TASK_MIGRATION_ESTIMATE_TIMEOUT_MS;
+ const check = () => {
+ scope.assertCurrent();
+ if (Date.now() > deadline) throw new Error('MIGRATION_TIMEOUT');
+ };
for (const root of roots) {
// The cap covers every copied directory together.
const next = await estimateWorkspace(
root,
- scope.assertCurrent,
+ check,
TASK_MIGRATION_MAX_FILES - estimate.fileCount,
);
estimate.fileCount += next.fileCount;
diff --git a/docs/product-rules/task-device-migration.md b/docs/product-rules/task-device-migration.md
index 8dddf54321..77f23d7273 100644
--- a/docs/product-rules/task-device-migration.md
+++ b/docs/product-rules/task-device-migration.md
@@ -28,7 +28,7 @@
5. 确认页使用接收电脑名称或“本机”,展示项目文件数量与复制前估算大小(含隐藏/忽略文件,整组共享目录去重)。
Git 历史、任务对话与附件另行复制,不计入项目文件统计;统计完成前不能开始复制。
`copyEstimate` 能力存在时才调用 `estimate`;旧源端无法统计时明确提示连接/版本检查,不开始复制。
- 统计请求超时时提示项目文件过多,不提示连接/版本;项目文件超过 50 万个时提前停止统计,
+ 统计在任务所在电脑上按 3 分钟截止(本机任务同样适用),超时时提示项目文件过多,不提示连接/版本;项目文件超过 50 万个时提前停止统计,
提示改为复制文件更少的项目,不开始复制。该上限只是确认页的准入检查,复制本身仍不设总量上限。
6. 复制全程保留弹窗,不提供隐藏到后台的入口;准备阶段显示不定进度,发送阶段显示本机上传字节进度及平均速度,明确接收尚未完成。
OSS 进度计 HTTP 请求体已提交字节(可能仍在缓冲),peer 计分段确认字节,不作为接收完成凭据。