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(desktop): 修复 codex 0.145.0 下 node_repl 禁用覆写导致 Codex 会话无法创建

daviddfe3cbb2aa0a
diff --git a/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts b/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
index a38996c97c..fae878ed40 100644
--- a/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/capability-routing.test.ts
@@ -70,14 +70,30 @@ describe('buildDesktopCapabilityRoutingPolicy', () => {
'chrome@openai-bundled',
]);
expect(routes.every((route) => route.replacement === undefined)).toBe(true);
- const nodeReplRoute = policy.overrides.find(
+ // The unprovisioned spawn config has no node_repl entry; a per-thread
+ // `mcp_servers.node_repl.enabled=false` on codex 0.145.0 would synthesize
+ // a transport-less entry and fail every thread/start with "invalid
+ // transport" (-32600). The route must be absent, not merely unreplaced.
+ expect(policy.overrides.some(
(route) => route.source.surface === 'mcp' && route.source.id === 'node_repl',
- );
- expect(nodeReplRoute).toMatchObject({
- invocation: 'disabled',
- source: expect.objectContaining({ surface: 'mcp', id: 'node_repl' }),
+ )).toBe(false);
+ });
+
+ it('drops the node_repl MCP route when Cindy Browser owns the capability but the companion was not provisioned', () => {
+ const policy = buildDesktopCapabilityRoutingPolicy({
+ cindyBrowserEnabled: true,
+ codexBrowserUseAvailable: false,
});
- expect(nodeReplRoute?.replacement).toBeUndefined();
+
+ expect(policy.overrides.some(
+ (route) => route.source.surface === 'mcp' && route.source.id === 'node_repl',
+ )).toBe(false);
+ // The plugin-wide disable does not synthesize an mcp_servers entry and
+ // must stay in force.
+ expect(policy.overrides).toContainEqual(expect.objectContaining({
+ invocation: 'disabled',
+ source: expect.objectContaining({ surface: 'plugin', id: 'chrome@openai-bundled' }),
+ }));
});
it('keeps remote Chrome available without claiming the local Cindy Browser replacement', () => {
diff --git a/apps/desktop/src/main/maker-host/__tests__/codex-browser-companion.test.ts b/apps/desktop/src/main/maker-host/__tests__/codex-browser-companion.test.ts
index 318e584c6a..fe395e3695 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codex-browser-companion.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codex-browser-companion.test.ts
@@ -230,6 +230,41 @@ describe('prepareCodexBrowserCompanion', () => {
arch: 'x64',
});
+ expect(companion).toMatchObject({
+ status: 'unavailable',
+ reason: 'platform_unsupported',
+ });
+ // codex 0.145.0 rejects a config whose node_repl entry has no complete
+ // transport ("invalid transport" → child exit 1). With no runnable entry
+ // in the isolated config there is nothing to disable, so the fail-closed
+ // result must not synthesize one via `-c` overrides.
+ expect(resolveCodexBrowserCompanionSpawnConfig(companion)).toEqual({
+ codexBrowserUseAvailable: false,
+ extraArgs: [],
+ });
+ });
+
+ it('fails closed against a runnable node_repl entry in the isolated config', async () => {
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'codex-browser-companion-'));
+ tempDirs.push(root);
+ const codexHome = path.join(root, 'cindy-codex-home');
+ await fs.mkdir(codexHome, { recursive: true });
+ await fs.writeFile(
+ path.join(codexHome, 'config.toml'),
+ [
+ '[mcp_servers.node_repl]',
+ 'command = "/tmp/untrusted/node_repl"',
+ '',
+ ].join('\n'),
+ 'utf8',
+ );
+
+ const companion = await prepareCodexBrowserCompanion({
+ codexHome,
+ platform: 'win32',
+ arch: 'x64',
+ });
+
expect(companion).toMatchObject({
status: 'unavailable',
reason: 'platform_unsupported',
@@ -240,6 +275,41 @@ describe('prepareCodexBrowserCompanion', () => {
});
});
+ it('does not complete a transport-less node_repl entry into a fatal override', async () => {
+ // A `-c mcp_servers.node_repl.*` override on a transport-less entry turns
+ // codex's survivable "Invalid configuration; using defaults" degradation
+ // into a fatal config load error. Codex already refuses to run such an
+ // entry, so no override may be emitted.
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'codex-browser-companion-'));
+ tempDirs.push(root);
+ const codexHome = path.join(root, 'cindy-codex-home');
+ await fs.mkdir(codexHome, { recursive: true });
+ await fs.writeFile(
+ path.join(codexHome, 'config.toml'),
+ [
+ '[mcp_servers.node_repl.env]',
+ 'NODE_OPTIONS = "--require=/tmp/untrusted.cjs"',
+ '',
+ ].join('\n'),
+ 'utf8',
+ );
+
+ const companion = await prepareCodexBrowserCompanion({
+ codexHome,
+ platform: 'win32',
+ arch: 'x64',
+ });
+
+ expect(companion).toMatchObject({
+ status: 'unavailable',
+ reason: 'platform_unsupported',
+ });
+ expect(resolveCodexBrowserCompanionSpawnConfig(companion)).toEqual({
+ codexBrowserUseAvailable: false,
+ extraArgs: [],
+ });
+ });
+
it('keeps the control-plane host neutral when no companion preflight applies', () => {
expect(resolveCodexBrowserCompanionSpawnConfig(null)).toEqual({
codexBrowserUseAvailable: false,
diff --git a/apps/desktop/src/main/maker-host/capability-routing.ts b/apps/desktop/src/main/maker-host/capability-routing.ts
index 1ee6373cd3..ff8bec3f18 100644
--- a/apps/desktop/src/main/maker-host/capability-routing.ts
+++ b/apps/desktop/src/main/maker-host/capability-routing.ts
@@ -187,6 +187,28 @@ const CODEX_CHROME_USE_UNAVAILABLE_OVERRIDES = CODEX_CHROME_USE_OVERRIDES.map(
}),
) satisfies CapabilityRoutingPolicy['overrides'];
+/**
+ * codex 0.145.0's config loader requires every `mcp_servers` entry to carry a
+ * complete transport even when disabled, and thread/start validates per-thread
+ * overrides against the same loader. The spawn config defines a node_repl
+ * entry only when the verified Browser companion was provisioned; without it,
+ * the per-thread `mcp_servers.node_repl.enabled=false` override synthesizes a
+ * transport-less entry and every thread/start fails with "invalid transport"
+ * (-32600). Emit the node_repl MCP route only when the entry exists — when it
+ * does not, the capability is already absent and fail-closed holds without
+ * the directive.
+ */
+function withoutUnprovisionedNodeReplRoute(
+ overrides: readonly CapabilityRouteOverride[],
+ codexBrowserUseAvailable: boolean | undefined,
+): CapabilityRouteOverride[] {
+ if (codexBrowserUseAvailable === true) return [...overrides];
+ return overrides.filter(
+ (override) =>
+ !(override.source.surface === 'mcp' && override.source.id === 'node_repl'),
+ );
+}
+
/** Freeze workspace-scoped capability arbitration for one new runtime. */
export function buildDesktopCapabilityRoutingPolicy(opts: {
/** Whether the current Codex bridge exposes Cindy's Computer Use host. */
@@ -208,9 +230,15 @@ export function buildDesktopCapabilityRoutingPolicy(opts: {
const chromeOverrides = cindyBrowserEnabled === undefined
? []
: cindyBrowserEnabled
- ? CODEX_CHROME_USE_OVERRIDES
+ ? withoutUnprovisionedNodeReplRoute(
+ CODEX_CHROME_USE_OVERRIDES,
+ opts.codexBrowserUseAvailable,
+ )
: opts.codexBrowserUseAvailable === false
- ? CODEX_CHROME_USE_UNAVAILABLE_OVERRIDES
+ ? withoutUnprovisionedNodeReplRoute(
+ CODEX_CHROME_USE_UNAVAILABLE_OVERRIDES,
+ opts.codexBrowserUseAvailable,
+ )
: [];
return {
overrides: [
diff --git a/apps/desktop/src/main/maker-host/codex-browser-companion.ts b/apps/desktop/src/main/maker-host/codex-browser-companion.ts
index d2d8ae899c..8bfb347960 100644
--- a/apps/desktop/src/main/maker-host/codex-browser-companion.ts
+++ b/apps/desktop/src/main/maker-host/codex-browser-companion.ts
@@ -45,7 +45,8 @@ export type CodexBrowserCompanionResult =
}
| {
status: 'unavailable';
- extraArgs: [];
+ /** Fail-closed spawn overrides prepared for this result (may be empty). */
+ extraArgs: string[];
reason: CodexBrowserCompanionUnavailableReason;
detail: string;
};
@@ -58,7 +59,8 @@ export type CodexBrowserCompanionSpawnConfig = {
/**
* Only a verified companion may enable Cindy's privileged node_repl bridge.
* A null result belongs to the control-plane host and must remain neutral;
- * every concrete unavailable result fails closed for the local app-server.
+ * every concrete unavailable result fails closed for the local app-server
+ * (its extraArgs carry the disable override when one is applicable).
*/
export function resolveCodexBrowserCompanionSpawnConfig(
companion: CodexBrowserCompanionResult | null,
@@ -66,12 +68,9 @@ export function resolveCodexBrowserCompanionSpawnConfig(
if (companion === null) {
return { codexBrowserUseAvailable: false, extraArgs: [] };
}
- if (companion.status === 'ready') {
- return { codexBrowserUseAvailable: true, extraArgs: companion.extraArgs };
- }
return {
- codexBrowserUseAvailable: false,
- extraArgs: ['-c', 'mcp_servers.node_repl.enabled=false'],
+ codexBrowserUseAvailable: companion.status === 'ready',
+ extraArgs: companion.extraArgs,
};
}
@@ -593,17 +592,55 @@ async function inspectCodexBrowserCompanion(
};
}
+/**
+ * Codex 0.145.0's config loader requires every `mcp_servers` entry to carry a
+ * complete transport even when disabled: a bare
+ * `-c mcp_servers.node_repl.enabled=false` on a config whose node_repl entry
+ * is missing (or transport-less) synthesizes/completes an invalid entry and
+ * kills the app-server at spawn ("invalid transport", child exit 1; verified
+ * against codex-cli 0.145.0). Only emit the fail-closed disable when the
+ * isolated config defines the entry with a real transport — the override then
+ * deep-merges onto that transport, which the loader accepts. In every other
+ * case codex itself refuses to load a runnable node_repl from that config
+ * (absent entry, or "Invalid configuration; using defaults"), so fail-closed
+ * already holds without an override.
+ */
+async function nodeReplFailClosedOverrideArgs(codexHome: string): Promise<string[]> {
+ try {
+ const parsed = parseToml(
+ await fsp.readFile(path.join(codexHome, 'config.toml'), 'utf8'),
+ ) as Record<string, unknown>;
+ const mcpServers = isRecord(parsed.mcp_servers) ? parsed.mcp_servers : {};
+ const nodeRepl = mcpServers.node_repl;
+ if (
+ isRecord(nodeRepl)
+ && (typeof nodeRepl.command === 'string' || typeof nodeRepl.url === 'string')
+ ) {
+ return ['-c', 'mcp_servers.node_repl.enabled=false'];
+ }
+ } catch {
+ // Missing or unparseable isolated config: codex cannot load a node_repl
+ // entry from it either, so there is nothing to fail closed against.
+ }
+ return [];
+}
+
export async function prepareCodexBrowserCompanion(
opts: PrepareCodexBrowserCompanionOptions,
): Promise<CodexBrowserCompanionResult> {
+ let result: CodexBrowserCompanionResult;
try {
- return await inspectCodexBrowserCompanion(opts);
+ result = await inspectCodexBrowserCompanion(opts);
} catch (error) {
- return unavailable(
+ result = unavailable(
'descriptor_invalid',
`browser companion preflight failed: ${error instanceof Error ? error.message : String(error)}`,
);
}
+ if (result.status === 'unavailable') {
+ return { ...result, extraArgs: await nodeReplFailClosedOverrideArgs(opts.codexHome) };
+ }
+ return result;
}
/**