Skip to content

architecture: rethink config loading system and config files #774

Open

Description

@jbeda

Problem

Mecatl's configuration system has grown from several legitimate needs, but its current ownership model is difficult to reason about:

  • command roots parse flags and some environment/auth-file inputs;
  • app.Build constructs and reads/resolves operator settings through permconfig;
  • per-workspace, trust-gated project configuration must resolve after a session workspace is known;
  • provider and MCP credentials have different loading/lifecycle seams;
  • some settings are load-time snapshots while others are re-resolved or refreshed.

This makes it unclear which settings are process-static, which can safely become live-reloadable, and where a Kubernetes/database-backed configuration source should attach.

Goal

Design a coherent configuration architecture that separates:

  1. source acquisition — CLI flags, environment, operator files, auth files, Kubernetes ConfigMaps/Secrets, database/remote sources;
  2. process-wide operator resolution — typed validation and explicit per-field precedence/merge policy;
  3. workspace/session resolution — trust-gated project settings that must remain dependent on a workspace root;
  4. runtime composition — app.Build consumes resolved configuration and injected resolvers/loaders rather than owning file-source selection.

The design must classify each configuration subtree as one of:

  • process-static / restart required;
  • reloadable atomically at runtime;
  • per-session/per-workspace resolved;
  • credential lifecycle-managed.

It should define safe live-reload semantics: validation before swap, last-known-good behavior, diagnostics, atomicity, which resources are rebuilt or retained, and security/trust constraints. It must preserve existing non-generic merge policies such as deny dominance, operator-only settings, CLI precedence, secret separation, and provider endpoint precedence.

Non-goals

  • Replacing the system opportunistically inside the operator-defined-provider PR.
  • A generic YAML overlay that erases security/trust-specific merge rules.
  • Making secrets available in ordinary settings.yaml.
  • Claiming every setting can be live reloaded.

Starting evidence

  • internal/adapter/permconfig combines user-global/operator and per-workspace project configuration.
  • internal/app.Build constructs the resolver and folds several operator subtrees.
  • internal/cliconfig resolves command-side flags, environment, auth-file snapshots, and profile loaders.
  • Provider profile loading now has an injected composition seam, while MCP already has a profile-loader/lifecycle seam.
  • docs/configuration-reference.md documents schema keys, but not a cross-root effective-configuration or reloadability model.

Related

