Skip to content

fix(setup): validate registration overrides with runtime semantics - #2769

Closed
To3akaRin wants to merge 12 commits into
morluto:mainfrom
To3akaRin:codex/registration-runtime-validation
Closed

To3akaRin wants to merge 12 commits into
morluto:mainfrom
To3akaRin:codex/registration-runtime-validation

Conversation

@To3akaRin

@To3akaRin To3akaRin commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Setup and doctor could report a registration as current even when its explicit environment prevented MCP startup. They now use the same pure environment parsing rules as startup, report the offending setting, and refuse setup writes until the caller repairs it. Valid settings split across OpenCode configuration files remain valid after merging.

Fixes #2665.

Problem and expected behavior

For example, a Cursor entry with HOPPER_LOADER_ARGS_JSON: "{" was accepted as aligned although rea mcp immediately exited with a configuration error. An unpaired REA_GHIDRA_COMPILER_SPEC_ID had the same mismatch. These failures must be diagnosed before creating a backup or changing the registration. OpenCode may put the language identifier in opencode.json and the compiler specification in opencode.jsonc; that pair must be checked in their merged environment, while malformed values in either source must still be reported.

Change and scope

  • Use two pure parsing stages: parseEnvironmentValues parses individual settings and decoded arrays; parseEnvironment also validates dependencies in a complete environment. Startup consumes the parsed collections instead of decoding them again. Neither stage probes the host.
  • Validate every client file as a fragment before merging, then validate the effective environment. A valid higher-priority override cannot hide a malformed map, value or JSON array in a lower-priority source.
  • Retain each parsed layer's source path. Setup, alignment checks and desired-registration construction replace the reread target at its original precedence position before validation, including a missing or non-final write target. Persist only that target's explicit overrides; inherited settings are not copied into a higher-priority file.
  • Existing client registration readers validate through that owner while retaining the original explicit strings, unknown caller keys and absence of defaults.
  • DSH carries expression-backed setting identities separately from literal values. A language expression is unknown, not a proven missing companion; a literal override receives normal validation. Expressions remain preserved and are never evaluated by REA's registration reader.
  • Document the distinction between registration alignment and validation of eventual expression values.

Contract and boundary impact

  • Semantic owners: pure environment value/dependency parsing and the existing effective client-configuration merger, before projection or persistence.
  • Scope decision: not applicable; correctness fix within existing setup/diagnostic boundaries, with no provider or execution-authority expansion.
  • CLI/MCP contracts: existing statuses and configuration errors; setup reports needs_human with empty planned/applied actions, doctor reports the registration as invalid, and startup retains its existing error. Tool schemas and Evidence are unchanged.
  • Provider/platform compatibility: runtime semantics stay the same. Previously accepted but startup-invalid registration literals are rejected earlier.
  • Installation: valid strings, unrelated entries, backups and idempotence remain intact. No new setting, dependency, release metadata or committed generated output.
  • Existing workflow effects: read client configuration; approved setup writes configuration and backups. Verification also launches isolated CLI/MCP processes and uses package-install network access. This change adds no target execution, injection, protection recovery or network behavior.

Evidence and regression coverage

On base f0f09950f34d96e3b1c62fd04821af5e301f80c7, the extended registration boundary tests produced 10 failures / 92 passes before the production change. The failures covered malformed loader JSON, wrong JSON shape, NUL arguments, malformed/empty exclusion patterns, the missing language companion, DSH literal settings and an invalid literal replacing a DSH expression.

Real compiled CLI tests compare MCP startup with setup and doctor for Cursor and DSH, assert unchanged bytes and no backup on refusal, then repair the fixture and verify raw-value preservation, backup readback and repeatable setup. Filesystem boundary controls cover Cursor, Codex, OpenCode and Hermes, including exact environment equality so defaults cannot leak into a registration. DSH controls preserve tagged expressions and distinguish known companions from unresolved ones. Eight additional layered filesystem cases verify split settings, a genuinely missing companion, precedence, unchanged lower-layer bytes, backups, invalid lower-priority fields, missing targets and non-final write targets. A real OpenCode CLI journey verifies setup/doctor accept the valid split pair without writes and reject the same configuration after its required language is removed.

Validation performed

