Skip to content

fix(setup): preserve configured MCP server environment - #1607

Merged
morluto merged 3 commits into
morluto:mainfrom
Adkid-Zephyr:fix/setup-preserve-registration-environment
Oct 10, 2026
Merged

morluto merged 3 commits into
morluto:mainfrom
Adkid-Zephyr:fix/setup-preserve-registration-environment

Conversation

@Adkid-Zephyr

@Adkid-Zephyr Adkid-Zephyr commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1606. Setup discarded existing REA server environment settings while migrating its launcher or updating provider paths. Keep valid overrides, and refuse malformed maps or invalid known environment settings before writing rather than dropping the whole map or reporting a server that cannot start as aligned.

Problem and expected behavior

setup --client pi --skill=false --yes --json removed REA_MCP_INPUT_SCHEMA_PROFILE=compact from an existing registration. Its next stdio tools/list contained four schemas above the compact budget. #1484/#1514 document whole-request failures caused by the full catalog in size-capped clients.

Likewise, one numeric/boolean/null environment value must not cause all string peers to disappear. An empty or invalid schema profile must produce a source-specific setup/doctor diagnostic, leaving the original configuration intact.

Change and scope

  • Read and validate REA's explicit string environment map once through a shared boundary. Reuse the runtime's environment parser for known settings; retain original string values and unknown keys without persisting defaults or ambient process variables.
  • Merge detected provider settings over matching keys, preserving the others across JSON, TOML, OpenCode environment, Hermes YAML and OpenCode V1-to-V2 migration.
  • Apply validation to setup preflight and doctor registration inspection. Uninstall can still remove a broken owned registration for recovery.
  • Explain retained overrides and detected-key precedence in the setup plan and installation guide.

Contract and boundary impact

  • Semantic owner and earliest changed stage: client registration environment, before setup plans or writes.
  • CLI/MCP/tool-catalog contract: existing schemas unchanged; configured runtime presentation survives.
  • Provider/bridge/platform compatibility: no provider protocol change; detected provider keys still win over old values.
  • Evidence/artifact/provenance/reconstruction contract: none.
  • Process execution/authorization/cleanup/containment impact: none; no ambient-environment persistence.
  • Generated metadata/package/installation impact: setup/doctor diagnostics and preservation only; no dependency or release metadata change.

Evidence and regression coverage

  • Before the initial fix: four filesystem cases and the actual CLI/stdio-MCP compact-budget regression failed. After it, valid environment settings survive migration, provider-key replacement and repeated setup.
  • Before validation: nine filesystem cases failed for malformed maps/members or invalid profile/budget; two public CLI cases incorrectly exited successfully with invalid profiles. They now pass and prove no configuration rewrite or backup creation on refusal.
  • CLI/MCP test launches the written command, checks all schemas within 13,312 bytes and a successful ping. Dry-run discloses preserved overrides; repeat setup has empty planned/applied actions.
  • Coverage includes sibling preservation, original backups, JSON/TOML/YAML, OpenCode migration, doctor invalid-state reporting and named remediation.
  • Remaining proof gaps: no paid model request, live client UI, Windows host or real analysis engine. The model-provider consequence relies on upstream feat(mcp): compact input schema profile for size-capped providers (kimi-cli/Moonshot) #1514's executed evidence.

Evidence-bearing checklist: not applicable; no analysis Evidence changes.

Validation performed

Integrated upstream main bbd0192; Node 24.18.0 / npm 11.16.0 / macOS arm64:

  • 16 setup/client suites — 248 passed, zero failures. This includes the previously reported six uninstall failures, corrected upstream.
  • Final tests/acceptance/setup/piClientSetup.test.ts after the plan assertion — 6 passed.
  • All 17 suites containing failures in the original CI run — 212 passed, 26 skipped, 2 failed in the first broader local run. The two macOS process cases reported ambiguous_environment_boundary; that suite then passed 13/13 in an isolated run on this head and 13/13 on unmodified bbd0192. Process production/test code is identical to main; no assertion or timeout was relaxed here.
  • npm run check — passed, including typecheck, lint, format, knip, metadata and architecture guards (existing warnings remain).
  • npm run docs:check — passed.
  • npm run verify:test-discovery — passed, 775 files exactly once.
  • npm run verify:package — passed, including isolated installed CLI/MCP, setup/update and skill verification.
  • npm pack --dry-run, git diff --check, pre-commit and pre-push checks — passed.

