fix(setup): use Windows launch settings for registration deadlines (#13512)

This commit is contained in:
morluto authored and GitHub committed 2026-11-22 17:38:54 +00:00
1 parent a9ae4aa0bc
commit 411f8a4342
4 files changed
+174 -160

No files matched your search

@@ -2,7 +2,10 @@ import type {
OwnedProviderSetting,
RecordedProviderSettings,
} from "../ports/DesktopBuildHost.js";
import { validateRegistrationEnvironment } from "./RegistrationEnvironmentValidation.js";
import {
validateRegistrationEnvironment,
type ValidatedRegistrationEnvironment,
} from "./RegistrationEnvironmentValidation.js";
import {
clientRegistrationSource,
gooseEnvironmentField,
@@ -10,7 +13,6 @@ import {
import type { SetupClient } from "./SupportedClients.js";
import { launchAnalysisSetting } from "../config/analysisSettings.js";
import type { Environment } from "../config/environment.js";
import {
DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS,
DEFAULT_HOPPER_STARTUP_TIMEOUT_MS,
@@ -24,10 +26,7 @@ import {
} from "./ClientConfigurationDocument.js";
import { PRODUCT_IDENTITY } from "../identity.js";
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
import {
mergeEnvironmentOverrides,
snapshotEnvironment,
} from "../process/snapshotEnvironment.js";
import { mergeEnvironmentOverrides } from "../process/snapshotEnvironment.js";
import { dshDocument } from "./DshCordisPatch.js";
import { mergeRegistrationEnvironment } from "./UserConfigurationLocation.js";
import type { McpToolTimeoutInputs } from "../config/mcpStartupPolicy.js";
@@ -51,6 +50,8 @@ export interface ProviderRequestBudgetResolver {
export interface ClientRegistrationEnvironmentDetails {
readonly values: Readonly<Record<string, string>>;
/** The platform-admitted keys used for launch setting and budget lookup. */
readonly runtimeEnvironment: Readonly<Record<string, string>>;
readonly configHomeFallbackApplied?: true;
readonly unresolvedSettings: ReadonlySet<string>;
readonly timeoutInputs: McpToolTimeoutInputs | undefined;
@@ -145,13 +146,7 @@ export const clientRegistrationEnvironmentDetails = (
platform,
);
if (!environment.ok) return environment;
return ok(
environmentDetails(
environment.value.values,
environment.value.configuration,
environment.value.unresolvedSettings,
),
);
return ok(environmentDetails(environment.value.values, environment.value));
}
const key = parsed?.environmentKey ?? "env";
const registration =
@@ -229,34 +224,24 @@ export const recordedProviderSettings = (
"fragment",
);
if (!details.ok) return { unrecorded: [], differing: [], unresolved: names };
const recorded = snapshotEnvironment(details.value.values, platform);
// Expression names fold like every other environment name on this platform.
const expressions = snapshotEnvironment(
Object.fromEntries(
[...details.value.unresolvedSettings].map((name) => [name, ""]),
),
platform,
);
const { runtimeEnvironment: recorded, unresolvedSettings } = details.value;
const isUnresolved = (name: string): boolean =>
unresolvedSettings.has(identity(name));
for (const name of names) {
const value = recorded[identity(name)];
if (value !== undefined && expressions[identity(name)] === undefined)
observe?.(name, value);
if (value !== undefined && !isUnresolved(name)) observe?.(name, value);
}
const facts = {
unrecorded: names.filter(
(name) =>
recorded[identity(name)] === undefined &&
expressions[identity(name)] === undefined,
(name) => recorded[identity(name)] === undefined && !isUnresolved(name),
),
differing: names.filter(
(name) =>
expressions[identity(name)] === undefined &&
!isUnresolved(name) &&
recorded[identity(name)] !== undefined &&
recorded[identity(name)] !== selection[name],
),
unresolved: names.filter(
(name) => expressions[identity(name)] !== undefined,
),
unresolved: names.filter(isUnresolved),
};
const owned = names.filter((name) => {
const value = recorded[identity(name)];
@@ -293,17 +278,13 @@ export const clientRegistrationEnvironmentDetailsWithBudget = async (
// The budget gate stays fail-closed: settings the resolver may read must be
// literals, and an undeclared read set keeps every unresolved expression
// blocking, because an unreadable budget cannot be treated as absent.
const { timeoutInputs, values } = details.value;
const environment =
resolveProviderRequestBudget === undefined
? values
: snapshotEnvironment(values, platform);
const { timeoutInputs, runtimeEnvironment } = details.value;
const budgetSettings =
timeoutInputs === undefined
? undefined
: resolveProviderRequestBudget?.budgetSettings?.(
timeoutInputs.analysisProvider,
environment,
runtimeEnvironment,
);
const unresolved = [...details.value.unresolvedSettings].filter(
(setting) =>
@@ -327,7 +308,7 @@ export const clientRegistrationEnvironmentDetailsWithBudget = async (
);
const resolved = { ...details.value, timeoutInputs };
if (resolveProviderRequestBudget === undefined) return ok(resolved);
return validatedBudget(resolved, resolveProviderRequestBudget, environment);
return validatedBudget(resolved, resolveProviderRequestBudget);
};
const validatedDetails = (
@@ -343,13 +324,7 @@ const validatedDetails = (
platform,
);
return validated.ok
? ok(
environmentDetails(
environment,
validated.value.configuration,
validated.value.unresolvedSettings,
),
)
? ok(environmentDetails(environment, validated.value))
: validated;
};
@@ -405,14 +380,18 @@ const registrationTimeoutInputs = (
const environmentDetails = (
environment: Readonly<Record<string, string>>,
configuration: Environment,
unresolvedSettings: ReadonlySet<string>,
{
configuration,
runtimeEnvironment,
unresolvedSettings,
}: ValidatedRegistrationEnvironment,
): ClientRegistrationEnvironmentDetails => ({
values: Object.fromEntries(
Object.entries(environment).sort(([left], [right]) =>
compareUnicodeCodePoints(left, right),
),
),
runtimeEnvironment,
unresolvedSettings,
timeoutInputs: [...unresolvedSettings].some((setting) =>
TIMEOUT_INPUT_SETTINGS.has(setting),
@@ -420,20 +399,19 @@ const environmentDetails = (
? undefined
: {
analysisProvider: configuration.REA_ANALYSIS_PROVIDER,
...registrationTimeoutInputs(environment),
...registrationTimeoutInputs(runtimeEnvironment),
},
});
const validatedBudget = async (
details: ResolvedClientRegistrationEnvironmentDetails,
resolveProviderRequestBudget: ProviderRequestBudgetResolver,
environment: Readonly<Record<string, string>>,
): Promise<
Result<ResolvedClientRegistrationEnvironmentDetails, ConfigurationError>
> => {
const providerBudget = await resolveProviderRequestBudget(
details.timeoutInputs.analysisProvider,
environment,
details.runtimeEnvironment,
);
if (!providerBudget.ok) return providerBudget;
return ok({
+5 -5
View File
@@ -1,4 +1,7 @@
import { validateRegistrationEnvironment } from "./RegistrationEnvironmentValidation.js";
import {
validateRegistrationEnvironment,
type ValidatedRegistrationEnvironment,
} from "./RegistrationEnvironmentValidation.js";
import {
isAlias,
isMap,
@@ -9,7 +12,6 @@ import {
type YAMLMap,
type YAMLSeq,
} from "yaml";
import type { Environment } from "../config/environment.js";
import { ConfigurationError } from "../domain/configurationErrors.js";
import { err, ok, type Result } from "../domain/result.js";
import type { ClientConfigurationDocument } from "./ClientConfigurationDocument.js";
@@ -255,11 +257,9 @@ export class DshCordisDocument {
validation: "fragment" | "effective",
platform: NodeJS.Platform,
): Result<
{
ValidatedRegistrationEnvironment & {
readonly values: Readonly<Record<string, string>>;
readonly sourceValues: Readonly<Record<string, unknown>>;
readonly configuration: Environment;
readonly unresolvedSettings: ReadonlySet<string>;
},
ConfigurationError
> {
@@ -8,19 +8,19 @@ import { ConfigurationError } from "../domain/configurationErrors.js";
import { err, ok, type Result } from "../domain/result.js";
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
export interface ValidatedRegistrationEnvironment {
readonly configuration: Environment;
readonly runtimeEnvironment: Readonly<Record<string, string>>;
readonly unresolvedSettings: ReadonlySet<string>;
}
/** Validate literal registration settings while retaining expression-owned unknowns. */
export const validateRegistrationEnvironment = (
values: Readonly<Record<string, string>>,
expressionSettings: ReadonlySet<string>,
validation: "fragment" | "effective",
platform: NodeJS.Platform,
): Result<
{
readonly configuration: Environment;
readonly unresolvedSettings: ReadonlySet<string>;
},
ConfigurationError
> => {
): Result<ValidatedRegistrationEnvironment, ConfigurationError> => {
const runtimeEnvironment = snapshotEnvironment(values, platform);
const unresolvedSettings = new Set(
Object.keys(
@@ -45,5 +45,9 @@ export const validateRegistrationEnvironment = (
settings: seedIssues,
}),
);
return ok({ configuration: validated.value, unresolvedSettings });
return ok({
configuration: validated.value,
runtimeEnvironment,
unresolvedSettings,
});
};
@@ -31,41 +31,75 @@ import { supportedClientRegistrationProfile } from "../../fixtures/clientRegistr
const staleOwnedCommand = ["npx", "-y", "rea-agents@6.6.0", "mcp"] as const;
it("awaits the owner-parsed provider request budget without changing caller strings", async () => {
const parsed = parseClientConfiguration(
JSON.stringify({
mcpServers: {
rea: {
command: "rea",
args: ["mcp"],
env: {
REA_ANALYSIS_PROVIDER: "ida",
REA_IDA_MCP_CONFIG: "/tmp/rea-registration.json/",
},
},
},
}),
"json",
);
const details = await clientRegistrationEnvironmentDetailsWithBudget(
parsed,
undefined,
{},
"effective",
async (provider) => {
expect(provider).toBe("ida");
return ok(17);
it.each([
{
platform: "win32",
env: {
rea_analysis_provider: "ghidra",
rea_ghidra_startup_timeout_ms: "17000",
rea_ghidra_decompile_timeout_seconds: "420",
},
HOST_PLATFORM.platform,
);
expect(details).toMatchObject({
ok: true,
value: {
values: { REA_IDA_MCP_CONFIG: "/tmp/rea-registration.json/" },
timeoutInputs: { providerRequestTimeoutMs: 17 },
deadline: 557_000,
},
{
platform: "win32",
env: {
rea_analysis_provider: "hopper",
rea_hopper_startup_timeout_ms: "85000",
},
});
});
deadline: 205_000,
},
{
platform: "win32",
env: { rea_jeb_mcp_timeout_ms: "800000" },
deadline: 920_000,
},
{
platform: "linux",
env: {
rea_analysis_provider: "hopper",
rea_hopper_startup_timeout_ms: "85000",
},
deadline: 450_000,
},
] as const)(
"writes the deadline derived from $env on $platform",
async ({ platform, env, deadline }) => {
const root = await createTestTempDirectory(
"rea-registration-launch-deadline-",
);
const configPath = join(root, "mcp.json");
const original = JSON.stringify({
mcpServers: { rea: { command: "rea", args: ["mcp"], env } },
});
await writeFile(configPath, original);
const client = {
name: "kimi",
registrationProfile: supportedClientRegistrationProfile("kimi"),
format: "kimi",
configPath,
} as const;
expect(
await configureClientConfiguration(
client,
{},
["rea", "mcp"],
undefined,
platform,
{},
),
).toEqual({
status: "configured",
backupPath: `${configPath}.rea.backup`,
});
const current = parseClientConfiguration(
await readFile(configPath, "utf8"),
"kimi",
);
expect(current.servers.rea).toMatchObject({ toolTimeoutMs: deadline });
expect(current.servers.rea).toHaveProperty("env", env);
},
);
it("preserves owner-parsed registration facts and revalidates later inspections", async () => {
const home = await createTestTempDirectory("rea-registration-snapshot-");
@@ -694,7 +728,7 @@ it("does not resolve a provider budget from an expression omitted from literal v
const resolved = await clientRegistrationEnvironmentDetailsWithBudget(
parsed,
undefined,
{ REA_IDA_MCP_CONFIG: "/selected/ida.json" },
{ REA_IDA_MCP_CONFIG: "/selected/ida.json/" },
"effective",
resolveBudget,
HOST_PLATFORM.platform,
@@ -703,40 +737,7 @@ it("does not resolve a provider budget from an expression omitted from literal v
ok: true,
value: { timeoutInputs: { providerRequestTimeoutMs: 17 } },
});
expect(observations).toEqual(["ida", "/selected/ida.json"]);
});
it("rejects a non-string caller environment key before editing configuration", async () => {
const root = await createTestTempDirectory("rea-invalid-own-environment-");
const configPath = join(root, "config.json");
const source =
'{"mcpServers":{"rea":{"command":"rea","args":["mcp"],"env":{"__proto__":123}}}}';
await writeFile(configPath, source);
const details = clientRegistrationEnvironmentDetails(
parseClientConfiguration(source, "json"),
undefined,
HOST_PLATFORM.platform,
);
expect(details).toMatchObject({
ok: false,
error: { settings: [{ setting: "env.__proto__" }] },
});
expect(
await configureClientConfiguration(
{
name: "cursor",
registrationProfile: supportedClientRegistrationProfile("cursor"),
format: "json",
configPath,
},
{},
["rea", "mcp"],
),
).toEqual({ status: "failed", reason: "readback" });
expect(await readFile(configPath, "utf8")).toBe(source);
await expect(access(`${configPath}.rea.backup`)).rejects.toMatchObject({
code: "ENOENT",
});
expect(observations).toEqual(["ida", "/selected/ida.json/"]);
});
it("does not hide an invalid JEB endpoint in an untouched configuration layer", async () => {
@@ -766,6 +767,12 @@ it("does not hide an invalid JEB endpoint in an untouched configuration layer",
status: "invalid",
remediation: expect.stringContaining(lower),
});
expect(
await configureClientConfiguration(client, selected, ["rea", "mcp"]),
).toEqual({
status: "failed",
reason: "readback",
});
expect(await readFile(lower, "utf8")).toBe(bad);
expect(await readFile(configPath, "utf8")).toBe("{}\n");
});
@@ -807,12 +814,12 @@ it("retains legacy OpenCode environment when migrating into a native server tabl
).toEqual({ status: "unchanged" });
});
const registrationWithEnvironment = (env: unknown): string =>
JSON.stringify({
mcpServers: { rea: { command: "rea", args: ["mcp"], env } },
});
it.each([
[
"environment name containing an equals delimiter",
{ "CALLER=SETTING": "value" },
"CALLER=SETTING",
],
[
"non-string member",
{ REA_MCP_INPUT_SCHEMA_PROFILE: "compact", PORT: 8080 },
@@ -828,7 +835,6 @@ it.each([
{ REA_MCP_INPUT_SCHEMA_PROFILE: "compact", VALUE: null },
"env.VALUE",
],
["array", [], "env"],
["string", "not-a-map", "env"],
["null map", null, "env"],
[
@@ -836,11 +842,6 @@ it.each([
{ REA_MCP_INPUT_SCHEMA_PROFILE: "" },
"REA_MCP_INPUT_SCHEMA_PROFILE",
],
[
"invalid profile",
{ REA_MCP_INPUT_SCHEMA_PROFILE: "bogus" },
"REA_MCP_INPUT_SCHEMA_PROFILE",
],
[
"empty output profile",
{ REA_MCP_OUTPUT_SCHEMA_PROFILE: "" },
@@ -856,11 +857,6 @@ it.each([
{ REA_MCP_MAX_RESPONSE_BYTES: "1" },
"REA_MCP_MAX_RESPONSE_BYTES",
],
[
"ASAR header admission above its maximum",
{ REA_ASAR_MAX_HEADER_BYTES: "268435457" },
"REA_ASAR_MAX_HEADER_BYTES",
],
[
"regex matching deadline of zero",
{ REA_REGEX_MATCHING_DEADLINE_MS: "0" },
@@ -931,11 +927,6 @@ it.each([
{ REA_REFERENCE_SECRET_PATTERNS_JSON: '[""]' },
"REA_REFERENCE_SECRET_PATTERNS_JSON",
],
[
"unpaired compiler specification",
{ REA_GHIDRA_COMPILER_SPEC_ID: "borlandcpp" },
"REA_GHIDRA_COMPILER_SPEC_ID",
],
[
"Windows ChangeTime drift window of zero",
{ REA_WINDOWS_CHANGE_TIME_DRIFT_MS: "0" },
@@ -951,6 +942,49 @@ it.each([
{ REA_WINDOWS_CHANGE_TIME_SETTLE_MAX_POLLS: "1001" },
"REA_WINDOWS_CHANGE_TIME_SETTLE_MAX_POLLS",
],
] as const)(
"identifies the malformed registration setting for %s",
(_name, env, setting) => {
const parsed = parseClientConfiguration(
registrationWithEnvironment(env),
"json",
);
expect(
clientRegistrationEnvironmentDetails(
parsed,
undefined,
HOST_PLATFORM.platform,
),
).toMatchObject({
ok: false,
error: { settings: [{ setting }] },
});
},
);
it.each([
["non-string own key", { ["__proto__"]: 123 }, "env.__proto__"],
[
"environment name containing an equals delimiter",
{ "CALLER=SETTING": "value" },
"CALLER=SETTING",
],
["array", [], "env"],
[
"invalid profile",
{ REA_MCP_INPUT_SCHEMA_PROFILE: "bogus" },
"REA_MCP_INPUT_SCHEMA_PROFILE",
],
[
"ASAR header admission above its maximum",
{ REA_ASAR_MAX_HEADER_BYTES: "268435457" },
"REA_ASAR_MAX_HEADER_BYTES",
],
[
"unpaired compiler specification",
{ REA_GHIDRA_COMPILER_SPEC_ID: "borlandcpp" },
"REA_GHIDRA_COMPILER_SPEC_ID",
],
] as const)(
"refuses %s before changing the configuration",
async (_name, env, setting) => {
@@ -958,9 +992,7 @@ it.each([
const directory = join(home, ".cursor");
const configPath = join(directory, "mcp.json");
await mkdir(directory);
const original = JSON.stringify({
mcpServers: { rea: { command: "rea", args: ["mcp"], env } },
});
const original = registrationWithEnvironment(env);
await writeFile(configPath, original);
const client = {
name: "cursor",
@@ -1110,17 +1142,17 @@ it("keeps a differently cased Qwen expression unresolved on Windows", () => {
{},
"fragment",
);
expect(details.ok).toBe(true);
if (!details.ok) return;
expect(
[...details.value.unresolvedSettings].map((name) => name.toUpperCase()),
).toEqual(["REA_GHIDRA_STARTUP_TIMEOUT_MS"]);
if (!details.ok) throw details.error;
expect(details.value.unresolvedSettings).toEqual(
new Set(["REA_GHIDRA_STARTUP_TIMEOUT_MS"]),
);
expect(details.value.timeoutInputs).toBeUndefined();
expect(details.value.values.rea_ghidra_startup_timeout_ms).toBe("${JOBS}");
});
it.each([
["cline", "selected"],
["cline", 42],
["cursor", "metadata"],
["cursor", 42],
] as const)(
"reads only the profile-selected %s environment with nested value %j",