Search and contents

Sharing configuration fragments across node instances

How to stop hand-copying the same config values into every node appliance's config file, using load_node_config's "$shared" reference mechanism (engine/config_loader.py).

Configuration versioning and rollback need no new mechanism. Config files are JSON kept in source control, and git's own history gives versioning and rollback for free. Shared Configuration Fragments don't change that: they are a value-composition step that runs before schema validation, and the fragments are still git-committed and fully auditable.

What they solve is duplication. A value that is genuinely shared across node instances no longer needs its own hand-edited copy in every config file. The tuning values that Changing the inference model walks through discovering are an example: every node appliance pointed at the same Ollama endpoint should run the same context_window_tokens, timeout_seconds and retry schedule.

1. Decide whether a value belongs in a shared fragment

A value is a good fit if it's the same across more than one node instance's config because of something external to any one node. Examples are a shared Ollama endpoint, a shared Postgres host, or anything else tied to site infrastructure rather than to one node type's own domain logic.

It's a bad fit if:

  • it's secret (SOPS-encrypted values are rejected outright; see Pitfalls), or
  • two node instances only happen to have the same value today, with no reason they'd need to change together.

2. Write the fragment

A shared fragment is a plain JSON object, <name>.json, in a directory of your choosing (a per-site shared/ directory alongside the site's node config files is the natural place):

{
  "endpoint": "http://ollama.example.local:11434",
  "context_window_tokens": 8192,
  "reserved_output_tokens": 400,
  "timeout_seconds": 30,
  "retry": {
    "max_attempts": 2,
    "temperatures": [0.1, 0.5],
    "top_p": [0.9, 1.0]
  }
}

Leave out anything that should stay node-specific — model is a common one: two node instances on the same endpoint might legitimately run different models.

3. Reference it from a node's config

Replace the literal object with {"$shared": "<name>", ...local overrides...}:

{
  "node_type": "MES",
  "node_type_version": "0.7.0",
  "config_version": 1,
  "config": {
    "inference": {
      "$shared": "site_inference_tuning",
      "model": "example-llm"
    }
  }
}

model here isn't in the fragment, so it passes straight through as this config's own value. Any key present in both the fragment and the reference is decided by the reference — a node can override a shared value for its own reasons without forking the whole fragment.

4. Load it with shared_dir set

document = load_node_config(node_type, config_path, shared_dir=Path("shared/"))

The node entrypoints (node_main, erp_main, plc_generic_device_main, production_scheduling_main) take the same directory as --shared-config-dir. The management service reads it from MANAGEMENT_SHARED_CONFIG_DIR (see management-api.md).

Omit shared_dir for a config file that never uses "$shared": nothing changes, and load_node_config behaves exactly as it always has. Passing shared_dir when it's not needed is harmless too, because it's only consulted if a "$shared" key actually shows up.

5. Update the value in one place

This is the point of the mechanism. When a retune is needed (say the runbook in changing-the-inference-model.md turns up a different timeout_seconds for the current model), edit the fragment file once and commit it. Every config referencing it picks up the new value the next time it's loaded. There is no per-appliance SSH session, and no risk of one node getting updated while another is missed.

Pitfalls

  • Fragments are non-secret by design, and this is enforced, not just documented.
    • A fragment named with the .enc.json SOPS convention is rejected with a clear error rather than silently read as ciphertext or plaintext.
    • Secrets stay where credentials are normally kept: per-node, decrypted with a key that only ever lives locally on that appliance. Don't try to route a credential through a shared fragment to save an edit; it won't load.
    • The same rule catches a plain fragment that sets a field the Configuration Schema marks x-sensitive (engine/sensitive_config_fields.py). The load fails naming the field, and the value belongs in the node's own, optionally SOPS-encrypted, config file.
  • A fragment name is letters, digits, _ and - only. Any other "$shared" name is rejected before a file is looked up, so a name cannot reach outside shared_dir.
  • Nesting isn't supported. A fragment's own content may not itself contain "$shared" — it must already be a plain, resolved value. This is a deliberate simplicity choice, not a current limitation to work around: the mechanism is single-level value composition, not a general templating system. If you find yourself wanting a fragment to reference another fragment, that's a sign the two should probably just be one fragment.
  • A missing shared_dir fails loudly, not silently. Using "$shared" in a config file without passing shared_dir to load_node_config raises ConfigValidationError immediately. It never falls back to treating the reference as a literal object, which would then fail the Node Type's own Configuration Schema validation with a much more confusing error about a "$shared" key it doesn't recognize.
  • The merged result still has to pass the Node Type's own Configuration Schema. A fragment missing a required field, with no override supplying it either, fails validation exactly the way a hand-written config missing that field would — resolution happens before validation, not instead of it.

Release: v0.11.0