Latest head bc90619 triggered CI run 38083744360, which explicitly awaits approval from a maintainer. No jobs have executed on this head yet; local validation is not a remote CI pass claim.

Compatibility, safety, and release

  • Breaking changes/migration: no schema change. Repair a named malformed environment value before setup; remove unwanted valid overrides explicitly in the client file.
  • Real provider/OS coverage: actual macOS filesystem, CLI and stdio MCP with synthetic inputs; no live model or analysis provider.
  • Package/release metadata: unchanged.
  • Security/privacy/process/containment review: ordinary configuration correctness only, synthetic files and owned local processes; no added authority.

Review checklist

  • Concrete problem, focused Conventional Commit title, linked issue.
  • Observable regressions, refusal before mutation, migration, precedence and repeat coverage.
  • Owning documentation and representative CLI/MCP output covered.
  • Final diff checked for unrelated changes and unsupported claims.

Disclosure: implementation and regression tests were prepared with OpenAI Codex assistance.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: Fixed: setup now keeps the env keys already in REA's entry, and the compact schema setting survives. Still open: one non-string value, like a bare number, drops the whole env block, and setup says ready. Also, setup now keeps an invalid schema profile and says ready for a server that cannot start.

I ran 23 cases on the PR head 4560e0ddc and on current main 0d8997833. That is 46 runs, each in a fresh fake home. Main is two commits past the PR base 603d04ee3. I read the config files each client writes. I did not install any client.

Case (runs per build) Main 0d8997833 PR 4560e0ddc
#1606 repro: Pi (MIT) with compact and silent (1) Both keys gone. 4 tools exceed the 13,312-byte limit. The largest is 57,018 bytes. Both keys kept. 0 tools exceed it. The largest is 11,026 bytes.
Three keys: a user key, an unrelated key, and one setup finds. JSON, TOML, OpenCode (3 shapes), Hermes YAML (8) Only the found key is left. The user key and the unrelated key stay. Found key updated. No key repeats.
User sets the same key that setup finds (1) Found value written. Found value wins.
Setup no longer finds a key it found before (1) Old key dropped. Old key kept, with its old value.
Schema profile empty, or bogus (2) Key dropped. Server starts. Key kept. Server cannot start, as before setup.
One number, true or null among string values (6) Whole env dropped. Whole env dropped. Setup says ready.
Env is an array, a string or null (3) Env dropped. Env dropped. No refusal.
Env is an empty object (1) No env. No env.
  • Every run: a second setup changed nothing (46 of 46). Doctor said aligned after setup (46 of 46). Uninstall removed the REA entry (46 of 46). In the 42 runs with a second server, that server stayed.
  • After uninstall: the user's env keys went with the REA entry. No stray env table or rea: stub stayed behind. The .rea.backup file holds the original, byte for byte.
  • New tests: the PR's 6 new cases fail on main and pass on the PR head. That held on Node 22.23.1, 24.18.0 and 26.11.1.
  • clientLifecycle.test.ts: 4 tests fail on the PR head, on all three Nodes. Main passes them, because main commit 11e3fae69 edited that test file. With main's file plus the PR's four hunks, 43 of 43 pass on Node 24.18.0.
  • npm run check:fast: passes on the PR head (Node 24.18.0).
  • Plan text: the plan says "No additional environment variables" even though two stay. When setup finds a key, the plan lists only that key.

Not run

  • The client apps themselves, Windows, macOS, and any paid model call.
  • Hopper and Ghidra discovery. A stub IDA registration file stood in for the found key. IDA never ran.
  • The npx rea-agents launcher. Setup wrote a local path in my runs.
  • Config files with comments (JSONC, commented TOML).
  • npm run check, docs:check, verify:package and the full test suite.

Edit: The rerun on the new head bc90619 is in my new comment. Both open findings are fixed there.

