LearnNewsExamplesServices
Frontmatter
id10842
titleSubstrate Config Refactor: applyEnv Priority Inversion Fix
stateClosed
labels
airefactoring
assigneesneo-gemini-3-1-pro
createdAtMay 6, 2026, 8:36 PM
updatedAtMay 7, 2026, 2:45 AM
githubUrlhttps://github.com/neomjs/neo/issues/10842
authorneo-gemini-3-1-pro
commentsCount0
parentIssue10822
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMay 7, 2026, 2:45 AM

Substrate Config Refactor: applyEnv Priority Inversion Fix

Closedairefactoring
neo-gemini-3-1-pro
neo-gemini-3-1-pro commented on May 6, 2026, 8:36 PM

Context Epic #10822 aims to establish clear environment variable vs configuration priority. We identified a systemic priority inversion where Config.load() (Neo.merge) inadvertently overwrote environment variable defaults with JSON config values across multiple MCP servers.

The Problem Fragmented, one-off "normalizer" helpers (e.g., in DeploymentConfig.mjs and EmbeddingProviderConfig.mjs) failed to address the core priority inversion. These helpers were ad-hoc and did not natively support nested keys, strict validation safety, or empty-string preservation.

The Architectural Reality The triad swarm reached consensus in Discussion #10840: we must shift to a single source-of-truth applyEnv() reflex. This pattern uses a flat, dot-path ledger (envBindings) mapping environment variables to configuration keys, combined with explicit parsing functions (e.g., parsePort, parseBool) to guarantee runtime safety.

The Fix Implement the new EnvConfig.mjs utility and strict parsers, migrate all MCP server config.template.mjs files to use the envBindings map, and completely deprecate the legacy helper files.

Acceptance Criteria

  • New EnvConfig.mjs helper (applyEnvBindings + setDeep + parsers) created in ai/mcp/server/shared/helpers/.
  • Tier 1 ai/config.template.mjs migrates to envBindings (no process.env in defaults).
  • MC + KB config.template.mjs migrate to envBindings.
  • Delete DeploymentConfig.mjs 5 helpers + EmbeddingProviderConfig.mjs entire file.
  • Unit suite: all rejection paths + nested-write + empty-string preservation.
  • Integration suite: MC + KB load-config-then-env-override.
  • Final migration audit: zero process.env.X reads in config templates for env-bound keys (or explicit justification).

Origin Session ID 88a6ed3a-b1b9-461a-aaf3-7c9984bd12e7

tobiu referenced in commit e2f7377 - "refactor(mcp): EnvConfig priority inversion fix (#10842) (#10863) on May 7, 2026, 2:45 AM
tobiu closed this issue on May 7, 2026, 2:45 AM