Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): require applied remote helper configuration
Chris8b6c0241beb2
diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.tsindex ed354d84f7..f432bcfba4 100644--- a/apps/desktop/src/main/maker-host/index.ts+++ b/apps/desktop/src/main/maker-host/index.ts@@ -236,6 +236,7 @@ import { cleanupComputerDriverSession } from '../mcp-integrations/computer.js';import { createPluginRegistry, resetPluginRegistry } from './plugins/index.js';import {withCodexMcpDiscoveryContext,+ getActiveCodexBridgeInstanceId,getActiveCodexBridgeServerNames,getCodexExtraSpawnConfig,registerCodexMcpThreadContext,@@ -1455,7 +1456,12 @@ export function getMaker(): Maker {codexProxyActive: false,codexBrowserUseAvailable: true,buildSessionMcpConfig: (instance: string) =>- buildRemoteCodexSessionMcpConfig(ctx.remoteHostId!, instance),+ buildRemoteCodexSessionMcpConfig(ctx.remoteHostId!, instance, {+ bridgeInstanceId: getActiveCodexBridgeInstanceId(),+ serverNames: getActiveCodexBridgeServerNames() ?? [],+ collabEnabled: pluginRegistry.isEnabled('collab'),+ makerMemoryEnabled: _maker?.makerMemory?.isEnabled() ?? false,+ }),};}const isControlPlane = ctx.hostPurpose === 'control-plane';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 bd6b422cf9..d71488ec50 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@@ -1354,6 +1354,11 @@ describe('codex-connector R27 regressions', () => {describe('remote Bot helper transport', () => {+ const helperConfigOpts = {+ bridgeInstanceId: 'helper-bridge', serverNames: ['cindy_helper'],+ collabEnabled: false, makerMemoryEnabled: false,+ };+it('keeps the shared helper disabled and binds per-thread URLs with collab and memory off', async () => {const { host, inputs } = fakeHost('host-helper-only', '');const ensured = await ensureRemoteCodexMcpBridge(host, {@@ -1363,16 +1368,53 @@ describe('remote Bot helper transport', () => {expect(ensured.ok).toBe(true);expect(decodeWrittenConfig(inputs)).toContain('[mcp_servers.cindy_helper]');expect(decodeWrittenConfig(inputs)).toContain('enabled = false');- const config = buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance');+ const config = buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance', helperConfigOpts);expect(config).toMatchObject({'mcp_servers.cindy_helper.url': 'http://127.0.0.1:47921/mcp/cindy_helper?instance=bot-instance','mcp_servers.cindy_helper.bearer_token_env_var': 'LIZI_MCP_TOKEN','mcp_servers.cindy_helper.enabled': false,});- expect(buildRemoteCodexSessionMcpConfig('missing-host', 'bot-instance')).toEqual({});+ expect(buildRemoteCodexSessionMcpConfig('missing-host', 'bot-instance', helperConfigOpts)).toEqual({});+ expect(buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance', { ...helperConfigOpts, serverNames: [] })).toEqual({});expect(hasPendingRemoteMcpDrift(host.id, {collabEnabled: false, makerMemoryEnabled: false, botHelperAvailable: true,token: 'test-persistent-token', bridgeInstanceId: 'helper-bridge',})).toBe(false);});++ it.each(['first-injection', 'helper-added', 'token', 'bridge'] as const)(+ 'withholds the helper during deferred %s and exposes it after bootstrap', async (drift) => {+ const { host, execCmds } = fakeHost(`host-helper-deferred-${drift}`, '');+ const bridge = { port: 38991, serverNames: [...SERVERS, 'cindy_helper'], bridgeInstanceId: 'helper-bridge' };+ const opts = () => ({ ...bridge, collabEnabled: true, makerMemoryEnabled: false });+ const deps = (live: boolean) => ({+ ensureBridgeStarted: async () => bridge,+ hasLiveTurnOnHost: () => live,+ });+ try {+ if (drift !== 'first-injection') {+ if (drift === 'helper-added') bridge.serverNames = [...SERVERS];+ expect((await ensureRemoteCodexMcpBridge(host, deps(false))).ok).toBe(true);+ }+ bridge.serverNames = [...SERVERS, 'cindy_helper'];+ if (drift === 'token') vi.mocked(getRemoteMcpBridgeToken).mockReturnValue('test-rotated-token');+ if (drift === 'bridge') bridge.bridgeInstanceId = 'helper-bridge-next';+ // Check both before and after ensure: a stale persisted fingerprint must+ // not be accepted even before the next SSH configuration write.+ expect(buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance', opts())).toEqual({});+ execCmds.length = 0;+ expect(await ensureRemoteCodexMcpBridge(host, deps(true)))+ .toMatchObject({ ok: true, daemonRebootstrapped: false });+ expect(execCmds.join('\n')).not.toContain('bootstrap');+ expect(buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance', opts())).toEqual({});++ expect(await ensureRemoteCodexMcpBridge(host, deps(false)))+ .toMatchObject({ ok: true, daemonRebootstrapped: true });+ expect(buildRemoteCodexSessionMcpConfig(host.id, 'bot-instance', opts()))+ .toHaveProperty('mcp_servers.cindy_helper.url', 'http://127.0.0.1:47921/mcp/cindy_helper?instance=bot-instance');+ } finally {+ vi.mocked(getRemoteMcpBridgeToken).mockReturnValue('test-persistent-token');+ }+ },+ );});diff --git a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.tsindex baf835b147..8c2e56acc8 100644--- a/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts+++ b/apps/desktop/src/main/remote-ssh/codex-remote-mcp.ts@@ -208,9 +208,29 @@ export function invalidateRemoteCodexMcpEndpointState(hostId: string): void {export function buildRemoteCodexSessionMcpConfig(hostId: string,sessionInstanceId: string,+ opts: {+ bridgeInstanceId: string | null;+ serverNames: string[];+ collabEnabled: boolean;+ makerMemoryEnabled: boolean;+ },): Record<string, unknown> {const prefs = readPortPrefs()[hostId];- if (!prefs?.appliedFingerprint || !sessionInstanceId) return {};+ const token = getRemoteMcpBridgeToken();+ if (!prefs?.appliedFingerprint || !sessionInstanceId || !token || !opts.bridgeInstanceId) return {};+ const serverNames = selectRemoteInjectableServerNames(opts.serverNames, {+ collabEnabled: opts.collabEnabled,+ memoryEnabled: opts.makerMemoryEnabled,+ botHelperEnabled: true,+ });+ // A written config is not proof that a busy daemon has loaded this generation.+ // Never combine a new route with its old token or pre-helper server config.+ if (!serverNames.includes(REMOTE_BOT_HELPER_SERVER_NAME) || prefs.appliedFingerprint !== computeRemoteMcpFingerprint({+ token,+ bridgeInstanceId: opts.bridgeInstanceId,+ remotePort: prefs.remotePort,+ serverNames,+ })) return {};return {[`mcp_servers.${REMOTE_BOT_HELPER_SERVER_NAME}.url`]: withMcpRouteIdentity(`http://127.0.0.1:${prefs.remotePort}/mcp/${REMOTE_BOT_HELPER_SERVER_NAME}`,diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 094e4ac6ac..de9e38c208 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -8544,6 +8544,42 @@ describe('CodexAgent MCP thread context hooks', () => {},);+ it.each([+ { resume: false, driftAfterRead: false }, { resume: true, driftAfterRead: false },+ { resume: false, driftAfterRead: true }, { resume: true, driftAfterRead: true },+ ])('does not start a remote Bot with unapplied helper config (resume=$resume, late=$driftAfterRead)', async ({ resume, driftAfterRead }) => {+ const agent = new CodexAgent(createDeps());+ let ready = false;+ let reads = 0;+ const host = installFakeHost(agent, (method) => method === Method.ConfigRead+ ? { config: { mcp_servers: { cindy_helper: { url: 'http://127.0.0.1:47921/mcp/cindy_helper' } } } }+ : undefined, {+ userAgent: 'mock-codex/0.145.0',+ // config/read can still contain an old daemon transport. Only the Host's+ // current instance-bound config proves its generation has been applied.+ buildSessionMcpConfig: () => ready || (driftAfterRead && reads++ === 0)+ ? { 'mcp_servers.cindy_helper.url': 'http://127.0.0.1:47921/mcp/cindy_helper?instance=remote-instance' }+ : {},+ });+ const opts = {+ sessionId: 'remote-bot', sessionInstanceId: 'remote-instance', remoteHostId: 'ssh-host', workingDir: '/bot', model: 'gpt-5.4',+ ...(resume ? { resumeSessionId: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' } : {}),+ botRuntimeProfile: {+ botId: 'bot-1', profileVersion: 1,+ skillPolicy: { mode: 'allowlist' as const, configured: [], catalog: [] },+ mcpPolicy: { mode: 'allowlist' as const, configured: [], catalog: [] },+ toolsetPolicy: { mode: 'allowlist' as const, configured: [], catalog: [] },+ },+ };+ await expect(agent.startSession(opts)).rejects.toThrow('Remote Codex Bot tools are not ready');+ expect(host.request.mock.calls.some(([method]) =>+ method === Method.ThreadStart || method === Method.ThreadResume || method === Method.TurnStart)).toBe(false);+ expect(host.request.mock.calls.some(([method]) => method === Method.TurnInterrupt)).toBe(false);+ ready = true;+ const handle = await agent.startSession(opts);+ await handle.close();+ });+it('applies instance-bound MCP URLs to both thread/start and thread/resume', async () => {const buildConfig = (sessionInstanceId?: string) => ({'mcp_servers.cindy_ghosts.url': `http://127.0.0.1:47100/mcp/cindy_ghosts?instance=${sessionInstanceId}`,diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex 8bdabda3b8..9cb7cee8a4 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -4792,6 +4792,14 @@ export class CodexAgent extends BaseAgent {);}}+ const readSessionMcpConfig = (): Record<string, unknown> => {+ const config = host.getSessionMcpConfig(opts.sessionInstanceId);+ if (opts.remoteHostId && opts.botRuntimeProfile?.mcpPolicy+ && typeof config['mcp_servers.cindy_helper.url'] !== 'string') {+ throw new Error('Remote Codex Bot tools are not ready. Retry after the active remote task finishes.');+ }+ return config;+ };let botMcpConfig: Record<string, unknown> = {};if (!reviewMode && opts.botRuntimeProfile?.mcpPolicy) {try {@@ -4802,7 +4810,7 @@ export class CodexAgent extends BaseAgent {assertCurrentHost('Bot MCP configuration');const transports = new Set(Object.entries(asRecord(asRecord(response.config).mcp_servers)).filter(([, value]) => hasCodexMcpTransport(value)).map(([name]) => name));- for (const [key, value] of Object.entries(host.getSessionMcpConfig(opts.sessionInstanceId))) {+ for (const [key, value] of Object.entries(readSessionMcpConfig())) {const match = /^mcp_servers\.([A-Za-z0-9_-]+)\.(?:url|command)$/.exec(key);if (match && typeof value === 'string' && value.trim()) transports.add(match[1]);}@@ -5590,7 +5598,7 @@ export class CodexAgent extends BaseAgent {const threadContextWindow = effectiveThreadContextWindow(contextLimit);const config = {// Apply transport defaults before the per-session Bot capability policy.- ...(reviewMode ? {} : host.getSessionMcpConfig(opts.sessionInstanceId)),+ ...(reviewMode ? {} : readSessionMcpConfig()),...capabilityRoutingConfig,...customProviderThreadConfig,// Bot memory and delegation belong to its Cindy Profile and Session