Thanks, Adkid-Zephyr, for the report, the fix and the new tests.

More findings
  • Number, true or null: the PR reads env as a map of strings. One other value type fails that read, and every key is dropped, valid ones too. I ran a JSON number, true and null in Pi's JSON, an integer in a TOML env table, and an unquoted number in Hermes YAML. All six dropped the whole block on both builds. The original stays only in .rea.backup.
  • Empty or invalid profile: with REA_MCP_INPUT_SCHEMA_PROFILE set to an empty string or bogus, that value was already invalid. The server could not start before setup either. Main dropped it by accident. The PR keeps it. The server stops at start, and its error says the setting must be full or compact. Setup and doctor still said ready and aligned.
  • Found key gone: a path setup wrote once stays after setup stops finding it. I seeded REA_IDA_MCP_CONFIG=/old/ida.json and gave setup no IDA file. The PR kept the old path. The server still started. Removing it now means editing the file.
  • Other fields on REA's entry: a timeout of 60,000 (JSON), timeout: 120 (YAML) and startup_timeout_sec = 45 (TOML) were reset on both builds. The TOML one went back to 30. The PR only claims env, so this is unchanged.
  • Env that is an array, a string or null: both builds replace it with no env and say nothing. The original stays only in .rea.backup.
  • Main and the PR base: the two commits past the PR base touch only clientLifecycle.test.ts among the PR's files. GitHub reports the PR as mergeable.
  • Doctor after uninstall: it exits 1 on both builds, because no client is registered any more.
Tests per Node

New PR tests plus clientLifecycle.test.ts, three files (52 tests):

Build Node 22.23.1 Node 24.18.0 Node 26.11.1
PR head 4560e0ddc 48 pass, 4 fail 48 pass, 4 fail 48 pass, 4 fail
Main 0d8997833 with the PR's two new test files copied in 46 pass, 6 fail 46 pass, 6 fail 46 pass, 6 fail
  • The 4 PR-head failures are skill-removal cases in clientLifecycle.test.ts. The 6 main failures are the PR's new cases: 5 in clientConfigurationEnvironment.test.ts and 1 in piClientSetup.test.ts.
  • The 16 suites the PR lists, on Node 24.18.0 only: the PR head has 231 pass and 6 fail (the 4 above and 2 in qwenClientConfiguration.test.ts). That matches the PR text. Main with the new files has 229 pass and 8 fail (the 6 new cases and the same 2 Qwen cases). So the Qwen failures also happen on main.
  • clientLifecycle.test.ts from main with the PR's four hunks applied, on the PR head source, Node 24.18.0: 43 of 43 pass.
Configs, before and after

Pi, the #1606 repro. Before, then main, then the PR:

{"mcpServers":{"rea":{"type":"stdio","command":"npx","args":["-y","[email protected]","mcp"],"env":{"REA_MCP_INPUT_SCHEMA_PROFILE":"compact","REA_LOG_LEVEL":"silent"}}}}
"rea": { "type": "stdio", "command": ".../scripts/rea.mjs", "args": ["mcp"] }
"rea": { "type": "stdio", "command": ".../scripts/rea.mjs", "args": ["mcp"],
  "env": { "REA_LOG_LEVEL": "silent", "REA_MCP_INPUT_SCHEMA_PROFILE": "compact" } }

A TOML client, three keys. After setup on the PR:

[mcp_servers.rea.env]
MY_CUSTOM_VAR = "mine"
REA_IDA_MCP_CONFIG = "<fake home>/ida.json"
REA_MCP_INPUT_SCHEMA_PROFILE = "compact"

Hermes Agent (MIT) YAML, same three keys. After setup on the PR:

    env:
      MY_CUSTOM_VAR: mine
      REA_IDA_MCP_CONFIG: <fake home>/ida.json
      REA_MCP_INPUT_SCHEMA_PROFILE: compact

OpenCode (MIT) uses the environment field. I ran it with the server under mcp.rea, under mcp.servers.rea, and with the old entry beside a mcp.servers table. In all three the PR kept the same three keys. In the third it moved the entry into mcp.servers and left other as it was.

A number among strings, Pi. Before, then main and the PR (same result):

