Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(setup): derive MCP tool deadlines and preserve caller timeout choices

morlutodadf909dce2e
diff --git a/docs/client-configuration.md b/docs/client-configuration.md
index 5ffb19f99..2fbaf9440 100644
--- a/docs/client-configuration.md
+++ b/docs/client-configuration.md
@@ -140,8 +140,18 @@ profiles](mcp-contracts.md#output-schemas).
Setup registers `rea` in `~/.kimi-code/mcp.json`, or
`$KIMI_CODE_HOME/mcp.json` when set, while preserving unrelated settings and
creating a `.rea.backup` before updating an existing file. Kimi Code infers
-stdio from the `command` entry, so setup does not add a `type` field. The
-registration includes `startupTimeoutMs = 30000` and `toolTimeoutMs = 120000`.
+stdio from the `command` entry, so setup does not add a `type` field. New
+registrations include `startupTimeoutMs = 30000` and a `toolTimeoutMs` derived
+from REA's known provider startup allowance plus 120 seconds of operation
+headroom. The default is 450000 ms, covering the default 330-second Ghidra
+startup; an explicit Ghidra startup timeout of 2700000 ms produces a 2820000 ms
+tool timeout. The startup allowance follows an explicitly selected Ghidra or
+Hopper provider, and otherwise uses the larger known Ghidra/Hopper deadline.
+This headroom is a practical default, not a guarantee for every analysis
+duration. Setup preserves positive timeout values already in the `rea` entry.
+You can edit `startupTimeoutMs` and `toolTimeoutMs` there; doctor keeps positive
+caller-selected values aligned and reports a non-blocking advisory when a tool
+timeout is shorter than the known provider startup allowance.
Setup selects the compact input-schema advertisement for new or refreshed Kimi
registrations unless their stored configuration or setup environment explicitly
selects `REA_MCP_INPUT_SCHEMA_PROFILE=full` or `compact`. This keeps REA's
@@ -219,8 +229,18 @@ standalone CLI check.
## Codex and Devin
-Codex treats an unset or empty `CODEX_HOME` as `~/.codex`. Devin honors
-`XDG_CONFIG_HOME` for its `devin/mcp_config.json` on non-Windows systems.
+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
+startup timeout and a tool timeout derived from the known provider startup
+allowance plus 120 seconds of operation headroom. This yields 450 seconds for
+the default Ghidra allowance; an explicit Ghidra startup timeout of 2700
+seconds yields 2820 seconds. Setup preserves positive caller-selected timeout
+values in the REA entry, and doctor reports a non-blocking advisory when a tool
+timeout is shorter than the known provider startup allowance. These values are
+client-side deadlines, so increase them in `~/.codex/config.toml` if a
+workload needs more time. Devin honors `XDG_CONFIG_HOME` for its
+`devin/mcp_config.json` on non-Windows systems.
## OMP
diff --git a/docs/installation.md b/docs/installation.md
index 0a766ea91..a428fbcb1 100644
--- a/docs/installation.md
+++ b/docs/installation.md
@@ -147,7 +147,8 @@ identity remains available at `identity.catalog`.
Setup pins package-runner MCP registrations to the exact installed REA version,
installs the matching skill and on-demand references in the same plan, and adds
-`startup_timeout_sec = 30` for Codex and Grok Build.
+`startup_timeout_sec = 30` for Codex and Grok Build. Codex also receives a
+`tool_timeout_sec` derived from known provider startup plus operation headroom.
## Limit REA to one project or agent profile
diff --git a/src/application/ClientRegistrationEnvironment.ts b/src/application/ClientRegistrationEnvironment.ts
index efe6838a4..518ce7abe 100644
--- a/src/application/ClientRegistrationEnvironment.ts
+++ b/src/application/ClientRegistrationEnvironment.ts
@@ -13,6 +13,12 @@ import {
import { PRODUCT_IDENTITY } from "../identity.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import { dshDocument } from "./DshCordisPatch.js";
+import type { McpToolTimeoutInputs } from "../mcpStartupPolicy.js";
+
+export interface ClientRegistrationEnvironmentDetails {
+ readonly values: Readonly<Record<string, string>>;
+ readonly timeoutInputs: McpToolTimeoutInputs;
+}
/** Read explicit REA overrides without dropping peers when one value is invalid. */
export const clientRegistrationEnvironment = (
@@ -22,6 +28,28 @@ export const clientRegistrationEnvironment = (
): Result<Readonly<Record<string, string>>, ConfigurationError> => {
if (parsed?.dialect === "dsh")
return dshDocument(parsed.document).environment(overrides, validation);
+ const details = clientRegistrationEnvironmentDetails(
+ parsed,
+ overrides,
+ validation,
+ );
+ return details.ok ? ok(details.value.values) : details;
+};
+
+/** Retain original strings and the parser-owned timeout facts. */
+export const clientRegistrationEnvironmentDetails = (
+ parsed: ClientConfigurationDocument | undefined,
+ overrides: Readonly<Record<string, string>> = {},
+ validation: "fragment" | "effective" = "effective",
+): Result<ClientRegistrationEnvironmentDetails, ConfigurationError> => {
+ if (parsed?.dialect === "dsh") {
+ const environment = dshDocument(parsed.document).environment(
+ overrides,
+ validation,
+ );
+ if (!environment.ok) return environment;
+ return validatedDetails(environment.value, validation);
+ }
const key =
parsed?.dialect === "opencode" || parsed?.dialect === "opencode_v2"
? "environment"
@@ -50,16 +78,31 @@ export const clientRegistrationEnvironment = (
// Validate known settings with the runtime's parser, but retain the original
// string overrides, including unknown client-specific keys and no defaults.
const environment = { ...existing.data, ...overrides };
+ return validatedDetails(environment, validation);
+};
+
+const validatedDetails = (
+ environment: Readonly<Record<string, string>>,
+ validation: "fragment" | "effective",
+): Result<ClientRegistrationEnvironmentDetails, ConfigurationError> => {
const validated =
validation === "fragment"
? parseEnvironmentValues(environment)
: parseEnvironment(environment);
if (!validated.ok) return validated;
- return ok(
- Object.fromEntries(
+ return ok({
+ values: Object.fromEntries(
Object.entries(environment).sort(([left], [right]) =>
compareUnicodeCodePoints(left, right),
),
),
- );
+ timeoutInputs: {
+ analysisProvider: validated.value.REA_ANALYSIS_PROVIDER,
+ ghidraStartupTimeoutMs: validated.value.REA_GHIDRA_STARTUP_TIMEOUT_MS,
+ hopperStartupTimeoutMs: validated.value.REA_HOPPER_STARTUP_TIMEOUT_MS,
+ ...(validated.value.REA_JEB_MCP_TIMEOUT_MS === undefined
+ ? {}
+ : { jebMcpTimeoutMs: validated.value.REA_JEB_MCP_TIMEOUT_MS }),
+ },
+ });
};
diff --git a/src/application/ClientRegistrationStatus.ts b/src/application/ClientRegistrationStatus.ts
index e3aa4ea18..b6fc8be9c 100644
--- a/src/application/ClientRegistrationStatus.ts
+++ b/src/application/ClientRegistrationStatus.ts
@@ -14,7 +14,13 @@ import { valid } from "semver";
import { PRODUCT_IDENTITY } from "../identity.js";
import { CURRENT_ENTRYPOINT_PATH } from "../process/CurrentEntrypointPath.js";
-import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js";
+import {
+ MCP_STARTUP_POLICY,
+ mcpProviderStartupAllowanceMs,
+ recommendedMcpToolTimeoutMs,
+ recommendedMcpToolTimeoutSeconds,
+ type McpToolTimeoutInputs,
+} from "../mcpStartupPolicy.js";
import {
clientRegistrationPackageReference,
classifyClientRegistrationCommand,
@@ -28,7 +34,7 @@ import {
import type { SetupClient } from "./SupportedClients.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import { dshDocument } from "./DshCordisPatch.js";
-import { clientRegistrationEnvironment } from "./ClientRegistrationEnvironment.js";
+import { clientRegistrationEnvironmentDetails } from "./ClientRegistrationEnvironment.js";
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
interface ClientRegistrationStatusBase {
@@ -36,6 +42,8 @@ interface ClientRegistrationStatusBase {
readonly config_path: string;
/** Exact package reference requested by npx/bunx, when registration uses one. */
readonly package_reference?: string;
+ /** Non-blocking timeout guidance; caller-selected values remain aligned. */
+ readonly advisory?: string;
}
type RegistrationCommand = readonly [string, ...string[]];
@@ -74,6 +82,7 @@ const registrationSchema = z
command: z.string().min(1),
args: z.array(z.string()).default([]),
startup_timeout_sec: z.number().positive().optional(),
+ tool_timeout_sec: z.number().positive().optional(),
startupTimeoutMs: z.number().positive().optional(),
toolTimeoutMs: z.number().positive().optional(),
type: z.string().optional(),
@@ -217,8 +226,8 @@ export const readClientRegistrationInspections = async (
: client;
const registration = parseRegistration(raw, effectiveClient);
const registrationEnvironment =
- client.name === "kimi"
- ? clientRegistrationEnvironment(parsed)
+ client.name === "kimi" || client.name === "codex"
+ ? clientRegistrationEnvironmentDetails(parsed)
: undefined;
if (registrationEnvironment !== undefined && !registrationEnvironment.ok)
throw registrationEnvironment.error;
@@ -239,7 +248,7 @@ export const readClientRegistrationInspections = async (
platform: options.platform ?? process.platform,
kimiInputSchemaProfileSelected:
registrationEnvironment?.ok === true &&
- registrationEnvironment.value.REA_MCP_INPUT_SCHEMA_PROFILE !==
+ registrationEnvironment.value.values.REA_MCP_INPUT_SCHEMA_PROFILE !==
undefined,
});
record(
@@ -263,6 +272,13 @@ export const readClientRegistrationInspections = async (
? unknownEntryPointRemediation()
: undefined),
packageReference,
+ registrationEnvironment?.ok === true
+ ? timeoutAdvisory(
+ client,
+ registration,
+ registrationEnvironment.value.timeoutInputs,
+ )
+ : undefined,
),
activation,
);
@@ -316,16 +332,21 @@ const registrationAligned = ({
if (identity === "unknown") return "unknown";
if (identity === "foreign") return "stale";
if (
- (client.name === "codex" || client.name === "grok_build") &&
+ client.name === "grok_build" &&
registration.startup_timeout_sec !==
MCP_STARTUP_POLICY.codexStartupTimeoutSeconds
)
return "stale";
+ if (
+ client.name === "codex" &&
+ (registration.startup_timeout_sec === undefined ||
+ registration.tool_timeout_sec === undefined)
+ )
+ return "stale";
if (
client.name === "kimi" &&
- (registration.startupTimeoutMs !==
- MCP_STARTUP_POLICY.kimiStartupTimeoutMs ||
- registration.toolTimeoutMs !== MCP_STARTUP_POLICY.kimiToolTimeoutMs)
+ (registration.startupTimeoutMs === undefined ||
+ registration.toolTimeoutMs === undefined)
)
return "stale";
if (client.name === "kimi" && !kimiInputSchemaProfileSelected) return "stale";
@@ -454,6 +475,7 @@ const configuredStatus = (
state: "aligned" | "stale" | "unknown",
policyRemediation?: string,
packageReference?: string,
+ advisory?: string,
): ClientRegistrationStatus =>
state === "aligned"
? {
@@ -465,6 +487,7 @@ const configuredStatus = (
: { package_reference: packageReference }),
state,
remediation: null,
+ ...(advisory === undefined ? {} : { advisory }),
}
: {
client: client.name,
@@ -477,6 +500,35 @@ const configuredStatus = (
remediation: policyRemediation ?? remediation(client),
};
+const timeoutAdvisory = (
+ client: SetupClient,
+ registration: z.output<typeof registrationSchema>,
+ timeoutInputs: McpToolTimeoutInputs,
+): string | undefined => {
+ const toolTimeout =
+ client.name === "kimi"
+ ? registration.toolTimeoutMs
+ : client.name === "codex"
+ ? registration.tool_timeout_sec
+ : undefined;
+ if (toolTimeout === undefined) return undefined;
+ const startupAllowance = mcpProviderStartupAllowanceMs(timeoutInputs);
+ const isKimi = client.name === "kimi";
+ const toolTimeoutMs = isKimi ? toolTimeout : toolTimeout * 1000;
+ if (toolTimeoutMs >= startupAllowance) return undefined;
+ const setting = isKimi ? "toolTimeoutMs" : "tool_timeout_sec";
+ const currentValue = isKimi
+ ? `${String(toolTimeout)} ms`
+ : `${String(toolTimeout)} seconds`;
+ const recommendedValue = isKimi
+ ? `${String(recommendedMcpToolTimeoutMs(timeoutInputs))} ms`
+ : `${String(recommendedMcpToolTimeoutSeconds(timeoutInputs))} seconds`;
+ const headroom = isKimi
+ ? `${String(MCP_STARTUP_POLICY.toolOperationHeadroomMs)} ms`
+ : `${String(MCP_STARTUP_POLICY.toolOperationHeadroomMs / 1000)} seconds`;
+ return `The configured ${setting} (${currentValue}) is shorter than REA's known provider startup allowance (${String(startupAllowance)} ms), so first-use startup may exceed this client deadline. REA recommends ${setting} = ${recommendedValue} to cover known startup plus ${headroom} of operation headroom; this additional headroom is a recommendation, not a guarantee for every analysis.`;
+};
+
const exactRegisteredPackageVersion = (
packageReference: string | undefined,
): string | undefined => {
diff --git a/src/application/Doctor.test.ts b/src/application/Doctor.test.ts
index 093063aae..2da77db08 100644
--- a/src/application/Doctor.test.ts
+++ b/src/application/Doctor.test.ts
@@ -363,6 +363,38 @@ describe("doctor scoped readiness", () => {
);
expect(staleSelected.healthy).toBe(false);
});
+
+ it("keeps a caller-selected short timeout healthy and reports its advisory as informational", async () => {
+ const result = await runDoctor(
+ undefined,
+ host({
+ clientRegistrations: () =>
+ Promise.resolve([
+ {
+ client: "kimi",
+ config_path: "/home/user/.kimi-code/mcp.json",
+ command: ["/current/rea", "mcp"],
+ state: "aligned",
+ remediation: null,
+ advisory: "The configured toolTimeoutMs is shorter than startup.",
+ },
+ ]),
+ }),
+ { clients: ["kimi"] },
+ );
+
+ expect(result.healthy).toBe(true);
+ expect(result.scope_checks).toContainEqual(
+ expect.objectContaining({ name: "registration:kimi", ok: true }),
+ );
+ expect(result.informational_checks).toContainEqual(
+ expect.objectContaining({
+ name: "registration_timeout:kimi",
+ ok: true,
+ detail: "The configured toolTimeoutMs is shorter than startup.",
+ }),
+ );
+ });
});
describe("Grok Bot readiness", () => {
diff --git a/src/application/Doctor.ts b/src/application/Doctor.ts
index 40b9cbadd..bcc6cc47e 100644
--- a/src/application/Doctor.ts
+++ b/src/application/Doctor.ts
@@ -220,7 +220,11 @@ const inspectDoctor = async (
providerInspections,
} = await collectDoctorDiagnostics(target, host);
const identity = await collectDoctorIdentity(host, scope);
- const checks = [...diagnosticChecks, ...identity.checks];
+ const checks = [
+ ...diagnosticChecks,
+ ...identity.checks,
+ ...registrationAdvisoryChecks(identity.value.registrations),
+ ];
const providers = {
hopperAvailable:
hopperPath !== undefined &&
@@ -252,6 +256,22 @@ const inspectDoctor = async (
};
};
+const registrationAdvisoryChecks = (
+ registrations: readonly ClientRegistrationStatus[],
+): readonly DoctorCheck[] =>
+ registrations.flatMap(({ client, advisory }) =>
+ advisory === undefined
+ ? []
+ : [
+ {
+ name: `registration_timeout:${client}`,
+ ok: true,
+ classification: "healthy" as const,
+ detail: advisory,
+ },
+ ],
+ );
+
const closeDoctorHost = async (
host: DoctorHost,
): Promise<string | undefined> => {
diff --git a/src/application/SetupClientConfiguration.ts b/src/application/SetupClientConfiguration.ts
index 104daf968..139b93a49 100644
--- a/src/application/SetupClientConfiguration.ts
+++ b/src/application/SetupClientConfiguration.ts
@@ -23,11 +23,18 @@ import { dshDocument, DshCordisDocument } from "./DshCordisPatch.js";
import { mkdir, rm, writeFile } from "node:fs/promises";
import { dirname } from "node:path";
import writeFileAtomic from "write-file-atomic";
-import { clientRegistrationEnvironment } from "./ClientRegistrationEnvironment.js";
+import {
+ clientRegistrationEnvironment,
+ clientRegistrationEnvironmentDetails,
+} from "./ClientRegistrationEnvironment.js";
import { PRODUCT_IDENTITY } from "../identity.js";
import { npxRegistrationCommand } from "./ClientRegistrationIdentity.js";
-import { MCP_STARTUP_POLICY } from "../mcpStartupPolicy.js";
+import {
+ MCP_STARTUP_POLICY,
+ recommendedMcpToolTimeoutMs,
+ recommendedMcpToolTimeoutSeconds,
+} from "../mcpStartupPolicy.js";
import { resolveClientConfigTransactionPath } from "./ClientConfigPath.js";
import { packageReadTargetChanged } from "./MsixPackageStorage.js";
import {
@@ -658,15 +665,15 @@ const clientConfigurationDesired = (
client,
document: parsed,
});
- const validated = clientRegistrationEnvironment(
- effective,
- providerEnvironment,
- );
- if (!validated.ok) throw validated.error;
const format = parsed?.dialect ?? client.format ?? "json";
const launcher =
command.length === 0 ? [PRODUCT_IDENTITY.cliBinary, "mcp"] : command;
if (format === "dsh") {
+ const validated = clientRegistrationEnvironment(
+ effective,
+ providerEnvironment,
+ );
+ if (!validated.ok) throw validated.error;
const desired = (
parsed === undefined
? new DshCordisDocument("")
@@ -675,8 +682,14 @@ const clientConfigurationDesired = (
if (!desired.ok) throw desired.error;
return desired.value;
}
+ const validated = clientRegistrationEnvironmentDetails(
+ effective,
+ providerEnvironment,
+ );
+ if (!validated.ok) throw validated.error;
// Preserve explicitly configured server settings, never the ambient process
- // environment. Newly discovered provider paths win only for their own keys.
+ // environment. The effective layered view validates precedence and supplies
+ // timeout facts; the target file's fragment remains the value being written.
const environment = clientRegistrationEnvironment(
parsed,
providerEnvironment,
@@ -708,14 +721,40 @@ const clientConfigurationDesired = (
...registration,
...(client.name === "codex" || client.name === "grok_build"
? {
- startup_timeout_sec: MCP_STARTUP_POLICY.codexStartupTimeoutSeconds,
+ startup_timeout_sec:
+ client.name === "codex"
+ ? (positiveTimeout(previous, "startup_timeout_sec") ??
+ MCP_STARTUP_POLICY.codexStartupTimeoutSeconds)
+ : MCP_STARTUP_POLICY.codexStartupTimeoutSeconds,
+ }
+ : {}),
+ ...(client.name === "codex"
+ ? {
+ tool_timeout_sec:
+ positiveTimeout(previous, "tool_timeout_sec") ??
+ recommendedMcpToolTimeoutSeconds(validated.value.timeoutInputs),
}
: {}),
...(client.name === "kimi"
? {
- startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
- toolTimeoutMs: MCP_STARTUP_POLICY.kimiToolTimeoutMs,
+ startupTimeoutMs:
+ positiveTimeout(previous, "startupTimeoutMs") ??
+ MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
+ toolTimeoutMs:
+ positiveTimeout(previous, "toolTimeoutMs") ??
+ recommendedMcpToolTimeoutMs(validated.value.timeoutInputs),
}
: {}),
};
};
+
+const positiveTimeout = (
+ registration: unknown,
+ key: string,
+): number | undefined => {
+ if (typeof registration !== "object" || registration === null) return;
+ const value: unknown = Reflect.get(registration, key);
+ return typeof value === "number" && Number.isFinite(value) && value > 0
+ ? value
+ : undefined;
+};
diff --git a/src/mcpStartupPolicy.ts b/src/mcpStartupPolicy.ts
index 8eea0c6df..7eac0bfb1 100644
--- a/src/mcpStartupPolicy.ts
+++ b/src/mcpStartupPolicy.ts
@@ -1,17 +1,56 @@
+import type { AnalysisProviderSelector } from "./contracts/providerSelection.js";
+
/**
- * Supported MCP startup deadlines and regression budgets.
+ * Supported MCP startup deadlines and operation headroom.
*
- * The Codex timeout is caller-facing configuration. The smaller phase budgets
+ * Client timeouts are caller-facing configuration. The smaller phase budgets
* preserve operational headroom, while the doctor deadline covers additional
* inventory requests after initialization.
*/
export const MCP_STARTUP_POLICY = {
codexStartupTimeoutSeconds: 30,
kimiStartupTimeoutMs: 30_000,
- kimiToolTimeoutMs: 120_000,
+ toolOperationHeadroomMs: 120_000,
initializeBudgetMs: 15_000,
toolsListBudgetMs: 5_000,
firstCatalogBudgetMs: 20_000,
doctorDeadlineMs: 30_000,
doctorStderrBytes: 64 * 1024,
} as const;
+
+/** Parsed provider deadlines that affect a client-side total tool deadline. */
+export interface McpToolTimeoutInputs {
+ readonly analysisProvider: AnalysisProviderSelector;
+ readonly ghidraStartupTimeoutMs: number;
+ readonly hopperStartupTimeoutMs: number;
+ readonly jebMcpTimeoutMs?: number;
+}
+
+/** Conservative known startup allowance for clients with a total call deadline. */
+export const mcpProviderStartupAllowanceMs = (
+ inputs: McpToolTimeoutInputs,
+): number => {
+ const selectedProvider = inputs.analysisProvider;
+ const selectedTimeout =
+ selectedProvider === "ghidra"
+ ? inputs.ghidraStartupTimeoutMs
+ : selectedProvider === "hopper"
+ ? inputs.hopperStartupTimeoutMs
+ : Math.max(
+ inputs.ghidraStartupTimeoutMs,
+ inputs.hopperStartupTimeoutMs,
+ );
+ return Math.max(selectedTimeout, inputs.jebMcpTimeoutMs ?? 0);
+};
+
+/** Add operation headroom to the parsed provider startup allowance. */
+export const recommendedMcpToolTimeoutMs = (
+ inputs: McpToolTimeoutInputs,
+): number =>
+ mcpProviderStartupAllowanceMs(inputs) +
+ MCP_STARTUP_POLICY.toolOperationHeadroomMs;
+
+/** Round up so Codex's whole-second deadline still covers the millisecond budget. */
+export const recommendedMcpToolTimeoutSeconds = (
+ inputs: McpToolTimeoutInputs,
+): number => Math.ceil(recommendedMcpToolTimeoutMs(inputs) / 1000);
diff --git a/tests/boundary/filesystem/clientLifecycle.test.ts b/tests/boundary/filesystem/clientLifecycle.test.ts
index 957b71dcc..b94bfa2b8 100644
--- a/tests/boundary/filesystem/clientLifecycle.test.ts
+++ b/tests/boundary/filesystem/clientLifecycle.test.ts
@@ -112,6 +112,7 @@ describe("client configuration filesystem lifecycle", () => {
expect(configured).toContain("[mcp_servers.rea]");
expect(configured).toContain('command = "rea"');
expect(configured).toContain("startup_timeout_sec = 30");
+ expect(configured).toContain("tool_timeout_sec = 450");
expect(configured).toContain('GHIDRA_INSTALL_DIR = "/opt/ghidra"');
expect(configured).toContain('JAVA_HOME = "/opt/jdk-21"');
expect(
@@ -134,7 +135,7 @@ describe("client configuration filesystem lifecycle", () => {
await mkdir(dirname(configPath), { recursive: true });
await writeFile(
configPath,
- `[mcp_servers.rea]\ncommand = "rea"\nargs = ["mcp"]\nstartup_timeout_sec = 30\n\n[mcp_servers.rea.env]\nJAVA_HOME = "/opt/jdk-21"\nHOPPER_LAUNCHER_PATH = "/Hopper Path"\nGHIDRA_INSTALL_DIR = "/opt/ghidra"\n`,
+ `[mcp_servers.rea]\ncommand = "rea"\nargs = ["mcp"]\nstartup_timeout_sec = 30\ntool_timeout_sec = 450\n\n[mcp_servers.rea.env]\nJAVA_HOME = "/opt/jdk-21"\nHOPPER_LAUNCHER_PATH = "/Hopper Path"\nGHIDRA_INSTALL_DIR = "/opt/ghidra"\n`,
);
const original = await readFile(configPath, "utf8");
@@ -154,7 +155,52 @@ describe("client configuration filesystem lifecycle", () => {
readFile(`${configPath}.rea.backup`, "utf8"),
).rejects.toThrow();
});
+});
+
+describe("Codex MCP tool deadlines", () => {
+ it("derives the Codex tool deadline from an explicit Ghidra startup allowance", async () => {
+ const home = await createTestTempDirectory("rea-codex-long-timeout-");
+ roots.push(home);
+ const configPath = join(home, ".codex/config.toml");
+ await mkdir(dirname(configPath), { recursive: true });
+ expect(
+ await configureClientConfiguration(
+ { name: "codex", configPath, format: "toml" },
+ { REA_GHIDRA_STARTUP_TIMEOUT_MS: "2700001" },
+ ["rea", "mcp"],
+ ),
+ ).toMatchObject({ status: "configured" });
+ expect(await readFile(configPath, "utf8")).toContain(
+ "tool_timeout_sec = 2821",
+ );
+ expect(await readFile(configPath, "utf8")).toContain(
+ 'REA_GHIDRA_STARTUP_TIMEOUT_MS = "2700001"',
+ );
+ });
+
+ it("preserves positive caller-selected Codex startup and tool deadlines", async () => {
+ const home = await createTestTempDirectory("rea-codex-custom-timeout-");
+ roots.push(home);
+ const configPath = join(home, ".codex/config.toml");
+ await mkdir(dirname(configPath), { recursive: true });
+ await writeFile(
+ configPath,
+ '[mcp_servers.rea]\ncommand = "old-rea"\nargs = ["mcp"]\nstartup_timeout_sec = 5\ntool_timeout_sec = 10\n',
+ );
+ expect(
+ await configureClientConfiguration(
+ { name: "codex", configPath, format: "toml" },
+ {},
+ ["rea", "mcp"],
+ ),
+ ).toMatchObject({ status: "configured" });
+ const configured = await readFile(configPath, "utf8");
+ expect(configured).toContain("startup_timeout_sec = 5");
+ expect(configured).toContain("tool_timeout_sec = 10");
+ });
+});
+describe("client configuration filesystem lifecycle", () => {
it("updates a symlink target without replacing the TOML config symlink", async () => {
const home = await createTestTempDirectory("rea-toml-symlink-");
roots.push(home);
diff --git a/tests/boundary/filesystem/clientRegistrationStatus.test.ts b/tests/boundary/filesystem/clientRegistrationStatus.test.ts
index 8ee7417e4..1612ac6aa 100644
--- a/tests/boundary/filesystem/clientRegistrationStatus.test.ts
+++ b/tests/boundary/filesystem/clientRegistrationStatus.test.ts
@@ -51,7 +51,7 @@ describe("client registration status", () => {
]);
await writeFile(
join(home, ".codex/config.toml"),
- `[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "${PRODUCT_IDENTITY.registrationPackageSpecifier}", "mcp"]\nstartup_timeout_sec = 30\n`,
+ `[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "${PRODUCT_IDENTITY.registrationPackageSpecifier}", "mcp"]\nstartup_timeout_sec = 30\ntool_timeout_sec = 450\n`,
);
await writeFile(
join(home, ".cursor/mcp.json"),
@@ -309,14 +309,14 @@ describe("commandcode registration status", () => {
describe("Node-wrapped registration policy", () => {
it.each([1, 30])(
- "checks Codex startup timeout %d independently of launcher",
+ "accepts Codex caller-selected startup timeout %d independently of launcher",
async (timeout) => {
const home = await createTestTempDirectory("rea-node-registration-");
await mkdir(join(home, ".codex"));
const entry = resolve("scripts/rea.mjs");
await writeFile(
join(home, ".codex/config.toml"),
- `[mcp_servers.rea]\ncommand = ${JSON.stringify(process.execPath)}\nargs = [${JSON.stringify(entry)}, "mcp"]\nstartup_timeout_sec = ${String(timeout)}\n`,
+ `[mcp_servers.rea]\ncommand = ${JSON.stringify(process.execPath)}\nargs = [${JSON.stringify(entry)}, "mcp"]\nstartup_timeout_sec = ${String(timeout)}\ntool_timeout_sec = 450\n`,
);
const statuses = await readClientRegistrationStatuses(home, entry, {
environment: {},
@@ -324,12 +324,30 @@ describe("Node-wrapped registration policy", () => {
expect(statuses).toEqual([
expect.objectContaining({
client: "codex",
- state: timeout === 30 ? "aligned" : "stale",
+ state: "aligned",
}),
]);
},
);
+ it("keeps a short positive Codex tool timeout aligned and reports an advisory", async () => {
+ const home = await createTestTempDirectory("rea-codex-short-tool-timeout-");
+ await mkdir(join(home, ".codex"));
+ const entry = resolve("scripts/rea.mjs");
+ await writeFile(
+ join(home, ".codex/config.toml"),
+ `[mcp_servers.rea]\ncommand = ${JSON.stringify(process.execPath)}\nargs = [${JSON.stringify(entry)}, "mcp"]\nstartup_timeout_sec = 5\ntool_timeout_sec = 10\n`,
+ );
+ const [status] = await readClientRegistrationStatuses(home, entry, {
+ environment: {},
+ });
+ expect(status).toMatchObject({
+ client: "codex",
+ state: "aligned",
+ advisory: expect.stringContaining("tool_timeout_sec = 450 seconds"),
+ });
+ });
+
it.each([1, 30])(
"checks Grok Build startup timeout %d independently of launcher",
async (timeout) => {
diff --git a/tests/boundary/filesystem/kimiClientConfiguration.test.ts b/tests/boundary/filesystem/kimiClientConfiguration.test.ts
index 7a96c512d..077c24d3a 100644
--- a/tests/boundary/filesystem/kimiClientConfiguration.test.ts
+++ b/tests/boundary/filesystem/kimiClientConfiguration.test.ts
@@ -41,12 +41,13 @@ const exists = async (path: string): Promise<boolean> => {
const expectedRegistration = (
launcher: readonly string[],
profile = "compact",
+ toolTimeoutMs = 450_000,
) => ({
command: launcher[0],
args: launcher.slice(1),
env: { REA_MCP_INPUT_SCHEMA_PROFILE: profile },
startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
- toolTimeoutMs: MCP_STARTUP_POLICY.kimiToolTimeoutMs,
+ toolTimeoutMs,
});
describe("Kimi Code configuration paths and skills", () => {
@@ -111,6 +112,68 @@ describe("Kimi Code registration lifecycle", () => {
).toBe("unchanged");
});
+ it("preserves selected timeout values through refresh and keeps backups idempotent", async () => {
+ const { home, client } = await kimiClient();
+ const original = JSON.stringify({
+ mcpServers: {
+ rea: {
+ ...expectedRegistration(["old-rea", "mcp"]),
+ startupTimeoutMs: 90_000,
+ toolTimeoutMs: 300_000,
+ },
+ },
+ });
+ await writeFile(client.configPath, original);
+
+ expect(
+ await configureClientConfiguration(client, {}, command),
+ ).toMatchObject({
+ status: "configured",
+ backupPath: `${client.configPath}.rea.backup`,
+ });
+ expect(
+ JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
+ ).toEqual({
+ ...expectedRegistration(command),
+ startupTimeoutMs: 90_000,
+ toolTimeoutMs: 300_000,
+ });
+ expect(await readFile(`${client.configPath}.rea.backup`, "utf8")).toBe(
+ original,
+ );
+ expect(await configureClientConfiguration(client, {}, command)).toEqual({
+ status: "unchanged",
+ });
+ expect(
+ (
+ await readClientRegistrationStatuses(home, undefined, {
+ environment: {},
+ })
+ ).find(({ client: name }) => name === "kimi"),
+ ).toMatchObject({
+ state: "aligned",
+ advisory: expect.stringContaining("toolTimeoutMs = 450000 ms"),
+ });
+ });
+
+ it("derives a client deadline beyond Node's timer ceiling for an alternative provider selector", async () => {
+ const { client } = await kimiClient();
+ expect(
+ await configureClientConfiguration(
+ client,
+ {
+ REA_ANALYSIS_PROVIDER: "ida",
+ REA_GHIDRA_STARTUP_TIMEOUT_MS: "2147483647",
+ },
+ command,
+ ),
+ ).toMatchObject({ status: "configured" });
+ expect(
+ JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea
+ .toolTimeoutMs,
+ ).toBe(2_147_603_647);
+ });
+
it("registers without type, preserves unrelated settings, backs up, and is idempotent", async () => {
const { home, client } = await kimiClient();
const original = `{
@@ -267,7 +330,7 @@ describe("Kimi Code input-schema profile selection", () => {
command: command[0],
args: command.slice(1),
startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
- toolTimeoutMs: MCP_STARTUP_POLICY.kimiToolTimeoutMs,
+ toolTimeoutMs: 120_000,
},
},
}),
@@ -285,7 +348,7 @@ describe("Kimi Code input-schema profile selection", () => {
).toBe("configured");
expect(
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
- ).toEqual(expectedRegistration(command));
+ ).toEqual(expectedRegistration(command, "compact", 120_000));
});
});
@@ -439,7 +502,7 @@ describe("Kimi Code transport validation", () => {
);
});
-describe("Kimi Code timeout validation", () => {
+describe("Kimi Code timeout alignment", () => {
const kimiClient = async () => {
const home = await createTestTempDirectory("rea-kimi-timeout-");
const client = kimiPath(home, process.platform, {});
@@ -450,11 +513,11 @@ describe("Kimi Code timeout validation", () => {
};
it.each([
- ["startupTimeoutMs", 1],
- ["toolTimeoutMs", 1],
- ["startupTimeoutMs", undefined],
- ["toolTimeoutMs", undefined],
- ] as const)("reports stale when %s is %j", async (field, value) => {
+ ["startupTimeoutMs", 1, "aligned"],
+ ["toolTimeoutMs", 1, "aligned"],
+ ["startupTimeoutMs", undefined, "stale"],
+ ["toolTimeoutMs", undefined, "stale"],
+ ] as const)("reports %s timeout %j as %s", async (field, value, state) => {
const { home, client } = await kimiClient();
const registration = {
...expectedRegistration(command),
@@ -470,7 +533,7 @@ describe("Kimi Code timeout validation", () => {
environment: {},
})
).find(({ client: name }) => name === "kimi"),
- ).toMatchObject({ state: "stale" });
+ ).toMatchObject({ state });
});
it("uses a direct installed REA command without requiring a package runner", async () => {