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(remote-agent): 在断线恢复窗口内保留闲置收回通知

MagicLizie2103034b361
diff --git a/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts b/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts
index 41f70c32c7..00375c8fea 100644
--- a/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts
+++ b/apps/desktop/src/main/remote-agent/__tests__/hostLifecycle.test.ts
@@ -310,6 +310,28 @@ describe('idle reclaim by the provider', () => {
} finally { host.dispose(); }
});
+ // poller 允许断链后重试 2 分钟:收回通知不能在普通收尾的 60 秒后被删掉,否则连回只读到 missing,
+ // 使用方会关闭本应保留的本机部分。用 90 秒无 poll 复现,再确认恢复窗口结束后仍能清理。
+ it('retains the idle reclaim notification across a recoverable disconnect and eventually removes it', async () => {
+ const { host, pass, rows } = await openBusy(1, { turn: false, background: 0, wake: 0 });
+ try {
+ await pass(70_000);
+ expect(host.runCount()).toBe(0);
+ clock += 90_000;
+ await vi.advanceTimersByTimeAsync(5_000);
+ await settle();
+ await pass(0);
+ expect(rows.at(-1)).toEqual({ t: 'closed', reason: 'ended', idleReclaimed: true });
+ clock += 200_000;
+ await vi.advanceTimersByTimeAsync(5_000);
+ await settle();
+ const result = await host.handle('controller-1', {
+ op: 'poll', runs: [{ runId: RUN_1, cursor: 0 }], waitMs: 0,
+ });
+ expect(result).toMatchObject({ runs: [{ runId: RUN_1, missing: 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.ts
index f3410e6437..1b281a6639 100644
--- a/apps/desktop/src/main/remote-agent/host/runHost.ts
+++ b/apps/desktop/src/main/remote-agent/host/runHost.ts
@@ -850,7 +850,9 @@ export function createRemoteAgentHost(deps: RemoteAgentHostDeps) {
}
for (const run of runs.values()) {
if (run.closedAt !== undefined) {
- if (t - run.closedAt > REMOTE_AGENT_HOST_RETAIN_MS) void disposeRun(run);
+ // 闲置收回的通知必须覆盖控制端 2 分钟的断链重试;否则恢复后只读到 missing,会误关本机部分。
+ const retainMs = run.idleReclaimed ? REMOTE_AGENT_HOST_IDLE_MS : REMOTE_AGENT_HOST_RETAIN_MS;
+ if (t - run.closedAt > retainMs) void disposeRun(run);
continue;
}
if (!deps.isControllerAuthorized(run.controller)) {
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index b0784ed4f3..541de48459 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -1456,7 +1456,8 @@ Codex 原生图片恢复(#6412)在既有 `maker:remote-agent:v1` 上追加
执行中的调用、Claude Code 待生效的回退(`commitRewindFiles` 成功后到下一个 `done`;Codex / Pi 返回时已完成回退)、还没启动好,或 Agent 状态里有在跑 / 在准备的
回合、后台任务、待唤醒续跑(中转任务看组内电脑报来的同一组字段);巡检时忙就把闲置起点移到此刻。活动 = 打开、
`call` / `reply` / `push`、写进事件流的非 `state` 行;只被 `poll` 不算(闲着的任务 A 也一直在拉)。
- - **收尾**:`closed` 行写 `reason: 'ended'` 并带可选 `idleReclaimed: true`。旧 A 不认识这个字段,按 `ended` 静默收起,
+ - **收尾**:`closed` 行写 `reason: 'ended'` 并带可选 `idleReclaimed: true`,保留 3 分钟以覆盖 A 的 2 分钟断链重试
+ (普通收尾保留 1 分钟);Agent 进程与名额仍在收回时立即释放。旧 A 不认识这个字段,按 `ended` 静默收起,
Maker 把事件流结束当成句柄已死、自动关闭任务,下次发送照常重建并带原生会话 id 接回(本机后台命令随句柄结束);
新 A 不关句柄,与连接池让出名额同一状态(released),本机部分保留,下次要 B 干活时连回。中转时组所在电脑把这个字段
原样转给受邀者(`relayClosed`),`ended` 本来就在正常收尾的原因里,不触发换电脑。