diff --git a/docs/getting-started/client-configuration.md b/docs/getting-started/client-configuration.md index 7c46e11b113..d680b2c3451 100644 --- a/docs/getting-started/client-configuration.md +++ b/docs/getting-started/client-configuration.md @@ -601,7 +601,10 @@ registration. Codex's server and per-tool approval policies are user choices. Setup patches REA's connection fields in the selected file and retains other server settings, including `default_tools_approval_mode`, nested `[mcp_servers.rea.tools.]` tables, tool allow/deny lists, and unrecognized -client settings. Doctor accepts Codex's per-tool policy tables. Known malformed +client settings. Doctor also checks the working directory type, the bootstrap flags `required` and +`supports_parallel_tool_calls` and the `env_vars` list. Each list item can be a +variable name or a table with `name` and optional `source` (`local` or +`remote`). Setup retains these references without expanding them. Known malformed policy values block setup before it writes the configuration or a backup, and the diagnostic identifies the setting to repair. See the [Codex configuration reference](https://developers.openai.com/codex/config-reference/) @@ -614,13 +617,13 @@ REA was invoked through another symlink. Setup also retains that spelling when another field, such as an invalid timeout, needs repair. Unresolved identity does not prove equivalence. -| Settings | Setup ownership | -| ------------------------------------------- | --------------------------------------------------------------------------------------- | -| Launcher, transport and activation | Refreshes the REA stdio connection and enables it. | -| Explicit server environment | Preserves configured overrides and merges selected provider settings. | -| Codex timeouts | Retains positive values; repairs missing or invalid values to recommended REA defaults. | -| Codex approval policies and tool selections | Retains caller choices; refuses known malformed values. | -| Unrelated or future server settings | Retains their parsed values. | +| Settings | Setup ownership | +| ------------------------------------------- | --------------------------------------------------------------------------------- | +| Launcher, transport and activation | Refreshes the REA stdio connection and enables it. | +| Explicit server environment | Preserves configured overrides and merges selected provider settings. | +| Codex timeouts | Keeps positive deadlines, defaults missing ones and flags malformed milliseconds. | +| Codex approval policies and tool selections | Retains caller choices; refuses known malformed values. | +| Unrelated or future server settings | Retains their parsed values. | Dry-run applies the same policy validation and writes no files. A successful refresh keeps an exact recovery snapshot of the original configuration; @@ -631,8 +634,10 @@ configuration alignment; it does not prove that a particular client or fork successfully exposes every REA tool. Codex treats an unset or empty `CODEX_HOME` as `~/.codex`. Its MCP server -registration supports `startup_timeout_sec` for connection initialization and -`tool_timeout_sec` for each tool call. New REA registrations use a 30-second +registration accepts `startup_timeout_sec` or the integer `startup_timeout_ms` +for connection initialization and `tool_timeout_sec` for each tool call. +When both startup settings exist, Codex uses seconds. Setup preserves a +positive milliseconds-only timeout in its original unit. New REA registrations use a 30-second startup timeout and a tool timeout derived from the known provider allowance plus 120 seconds of operation headroom. This yields 450 seconds for the default Ghidra allowance; an explicit Ghidra startup timeout of 2700 @@ -662,6 +667,45 @@ These values are client-side deadlines, so increase them in `~/.codex/config.tom workload needs more time. Devin honors `XDG_CONFIG_HOME` for its `devin/mcp_config.json` on non-Windows systems. +### ChatGPT Work on macOS + +If Work shows tools outside the families you selected, check the REA entry in +the trusted project's `.codex/config.toml`. On macOS build 30866, Work started +REA without the literal `REA_MCP_TOOL_FAMILIES` value from +`[mcp_servers.rea.env]`, so REA advertised its default catalog. The Codex CLI +bundled with that app delivered the same setting correctly. + +For a non-sensitive family selector, replace the existing REA entry's +`command` and `args` with the launcher below. Substitute the absolute Node and +REA paths from your registration, then open a fresh Work window in that project. + +```toml +[mcp_servers.rea] +command = "/usr/bin/env" +args = [ + "REA_MCP_TOOL_FAMILIES=electron,javascript-runtime", + "/absolute/path/to/node", + "/absolute/path/to/rea.mjs", + "mcp", +] +``` + +REA treats this wrapper as manually managed. Doctor reports foreign launcher +ownership and setup leaves the entry alone. Command arguments are visible to +local process inspection, so keep credentials out of the launcher. + +If the server is missing altogether, check its `env_vars` list. On the same +build, a server with `env_vars = [{ name = "LANG", source = "local" }]` did +not finish initialization. Using `env_vars = ["LANG"]` for that local variable +allowed it to start. The bundled CLI accepted both spellings. +[Literal environment report](https://github.com/openai/codex/issues/64622) · +[Structured environment report](https://github.com/openai/codex/issues/64625) + +Work returned a final answer in all three paired checks, including the runs +with a missing server. If you're reporting an “Error in message stream,” +include the desktop build and which configuration produced the error in a fresh +window. [Desktop test results](https://github.com/morluto/rea/issues/15077#issuecomment-7259889703) + ### Codex with Moonshot or Kimi models An older REA input containing acyclic local references was rejected by a diff --git a/src/application/ClientConfigurationToml.ts b/src/application/ClientConfigurationToml.ts index 076d5993525..ec84abe18da 100644 --- a/src/application/ClientConfigurationToml.ts +++ b/src/application/ClientConfigurationToml.ts @@ -1,4 +1,4 @@ -import { parse as parseToml, stringify as stringifyToml } from "smol-toml"; +import { parse as parseToml } from "smol-toml"; import { PRODUCT_IDENTITY } from "../identity.js"; import { clientConfigurationRecordSchema, @@ -10,12 +10,11 @@ const INT64_MIN = -(2n ** 63n); const INT64_MAX = 2n ** 63n - 1n; /** - * Parse client TOML with TOML 1.0's signed 64-bit integer contract. Integers - * beyond JavaScript's safe range stay exact as bigint; values outside Int64, - * which Codex rejects, are malformed. + * Keep TOML integers distinct from integral floats: native client fields can + * require an integer, and a refresh must preserve the types of caller settings. */ export const parseClientToml = (text: string): Record => { - const parsed = parseToml(text, { integersAsBigInt: "asNeeded" }); + const parsed = parseToml(text, { integersAsBigInt: true }); const pending: unknown[] = [parsed]; for (let value = pending.pop(); value !== undefined; value = pending.pop()) { if (typeof value === "bigint") { @@ -393,10 +392,7 @@ const tomlInlineValue = (value: unknown): string => { if (value === Infinity) return "inf"; if (value === -Infinity) return "-inf"; if (Object.is(value, -0)) return "-0.0"; - // A float outside the safe integer range must not become an Int64 token. - return Number.isInteger(value) && !Number.isSafeInteger(value) - ? value.toFixed(1) - : String(value); + return Number.isInteger(value) ? value.toFixed(1) : String(value); } // TomlDate overrides toISOString to retain local date/time and offset kinds. if (value instanceof Date) return value.toISOString(); @@ -414,6 +410,30 @@ const tomlInlineValue = (value: unknown): string => { throw new TypeError("Unsupported TOML inline value"); }; +/** Emit table headers separately so every assigned value uses the same TOML + * scalar writer, including signed zero in nested arrays and inline tables. */ +const stringifyToml = (table: object, path = ""): string => { + const fields: string[] = []; + const sections: string[] = []; + for (const [name, value] of Object.entries(table) as [string, unknown][]) { + const key = tomlInlineKey(name); + if ( + value !== null && + typeof value === "object" && + !Array.isArray(value) && + !(value instanceof Date) + ) + sections.push(stringifyToml(value, path === "" ? key : `${path}.${key}`)); + else fields.push(`${key} = ${tomlInlineValue(value)}`); + } + // Leave parents with only subtables implicit. The surrounding document may + // already declare the parent of a section being inserted. + if (path !== "" && (fields.length > 0 || sections.length === 0)) + fields.unshift(`[${path}]`); + if (fields.length > 0) sections.unshift(`${fields.join("\n")}\n`); + return sections.join("\n"); +}; + interface InlinePair { readonly leading: string; readonly text: string; diff --git a/src/application/ClientRegistration.ts b/src/application/ClientRegistration.ts index 21e59a0459f..9adb2575cce 100644 --- a/src/application/ClientRegistration.ts +++ b/src/application/ClientRegistration.ts @@ -118,13 +118,26 @@ const codexApprovalModeSchema = z.enum(["auto", "prompt", "writes", "approve"]); const codexToolPolicySchema = z .object({ approval_mode: codexApprovalModeSchema.optional(), - output_token_limit: z - .union([z.number().int().positive(), z.bigint().positive()]) - .optional(), + output_token_limit: z.bigint().positive().optional(), }) .passthrough(); const codexPolicySchema = z .object({ + startup_timeout_ms: z.bigint().nonnegative().optional(), + cwd: z.string().optional(), + required: z.boolean().optional(), + supports_parallel_tool_calls: z.boolean().optional(), + env_vars: z + .array( + z.union([ + z.string(), + z.strictObject({ + name: z.string(), + source: z.enum(["local", "remote"]).optional(), + }), + ]), + ) + .optional(), default_tools_approval_mode: codexApprovalModeSchema.optional(), enabled_tools: z.array(z.string()).optional(), disabled_tools: z.array(z.string()).optional(), @@ -554,14 +567,18 @@ export const refreshClientRegistration = ( existing.enable === false ) registration.enable = false; - if (client.name === "codex" || client.name === "grok_build") - registration.startup_timeout_sec = - positiveTimeout(existing.startup_timeout_sec) ?? - MCP_STARTUP_POLICY.codexStartupTimeoutSeconds; + if ( + (client.name === "codex" && !hasPositiveCodexStartupTimeout(existing)) || + (client.name === "grok_build" && + positiveTimeout(existing.startup_timeout_sec) === undefined) + ) + registration.startup_timeout_sec = BigInt( + MCP_STARTUP_POLICY.codexStartupTimeoutSeconds, + ); if (client.name === "codex") registration.tool_timeout_sec = positiveTimeout(existing.tool_timeout_sec) ?? - recommendedMcpToolTimeoutSeconds(timeoutInputs); + BigInt(recommendedMcpToolTimeoutSeconds(timeoutInputs)); if (client.name === "kimi") { registration.startupTimeoutMs = positiveTimeout(existing.startupTimeoutMs) ?? @@ -574,9 +591,16 @@ export const refreshClientRegistration = ( }; const positiveTimeout = (value: unknown): number | bigint | undefined => { - // TOML keeps integers beyond the safe Number range exact as bigint. + // TOML integers and floating-point values have distinct native types. if (typeof value === "bigint") return value > 0n ? value : undefined; return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined; }; + +/** Codex selects seconds when present, otherwise milliseconds. */ +export const hasPositiveCodexStartupTimeout = ( + entry: Readonly>, +): boolean => + positiveTimeout(entry.startup_timeout_sec ?? entry.startup_timeout_ms) !== + undefined; diff --git a/src/application/ClientRegistrationStatus.ts b/src/application/ClientRegistrationStatus.ts index c99ffad3c4e..2bfe7d30ff6 100644 --- a/src/application/ClientRegistrationStatus.ts +++ b/src/application/ClientRegistrationStatus.ts @@ -53,6 +53,7 @@ import type { ArtifactResourceScope } from "../resources/index.js"; import { clientRegistrationActivation, + hasPositiveCodexStartupTimeout, parseClientRegistrationPolicy, parseClientRegistrationLauncher, clientRegistrationOwnershipRemediation, @@ -603,7 +604,7 @@ const registrationAligned = ({ return "stale"; if ( client.name === "codex" && - (registration.startup_timeout_sec === undefined || + (!hasPositiveCodexStartupTimeout(registration) || registration.tool_timeout_sec === undefined) ) return "stale"; @@ -826,7 +827,7 @@ const timeoutAdvisory = ( return "The effective timeout is unknown because toolCallTimeoutMs is a caller-owned Cordis expression."; const providerAllowance = mcpProviderDeadlineAllowanceMs(timeoutInputs); const inMilliseconds = client.name === "kimi" || client.name === "dsh"; - // A bigint is beyond the safe Number range, so rounding cannot cross the allowance. + // Values too large for exact Number conversion already exceed the allowance. const toolTimeoutMs = Number(toolTimeout) * (inMilliseconds ? 1 : 1000); const batchScope = timeoutInputs.ghidraDecompileTimeoutMs !== undefined && diff --git a/tests/acceptance/setup/codexToolPolicySetup.test.ts b/tests/acceptance/setup/codexToolPolicySetup.test.ts index a7bdb4754b4..59b45772ec1 100644 --- a/tests/acceptance/setup/codexToolPolicySetup.test.ts +++ b/tests/acceptance/setup/codexToolPolicySetup.test.ts @@ -83,6 +83,7 @@ cliTest( const configured = await readFile(config, "utf8"); expect(configured).toContain("# retained root comment"); expect(configured).toContain("# caller approval"); + expect(configured).not.toContain("startup_timeout_sec"); expect( parseToml(configured, { integersAsBigInt: "asNeeded" }), ).toMatchObject({ @@ -91,7 +92,7 @@ cliTest( other: { command: "other" }, rea: { ...codexToolPolicy, - startup_timeout_sec: 19, + startup_timeout_ms: 75500, tool_timeout_sec: 999, env: { CALLER_SETTING: "kept exactly", diff --git a/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts b/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts index d44d8190f59..53389b03b9f 100644 --- a/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts +++ b/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts @@ -712,7 +712,7 @@ cliTest( "codex", join(codexHome, "config.toml"), "toml", - { tool_timeout_sec: 3021 }, + { tool_timeout_sec: 3021n }, ], [ "kimi", @@ -937,7 +937,7 @@ XDG_CONFIG_HOME = ${JSON.stringify(clientRoot)} "rea", ); expect(registration).toMatchObject({ - tool_timeout_sec: 1920, + tool_timeout_sec: 1920n, env: { XDG_CONFIG_HOME: clientRoot }, }); expect((await run(["doctor"])).json).toMatchObject({ @@ -1008,7 +1008,7 @@ cliTest( "rea", ); expect.soft(registration).toMatchObject({ - tool_timeout_sec: 1020, + tool_timeout_sec: 1020n, env: { XDG_CONFIG_HOME: configHome }, }); const launcher = z @@ -1145,7 +1145,7 @@ for (const [client, provider] of [ ), ).toMatchObject({ ...(client === "codex" - ? { tool_timeout_sec: 1921 } + ? { tool_timeout_sec: 1921n } : { toolTimeoutMs: 1_920_001 }), env: { REA_ANALYSIS_PROVIDER: provider, REA_IDA_MCP_CONFIG: idaConfig }, }); diff --git a/tests/boundary/filesystem/clientLifecycle.test.ts b/tests/boundary/filesystem/clientLifecycle.test.ts index e495ede3b52..92b8e2cf282 100644 --- a/tests/boundary/filesystem/clientLifecycle.test.ts +++ b/tests/boundary/filesystem/clientLifecycle.test.ts @@ -1109,7 +1109,7 @@ describe("Grok Build scalar and nested values", () => { }); }); - it("removes a nested array inside a Grok REA table", async () => { + it("removes Grok nested settings on uninstall and retains them on refresh", async () => { const home = await createTestTempDirectory("rea-grok-nested-array-"); const configPath = join(home, ".grok/config.toml"); await mkdir(dirname(configPath), { recursive: true }); @@ -1131,7 +1131,6 @@ describe("Grok Build scalar and nested values", () => { ); const removed = await readFile(configPath, "utf8"); expect(removed).toContain("[privacy]"); - expect(removed).not.toContain("[1, 2]"); expect(parseToml(removed)).toMatchObject({ privacy: { share: false } }); expect(parseToml(removed)).not.toHaveProperty("mcp_servers.rea"); @@ -1150,11 +1149,15 @@ describe("Grok Build scalar and nested values", () => { ).toMatchObject({ status: "configured" }); const configured = await readFile(configPath, "utf8"); expect(configured).toContain("[privacy]"); - expect(configured).not.toContain("[1, 2]"); expect(parseToml(configured)).toMatchObject({ privacy: { share: false }, mcp_servers: { - rea: { command: "rea", args: ["mcp"], startup_timeout_sec: 30 }, + rea: { + command: "rea", + args: ["mcp"], + extra: [[1, 2]], + startup_timeout_sec: 30, + }, }, }); }); diff --git a/tests/boundary/filesystem/clientRegistrationRefresh.test.ts b/tests/boundary/filesystem/clientRegistrationRefresh.test.ts index 270d7cbe511..3ca2aab3168 100644 --- a/tests/boundary/filesystem/clientRegistrationRefresh.test.ts +++ b/tests/boundary/filesystem/clientRegistrationRefresh.test.ts @@ -1,9 +1,8 @@ -import { expectResultValue } from "../../support/expectResultValue.js"; +import { parse as parseToml } from "smol-toml"; import { readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { expect, it } from "vitest"; import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js"; -import { parseClientConfiguration } from "../../../src/application/ClientConfigurationDocument.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { supportedClientRegistrationProfile } from "../../fixtures/clientRegistrationProfile.js"; @@ -24,15 +23,16 @@ it.each([90, 120])( await configureClientConfiguration(client, {}, ["rea", "mcp"]), ).toMatchObject({ status: "configured" }); const refreshed = await readFile(configPath, "utf8"); - expect( - expectResultValue(parseClientConfiguration(refreshed, "grok")).servers - .rea, - ).toMatchObject({ - command: "rea", - args: ["mcp"], - startup_timeout_sec: timeout, - custom_policy: "caller", - env: { PATH: "/caller/bin:/usr/bin", CUSTOM: "preserved" }, + expect(parseToml(refreshed, { integersAsBigInt: true })).toMatchObject({ + mcp_servers: { + rea: { + command: "rea", + args: ["mcp"], + startup_timeout_sec: BigInt(timeout), + custom_policy: "caller", + env: { PATH: "/caller/bin:/usr/bin", CUSTOM: "preserved" }, + }, + }, }); expect(await readFile(`${configPath}.rea.backup`, "utf8")).toBe(source); expect( diff --git a/tests/boundary/filesystem/codexClientPolicy.test.ts b/tests/boundary/filesystem/codexClientPolicy.test.ts index d00738f8950..719c3ebddf1 100644 --- a/tests/boundary/filesystem/codexClientPolicy.test.ts +++ b/tests/boundary/filesystem/codexClientPolicy.test.ts @@ -57,18 +57,20 @@ it.each(["tables", "inline table"] as const)( ), ).toMatchObject({ status: "configured" }); const configured = await readFile(configPath, "utf8"); - expect( - parseToml(configured, { integersAsBigInt: "asNeeded" }), - ).toMatchObject({ + expect(parseToml(configured, { integersAsBigInt: true })).toMatchObject({ mcp_servers: { rea: { ...codexToolPolicy, - startup_timeout_sec: 19, - tool_timeout_sec: 999, + startup_timeout_ms: 75500n, + ...(layout === "inline table" + ? { startup_timeout_sec: 19.5, tool_timeout_sec: 999.5 } + : { tool_timeout_sec: 999n }), env: { CALLER_SETTING: "kept exactly", ...overrides }, }, }, }); + if (layout === "tables") + expect(configured).not.toContain("startup_timeout_sec"); expect(await status()).toMatchObject({ state: "aligned" }); expect( await configureClientConfiguration( @@ -95,6 +97,19 @@ it.each([ ], ['default_tools_approval_mode = "unknown"', "default_tools_approval_mode"], ["enabled_tools = true", "enabled_tools"], + ['env_vars = "LANG"', "env_vars"], + ['env_vars = [{name = "LANG", source = "sideways"}]', "env_vars"], + ['env_vars = [{source = "local"}]', "env_vars"], + ['env_vars = [{name = "LANG", ignored = true}]', "env_vars"], + ['required = "yes"', "required"], + ["cwd = 5", "cwd"], + ["supports_parallel_tool_calls = 2", "supports_parallel_tool_calls"], + ["startup_timeout_ms = -1", "startup_timeout_ms"], + ["startup_timeout_ms = 75500.0", "startup_timeout_ms"], + [ + "tools.binary_session.output_token_limit = 2.0", + "tools.binary_session.output_token_limit", + ], ] as const)( "blocks malformed Codex policy %s before writes", async (setting, field) => { diff --git a/tests/fixtures/codexToolPolicy.ts b/tests/fixtures/codexToolPolicy.ts index c45da694350..4ace6f3bda3 100644 --- a/tests/fixtures/codexToolPolicy.ts +++ b/tests/fixtures/codexToolPolicy.ts @@ -4,9 +4,16 @@ export const codexToolPolicy = { default_tools_approval_mode: "prompt", enabled_tools: ["binary_session", "inspect_binary"], disabled_tools: ["run_script"], + env_vars: [ + "LANG", + { name: "HOST_TERM" }, + { name: "LOCAL_FLAG", source: "local" }, + { name: "REMOTE_FLAG", source: "remote" }, + ], required: true, + supports_parallel_tool_calls: false, cwd: "/caller/working-directory", - future_policy: { label: "retain this client setting" }, + future_policy: { label: "retain this client setting", weight: 2, offset: -0 }, tools: { binary_session: { approval_mode: "approve", @@ -33,14 +40,16 @@ export const codexToolPolicySource = ( "[mcp_servers.rea]", `command = ${JSON.stringify(command)}`, `args = ${JSON.stringify(args)}`, - "startup_timeout_sec = 19", + "startup_timeout_ms = 75500", "tool_timeout_sec = 999", 'default_tools_approval_mode = "prompt"', 'enabled_tools = ["binary_session", "inspect_binary"]', 'disabled_tools = ["run_script"]', + 'env_vars = ["LANG", {name = "HOST_TERM"}, {name = "LOCAL_FLAG", source = "local"}, {name = "REMOTE_FLAG", source = "remote"}]', "required = true", + "supports_parallel_tool_calls = false", 'cwd = "/caller/working-directory"', - 'future_policy = { label = "retain this client setting" }', + 'future_policy = { label = "retain this client setting", weight = 2.0, offset = -0.0 }', "[mcp_servers.rea.env]", 'CALLER_SETTING = "kept exactly"', "[mcp_servers.rea.tools.binary_session]", @@ -58,7 +67,7 @@ export const codexToolPolicySource = ( : [ "# retained root comment", 'model = "caller-model"', - `mcp_servers = { other = { command = "other" }, rea = { command = ${JSON.stringify(command)}, args = ${JSON.stringify(args)}, startup_timeout_sec = 19, tool_timeout_sec = 999, default_tools_approval_mode = "prompt", enabled_tools = ["binary_session", "inspect_binary"], disabled_tools = ["run_script"], required = true, cwd = "/caller/working-directory", future_policy = { label = "retain this client setting" }, env = { CALLER_SETTING = "kept exactly" }, tools = { binary_session = { approval_mode = "approve", output_token_limit = 9007199254740993 }, "inspect.binary" = { approval_mode = "auto" }, "run/script" = { approval_mode = "writes" }, __proto__ = { approval_mode = "prompt", future_option = true } } } }`, + `mcp_servers = { other = { command = "other" }, rea = { command = ${JSON.stringify(command)}, args = ${JSON.stringify(args)}, startup_timeout_sec = 19.5, startup_timeout_ms = 75500, tool_timeout_sec = 999.5, default_tools_approval_mode = "prompt", enabled_tools = ["binary_session", "inspect_binary"], disabled_tools = ["run_script"], env_vars = ["LANG", {name = "HOST_TERM"}, {name = "LOCAL_FLAG", source = "local"}, {name = "REMOTE_FLAG", source = "remote"}], required = true, supports_parallel_tool_calls = false, cwd = "/caller/working-directory", future_policy = { label = "retain this client setting", weight = 2.0, offset = -0.0 }, env = { CALLER_SETTING = "kept exactly" }, tools = { binary_session = { approval_mode = "approve", output_token_limit = 9007199254740993 }, "inspect.binary" = { approval_mode = "auto" }, "run/script" = { approval_mode = "writes" }, __proto__ = { approval_mode = "prompt", future_option = true } } } }`, "", ].join("\n"); };