"env":{"REA_MCP_INPUT_SCHEMA_PROFILE":"compact","REA_MCP_MAX_RESPONSE_BYTES":33554432,"MY_CUSTOM_VAR":"mine"}
"rea": { "type": "stdio", "command": ".../scripts/rea.mjs", "args": ["mcp"] }
Commands

Each step ran with HOME checked to sit inside my test folder. Steps: dry run, setup, doctor, setup again, uninstall, doctor. The dry run changed no file in any case.

env -i PATH="$NODE24/bin:/usr/bin:/bin" HOME="$FAKE" USERPROFILE="$FAKE" TMPDIR="$FAKE/tmp" \
  XDG_CONFIG_HOME="$FAKE/.config" XDG_DATA_HOME="$FAKE/.local/share" \
  XDG_CACHE_HOME="$FAKE/.cache" XDG_STATE_HOME="$FAKE/.local/state" \
  npm_config_cache="$FAKE/.npm" timeout 60 \
  node scripts/rea.mjs setup --client pi --skill=false --yes --json

The found key came from REA_IDA_MCP_CONFIG=$FAKE/ida.json, a file holding {"command":"true"}.

Schema sizes: I started the written command over stdio, sent initialize and tools/list, and measured each inputSchema. No model was called.

Tests, once per Node, with a fake home:

node scripts/run-development-tests.mjs focused \
  tests/boundary/filesystem/clientConfigurationEnvironment.test.ts \
  tests/acceptance/setup/piClientSetup.test.ts \
  tests/boundary/filesystem/clientLifecycle.test.ts
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (npm 11.16.0 on Node 24)
  • Head / base: 4560e0ddc / 603d04ee3. Main: 0d8997833.
  • Builds: npm ci and npm run build on Node 24.18.0 from git archive of each sha.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: Both open findings are fixed. Setup now refuses a bad env value or a bad schema profile before it writes, and doctor says invalid. The 12 other cases match the old head, and every test I ran passes on the new head.

This is the rerun promised in my earlier comment. I ran 24 cases on the new head bc90619 and on current main 69fe5b6, each in a fresh fake home. That is 48 runs. Main has moved since my first run, and the PR now includes upstream main bbd0192. I did not install any client.

I ran the 23 old cases plus one new case, because the new commit also checks the response-size setting. Each run did a dry run, setup, doctor, setup again, uninstall and doctor.

What changed against the old head 4560e0d

Case (runs per build) Old head 4560e0d New head bc90619
One number, true or null among string values (6: Pi (MIT) JSON, a TOML client, Hermes YAML (MIT), OpenCode (MIT)) Whole env dropped. Setup said ready. Setup stops with exit 1 and needs_human. The message names the bad key, such as env.FLAG. The file is untouched.
Env is an array, a string or null (3) Env dropped with no message. Setup stops the same way. The message names env.
Schema profile empty, or bogus (2) Key kept. Setup said ready for a server that cannot start. Setup stops. The message names REA_MCP_INPUT_SCHEMA_PROFILE and says it must be full or compact.
New case: response budget "1" (1) Not run on this head. Main drops the key and says ready. Setup stops. The message says the value must be at least 10,485,760.
Dry-run plan text The plan said it added no variables, even when two stayed. The plan now says old overrides stay.

The 12 other cases gave the same results as the old head. They are the #1606 repro, the eight three-key cases, the same-key case, the stale-key case and the empty-env case. In the repro, both keys stay, and no tool exceeds the 13,312-byte limit (largest 11,026 bytes).

  • Every refusal: doctor said invalid and exited 1. Setup run twice changed no file. Setup wrote no .rea.backup in any of the 12 refusals.
  • Every other run: setup said ready, doctor said aligned, and a second setup changed nothing.
  • Uninstall: it still removes a refused entry (exit 0), as the PR says. The .rea.backup it makes matches the original file byte for byte. A second server stayed in all 44 runs that had one.
  • Dry runs: none of the 48 changed a file.

Tests

