Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(setup): propagate selected provider deadlines through CLI registrations

morluto333e0ab0dfc1
diff --git a/docs/client-configuration.md b/docs/client-configuration.md
index 2fbaf9440..c209aaf92 100644
--- a/docs/client-configuration.md
+++ b/docs/client-configuration.md
@@ -142,16 +142,19 @@ Setup registers `rea` in `~/.kimi-code/mcp.json`, or
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. New
registrations include `startupTimeoutMs = 30000` and a `toolTimeoutMs` derived
-from REA's known provider startup allowance plus 120 seconds of operation
+from REA's known provider 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.
+An explicit `REA_JEB_MCP_TIMEOUT_MS` request budget also contributes to that
+maximum. Setup forwards these explicitly selected REA deadlines and the input
+schema profile into the registration; unrelated process values are omitted.
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.
+timeout is shorter than the known provider 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
@@ -232,12 +235,13 @@ standalone CLI check.
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
+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
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
+timeout is shorter than the known provider allowance. An explicitly selected
+JEB request budget also contributes to the 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.
diff --git a/docs/mcp-contracts.md b/docs/mcp-contracts.md
index 32cb3fb8a..a8fb74d05 100644
--- a/docs/mcp-contracts.md
+++ b/docs/mcp-contracts.md
@@ -522,7 +522,8 @@ missing tool deadlines from the known provider allowance plus 120 seconds of
operation headroom: 450 seconds with the default Ghidra allowance, or 2820
seconds with `REA_GHIDRA_STARTUP_TIMEOUT_MS=2700000`. Positive caller-selected
deadlines remain unchanged. Doctor reports an informational recommendation
-when a configured deadline is shorter than the known startup allowance.
+when a configured deadline is shorter than the known provider allowance. An
+explicit JEB upstream request budget also contributes to that allowance.
For an already connected client using the pinned SDK, request options are the
**second** argument of `callTool`:
diff --git a/src/application/ClientRegistrationStatus.ts b/src/application/ClientRegistrationStatus.ts
index b6fc8be9c..faa2c4205 100644
--- a/src/application/ClientRegistrationStatus.ts
+++ b/src/application/ClientRegistrationStatus.ts
@@ -16,7 +16,7 @@ import { PRODUCT_IDENTITY } from "../identity.js";
import { CURRENT_ENTRYPOINT_PATH } from "../process/CurrentEntrypointPath.js";
import {
MCP_STARTUP_POLICY,
- mcpProviderStartupAllowanceMs,
+ mcpProviderDeadlineAllowanceMs,
recommendedMcpToolTimeoutMs,
recommendedMcpToolTimeoutSeconds,
type McpToolTimeoutInputs,
@@ -512,10 +512,10 @@ const timeoutAdvisory = (
? registration.tool_timeout_sec
: undefined;
if (toolTimeout === undefined) return undefined;
- const startupAllowance = mcpProviderStartupAllowanceMs(timeoutInputs);
+ const providerAllowance = mcpProviderDeadlineAllowanceMs(timeoutInputs);
const isKimi = client.name === "kimi";
const toolTimeoutMs = isKimi ? toolTimeout : toolTimeout * 1000;
- if (toolTimeoutMs >= startupAllowance) return undefined;
+ if (toolTimeoutMs >= providerAllowance) return undefined;
const setting = isKimi ? "toolTimeoutMs" : "tool_timeout_sec";
const currentValue = isKimi
? `${String(toolTimeout)} ms`
@@ -526,7 +526,7 @@ const timeoutAdvisory = (
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.`;
+ return `The configured ${setting} (${currentValue}) is shorter than REA's known provider allowance (${String(providerAllowance)} ms), so provider startup or an upstream request may exceed this client deadline. REA recommends ${setting} = ${recommendedValue} to cover that allowance plus ${headroom} of operation headroom; this additional headroom is a recommendation, not a guarantee for every analysis.`;
};
const exactRegisteredPackageVersion = (
diff --git a/src/application/SetupHost.ts b/src/application/SetupHost.ts
index f6f69a91f..868b278f9 100644
--- a/src/application/SetupHost.ts
+++ b/src/application/SetupHost.ts
@@ -45,7 +45,10 @@ import {
RegularFileCleanupFailure,
retryRegularFileCleanup,
} from "./RegularFileRead.js";
-import { providerRegistrationEnvironment } from "./SetupRegistrationEnvironment.js";
+import {
+ explicitSetupRegistrationEnvironment,
+ providerRegistrationEnvironment,
+} from "./SetupRegistrationEnvironment.js";
import {
msixPackagesDirectory,
packagePrivateLauncherBlocker,
@@ -180,6 +183,7 @@ export const systemSetupHost = (
diagnosis.providerInspections ?? [],
),
...doctorHost.providerRegistrationEnvironment?.(),
+ ...explicitSetupRegistrationEnvironment(environment),
...(diagnosis.hopperPath === undefined
? {}
: { HOPPER_LAUNCHER_PATH: diagnosis.hopperPath }),
diff --git a/src/application/SetupRegistrationEnvironment.ts b/src/application/SetupRegistrationEnvironment.ts
index b9bf54f99..11724bc8e 100644
--- a/src/application/SetupRegistrationEnvironment.ts
+++ b/src/application/SetupRegistrationEnvironment.ts
@@ -1,6 +1,25 @@
import type { DoctorProviderInspection } from "./Doctor.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
+const SELECTED_REGISTRATION_SETTINGS = [
+ "REA_ANALYSIS_PROVIDER",
+ "REA_GHIDRA_STARTUP_TIMEOUT_MS",
+ "REA_HOPPER_STARTUP_TIMEOUT_MS",
+ "REA_JEB_MCP_TIMEOUT_MS",
+ "REA_MCP_INPUT_SCHEMA_PROFILE",
+] as const;
+
+/** Preserve selected setup settings without copying unrelated process values. */
+export const explicitSetupRegistrationEnvironment = (
+ environment: Readonly<Record<string, string | undefined>>,
+): Readonly<Record<string, string>> =>
+ Object.fromEntries(
+ SELECTED_REGISTRATION_SETTINGS.flatMap((key) => {
+ const value = environment[key];
+ return value === undefined ? [] : [[key, value]];
+ }),
+ );
+
/** Preserve adapter-published settings independently of runtime readiness. */
export const providerRegistrationEnvironment = (
inspections: readonly DoctorProviderInspection[],
diff --git a/src/mcpStartupPolicy.ts b/src/mcpStartupPolicy.ts
index 7eac0bfb1..3f054b448 100644
--- a/src/mcpStartupPolicy.ts
+++ b/src/mcpStartupPolicy.ts
@@ -18,7 +18,7 @@ export const MCP_STARTUP_POLICY = {
doctorStderrBytes: 64 * 1024,
} as const;
-/** Parsed provider deadlines that affect a client-side total tool deadline. */
+/** Parsed startup and upstream request budgets affecting a client's tool deadline. */
export interface McpToolTimeoutInputs {
readonly analysisProvider: AnalysisProviderSelector;
readonly ghidraStartupTimeoutMs: number;
@@ -26,8 +26,8 @@ export interface McpToolTimeoutInputs {
readonly jebMcpTimeoutMs?: number;
}
-/** Conservative known startup allowance for clients with a total call deadline. */
-export const mcpProviderStartupAllowanceMs = (
+/** Allow for known startup phases and caller-selected upstream request budgets. */
+export const mcpProviderDeadlineAllowanceMs = (
inputs: McpToolTimeoutInputs,
): number => {
const selectedProvider = inputs.analysisProvider;
@@ -43,11 +43,11 @@ export const mcpProviderStartupAllowanceMs = (
return Math.max(selectedTimeout, inputs.jebMcpTimeoutMs ?? 0);
};
-/** Add operation headroom to the parsed provider startup allowance. */
+/** Add operation headroom to the parsed provider deadline allowance. */
export const recommendedMcpToolTimeoutMs = (
inputs: McpToolTimeoutInputs,
): number =>
- mcpProviderStartupAllowanceMs(inputs) +
+ mcpProviderDeadlineAllowanceMs(inputs) +
MCP_STARTUP_POLICY.toolOperationHeadroomMs;
/** Round up so Codex's whole-second deadline still covers the millisecond budget. */
diff --git a/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts b/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts
index 1dc63877d..555e249b3 100644
--- a/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts
+++ b/tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts
@@ -236,3 +236,134 @@ cliTest(
});
},
);
+
+cliTest(
+ "public setup propagates selected provider deadlines and input profile to Codex and Kimi",
+ async ({ cli }) => {
+ const home = await createTestTempDirectory(
+ "rea-selected-registration-env-",
+ );
+ const codexHome = join(home, "codex");
+ const kimiHome = join(home, "kimi");
+ await Promise.all(
+ [codexHome, kimiHome].map((path) => mkdir(path, { recursive: true })),
+ );
+ const environment = {
+ HOME: home,
+ USERPROFILE: home,
+ XDG_CONFIG_HOME: join(home, ".config"),
+ CODEX_HOME: codexHome,
+ KIMI_CODE_HOME: kimiHome,
+ HOPPER_LAUNCHER_PATH: join(home, "missing-hopper"),
+ REA_ANALYSIS_PROVIDER: "auto",
+ REA_GHIDRA_STARTUP_TIMEOUT_MS: "2700001",
+ REA_HOPPER_STARTUP_TIMEOUT_MS: "2800002",
+ REA_JEB_MCP_TIMEOUT_MS: "2900003",
+ REA_MCP_INPUT_SCHEMA_PROFILE: "full",
+ REA_UNRELATED_MARKER: "do-not-persist",
+ };
+ const run = (arguments_: readonly string[]) =>
+ cli.run({
+ arguments: [...arguments_, "--json"],
+ cwd: home,
+ environment,
+ });
+
+ for (const client of ["codex", "kimi"] as const) {
+ const setup = await run([
+ "setup",
+ "--client",
+ client,
+ "--skill=false",
+ "--yes",
+ ]);
+ expect(setup.exitCode, setup.stderr).toBe(0);
+ expect(setup.json).toMatchObject({ status: "ready" });
+ }
+
+ const codexConfig = await readFile(join(codexHome, "config.toml"), "utf8");
+ const codexRegistration = effectiveClientServer(
+ parseClientConfiguration(codexConfig, "toml"),
+ "rea",
+ );
+ expect(codexRegistration).toMatchObject({ tool_timeout_sec: 3021 });
+ expect(codexConfig).toContain('REA_JEB_MCP_TIMEOUT_MS = "2900003"');
+ expect(codexConfig).not.toContain("REA_UNRELATED_MARKER");
+
+ const kimiPath = join(kimiHome, "mcp.json");
+ const kimiRegistration = effectiveClientServer(
+ parseClientConfiguration(await readFile(kimiPath, "utf8"), "kimi"),
+ "rea",
+ );
+ expect(kimiRegistration).toMatchObject({
+ toolTimeoutMs: 3_020_003,
+ env: {
+ REA_ANALYSIS_PROVIDER: "auto",
+ REA_GHIDRA_STARTUP_TIMEOUT_MS: "2700001",
+ REA_HOPPER_STARTUP_TIMEOUT_MS: "2800002",
+ REA_JEB_MCP_TIMEOUT_MS: "2900003",
+ REA_MCP_INPUT_SCHEMA_PROFILE: "full",
+ },
+ });
+ expect(await readFile(kimiPath, "utf8")).not.toContain(
+ "REA_UNRELATED_MARKER",
+ );
+
+ const doctor = await run(["doctor", "--client", "kimi"]);
+ expect(doctor.exitCode, doctor.stderr).toBe(0);
+ expect(doctor.json).toMatchObject({
+ identity: {
+ registrations: expect.arrayContaining([
+ expect.objectContaining({ client: "kimi", state: "aligned" }),
+ ]),
+ },
+ });
+ },
+ 120_000,
+);
+
+for (const invalidSetting of [
+ { setting: "REA_MCP_INPUT_SCHEMA_PROFILE", value: "unknown" },
+ { setting: "REA_GHIDRA_STARTUP_TIMEOUT_MS", value: "0" },
+ { setting: "REA_JEB_MCP_TIMEOUT_MS", value: "1.5" },
+] as const)
+ cliTest(
+ `setup rejects malformed selected ${invalidSetting.setting} before writing`,
+ async ({ cli }) => {
+ const home = await createTestTempDirectory(
+ "rea-invalid-selected-registration-env-",
+ );
+ const kimiHome = join(home, "kimi");
+ await mkdir(kimiHome, { recursive: true });
+ const config = join(kimiHome, "mcp.json");
+ const environment = {
+ HOME: home,
+ USERPROFILE: home,
+ XDG_CONFIG_HOME: join(home, ".config"),
+ KIMI_CODE_HOME: kimiHome,
+ HOPPER_LAUNCHER_PATH: join(home, "missing-hopper"),
+ [invalidSetting.setting]: invalidSetting.value,
+ };
+ const result = await cli.run({
+ arguments: [
+ "setup",
+ "--client",
+ "kimi",
+ "--skill=false",
+ "--yes",
+ "--json",
+ ],
+ cwd: home,
+ environment,
+ });
+ expect(result.exitCode).toBe(1);
+ expect(`${result.stdout}\n${result.stderr}`).toContain(
+ invalidSetting.setting,
+ );
+ await expect(access(config)).rejects.toMatchObject({ code: "ENOENT" });
+ await expect(access(`${config}.rea.backup`)).rejects.toMatchObject({
+ code: "ENOENT",
+ });
+ },
+ 120_000,
+ );