Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop,maker-cc-manager): 远端协同补全 R27 四案
yanfef839b766f2
diff --git a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.tsindex 0cdf5dae33..983037d208 100644--- a/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/remoteCcQueryFactory.test.ts@@ -143,8 +143,22 @@ describe('remoteCcQueryFactory persistent generation drift (R23 P2)', () => {expect(source).toContain('ccGenerationDrift');expect(source).toContain('mcpInjectFingerprint !== ccAppliedFingerprint');// drift 必须进入 forceFreshQuery 判定。- expect(source).toContain('|| ccGenerationDrift)');+ expect(source).toContain('!forcedFreshCcBridgeSessions.has(sessionId)) ||');// open 成功后 (含 attach) 必须落盘 applied 指纹。expect(source).toContain('writeCcAppliedFingerprint(sessionId, mcpInjectFingerprint)');});});++describe('remoteCcQueryFactory drift override (R27 P1)', () => {+ it('does not let the forced-fresh set suppress a detected generation drift', () => {+ expect(source).toContain('ccGenerationDrift;');+ const driftCheck = source.indexOf('ccGenerationDrift =');+ const forceFreshAssign = source.indexOf('const forceFreshQuery =', driftCheck);+ expect(forceFreshAssign).toBeGreaterThan(driftCheck);+ // drift 独立成项:豁免闭括号 (has(sessionId)) 之后的 || 分支即 drift。+ const exemptClose = source.indexOf('!forcedFreshCcBridgeSessions.has(sessionId)) ||', forceFreshAssign);+ const orDrift = source.indexOf('ccGenerationDrift;', exemptClose);+ expect(exemptClose).toBeGreaterThan(forceFreshAssign);+ expect(orDrift).toBeGreaterThan(exemptClose);+ });+});diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.tsindex 875346fdda..69bb7e705b 100644--- a/apps/desktop/src/main/maker-host/index.ts+++ b/apps/desktop/src/main/maker-host/index.ts@@ -754,9 +754,15 @@ export function getMaker(): Maker {mcpInjectFingerprint !== undefined &&ccAppliedFingerprint !== null &&mcpInjectFingerprint !== ccAppliedFingerprint;+ // 持久代际 drift (ccGenerationDrift) 不受 fresh 集合豁免:+ // token/bridge/端口变化后 applied 指纹 ≠ desired 时, 已 fresh 过的+ // session 也必须重新 forceFresh — 否则豁免让 drift 判定只在「从未+ // fresh 过」时生效, attach 回持旧 Authorization/URL 的 query+ // (codex-connector R27 P1)。fresh 集合只豁免「同代际的重复注入」。const forceFreshQuery =- (injectedServerCount > 0 || mcpNeedsFreshStart || staleInvalidatedCcSessions.has(sessionId) || ccGenerationDrift) &&- !forcedFreshCcBridgeSessions.has(sessionId);+ ((injectedServerCount > 0 || mcpNeedsFreshStart || staleInvalidatedCcSessions.has(sessionId)) &&+ !forcedFreshCcBridgeSessions.has(sessionId)) ||+ ccGenerationDrift;// 协同 MCP 已 mutate 进 startParams.mcpServers;这里再把 proxy env 合入// 得到最终 startParams (mcpServers 与 env 都带上)。diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 58ed58a74e..aa4c3e5131 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -4410,13 +4410,18 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)// codex 远端 daemon 的 live-turn 判定 (ensure 与 turn-done 挂钩共用):// bootstrap 重启会断同 host 的 live turn, defer/补刀都以此为据。- const codexRemoteHasLiveTurn = (hostId: string): boolean =>- maker.listActiveSessions().some(+ // function 声明 (hoisted):const 箭头形态下, 任何早于本行执行的调用路径+ // (如注册流程中被直线调用的 resume 分支) 都会 TDZ ReferenceError — 用+ // 声明消除整类风险 (reviewer R27 指出;当前调用点虽均在初始化后, 不+ // 留隐患)。+ function codexRemoteHasLiveTurn(hostId: string): boolean {+ return maker.listActiveSessions().some((s) =>s.remoteHostId === hostId &&s.agentKind === 'codex' &&(agentInputCoordinatorHolder?.hasActiveTurnForRewind(s.id) ?? false),);+ }setRemoteCodexLiveTurnChecker(codexRemoteHasLiveTurn);// turn 结束后补一次远端 MCP ensure (best-effort):live turn 期间被推迟的diff --git a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.tsindex f8b274df2a..60e02e251a 100644--- a/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts+++ b/apps/desktop/src/main/remote-ssh/__tests__/codex-remote-mcp.test.ts@@ -1207,3 +1207,59 @@ describe('codex-connector R24 regressions', () => {expect(readCmd).not.toContain('|| true');});});++describe('codex-connector R27 regressions', () => {+ it('runs cleanup-only strip when the bridge is unavailable but the host was previously injected (R27 P2)', async () => {+ const stale = renderManagedMcpBlock({ remotePort: 47921, serverNames: SERVERS, tokenFingerprint: 'fp-old' });+ let configContent = `model = "gpt-5.5"\n\n${stale}\n`;+ const execCmds: string[] = [];+ const host = {+ id: 'host-bridge-down-cleanup',+ exec: async (cmd: string, opts?: { input?: string }) => {+ execCmds.push(cmd);+ if (cmd.includes('cat "$CODEX_HOME/config.toml"')) {+ return { exitCode: 0, stdout: configContent, stderr: '' };+ }+ if (cmd.includes('base64 -d')) {+ const written = decodeWrittenConfig(opts?.input ? [opts.input] : []);+ if (written !== null) configContent = written;+ }+ return { exitCode: 0, stdout: 'ok', stderr: '' };+ },+ ensureRemoteForward: async (spec: { localHost: string; localPort: number; preferredRemotePort?: number }) => ({+ remotePort: spec.preferredRemotePort ?? 47921,+ close: async () => {},+ }),+ closeRemoteForward: async () => {},+ } as unknown as RemoteHost;++ expect((await ensureRemoteCodexMcpBridge(host, {+ ensureBridgeStarted: async () => ({ port: 38080, serverNames: SERVERS, bridgeInstanceId: 'bridge-1' }),+ hasLiveTurnOnHost: () => false,+ })).ok).toBe(true);+ expect(prefsOf('host-bridge-down-cleanup')?.appliedFingerprint).toBeTruthy();+ execCmds.length = 0;++ const result = await ensureRemoteCodexMcpBridge(host, {+ ensureBridgeStarted: async () => null,+ hasLiveTurnOnHost: () => false,+ });+ expect(result.ok).toBe(true);+ const joined = execCmds.join('\n');+ expect(joined).toContain('base64 -d');+ expect(joined).toContain('bootstrap');+ expect(configContent).not.toContain('cindy-remote-mcp');+ expect(prefsOf('host-bridge-down-cleanup')?.appliedFingerprint).toBeUndefined();+ });++ it('still returns bridge-unavailable when the bridge is down and there is nothing to clean', async () => {+ const { host, execCmds } = fakeHost('host-bridge-down-virgin', '');+ const result = await ensureRemoteCodexMcpBridge(host, {+ ensureBridgeStarted: async () => null,+ hasLiveTurnOnHost: () => false,+ });+ expect(result.ok).toBe(false);+ expect(result.reason).toBe('bridge-unavailable');+ expect(execCmds.join('\n')).not.toContain('bootstrap');+ });+});diff --git a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.tsindex 04ed853347..6c98c5c55e 100644--- a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts+++ b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts@@ -577,7 +577,19 @@ export function stripRemoteCodexMcpConfig(host: RemoteHost,deps?: { hasLiveTurnOnHost?: (hostId: string) => boolean },): Promise<void> {- return withHostSerial(host.id, async () => {+ return withHostSerial(host.id, () => doStripRemoteCodexMcpConfig(host, deps));+}++/**+ * stripRemoteCodexMcpConfig 的无锁核心 — 供已持有 per-host 串行锁的+ * ensure 路径直调 (R27 P2:bridge 不可用的 cleanup-only 分支;锁内再入+ * withHostSerial 会自死锁)。+ */+async function doStripRemoteCodexMcpConfig(+ host: RemoteHost,+ deps?: { hasLiveTurnOnHost?: (hostId: string) => boolean },+): Promise<void> {+ {try {if (deps?.hasLiveTurnOnHost?.(host.id)) return;const existing = await readRemoteConfig(host);@@ -605,7 +617,7 @@ export function stripRemoteCodexMcpConfig(error: err instanceof Error ? err.message : String(err),});}- });+ }}/**@@ -696,6 +708,25 @@ async function doEnsureRemoteCodexMcpBridge(try {const bridge = await deps.ensureBridgeStarted();if (!bridge) {+ // bridge 起不来时清理场景 (collab 全局禁用 / token 失效 / 曾注入过)+ // 不需要 bridge — 剥 config / 清 env 都是纯远端操作。直接走 strip+ // (R21 的无 bridge 变体), 否则 bridge 停机期间旧 config/env 残留,+ // 远端持续暴露死 MCP (codex-connector R27 P2)。从未注入过且无清理+ // 对象的维持 bridge-unavailable 早退。+ const applied = readPortPrefs()[host.id]?.appliedFingerprint;+ const collabEnabled = deps.isCollabEnabled?.() ?? true;+ const token = getRemoteMcpBridgeToken();+ if (applied || !collabEnabled || !token) {+ log.warn('bridge unavailable — running cleanup-only strip on remote host', {+ host: host.id,+ hadAppliedFingerprint: Boolean(applied),+ collabEnabled,+ hasToken: Boolean(token),+ });+ // 已在 per-host 串行锁内 (ensure 持锁), 直调无锁核心 (R27 P2 自死锁修正)。+ await doStripRemoteCodexMcpConfig(host, { hasLiveTurnOnHost: deps.hasLiveTurnOnHost });+ return { ok: true };+ }log.warn('remote MCP injection skipped: http bridge unavailable', { host: host.id });return { ok: false, reason: 'bridge-unavailable' };}diff --git a/packages/maker-cc-manager/__tests__/kill-pending-send.test.ts b/packages/maker-cc-manager/__tests__/kill-pending-send.test.tsindex 05f9021e9b..b89893a523 100644--- a/packages/maker-cc-manager/__tests__/kill-pending-send.test.ts+++ b/packages/maker-cc-manager/__tests__/kill-pending-send.test.ts@@ -61,3 +61,13 @@ describe('kill 终止窗口的 sendMessage 拒绝 (Greptile P1)', () => {expect(() => registry.sendMessage('s2', { text: 'hello' })).toThrowError(/SESSION_NOT_FOUND|no longer alive/);});});++ it('kill resolves only after the consume loop has fully exited (daemon-side settle guarantee)', async () => {+ // Greptile R27:kill RPC 返回时 session 必然不再 alive — client 不再需要+ // 用固定期限轮询猜终止状态 (buildBlockingFactory 的 loop 在 end 后还挂+ // 150ms, 同步等待必须覆盖它)。+ const registry = new SessionRegistry({ sdkQueryFactory: buildBlockingFactory() });+ const session = await registry.create({ sessionId: 's3', cwd: '/repo', model: 'm', env: {} });+ await registry.kill('s3');+ expect(session.alive).toBe(false);+ });diff --git a/packages/maker-cc-manager/src/session-registry.ts b/packages/maker-cc-manager/src/session-registry.tsindex c8f2a2ddbf..068c679a07 100644--- a/packages/maker-cc-manager/src/session-registry.ts+++ b/packages/maker-cc-manager/src/session-registry.ts@@ -159,6 +159,8 @@ interface SessionState {* 用户消息看似成功实则消失)。*/killing?: boolean;+ /** consume loop 的完成 promise — kill 同步等待它 (带看门狗)。 */+ consumeLoopDone?: Promise<void>;/** Currently attached client's notify function; null when no client is attached. */attachedNotify: AttachedNotify | null;/**@@ -502,7 +504,28 @@ export class SessionRegistry {});}s.inputQueue.end();- // Loop will discover end + remove from registry.+ // 同步等 consume loop 真正退出 (带 10s 看门狗):kill 返回时 session+ // 必然不再 alive — client 不再需要用「固定期限轮询 list」猜终止状态+ // (Greptile R27 confidence:固定期限的客户端等待没有 daemon 侧保证,+ // 慢退出场景反复失败)。看门狗超时 = consume loop 卡死 (daemon 病态),+ // 强制标记 dead 让恢复路径继续, 不让 kill RPC 永不返回。+ const KILL_SETTLE_WATCHDOG_MS = 10_000;+ if (s.consumeLoopDone) {+ const settled = await Promise.race([+ s.consumeLoopDone.then(() => true),+ new Promise<false>((resolve) => {+ const timer = setTimeout(() => resolve(false), KILL_SETTLE_WATCHDOG_MS);+ timer.unref?.();+ }),+ ]);+ if (!settled) {+ this.logger.warn('consume loop did not exit within watchdog after kill — marking dead forcibly', {+ sessionId,+ watchdogMs: KILL_SETTLE_WATCHDOG_MS,+ });+ s.alive = false;+ }+ }}/**@@ -631,7 +654,7 @@ export class SessionRegistry {/* ============================== private ============================== */private startConsumeLoop(session: SessionState): void {- void (async (): Promise<void> => {+ session.consumeLoopDone = (async (): Promise<void> => {try {for await (const message of session.query) {this.recordEvent(session, message);@@ -648,6 +671,8 @@ export class SessionRegistry {this.notifyClosed(session, 'error', (err as Error).message);}})();+ // 迟到失败不成 unhandled rejection (kill 的同步等待另有 race 兜底)。+ session.consumeLoopDone.catch(() => undefined);}private recordEvent(session: SessionState, message: unknown): void {