When to Use
Invoke this skill at the moment a build is about to move between environments — a CI/CD
promotion step, or the pre-flight check a trading process runs before it opens its
broker socket. It answers one question: is this environment the one this release was
approved to run in?
The five vectors it audits are the ones whose drift produces silent, expensive failures
rather than loud ones: a Python patch release that differs from the one the strategy was
validated on, a dependency set that is not the locked set, a database missing the
migration the new code expects, mandatory configuration that never made it into the
environment, and — the one that costs real money — a paper environment wired to a live
broker endpoint.
It sits alongside configuration-drift-detection-across-environments, which compares a
full configuration tree key-by-key. This skill is deliberately narrower: five named
vectors, an all-or-nothing verdict, cheap enough to run on every promotion.
When NOT to Use
- As evidence about a running host. Every value audited is declared by the caller
in an
EnvironmentSpec. Nothing connects to an interpreter, a database or a broker.
The audit is exactly as trustworthy as the collection step that built the spec — a
spec hand-written to match the baseline passes cleanly. Collect the values from the
live target, not from a config file describing it.
- As proof that two environments have the same packages installed. A matching
lockfile hash proves the lockfile file is byte-identical. Dependency specifiers
carry environment markers —
python_version, sys_platform, platform_machine —
so the same file resolves to different distributions on different hosts. Use
dependency-pinning-and-reproducible-builds to audit the lockfile itself, and
verify the installed set separately.
- As a config-tree differ. Only the presence of named environment variables is
checked, never their values. For arbitrary nested configuration use
configuration-drift-detection-across-environments.
- As an API contract check. That a staging endpoint is labelled TESTNET says
nothing about whether its payload schema still matches production's — see
sandbox-vs-production-endpoint-drift.
- For research-vs-production signal parity. Comparing model outputs, float
precision and feature definitions is a different problem; see
research-environment-vs-production-environment-parity.
Prerequisites
- An
EnvironmentSpec for the environment under audit, with env_name one of exactly
DEV, STAGING, PRODUCTION. Other names are rejected, not guessed at.
- An
EnvironmentSpec for the release specification, named PRODUCTION. This is
the Python release, lockfile hash and schema head the release was approved to run
on — not a snapshot of whatever is live in production right now. See the decision
point in step 3.
python_version as a full major.minor.patch release (current_python_version()
returns it in the right form). 3.11 is rejected.
lockfile_sha256 as a 64-character hex digest. Produce it with
sha256_of_lockfile(path) so every environment digests the file identically.
db_schema_revision as the complete alembic heads output — every head, not the
first line.
- The list of mandatory environment variable names (defaults:
BROKER_API_KEY, MAX_POSITION_LIMIT, DATABASE_URL).
Workflow
Collect specs, and let collection failures fail loudly.
Build one EnvironmentSpec per environment from the live target.
- Decision point — a value you could not resolve is not an empty string. A blank
field raises
ValueError rather than being audited. This is the single most
important behaviour in the module: under naive string equality, two environments
that both failed to resolve a lockfile hash compare "" == "", pass, and the gate
reports 100% parity on no evidence at all. If a collection step fails, fail the
pipeline step — never substitute a default.
Python runtime and dependency audit.
Compare the full release version and the lockfile SHA-256 against the baseline.
- Decision point — a lockfile mismatch is not automatically a build error. Decide
whether the lockfile legitimately changed (a dependency was intentionally bumped,
so the baseline is stale and needs re-approval) or whether the environment is
running something nobody locked. Re-approve the baseline in the first case; rebuild
the environment in the second. Do not edit the spec to make the audit pass.
Database schema revision audit.
Compare migration heads order-independently — alembic heads prints multiple heads
on a branched history in no guaranteed order, so "a, b" and "b, a" are the same
state.
- Decision point — which direction is the drift? If staging is ahead of live
production because it is validating a migration, that is the normal workflow and
the baseline is the release spec, which already includes the new head. If the
environment is behind the baseline, the new code will hit a missing column on its
first query: apply the migration before promoting, never after.
Broker endpoint mode verification.
DEV and STAGING must be wired to TESTNET; PRODUCTION must be wired to
MAINNET. Both directions are failures, not just one.
- Decision point — the reverse misconfiguration is also a failure. A production
release pointed at a testnet endpoint will start, connect, log fills and report
P&L, all against paper. It is silent for as long as nobody reconciles against the
broker statement. Do not treat "at least it isn't trading real money" as safe.
Mandatory environment variable audit.
Presence and non-emptiness only. Values are never compared — DATABASE_URL and
BROKER_API_KEY are supposed to differ per environment — and never copied into the
report.
Gate on the verdict, not the score.
- Decision point —
parity_score_pct is diagnostic, is_deployment_allowed is the
gate. A staging environment wired to MAINNET scores 80%. Eighty percent is not a
near-pass; it is one failed vector away from executing live orders from a paper
strategy. Branch on is_deployment_allowed (or audit_status == "PARITY_VIOLATION_BLOCKED"), never on a score threshold.
Full procedure: see references/workflows.md.
Standards reference: see references/standards.md.
Printable pre-flight checklist: see assets/checklist.md.
Common Pitfalls
- Auditing missing evidence as parity. The failure mode that makes a parity gate
worse than no gate: a collection script returns empty strings for every vector, each
vector compares equal to the equally-empty baseline, and the pipeline records
PARITY_VERIFIED_PASSED at 100%. Absent evidence must raise. Never default a parity
field.
- Free-form environment names. Classifying anything that is not literally
PRODUCTION as non-production means an environment named PROD or prod-eu-1 is
expected to be on TESTNET — so a genuinely live deployment wired to a paper endpoint
passes the endpoint check. Environment names are matched against a closed set and an
unrecognised name is rejected.
- Pinning only the minor version.
3.11 on both sides compares equal while one host
runs 3.11.2 and the other 3.11.8. Patch releases ship stdlib bug fixes and security
patches; pin major.minor.patch and let the gate enforce it. (Note the verifiable
risk is behavioural change in the standard library and its C extensions — not
floating-point arithmetic, which CPython does not vary across patch releases.)
- Reading an identical lockfile hash as an identical environment. It is not.
Environment markers (PEP 508) resolve the same file differently per Python version,
platform and architecture. Two hosts can hold the same lockfile and different site
packages.
- Line endings silently breaking the hash. A
requirements.lock checked out on
Windows with core.autocrlf=true has CRLF endings; on a Linux build host it has LF.
Same content, different SHA-256, gate blocked forever. Fix the checkout
(core.autocrlf=input, or mark the lockfile -text in .gitattributes) — do not
"fix" it by hashing in text mode, which would also hide genuine changes.
- Passing one Alembic head when the history has two.
alembic current on a branched
database reports several revisions. Pass the complete head set; a single head compared
against a two-head baseline is drift, but a single head passed as though it were the
whole story is a partially-migrated database that the gate cannot see.
- Comparing environment variable values. They must differ. Auditing them produces
permanent false failures and puts secrets in CI logs.
- Leaking secrets through a dataclass repr.
EnvironmentSpec.env_vars holds live
credentials; an unguarded repr puts BROKER_API_KEY into every traceback and CI log
line. The field is declared repr=False for exactly this reason — keep it that way.
- Swapping the two arguments. Both are
EnvironmentSpec, so an order swap type-checks
and produces a plausible-looking report about the wrong environment. The baseline is
required to be a PRODUCTION spec so the mistake raises instead.
Verification
- Construct a
PRODUCTION baseline and a matching STAGING spec on TESTNET; verify
parity_score_pct == 100.0, is_deployment_allowed is True, and audit_status == "PARITY_VERIFIED_PASSED".
- Flip the staging spec to
MAINNET; verify the audit blocks with
failed_vector_names == ["BROKER_ENDPOINT"] at 80%. Repeat with a PRODUCTION spec on
TESTNET — that must block too.
- Regression checks against fail-open behaviour: a blank
python_version,
lockfile_sha256, db_schema_revision or broker_endpoint_mode must raise, not pass;
"3.11" must raise; a 16-character "hash" must raise; env_name="PROD" must raise.
- Verify
"27c6a30d7c24, ae1027a6acf" and "ae1027a6acf\n27c6a30d7c24" compare equal,
and that a single head against that two-head baseline blocks.
- Verify a secret placed in
env_vars appears in neither repr(spec) nor repr(report).
- Run
python -m unittest discover -s skills/environment-parity-dev-staging-production/scripts and confirm a 100% pass rate.
Related Skills
configuration-drift-detection-across-environments
dependency-pinning-and-reproducible-builds
sandbox-vs-production-endpoint-drift
research-environment-vs-production-environment-parity
paper-to-live-promotion-checklist
blue-green-deployment-for-live-strategy-updates
1---2name: environment-parity-dev-staging-production3description: >-4 Use as the gate when a build moves between dev, staging and production, auditing5 declared runtime release, dependency lockfile hash, schema head and broker endpoint.6 Numeric research-versus-live signal parity is7 research-environment-vs-production-environment-parity.8license: Apache-2.09metadata:10 source: https://skillmd.com/skills/himanshuj16/environment-parity-dev-staging-production11 domain: algorithmic-trading12 subdomain: deployment-ops13 tags: deployment-ops, environment-parity, dev-staging-prod, 12-factor-app, dependency-lockfile, db-schema-parity, ci-cd-gate14 brokers_frameworks: "12-Factor App; Alembic; Python Dataclasses"15 version: "2.0.0"16 author: algo-trading-skills-contributors17---1819## When to Use2021Invoke this skill at the moment a build is about to move between environments — a CI/CD22promotion step, or the pre-flight check a trading process runs before it opens its23broker socket. It answers one question: *is this environment the one this release was24approved to run in?*2526The five vectors it audits are the ones whose drift produces silent, expensive failures27rather than loud ones: a Python patch release that differs from the one the strategy was28validated on, a dependency set that is not the locked set, a database missing the29migration the new code expects, mandatory configuration that never made it into the30environment, and — the one that costs real money — a paper environment wired to a live31broker endpoint.3233It sits alongside `configuration-drift-detection-across-environments`, which compares a34full configuration tree key-by-key. This skill is deliberately narrower: five named35vectors, an all-or-nothing verdict, cheap enough to run on every promotion.3637## When NOT to Use3839- **As evidence about a running host.** Every value audited is *declared* by the caller40 in an `EnvironmentSpec`. Nothing connects to an interpreter, a database or a broker.41 The audit is exactly as trustworthy as the collection step that built the spec — a42 spec hand-written to match the baseline passes cleanly. Collect the values from the43 live target, not from a config file describing it.44- **As proof that two environments have the same packages installed.** A matching45 lockfile hash proves the lockfile *file* is byte-identical. Dependency specifiers46 carry environment markers — `python_version`, `sys_platform`, `platform_machine` —47 so the same file resolves to different distributions on different hosts. Use48 `dependency-pinning-and-reproducible-builds` to audit the lockfile itself, and49 verify the installed set separately.50- **As a config-tree differ.** Only the presence of named environment variables is51 checked, never their values. For arbitrary nested configuration use52 `configuration-drift-detection-across-environments`.53- **As an API contract check.** That a staging endpoint is *labelled* TESTNET says54 nothing about whether its payload schema still matches production's — see55 `sandbox-vs-production-endpoint-drift`.56- **For research-vs-production signal parity.** Comparing model outputs, float57 precision and feature definitions is a different problem; see58 `research-environment-vs-production-environment-parity`.5960## Prerequisites6162- An `EnvironmentSpec` for the environment under audit, with `env_name` one of exactly63 `DEV`, `STAGING`, `PRODUCTION`. Other names are rejected, not guessed at.64- An `EnvironmentSpec` for the **release specification**, named `PRODUCTION`. This is65 the Python release, lockfile hash and schema head the release was *approved* to run66 on — not a snapshot of whatever is live in production right now. See the decision67 point in step 3.68- `python_version` as a full `major.minor.patch` release (`current_python_version()`69 returns it in the right form). `3.11` is rejected.70- `lockfile_sha256` as a 64-character hex digest. Produce it with71 `sha256_of_lockfile(path)` so every environment digests the file identically.72- `db_schema_revision` as the **complete** `alembic heads` output — every head, not the73 first line.74- The list of mandatory environment variable names (defaults:75 `BROKER_API_KEY`, `MAX_POSITION_LIMIT`, `DATABASE_URL`).7677## Workflow78791. **Collect specs, and let collection failures fail loudly.**80 Build one `EnvironmentSpec` per environment from the live target.81 - **Decision point — a value you could not resolve is not an empty string.** A blank82 field raises `ValueError` rather than being audited. This is the single most83 important behaviour in the module: under naive string equality, two environments84 that both failed to resolve a lockfile hash compare `"" == ""`, pass, and the gate85 reports 100% parity on no evidence at all. If a collection step fails, fail the86 pipeline step — never substitute a default.87882. **Python runtime and dependency audit.**89 Compare the full release version and the lockfile SHA-256 against the baseline.90 - **Decision point — a lockfile mismatch is not automatically a build error.** Decide91 whether the lockfile legitimately changed (a dependency was intentionally bumped,92 so the *baseline* is stale and needs re-approval) or whether the environment is93 running something nobody locked. Re-approve the baseline in the first case; rebuild94 the environment in the second. Do not edit the spec to make the audit pass.95963. **Database schema revision audit.**97 Compare migration heads order-independently — `alembic heads` prints multiple heads98 on a branched history in no guaranteed order, so `"a, b"` and `"b, a"` are the same99 state.100 - **Decision point — which direction is the drift?** If staging is *ahead* of live101 production because it is validating a migration, that is the normal workflow and102 the baseline is the release spec, which already includes the new head. If the103 environment is *behind* the baseline, the new code will hit a missing column on its104 first query: apply the migration before promoting, never after.1051064. **Broker endpoint mode verification.**107 `DEV` and `STAGING` must be wired to `TESTNET`; `PRODUCTION` must be wired to108 `MAINNET`. Both directions are failures, not just one.109 - **Decision point — the reverse misconfiguration is also a failure.** A production110 release pointed at a testnet endpoint will start, connect, log fills and report111 P&L, all against paper. It is silent for as long as nobody reconciles against the112 broker statement. Do not treat "at least it isn't trading real money" as safe.1131145. **Mandatory environment variable audit.**115 Presence and non-emptiness only. Values are never compared — `DATABASE_URL` and116 `BROKER_API_KEY` are *supposed* to differ per environment — and never copied into the117 report.1181196. **Gate on the verdict, not the score.**120 - **Decision point — `parity_score_pct` is diagnostic, `is_deployment_allowed` is the121 gate.** A staging environment wired to MAINNET scores 80%. Eighty percent is not a122 near-pass; it is one failed vector away from executing live orders from a paper123 strategy. Branch on `is_deployment_allowed` (or `audit_status ==124 "PARITY_VIOLATION_BLOCKED"`), never on a score threshold.125126> Full procedure: see `references/workflows.md`.127> Standards reference: see `references/standards.md`.128> Printable pre-flight checklist: see `assets/checklist.md`.129130## Common Pitfalls131132- **Auditing missing evidence as parity.** The failure mode that makes a parity gate133 worse than no gate: a collection script returns empty strings for every vector, each134 vector compares equal to the equally-empty baseline, and the pipeline records135 `PARITY_VERIFIED_PASSED` at 100%. Absent evidence must raise. Never default a parity136 field.137- **Free-form environment names.** Classifying anything that is not literally138 `PRODUCTION` as non-production means an environment named `PROD` or `prod-eu-1` is139 expected to be on TESTNET — so a genuinely live deployment wired to a paper endpoint140 passes the endpoint check. Environment names are matched against a closed set and an141 unrecognised name is rejected.142- **Pinning only the minor version.** `3.11` on both sides compares equal while one host143 runs 3.11.2 and the other 3.11.8. Patch releases ship stdlib bug fixes and security144 patches; pin `major.minor.patch` and let the gate enforce it. (Note the *verifiable*145 risk is behavioural change in the standard library and its C extensions — not146 floating-point arithmetic, which CPython does not vary across patch releases.)147- **Reading an identical lockfile hash as an identical environment.** It is not.148 Environment markers (PEP 508) resolve the same file differently per Python version,149 platform and architecture. Two hosts can hold the same lockfile and different site150 packages.151- **Line endings silently breaking the hash.** A `requirements.lock` checked out on152 Windows with `core.autocrlf=true` has CRLF endings; on a Linux build host it has LF.153 Same content, different SHA-256, gate blocked forever. Fix the checkout154 (`core.autocrlf=input`, or mark the lockfile `-text` in `.gitattributes`) — do not155 "fix" it by hashing in text mode, which would also hide genuine changes.156- **Passing one Alembic head when the history has two.** `alembic current` on a branched157 database reports several revisions. Pass the complete head set; a single head compared158 against a two-head baseline is drift, but a single head passed as though it were the159 whole story is a partially-migrated database that the gate cannot see.160- **Comparing environment variable values.** They must differ. Auditing them produces161 permanent false failures and puts secrets in CI logs.162- **Leaking secrets through a dataclass repr.** `EnvironmentSpec.env_vars` holds live163 credentials; an unguarded `repr` puts `BROKER_API_KEY` into every traceback and CI log164 line. The field is declared `repr=False` for exactly this reason — keep it that way.165- **Swapping the two arguments.** Both are `EnvironmentSpec`, so an order swap type-checks166 and produces a plausible-looking report about the wrong environment. The baseline is167 required to be a `PRODUCTION` spec so the mistake raises instead.168169## Verification170171- Construct a `PRODUCTION` baseline and a matching `STAGING` spec on `TESTNET`; verify172 `parity_score_pct == 100.0`, `is_deployment_allowed` is `True`, and `audit_status ==173 "PARITY_VERIFIED_PASSED"`.174- Flip the staging spec to `MAINNET`; verify the audit blocks with175 `failed_vector_names == ["BROKER_ENDPOINT"]` at 80%. Repeat with a `PRODUCTION` spec on176 `TESTNET` — that must block too.177- Regression checks against fail-open behaviour: a blank `python_version`,178 `lockfile_sha256`, `db_schema_revision` or `broker_endpoint_mode` must raise, not pass;179 `"3.11"` must raise; a 16-character "hash" must raise; `env_name="PROD"` must raise.180- Verify `"27c6a30d7c24, ae1027a6acf"` and `"ae1027a6acf\n27c6a30d7c24"` compare equal,181 and that a single head against that two-head baseline blocks.182- Verify a secret placed in `env_vars` appears in neither `repr(spec)` nor `repr(report)`.183- Run `python -m unittest discover -s skills/environment-parity-dev-staging-production/scripts` and confirm a 100% pass rate.184185## Related Skills186187- `configuration-drift-detection-across-environments`188- `dependency-pinning-and-reproducible-builds`189- `sandbox-vs-production-endpoint-drift`190- `research-environment-vs-production-environment-parity`191- `paper-to-live-promotion-checklist`192- `blue-green-deployment-for-live-strategy-updates`