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): exec-server 连接带着工作被整条关掉时也算由忙转闲
fmfsaisaibe73cf074d47
diff --git a/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts b/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.tsindex 4e4fa48889..7909c979f7 100644--- a/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts+++ b/apps/desktop/src/main/remote-agent/__tests__/execServerProjection.e2e.test.ts@@ -84,7 +84,7 @@ describe.skipIf(!fs.existsSync(CODEX))('native exec-server workspace projection'// Codex 的后台终端在本机 exec-server 里:还有进程在跑时中继算忙,连接池不能让出名额// (对方 Codex 一退出,本机 exec-server 随连接关闭,后台终端就没了)。describe.skipIf(!fs.existsSync(CODEX) || process.platform === 'win32')('exec-server relay busy tracking', () => {- it('is busy while a started process runs, idle after it closes, and reset drops the exec-server', async () => {+ it('is busy while a started process runs, idle after it closes or its connection is dropped, and reset drops the exec-server', async () => {const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cindy-exec-busy-')));const workspace = new ExecutorWorkspace({ workingDir: root });const messages: Array<{ id?: number; method?: string; params?: { processId?: string }; error?: unknown }> = [];@@ -141,6 +141,14 @@ describe.skipIf(!fs.existsSync(CODEX) || process.platform === 'win32')('exec-ser// closed / exited 可能都会来,只算一次。expect(ended).toBe(2);+ // 连接带着还在跑的进程被整条关掉(对方关闭 WebSocket、exec-server 异常退出),同样算一次由忙转闲。+ start(6, 'dropped', 'sleep 30');+ await expect.poll(() => messages.some((item) => item.id === 6), { timeout: 5000 }).toBe(true);+ expect(relay.busy()).toBe(true);+ relay.handle({ t: 'ws', connId: 'c1', kind: 'close' });+ await expect.poll(() => relay.busy(), { timeout: 5000 }).toBe(false);+ expect(ended).toBe(3);+// 让出名额后关掉 exec-server,中继本身还能接新的连接。relay.reset();expect(relay.busy()).toBe(false);diff --git a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts b/apps/desktop/src/main/remote-agent/controller/execServerRelay.tsindex c9cfa25317..dcf554b795 100644--- a/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts+++ b/apps/desktop/src/main/remote-agent/controller/execServerRelay.ts@@ -46,7 +46,9 @@ export interface ExecServerRelayDeps {env?: NodeJS.ProcessEnv;log?: { warn(message: string, meta?: Record<string, unknown>): void };now?: () => number;- /** 最后一个在跑的进程(含后台终端)结束了:对连接池来说这是一次活动。 */+ /**+ * 由忙转闲:最后一个在跑的进程(含后台终端)结束,或带着工作的连接被整条关掉。对连接池来说这是一次活动。+ */onProcessesEnded?(): void;}@@ -547,6 +549,8 @@ export class ExecServerRelay {private dropConnection(connId: string, notifyRemote: boolean): void {const connection = this.connections.get(connId);if (!connection || connection.closed) return;+ // 连接带着在跑的进程、启动中的请求或待确认的消息被整条删掉(异常退出、对方关闭),同样是一次由忙转闲。+ const hadWork = connection.processes.size > 0 || connection.starting.size > 0 || Boolean(connection.queue);connection.closed = true;this.connections.delete(connId);try {@@ -556,6 +560,7 @@ export class ExecServerRelay {// 进程已退出。}if (notifyRemote) this.send({ connId, kind: 'close' });+ if (hadWork && !this.busy()) this.deps.onProcessesEnded?.();}/** 一条消息:超过单帧上限时拆成多段(除最后一段外带 more)。 */diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex e9a889d6d2..71be1f9be8 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -1350,7 +1350,7 @@ Codex 原生图片恢复(#6412)在既有 `maker:remote-agent:v1` 上追加Claude Code 后台子代理与后台任务、Pi 子代理)与待唤醒续跑(`pendingWake`);Codex 中继里没有仍在运行的 `process/start` 进程(后台终端;按 exec-server 的 `process/closed` / `process/exited` 与启动失败判断,固定 Codex 0.159.2 实测),也没有在等本机确认的消息;回到某条消息后、下一轮跑完前也算忙(Claude Code 要到下一次发送才在 B 上截断)。A 本机执行器里的后台命令不算忙。「闲置满 N 分钟」从最后一次活动算起:由忙转闲(后台任务、待唤醒续跑清空,- Codex 中继里最后一个进程结束)本身算一次活动,后台工作再久,结束后也要再闲置满 N 分钟才让。+ Codex 中继里最后一个进程结束,或带着进程、启动中请求、待确认消息的 exec-server 连接被整条关掉)本身算一次活动,后台工作再久,结束后也要再闲置满 N 分钟才让。会话 id 会被 B 改写的也不让:B 打开时把启动选项里的字符串按 A 的工作目录及各级上级目录、用户目录与附加目录投影到虚拟工作区,`resumeSessionId` 也不例外;Pi 的会话 id 是 B 上的会话文件路径,两台同为 Mac(`/Users`)或同为 Windows 时常落在这些前缀下,带过去会变成不存在的文件。A 按同一规则预判(`hostRewritesResumeId`),这样的 Pi 任务不让出。