When to Use
Invoke this skill when a configuration tree is about to take effect in an environment
that can send orders, and you need positive evidence that it matches the baseline someone
actually approved. The failure it prevents is specific: a risk parameter edited in
staging for a debugging session and carried into production, a broker_endpoint still
pointing at sandbox after a promotion, a max_order_usd that arrived as the string
"100000" and silently disabled a numeric comparison downstream.
Use it in two places, not one: as a CI/CD gate before an artifact is promoted, and again
during process initialization before the trading socket opens. The first catches the
mistake earlier; the second is the one that actually protects live capital, because it
runs on the host and against the file the engine will really read.
When NOT to Use
Do not use it when:
- The two environments are supposed to differ structurally. This detector compares
one tree against one baseline. A research sandbox with a different schema entirely will
produce noise, not signal — see
research-environment-vs-production-environment-parity
for that comparison.
- You need to know what changed over time in one environment. This is a two-way
comparison at a point in time, not a change log. Use
audit-logging-for-configuration-changes for the who/when/why record.
- You have not decided which config is authoritative. If two candidate baselines
exist, the audit result is arbitrary. Designate the Golden Source first
(
reference-data-golden-source-designation).
- What you actually need is approval workflow. Detecting that a risk limit drifted is
not the same as governing who may change it; see
risk-control-configuration-change-approval-workflow.
- The value you care about is not in the config file. A limit injected at runtime by
a feature-flag service or mutated by an operator after startup is invisible to this
audit, which compares configuration to configuration.
Prerequisites
- A single designated Golden Source configuration tree, version-controlled, loaded as a
dict.
- The target environment configuration, loaded from the same source the trading process
will actually read — not a copy prepared for the audit.
- An explicit override policy, split two ways:
allowed_overrides — connectivity, naming and logging keys that legitimately differ
(env_name, api_url, broker_endpoint, log_level, port, host, db_name).
Pass an empty set for zero-tolerance auditing.
protected_keys — risk-control parameters that may never be whitelisted. The
built-in DEFAULT_PROTECTED_KEYS is a starting point keyed on leaf name; extend it
with the risk parameters your own schema uses.
- A caller that treats
is_compliant is False as a hard stop, with the authority to fail
the pipeline or abort startup.
Workflow
- Ingest both trees. Load
golden_baseline and target_config as dicts. Non-dict
input raises TypeError rather than being audited partially.
- Flatten to dot-separated paths. Nested dicts collapse to
system.api_url. Two
distinct keys that flatten to the same path (a literal "a.b" alongside a nested
{"a": {"b": ...}}) raise ValueError — one branch would otherwise be dropped from
the audit and real drift could surface as a PASS. An empty nested dict is kept as a
leaf so a whole missing section is still reported.
- Classify every key in the union of both trees:
- Key in baseline, missing from target →
CRITICAL. This holds even for
whitelisted keys: an override may change a value, not delete a setting the engine
expects to read.
- Value or type differs on a protected key →
CRITICAL, regardless of the
whitelist.
- Value or type differs on a whitelisted, non-protected key →
ALLOWED.
- Value or type differs otherwise →
CRITICAL.
- Key in target, absent from baseline →
WARNING.
- Decide.
critical_drift_count > 0 sets is_compliant = False. Block the
promotion or abort initialization before the socket opens — do not connect first and
alert afterwards. On a compliant report with warnings, proceed but route the WARNING
items to human review.
- Record. Persist
report.drift_items to the deployment audit log alongside the
authorizing person. For firms in scope of MiFID II RTS 6 this record supports the
Art. 5(7) and Art. 11 obligations — see references/standards.md for what those
articles do and do not require.
Full procedure: see references/workflows.md.
Standards reference: see references/standards.md.
Printable pre-flight checklist: see assets/checklist.md.
Common Pitfalls
- Whitelisting a risk parameter to silence a noisy alert. Adding
max_position_size
to allowed_overrides does not fix the drift; it disables the gate on exactly the
value the gate exists to protect. The detector refuses this at construction time, but
the same instinct reappears as "let me just widen protected_keys's exceptions" —
resolve the drift instead.
- Assuming an empty whitelist means strict. It does now, and that is a fix, not a
given: this detector previously treated
allowed_overrides=set() as falsy and
substituted the permissive built-in default, turning the strictest possible request
into the loosest available policy. If you have forked or reimplemented this pattern,
check that line.
- Reading a PASS as "the environments are identical." Extra keys in the target are
WARNING and never block, because the baseline cannot know what a legitimately-added
key means. A config with an unreviewed extra flag passes this audit.
- Whitelisting by bare leaf name when you meant one section.
api_url in
allowed_overrides whitelists that name everywhere in the tree, including under a
section you never intended to relax. Use the exact path system.api_url when the
override should be scoped.
- Ignoring type coercion drift.
max_order_qty as the string "100" instead of the
integer 100 compares as drift here precisely because it will not compare as a number
downstream. Do not "fix" a type-mismatch alert by relaxing the comparison.
- Post-startup auditing. Running the check after the trading engine is live reports a
breach rather than preventing one.
- Auditing a file the engine never opens. A pipeline that audits
prod_baseline.json
from the repo while the host loads a locally-templated config proves nothing about the
host.
Verification
- Instantiate
ConfigurationDriftDetector with allowed_overrides={"api_url"}. Feed a
Golden Source config and a target whose max_order_usd is 1,000,000 against a baseline
of 100,000: the report must show CRITICAL severity, the description must name it as a
protected risk-control parameter, and is_compliant must be False. Change only
api_url instead: allowed_override_count must be 1 and is_compliant True.
- Confirm the gate cannot be disabled:
ConfigurationDriftDetector(allowed_overrides={"max_position_size"})
must raise ValueError.
- Confirm zero tolerance is honoured:
ConfigurationDriftDetector(allowed_overrides=set())
must flag a broker_endpoint change as CRITICAL, not ALLOWED.
- Run
python -m unittest discover -s skills/configuration-drift-detection-across-environments/scripts
and confirm all 28 tests pass.
Related Skills
research-environment-vs-production-environment-parity
environment-parity-dev-staging-production
blue-green-deployment-for-live-strategy-updates
audit-logging-for-configuration-changes
risk-control-configuration-change-approval-workflow
reference-data-golden-source-designation
1---2name: configuration-drift-detection-across-environments3description: >-4 Use before a configuration tree takes effect somewhere that can send orders, to prove5 it matches the approved baseline; catches missing keys, changed values and silent type6 changes carried over from a debugging session.7license: Apache-2.08metadata:9 source: https://skillmd.com/skills/himanshuj16/configuration-drift-detection-across-environments10 domain: algorithmic-trading11 subdomain: deployment-ops12 tags: configuration-drift, deployment-ops, env-parity, golden-source, pre-trade-gate, risk-control13 brokers_frameworks: ""14 version: "1.1.0"15 author: algo-trading-skills-contributors16---1718## When to Use1920Invoke this skill when a configuration tree is about to take effect in an environment21that can send orders, and you need positive evidence that it matches the baseline someone22actually approved. The failure it prevents is specific: a risk parameter edited in23staging for a debugging session and carried into production, a `broker_endpoint` still24pointing at sandbox after a promotion, a `max_order_usd` that arrived as the string25`"100000"` and silently disabled a numeric comparison downstream.2627Use it in two places, not one: as a CI/CD gate before an artifact is promoted, and again28during process initialization before the trading socket opens. The first catches the29mistake earlier; the second is the one that actually protects live capital, because it30runs on the host and against the file the engine will really read.3132## When NOT to Use3334Do **not** use it when:3536- **The two environments are supposed to differ structurally.** This detector compares37 one tree against one baseline. A research sandbox with a different schema entirely will38 produce noise, not signal — see `research-environment-vs-production-environment-parity`39 for that comparison.40- **You need to know what changed over time in one environment.** This is a two-way41 comparison at a point in time, not a change log. Use42 `audit-logging-for-configuration-changes` for the who/when/why record.43- **You have not decided which config is authoritative.** If two candidate baselines44 exist, the audit result is arbitrary. Designate the Golden Source first45 (`reference-data-golden-source-designation`).46- **What you actually need is approval workflow.** Detecting that a risk limit drifted is47 not the same as governing who may change it; see48 `risk-control-configuration-change-approval-workflow`.49- **The value you care about is not in the config file.** A limit injected at runtime by50 a feature-flag service or mutated by an operator after startup is invisible to this51 audit, which compares configuration to configuration.5253## Prerequisites5455- A single designated Golden Source configuration tree, version-controlled, loaded as a56 dict.57- The target environment configuration, loaded from the same source the trading process58 will actually read — not a copy prepared for the audit.59- An explicit override policy, split two ways:60 - `allowed_overrides` — connectivity, naming and logging keys that legitimately differ61 (`env_name`, `api_url`, `broker_endpoint`, `log_level`, `port`, `host`, `db_name`).62 Pass an empty set for zero-tolerance auditing.63 - `protected_keys` — risk-control parameters that may never be whitelisted. The64 built-in `DEFAULT_PROTECTED_KEYS` is a starting point keyed on leaf name; extend it65 with the risk parameters your own schema uses.66- A caller that treats `is_compliant is False` as a hard stop, with the authority to fail67 the pipeline or abort startup.6869## Workflow70711. **Ingest both trees.** Load `golden_baseline` and `target_config` as dicts. Non-dict72 input raises `TypeError` rather than being audited partially.732. **Flatten to dot-separated paths.** Nested dicts collapse to `system.api_url`. Two74 distinct keys that flatten to the same path (a literal `"a.b"` alongside a nested75 `{"a": {"b": ...}}`) raise `ValueError` — one branch would otherwise be dropped from76 the audit and real drift could surface as a PASS. An empty nested dict is kept as a77 leaf so a whole missing section is still reported.783. **Classify every key in the union of both trees:**79 - Key in baseline, **missing** from target → `CRITICAL`. This holds even for80 whitelisted keys: an override may change a value, not delete a setting the engine81 expects to read.82 - Value or type differs on a **protected** key → `CRITICAL`, regardless of the83 whitelist.84 - Value or type differs on a **whitelisted, non-protected** key → `ALLOWED`.85 - Value or type differs otherwise → `CRITICAL`.86 - Key in target, **absent** from baseline → `WARNING`.874. **Decide.** `critical_drift_count > 0` sets `is_compliant = False`. Block the88 promotion or abort initialization before the socket opens — do not connect first and89 alert afterwards. On a compliant report with warnings, proceed but route the WARNING90 items to human review.915. **Record.** Persist `report.drift_items` to the deployment audit log alongside the92 authorizing person. For firms in scope of MiFID II RTS 6 this record supports the93 Art. 5(7) and Art. 11 obligations — see `references/standards.md` for what those94 articles do and do not require.9596> Full procedure: see `references/workflows.md`.97> Standards reference: see `references/standards.md`.98> Printable pre-flight checklist: see `assets/checklist.md`.99100## Common Pitfalls101102- **Whitelisting a risk parameter to silence a noisy alert.** Adding `max_position_size`103 to `allowed_overrides` does not fix the drift; it disables the gate on exactly the104 value the gate exists to protect. The detector refuses this at construction time, but105 the same instinct reappears as "let me just widen `protected_keys`'s exceptions" —106 resolve the drift instead.107- **Assuming an empty whitelist means strict.** It does now, and that is a fix, not a108 given: this detector previously treated `allowed_overrides=set()` as falsy and109 substituted the permissive built-in default, turning the strictest possible request110 into the loosest available policy. If you have forked or reimplemented this pattern,111 check that line.112- **Reading a PASS as "the environments are identical."** Extra keys in the target are113 `WARNING` and never block, because the baseline cannot know what a legitimately-added114 key means. A config with an unreviewed extra flag passes this audit.115- **Whitelisting by bare leaf name when you meant one section.** `api_url` in116 `allowed_overrides` whitelists that name *everywhere* in the tree, including under a117 section you never intended to relax. Use the exact path `system.api_url` when the118 override should be scoped.119- **Ignoring type coercion drift.** `max_order_qty` as the string `"100"` instead of the120 integer `100` compares as drift here precisely because it will not compare as a number121 downstream. Do not "fix" a type-mismatch alert by relaxing the comparison.122- **Post-startup auditing.** Running the check after the trading engine is live reports a123 breach rather than preventing one.124- **Auditing a file the engine never opens.** A pipeline that audits `prod_baseline.json`125 from the repo while the host loads a locally-templated config proves nothing about the126 host.127128## Verification129130- Instantiate `ConfigurationDriftDetector` with `allowed_overrides={"api_url"}`. Feed a131 Golden Source config and a target whose `max_order_usd` is 1,000,000 against a baseline132 of 100,000: the report must show `CRITICAL` severity, the description must name it as a133 protected risk-control parameter, and `is_compliant` must be `False`. Change only134 `api_url` instead: `allowed_override_count` must be 1 and `is_compliant` `True`.135- Confirm the gate cannot be disabled: `ConfigurationDriftDetector(allowed_overrides={"max_position_size"})`136 must raise `ValueError`.137- Confirm zero tolerance is honoured: `ConfigurationDriftDetector(allowed_overrides=set())`138 must flag a `broker_endpoint` change as `CRITICAL`, not `ALLOWED`.139- Run `python -m unittest discover -s skills/configuration-drift-detection-across-environments/scripts`140 and confirm all 28 tests pass.141142## Related Skills143144- `research-environment-vs-production-environment-parity`145- `environment-parity-dev-staging-production`146- `blue-green-deployment-for-live-strategy-updates`147- `audit-logging-for-configuration-changes`148- `risk-control-configuration-change-approval-workflow`149- `reference-data-golden-source-designation`