Executed on macOS arm64 with Node 24.19.0 / npm 11.17.0 and locked dependencies. The repository pins 24.18.0 / 11.16.0; the exact pinned pair was not used for these runs.

  • npm run test:focused -- src/config.test.ts tests/boundary/filesystem/clientConfigurationEnvironment.test.ts tests/boundary/filesystem/clientConfigurationLayeredEnvironment.test.ts tests/boundary/filesystem/clientConfigurationDialects.test.ts tests/boundary/filesystem/dshClientConfiguration.test.ts tests/acceptance/setup/registrationRuntimeEnvironmentCli.test.ts tests/acceptance/setup/dshClientSetup.test.ts tests/acceptance/setup/clientConfigurationDiagnosticsCli.test.ts — 197 passed / 8 files. Includes the existing DSH setup, actual SDK MCP connection, repeat and uninstall journey.
  • npm run check — passed; typecheck, format, lint, knip, metadata and architecture guards. Lint reported 0 errors and 1,051 repository warnings.
  • npm run docs:check — passed, including 2 README consistency tests.
  • npm run verify:test-discovery — all 1,057 test files discovered exactly once.
  • npm run jscpd — passed, 2.98% duplicated lines.
  • npm run verify:package — passed: isolated install/update, CLI/MCP, setup/uninstall, backups, failure recovery and cleanup; 191 tools / 6 prompts, verified lineage with no descendants.
  • npm pack --dry-run --json — passed, 1,549 package entries.
  • git diff --check — passed.

Compatibility, safety, and release

No migration for valid configurations. Invalid literal overrides need the named setting repaired before setup can continue. Error settings and startup diagnostics retain the existing contract.

Remaining coverage limits: no live Cursor/Codex/Hermes application or native Hopper/Ghidra execution, no Windows/Linux run, and no evaluation of DSH expressions in a real Harness process. The package verifier's controlled bridges do not establish real-provider behavior. All registration mutations used test-owned temporary homes; no user registration was changed.

Before merge

  • Concrete issue, focused outcome and conventional title.
  • Scope and authority are resolved for this existing-boundary correction.
  • Regression tests cover changed behavior, preservation and failure paths.
  • Owning installation documentation is updated; no public tool schema changes.
  • Public CLI behavior and actual verification scope are stated.
  • Final diff checked for unrelated cleanup, secrets and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-13T11:14:29.572892Z c1074f6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable defects remain in the reviewed changes.

Summary

Setup and doctor now share startup’s environment checks without adding defaults to saved registrations.

  • Setup and doctor check registration settings like MCP startup does.
  • OpenCode checks each layer and keeps overrides in their source file.
  • Harness expressions stay unknown during registration checks.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read client files] --> B[Check each file's values]
  B --> C[Merge files in precedence order]
  C --> D[Check setting dependencies]
  D --> E[Doctor reports registration state]
  D --> F[Setup rereads selected target]
  F --> G[Replace target at its original position]
  G --> H[Check desired environment]
  H --> I[Write only target overrides]
Loading

Reviews (8) · Last reviewed commit: "Merge branch 'main' into codex/registrat..." · Reviewed by Greptile

Comment thread src/config/environment.ts Resolved
@morluto morluto added bug Something isn't working area: setup Setup, packaging, upgrade, install, Doctor, and client registration area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions P2: medium Medium priority issue labels Oct 13, 2026
morluto and others added 8 commits October 13, 2026 23:01
* fix(comparison): preserve incomplete function call evidence

Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty.

Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls.

* fix(comparison): recheck historical calls-only changes

---------

Co-authored-by: morluto <[email protected]>
morluto added a commit that referenced this pull request Oct 14, 2026
Keep layered environment choices, current byte-exact recovery snapshots, and package-manager failure details. Report pinned package drift without claiming runner resolution. Retain failed Linux installer cleanup for host-owned retry while preserving the install outcome.

Reviewed fixes include #2632, #2769, #2783, #2959, #2979, #2983, #2995, #3009, and #2559.

Validation: 98 focused setup/registration tests passed; 45 Linux installer tests passed. Real Linux package installation remains unverified.
Merge main at bcc1415, preserving layered environment validation and the current recovery backup owner. Include the upstream Windows inspection verifier correction for retained handles after rename.

Validated 277 focused tests, npm run check, npm run docs:check, npm run verify:package, and npm pack --dry-run. The integrated tree matches the captured main revision, which already incorporates PR morluto#2769.
@CassieFox23

Copy link
Copy Markdown
Contributor

Heads up: main already has this change in ec56c1d. The code is in src/application/ClientRegistrationEnvironment.ts. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

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

@To3akaRin

Copy link
Copy Markdown
Contributor Author

Thanks for checking! I compared the current PR head (d3c3967) with main (bcc1415). Both have the same Git tree, and the PR has no remaining file changes. Main fully covers this PR, so it can be closed as superseded. Thanks for integrating the fix and tracking the cleanup!

@To3akaRin To3akaRin closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @To3akaRin for catching that registration could pass setup validation yet fail at runtime because its environment was invalid. Main now reuses runtime environment semantics during registration checks in ec56c1da0 (main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands area: domain Domain logic, errors, and pure functions area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working P2: medium Medium priority issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(setup): report runtime-invalid server overrides instead of aligned registrations

4 participants