Activity

  1. jbeda commented on Aug 26, 2026

    @jbeda
    ContributorAuthor

    Concrete symptom: composition downcasts a policy resolver for operator settings

    internal/app.Config stores permResolver as the intentionally narrow permpolicy.RuleResolver, because the permission-policy consumer should only resolve workspace rules. app.Build then repeatedly downcasts it back to *permconfig.Resolver to access unrelated operator settings, for example provider definitions/overrides at internal/app/build.go:1431.

    The assertion is guarded and works in production because Build constructs that concrete resolver, but it is a sign that one object is serving two contracts:

    • a narrow per-workspace permission-rule resolver consumed by policy; and
    • a broad operator-settings accessor consumed by composition for providers, MCP, models, guardrails, posture, retention, and similar subtrees.

    Do not widen permpolicy.RuleResolver with unrelated configuration accessors. The redesign should provide separate views over one underlying concrete source:

    *permconfig.Resolver
      ├─ permpolicy.RuleResolver  → policy/workspace rules
      └─ OperatorConfigSource     → composition/operator settings
    

    An interim implementation could retain a concrete operator-resolver reference inside internal/app; the longer-term source abstraction should permit file, Kubernetes, database, or remote operator configuration without app.Build downcasts.

  2. jbeda commented on Oct 28, 2026

    @jbeda
    ContributorAuthor

    Additional configuration/composition cleanup evidence

    Reviewing MCP credential resolution in PR #2583 exposed another instance of the ownership problem tracked here:

    • app.Config.permResolver stores the settings resolver as the narrow permpolicy.RuleResolver interface, even though composition needs the wider operator-settings object.
    • buildPermResolver constructs a concrete *permconfig.Resolver, narrows it on return, and composition then repeatedly asserts it back to that concrete type to access provider definitions, credential-store configuration, MCP configuration, model routing, learning, retention, harness context, and other operator settings.
    • At the time of review, there were roughly three dozen such assertions across about 15 files under internal/app. A representative example is internal/app/build.go:1855 at PR head 538bfa59c54bedf069a0efbbb8150678574797f9.

    Suggested cleanup within this architecture work

    Retain the wider concrete settings resolver at the composition layer, preferably with a name such as settingsResolver, and narrow it to permpolicy.RuleResolver only at permission-policy and child-resolver boundaries. Do not widen the permission interface with unrelated operator-settings methods, and do not introduce another resolver/cache or settings-discovery pass.

    Preserve these constraints:

    • Explicitly handle nil before conversion to an interface, avoiding typed-nil permission resolvers.
    • Preserve settings construction order, project-trust admission, source precedence, and workspace/session pinning.
    • Keep narrow permission test seams; tests that currently install a fake rule resolver into the broad composition field should instead exercise the appropriate permission-wrapper boundary.

    This is follow-up work for #774, not scope to fold into the MCP credential PR. The current MCP implementation does not depend on this cleanup for correctness.

  3. jbeda commented on Nov 8, 2026

    @jbeda
    ContributorAuthor

    Configuration cleanup: conceptual model and initial scope

    The initial priority is to make the existing configuration system understandable and structurally coherent—not to add LSP support, per-repository MCP, or a general extension framework. Those are eventual use cases against which to check the design, not the first deliverables.

    Substantial implementation should follow stabilization of the new kernel's construction and capability/lifecycle boundaries. Conceptual work can happen now. Relevant design material lives under docs/drafts/session-history/, especially implementation/kernel.md and implementation/components.md; those are design drafts, not claims about current behavior.

    Dimensions to make explicit

    1. Role: defaults, constraints, and selections

    • Defaults supply values when nothing more specific is selected.
    • Selections express an explicit preference or choice.
    • Constraints restrict acceptable choices or behavior regardless of which source supplied them.

    Define selection/default precedence explicitly, but do not reduce constraints to another last-wins layer. Some settings expand available behavior while others constrain it; their interactions need explicit, setting-specific combination rules, including interactions across settings. A higher-precedence selection cannot cancel an operator ceiling or configured Deny/Ask. Decide explicitly whether a disallowed selection is rejected or adjusted; do not silently substitute a value without a defined contract. This calls for understandable rules for the interactions we actually have, not a general-purpose policy algebra.

    2. Authority / configuration level: operator, user, workspace, session

    These describe whose input is admitted and what that actor may control. In embedded mecatui, the user and operator are usually the same person; in a shared mecak8s deployment they are not. Model the distinction even when one person fills both roles.

    Current user-global settings act as operator configuration; there is not a general separate user-preference plane. A personal .mecatl/settings.local.yaml remains project-authority input, despite being local/gitignored. We should not silently promote its authority.

    Workspace-supplied configuration and session choices must stay within the applicable operator policy. Session input may come from authorized API controls, extensions, or hosting code at creation/rebinding, not necessarily a file.

    3. Applicability scope and identity

    Authority is separate from how widely an input applies: deployment/global, one user, one workspace, or one session. Operator-owned configuration can be workspace-scoped; user preferences can also have workspace-specific applicability. What we have called “per-repo” configuration in this discussion means per-workspace, not a separate repository-wide configuration tier.

    Workspace scope needs a strong workspace identity to which configuration can attach. A local filesystem path can help locate a workspace, but cannot be the universal identity: Kubernetes-hosted filesystems and remote execution must fit the same conceptual model. Identity, filesystem location, and execution placement are distinct; host governance roots and execution roots must not be conflated. An authenticated user likewise is not a username string supplied by a client.

    Establish where workspace identity belongs: in the kernel or in a host/session layer immediately above it. That boundary is an open design question to coordinate with the kernel work, not something this config issue should settle by introducing its own competing workspace identifier. Start from existing placement and ownership contracts; do not build a workspace registry, repository-discovery system, or new lifecycle service merely to support configuration.

    4. Component ownership and configuration routing

    Make it clear which component owns a setting, validates it, and consumes it. Avoid reducing everything into one broad config bag that every component must understand.

    Distinguish host/resource construction, kernel execution policy, provider settings, and capability/extension settings. Components should receive narrow typed settings and the capabilities they need, not source-selection machinery or the whole host config. Configuration extensibility need not imply one universal extension interface or dynamic plugin loader.

    5. Acquisition mechanism and provenance

    Flags, environment variables, files, deployment services, and injected hosting inputs are mechanisms—not authorities or scopes. Define which mechanisms each setting supports and how source authority is established. There need not be an environment equivalent for every nested setting, but support and precedence should be deliberate and discoverable.

    Acquire operator inputs coherently rather than repeatedly rereading them during startup. Preserve safe provenance: where a value came from, which default applied, and why an input was ignored, rejected, or superseded. Never expose raw secret-bearing configuration through an effective-config dump.

    6. Value semantics and combination rules

    Specify absent versus explicit false, 0, empty string/list/map, and any reset/unset behavior. Specify scalar replacement, whole-section replacement, keyed merge, accumulation, and policy intersection where applicable. Do not assume one recursive YAML overlay is correct for all settings.

    Characterize current behavior before changing it. Existing inconsistencies include presence-aware steer versus first-true capture of plan-mode-auto-approve; most operator sections currently select a whole block rather than deep-merge fields. Permissions combine under their own effect/audience rules.

    7. Lifecycle, binding time, and consistency

    Classify when values are acquired/resolved, when they become binding, and what changing them affects: process startup, session creation/rebinding, run start, or operation admission. Distinguish startup snapshots, revalidated workspace policy, runtime discovery, and lifecycle-managed credentials/resources.

    Define whether a change affects existing sessions, future runs, or only new processes. Historical effective model inputs/actions must remain reconstructible without being reinterpreted through today's config; current authorization/freshness checks remain distinct. A config revision is not a substitute for retaining required effective values. Live reload is not an initial requirement.

    8. Validation and failure behavior

    Define behavior for missing optional sources, unreadable explicitly selected sources, unknown keys, invalid values, unauthorized settings, incompatible combinations, and unavailable required components. Be explicit about whole-file versus per-section rejection and whether fallback is allowed.

    Current behavior is mixed: some malformed files warn and skip, potentially losing sibling Deny/Ask rules; selected operator errors fail composition. Cleanup should characterize these contracts and deliberately choose changes rather than accidentally changing them through a new loader.

    Compatibility and implementation posture

    The eight dimensions above are a checklist for reasoning about known problems, not a requirement to implement every combination of authority, scope, source, and lifecycle. Configuration is a deep area; keep this effort bounded. Prefer explicit typed rules and small shared mechanisms over a universal configuration framework. Add abstractions only where concrete existing cases justify them.

    Prefer a clean internal pipeline while preserving existing settings syntax wherever its semantics remain sound:

    acquire inputs → resolve typed policy → construct owned resources → bind workspace/session components

    Existing file formats can translate into that model without retaining two competing resolution systems. Assess compatibility separately for file syntax, effective behavior/defaults, host Go APIs, remote APIs, and stored session data. The kernel's planned storage/protocol cutover is not by itself a reason to break settings files.

    First research deliverable: a representative setting inventory covering role, authority, scope, owner/consumer, supported sources, presence/merge semantics, precedence, binding time, failure policy, and safe provenance. Use it to expose contradictions before choosing a replacement schema or framework.

    The first implementation slice should simplify existing acquisition/resolution, not add workspace MCP, LSP, hot reload, or new configuration planes. Narrow component inputs should be aligned with the stabilized kernel seams rather than introducing a competing construction model now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions