Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(remote-agent): 轮询批次之间保留忙碌任务
MagicLizida5595607e39
diff --git a/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts b/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.tsindex c26d58b9bf..bf1b4ea369 100644--- a/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts@@ -275,6 +275,26 @@ describe('idle reclaim by the provider', () => {} finally { host.dispose(); }});+ // 1000 个任务按批轮询时,同一任务可能超过 1 分钟才再次被拉取。hold 必须在控制端存活窗口内持续保护,+ // 后续 poll 明确不带 hold 时解除,不能把仍在本机执行的进程误当闲置收回。+ it('keeps a held run between poll batches and starts its idle period after the hold is cleared', async () => {+ const { host, pass, rows } = await openBusy(1, { turn: false, background: 0, wake: 0 });+ try {+ await pass(0, true);+ clock += 70_000;+ await vi.advanceTimersByTimeAsync(5_000);+ await settle();+ expect(host.runCount()).toBe(1);+ await pass(0);+ await pass(50_000);+ expect(host.runCount()).toBe(1);+ await pass(20_000);+ await pass(0);+ expect(host.runCount()).toBe(0);+ expect(rows.at(-1)).toEqual({ t: 'closed', reason: 'ended', idleReclaimed: true });+ } finally { host.dispose(); }+ });+it('never reclaims with 0 minutes and declares the setting in caps', async () => {const { host, pass } = await openBusy(0, { turn: false, background: 0, wake: 0 });try {diff --git a/apps/desktop/src/main/remote-agent/host/runHost.ts b/apps/desktop/src/main/remote-agent/host/runHost.tsindex 5a07b39f3d..a28357a58e 100644--- a/apps/desktop/src/main/remote-agent/host/runHost.ts+++ b/apps/desktop/src/main/remote-agent/host/runHost.ts@@ -100,10 +100,10 @@ export const REMOTE_AGENT_HOST_UNREAD_BYTES = 64 * 1024 * 1024;/** 运行中的任务超过这么久没有被读取,视为控制端已离开。 */export const REMOTE_AGENT_HOST_IDLE_MS = 3 * 60_000;/**- * 控制端在 poll 里报「这边还有工作在进行」(hold)后,本机多久内仍按有活动算。只给中转用:组所在电脑据此- * 在拉取组内电脑时接着报 hold;控制端每次 poll 最长挂起 10 秒,任务很多时按批轮转,留足余量。+ * 控制端在 poll 里报「这边还有工作在进行」(hold)后,在控制端存活窗口内按忙处理;后续 poll 不带 hold 就解除。+ * 组所在电脑据此在拉取组内电脑时接着报 hold。大量任务按批轮转可能超过最短的 1 分钟闲置设置。*/-const REMOTE_HOLD_FRESH_MS = 60_000;+const REMOTE_HOLD_FRESH_MS = REMOTE_AGENT_HOST_IDLE_MS;/** 结束后保留一段时间供控制端读完收尾事件。 */export const REMOTE_AGENT_HOST_RETAIN_MS = 60_000;/** 「需要换一台」凭证多久内有效(受邀者那边交接通常几秒内完成,重开时带回)。 */@@ -829,6 +829,7 @@ export function createRemoteAgentHost(deps: RemoteAgentHostDeps) {* 还没启动好,或 Agent 那边还有放不下的事(中转任务按组内电脑报来的状态)。*/function busyForReclaim(run: Run): boolean {+ if (run.heldAt !== undefined && now() - run.heldAt < REMOTE_HOLD_FRESH_MS) return true;if (run.pending.size > 0 || run.rewindPending) return true;for (const status of run.calls.values()) if (status === 'running') return true;if (run.relay) return !run.relay.started || activityBusy(run.relay.activity);@@ -2086,6 +2087,7 @@ export function createRemoteAgentHost(deps: RemoteAgentHostDeps) {run.lastReadAt = t;// 控制端那边还有这个任务的工作在进行:按有活动算,不按闲置收回。if (hold) run.activeAt = run.heldAt = t;+ else run.heldAt = undefined;}};const live = () => wanted.flatMap(({ runId, cursor }) => {diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 702b81afcc..388f92cdcf 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -1461,8 +1461,9 @@ Codex 原生图片恢复(#6412)在既有 `maker:remote-agent:v1` 上追加新 A 不关句柄,与连接池让出名额同一状态(released),本机部分保留,下次要 B 干活时连回。中转时组所在电脑把这个字段原样转给受邀者(`relayClosed`),`ended` 本来就在正常收尾的原因里,不触发换电脑。- **A 报 hold**:`poll` 的每个任务项可选 `hold: true`,表示 A 这边还有 B 看不到的工作(当前只有 Codex 经执行环境在 A 上起的、- 仍在运行的进程,`ExecServerRelay.busy()`)。B 收到就按有活动算;组所在电脑在 60 秒内接着给组内电脑报 hold。旧 B 解析 poll- 时丢弃不认识的字段。+ 仍在运行的进程,`ExecServerRelay.busy()`)。B 收到后在控制端的 3 分钟存活窗口内按忙处理,后续 poll 未带 hold 就解除,+ 再从忙完后计算闲置时长;组所在电脑在同一窗口内接着给组内电脑报 hold。大量任务按批轮询可能超过最短的 1 分钟+ 闲置设置,不能只把收到 hold 的那一刻算作活动。旧 B 解析 poll 时丢弃不认识的字段。- **caps**:B 声明 `idleReclaimMinutes`(不合法时当作没声明,不让整个 caps 作废)。A 的连接池按它判定「闲置满」,旧 B 不声明 = 0,不让出。- **四种组合**:A 新 × B 新 按上面;A 新 × B 旧 不收回、不让出;A 旧 × B 新 被收回后静默重建;A 旧 × B 旧 不变。