Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-core,desktop): 处理 R10 review 的 2 P1 + 1 P2 + CI typecheck
yanb096582035d4
diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.tsindex 34f7b3fb88..fc5be5aee9 100644--- a/apps/desktop/src/main/maker-host/index.ts+++ b/apps/desktop/src/main/maker-host/index.ts@@ -640,7 +640,16 @@ export function getMaker(): Maker {// codex daemon 的 env marker (漂移 → 重写 + 重启 daemon), 然后才让// transport 探活/拉起 daemon。pref 关闭时 reconcile 是幂等 no-op。beforeDaemonProbe: async () => {- await reconcileCodexAgentProxyEnv(remoteHost);+ // markerChanged && !daemonRestarted = 旧 daemon 活着跑旧 env —+ // 继续 probe 会 attach 到 stale daemon, UI 报 tunnel active 而+ // codex 流量走旧路由 (codex R10 P1): 按 bootstrap 失败抛出, 让+ // session start 显式报错, 而不是静默复用。+ const reconciled = await reconcileCodexAgentProxyEnv(remoteHost);+ if (reconciled.markerChanged && !reconciled.daemonRestarted) {+ throw new Error(+ 'codex daemon survived pkill after agent-proxy env change; refusing to attach the stale daemon (retry or restart the host)',+ );+ }},});},diff --git a/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts b/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.tsindex 1095c01395..2e66ae616d 100644--- a/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts+++ b/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts@@ -248,6 +248,44 @@ describe('reconcileCodexAgentProxyEnv', () => {await expect(reconcileCodexAgentProxyEnv(host)).rejects.toThrow(/delete agent-proxy marker failed/);expect(state.pkillCount).toBe(0);});++ it('rolls the marker back when pkill fails so the next reconcile retries the kill (codex R10 P2)', async () => {+ // disable 场景 (desired=null, current=旧 proxy marker): pkill 失败时若让+ // marker 停在 null, 下次 reconcile 命中 fast path (null===null) 永不重试+ // kill — 存活 daemon 握着指向已拆隧道的 proxy env 一直跑到手动重启。+ setSshHostAgentProxy('test-host', null);+ const staleMarker = "export HTTPS_PROXY='http://127.0.0.1:17893'";+ const { host, state } = makeFakeHost({ marker: staleMarker });+ let pkillShouldFail = true;+ let failedPkillCount = 0;+ const baseExec = host.exec.bind(host);+ host.exec = async (cmd: string, execOpts?: { input?: string }) => {+ if (cmd.includes('pkill') && pkillShouldFail) {+ failedPkillCount += 1;+ return {+ stdout: '',+ stderr: 'daemon still alive after TERM(5s)+KILL(2s)',+ exitCode: 3,+ signal: null,+ };+ }+ return baseExec(cmd, execOpts);+ };++ const first = await reconcileCodexAgentProxyEnv(host);+ expect(first).toEqual({ markerChanged: true, daemonRestarted: false });+ // marker 已回滚到原值 (与存活 daemon 的 env 一致)。+ expect(state.marker).toBe(staleMarker);++ // 下次 reconcile 仍 drift → 重写 + 重试 kill (自愈); pkill 恢复后清干净。+ pkillShouldFail = false;+ const second = await reconcileCodexAgentProxyEnv(host);+ expect(second).toEqual({ markerChanged: true, daemonRestarted: true });+ expect(state.marker).toBeNull();+ // 两次 reconcile 各发了一次 pkill: 第一次失败 (mock 拦截), 第二次重试成功。+ expect(failedPkillCount).toBe(1);+ expect(state.pkillCount).toBe(1);+ });});describe('killRemoteCodexDaemon', () => {@@ -319,7 +357,9 @@ describe('applyAgentProxyForHost disable path', () => {const { host, state } = makeFakeHost({ marker: null });let killStarted = false;- let releaseKill: (() => void) | null = null;+ // 对象持有 release: TS 不对属性做 closure 收窄 (let 声明会被 narrow 成+ // undefined → CI typecheck TS2349 "Type 'never' has no call signatures")。+ const killGate: { release?: () => void } = {};const baseExec = host.exec.bind(host);host.exec = async (cmd: string, execOpts?: { input?: string }) => {if (cmd.includes('pkill')) {@@ -327,7 +367,7 @@ describe('applyAgentProxyForHost disable path', () => {// 不能拿 execCalls 当等待信号)。killStarted = true;await new Promise<void>((resolve) => {- releaseKill = resolve;+ killGate.release = resolve;});}return baseExec(cmd, execOpts);@@ -352,7 +392,7 @@ describe('applyAgentProxyForHost disable path', () => {await Promise.resolve();expect(state.execCalls.length).toBe(execCountWhileFirstBlocked);- releaseKill?.();+ killGate.release?.();const [r1, r2] = await Promise.all([first, second]);expect(r1.markerChanged).toBe(true);expect(r1.daemonRestarted).toBe(true);@@ -363,6 +403,34 @@ describe('applyAgentProxyForHost disable path', () => {});});+describe('applyAgentProxyForHost enable path', () => {+ it('reports apply error and rolls the marker back when the daemon survives pkill (codex R10 P1)', async () => {+ // marker 漂移 (null → 新 proxy marker) 但 pkill 失败: 旧 daemon 还活着跑+ // 旧 env — 不得按成功落 active, 卡片显示错误; marker 回滚到 null 供下次+ // reconcile 重试。+ setSshHostAgentProxy('test-host', PREF);+ const { host, state } = makeFakeHost({ marker: null });+ const baseExec = host.exec.bind(host);+ host.exec = async (cmd: string, execOpts?: { input?: string }) => {+ if (cmd.includes('pkill')) {+ return {+ stdout: '',+ stderr: 'daemon still alive after TERM(5s)+KILL(2s)',+ exitCode: 3,+ signal: null,+ };+ }+ return baseExec(cmd, execOpts);+ };+ await applyAgentProxyForHost(host);+ const tunnelState = getAgentProxyTunnelState('test-host');+ expect(tunnelState?.active).toBe(false);+ expect(tunnelState?.lastError).toMatch(/survived pkill/);+ // 原 marker 为 null → 回滚即删除。+ expect(state.marker).toBeNull();+ });+});+describe('ssh-host-prefs-store agentProxy', () => {it('round-trips an enabled pref', () => {setSshHostAgentProxy('h1', PREF);diff --git a/apps/desktop/src/main/remote-ssh/agent-proxy.ts b/apps/desktop/src/main/remote-ssh/agent-proxy.tsindex e9559baaef..96446d7c19 100644--- a/apps/desktop/src/main/remote-ssh/agent-proxy.ts+++ b/apps/desktop/src/main/remote-ssh/agent-proxy.ts@@ -326,8 +326,10 @@ exit 3* 远端被别的客户端动过)。* 2. pref 变更 / host ready 的 applyAgentProxyForHost — 即时生效。*- * marker 一致时零副作用 (1 次 cat RTT)。pkill 失败不抛错 — marker 已写,- * 下次 daemon 自然重启时也会生效, 这里只降级为 warn。+ * marker 一致时零副作用 (1 次 cat RTT)。pkill 失败不抛错 — marker 回滚到+ * 原值 (与存活 daemon 的 env 保持一致, 否则下次 reconcile 命中 fast path+ * 永不重试 kill, codex R10 P1/P2), 调用方按 markerChanged && !daemonRestarted+ * 组合上报失败。*/export async function reconcileCodexAgentProxyEnv(host: RemoteHost,@@ -376,6 +378,22 @@ async function reconcileCodexAgentProxyEnvSerialized(});await writeRemoteMarker(host, desired);const kill = await killRemoteCodexDaemon(host);+ if (!kill.ok) {+ // daemon 没死透 → marker 回滚到原值 (codex R10 P1/P2): 存活 daemon 的+ // env 仍来自原 marker; 若让 marker 停在新值, 下次 reconcile 命中+ // marker-match fast path 永不重试 kill — disable 后旧 daemon 握着指向+ // 已拆隧道的 proxy env 跑到手动重启, enable 后旧 daemon 一直跑旧 env。+ // 回滚后 marker 与存活 daemon env 一致, 下次 reconcile 仍 drift →+ // 重写 + 重试 kill, 可自愈。回滚失败仅 warn: 调用方已按失败上报。+ try {+ await writeRemoteMarker(host, current);+ } catch (rollbackErr) {+ log.warn('agent-proxy marker rollback after pkill failure failed', {+ hostId: host.id,+ error: rollbackErr instanceof Error ? rollbackErr.message : String(rollbackErr),+ });+ }+ }return { markerChanged: true, daemonRestarted: kill.ok };}@@ -405,7 +423,15 @@ export async function applyAgentProxyForHost(host: RemoteHost): Promise<void> {return;}await ensureAgentProxyTunnel(host);- await reconcileCodexAgentProxyEnv(host);+ const reconciled = await reconcileCodexAgentProxyEnv(host);+ // 隧道建好但旧 daemon 没死透 = 它还跑着旧 env (无 proxy / 旧端口), 不得+ // 按成功落 active 状态 (codex R10 P1) — 与 disable 分支同款按失败上报,+ // 让卡片显示错误而不是说谎的「已开启」。+ if (reconciled.markerChanged && !reconciled.daemonRestarted) {+ throw new Error(+ 'codex daemon survived pkill after proxy enable/rebind; it still runs with the previous env (retry or restart the host)',+ );+ }} catch (err) {const msg = String((err as Error)?.message ?? err);log.warn('apply agent-proxy failed (will retry on next session)', { hostId: host.id, error: msg });diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex b7cc7e6291..6e36f00fd2 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -6438,6 +6438,8 @@ describe('CodexAgent turn lifecycle', () => {if (host.request.mock.calls.filter(([method]) => method === Method.TurnStart).length >= 2) break;await Promise.resolve();}+ // send2 开头的 turn-start status 先消费掉, 后续事件流才只反映通知路径。+ expect(await nextEvent(iterator)).toMatchObject({ type: 'status', data: { isRunning: true } });handlers.turnStarted?.({ threadId: 'start-thread-id', turn: { id: 'orphan-turn' } });expect(handle.isTurnRunning?.()).toBe(false);expect(handle.getCurrentTurnId?.()).toBeNull();@@ -6448,6 +6450,15 @@ describe('CodexAgent turn lifecycle', () => {),).toBe(false);+ // 缓冲期间孤儿 turn 的 item/error 事件不得穿透到本次 send 的事件流+ // (greptile R10 P1): stale guard 把 buffered id 一并隔离。+ handlers.itemStarted?.({+ threadId: 'start-thread-id',+ turnId: 'orphan-turn',+ item: { type: 'agentMessage', id: 'orphan-item', text: 'orphan output' },+ });+ await expect(nextEvent(iterator)).rejects.toThrow('timed out waiting for event');+// 第二次响应 turn-2 ≠ orphan-turn → 孤儿坐实: interrupt + 墓碑; turn-2 激活。secondStart.resolve({ turn: { id: 'turn-2' } });await send2;diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex c2c42ee377..9fa1c1b59f 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -3732,6 +3732,12 @@ export class CodexAgent extends BaseAgent {if (!turnId) return false;if (completedTurnIds.has(turnId)) return true;if (terminalErroredTurnIds.has(turnId)) return true;+ // 缓冲隔离中的歧义 turn (codex R9 P2): id 只拦 turnStarted 不够 —+ // 缓冲期间 currentTurnId 为 null, 孤儿 turn 的 item/usage/error 会穿透+ // stale guard 被按当前 pending turn 处理 (旧输出显示在新消息下 / 用量+ // 计错 turn / 孤儿 error 终结合法新 turn, greptile R10 P1)。其事件一律+ // 忽略; 若响应证明合法 (id 一致) buffer 已清空, 后续事件正常。+ if (bufferedOrphanTurnIds.has(turnId)) return true;return currentTurnId !== null && turnId !== currentTurnId;};