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): bound supplemental poll wait for successive starts

MagicLizia6cb68178785
diff --git a/apps/desktop/src/main/remote-agent/__tests__/poll.test.ts b/apps/desktop/src/main/remote-agent/__tests__/poll.test.ts
index 26b113fe69..055dacd60b 100644
--- a/apps/desktop/src/main/remote-agent/__tests__/poll.test.ts
+++ b/apps/desktop/src/main/remote-agent/__tests__/poll.test.ts
@@ -191,9 +191,16 @@ describe('multiplexed poll', () => {
await vi.waitFor(() => expect(sinks[2].text()).toContain(data));
expect(Date.now() - appendedAt).toBeLessThan(1_000);
}
+ // 补位 poll 也在等待时,再登记第四个任务:不能再次被三个旧长等待挡住 10 秒。
+ const fourth = collector(randomUUID());
+ host.add(fourth.run.runId).append({ step: 'fourth-started' });
+ poller.register(fourth.run);
+ await vi.advanceTimersByTimeAsync(1_001);
+ expect(fourth.text()).toContain('fourth-started');
for (const run of host.runs.values()) run.log.end();
await vi.advanceTimersByTimeAsync(REMOTE_AGENT_READ_WAIT_MS);
expect(sinks.every((sink) => sink.done)).toBe(true);
+ expect(fourth.done).toBe(true);
});
it.each([12, 130])('delivers %i runs exactly once with at most three polls in flight', async count => {
diff --git a/apps/desktop/src/main/remote-agent/controller/poller.ts b/apps/desktop/src/main/remote-agent/controller/poller.ts
index 202293b7af..a79bdb16e2 100644
--- a/apps/desktop/src/main/remote-agent/controller/poller.ts
+++ b/apps/desktop/src/main/remote-agent/controller/poller.ts
@@ -28,6 +28,8 @@ const RETRY_MAX_MS = 5_000;
const MAX_INFLIGHT_POLLS = 2;
/** 有任务没有被在途 poll 覆盖时,多留一个补位名额,直到普通 poll 接手。 */
const FRESH_RUN_EXTRA_POLLS = 1;
+/** 补位不要变成长等待,否则第四个新任务仍会被三个旧 poll 挡住。 */
+const FRESH_RUN_WAIT_MS = 1_000;
/** 对方连续几次立刻返回、却没有任何新数据时,放慢重拉(防止对方行为异常时空转)。 */
const EMPTY_FAST_STREAK = 3;
const EMPTY_FAST_MS = 50;
@@ -135,12 +137,13 @@ export class RemoteAgentPoller {
const wanted = this.snapshot();
const startedAt = this.now();
const coverage: ReadonlySet<string> = new Set(wanted.map((item) => item.runId));
+ const waitMs = this.inflight >= MAX_INFLIGHT_POLLS ? FRESH_RUN_WAIT_MS : REMOTE_AGENT_READ_WAIT_MS;
this.inflight += 1;
this.inflightCoverage.add(coverage);
let raw: unknown;
let failure: unknown = null;
try {
- raw = await this.invoke([{ op: 'poll', runs: wanted, waitMs: REMOTE_AGENT_READ_WAIT_MS }]);
+ raw = await this.invoke([{ op: 'poll', runs: wanted, waitMs }]);
} catch (error) {
failure = error;
} finally {
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index ca6eb23f04..a1f3342fd4 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -151,7 +151,8 @@ relay 以 close 1013 `inbound backpressure` 主动断连,此时任何「立即
3. **多 peer**:被控端按 `(控制端, runId)` 隔离任务;默认每台控制设备最多 16 个任务、整机最多 64 个,
主人可在「远程与分享」调整(最多 1000)。控制端每台被控端一个拉取器,每次 `poll` 最多带 64 个任务,
按整批轮转,挂起最多 10s,长等待同时在途最多两个;另留一个补位名额给没有被在途 poll 覆盖的任务,直到
- 普通 poll 接手(未覆盖任务排在最前并继续轮转),合计不超过 3 个,不占满共享的 12 个在途配额。
+ 普通 poll 接手(未覆盖任务排在最前并继续轮转)。补位 poll 最多等 1s,让后续新增任务也及时入列;合计不超过 3 个,
+ 不占满共享的 12 个在途配额。
补位名额解决的是:两个长等待都只含空闲的旧任务时,新任务的第一个事件及后续事件要等旧长等待超时 10s 才有人拉,
正好撞上 Codex 执行环境 initialize 握手的 10s 上限(2026-10-22 调查)。
`poll.test.ts` 用 130 / 1000 个空闲任务验证拉取间隔始终短于 3 分钟的回收期限,并复现上述新任务等待。