Run Node 22.23.1 Node 24.18.0 Node 26.11.1
New head: the PR's two changed test files plus clientLifecycle.test.ts (63 tests) 63 pass 63 pass 63 pass
Main plus the PR's two test files (63 tests) 46 pass, 17 fail 46 pass, 17 fail 46 pass, 17 fail

On Node 24.18.0 the 16 suites in the PR body pass on the new head (248 tests), and npm run check:fast passes. The 4 clientLifecycle.test.ts failures from the old head are gone.

Still not run

  • The client apps themselves, Windows, macOS, and any paid model call.
  • Hopper and Ghidra discovery. A stub IDA registration file stood in for the found key.
  • The npx rea-agents launcher. Setup wrote a local path in my runs.
  • Config files with comments (JSONC, commented TOML).
  • Setup for several clients at once, where only one has a bad env.
  • npm run check, docs:check, verify:package and the full test suite.

Thanks, Adkid-Zephyr, for the fix and the extra tests.

More findings
  • Hand repair: a refusal means the user edits the client file. I did not test whether quoting a number ("33554432") lets setup pass.
  • Found key gone: unchanged. A path setup wrote once stays after setup stops finding it. I seeded REA_IDA_MCP_CONFIG=/old/ida.json with no IDA file, and the old path stayed.
  • Other fields on REA's entry: unchanged. A timeout (JSON, YAML) is still dropped, and startup_timeout_sec = 45 still resets to 30. The PR only claims env.
  • Main moved: main now has 5 tools over the limit in the repro (the old run had 4). The new one is compare_source_to_bundle at 13,354 bytes. The largest is still 57,018 bytes.
  • Doctor after uninstall: it exits 1 on both builds, because no client is registered any more.
  • PR state: mergeable. No review comments yet. CI on the new head waits for a maintainer, as the PR body says.
Test details

Three files, 63 tests: clientConfigurationEnvironment.test.ts, piClientSetup.test.ts and clientLifecycle.test.ts.

  • All 17 main failures are in the PR's two files. They are the new tests, so they should fail on main.
  • The 4 clientLifecycle.test.ts failures from the old head are gone. The merge of upstream main fixed them.
  • The 16 suites in the PR body, on Node 24.18.0: 248 pass, 0 fail on the new head. That matches the PR text. Main plus the two files: 231 pass, 17 fail.
  • npm run check:fast on the new head, Node 24.18.0: passes.
  • The 17 main failures are 14 in clientConfigurationEnvironment.test.ts (5 keep-env cases and 9 refusal cases) and 3 in piClientSetup.test.ts.
Commands

Each step ran with HOME checked to sit inside my test folder. The dry run changed no file in any case.

env -i PATH="$NODE24/bin:/usr/bin:/bin" HOME="$FAKE" USERPROFILE="$FAKE" TMPDIR="$FAKE/tmp" \
  XDG_CONFIG_HOME="$FAKE/.config" XDG_DATA_HOME="$FAKE/.local/share" \
  XDG_CACHE_HOME="$FAKE/.cache" XDG_STATE_HOME="$FAKE/.local/state" \
  npm_config_cache="$FAKE/.npm" timeout 60 \
  node scripts/rea.mjs setup --client pi --skill=false --yes --json

Tests, once per Node, with a fake home:

node scripts/run-development-tests.mjs focused \
  tests/boundary/filesystem/clientConfigurationEnvironment.test.ts \
  tests/acceptance/setup/piClientSetup.test.ts \
  tests/boundary/filesystem/clientLifecycle.test.ts
Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1 (npm 11.16.0 on Node 24)
  • Head / old head: bc90619 / 4560e0d. Main: 69fe5b6.
  • Builds: npm ci and npm run build on Node 24.18.0 from git archive of each sha.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto
morluto merged commit 52331ab into morluto:main Oct 10, 2026
@morluto

morluto commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Welcome to REA, @Adkid-Zephyr! Thanks for preserving the environment overrides people have explicitly configured for their MCP server. The migration, backup, and idempotence coverage helps check that setup retains those settings while updating provider paths. Squash-merged.

@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration labels Oct 14, 2026
@morluto morluto added the area: setup Setup, packaging, upgrade, install, Doctor, and client registration label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] setup deletes configured MCP schema profile and adapter settings

3 participants