orchestrata_ultimate.governance._strict
Reference › orchestrata_ultimate › governance › _strict
The fail-closed switch for governance error handling (P0.3, ADR-009). governance_strict(env) returns True unless the environment variable ORCHESTRATA_GOVERNANCE_STRICT is set to false, 0, no or off (compared case-insensitively after trimming). It reads the variable at call time, never at import time, and takes an optional mapping so tests can pass their own environment instead of changing the process. Components that catch a Prolog or infrastructure error use it to choose between denying and allowing: policy_engine, constitutional, prolog_client, prolog_gate, the kernel policy_evaluator and dispatcher, and cli_main. It is traced to REQ-001-US-003-008.
At a glance
| Source | src/orchestrata_ultimate/governance/_strict.py |
| Lines of code | 32 |
| Classes | 0 |
| Functions | 1 |
| Imports (internal) | orchestrata_ultimate.core.base.traces |
| Imported by | orchestrata_ultimate.governance.constitutional, orchestrata_ultimate.governance.policy_engine, orchestrata_ultimate.governance.prolog_client, orchestrata_ultimate.governance.prolog_gate, orchestrata_ultimate.kernel.cli_main, orchestrata_ultimate.kernel.dispatcher, orchestrata_ultimate.kernel.policy_evaluator |
| Tests that import it | none |
Class diagram
No classes; see Functions.
Dependency diagram
API
Functions
| Function | Signature | Summary |
|---|---|---|
governance_strict traces |
governance_strict(env: Mapping[str, str] | None = None) -> bool |
Return True (fail-closed) unless ORCHESTRATA_GOVERNANCE_STRICT is explicitly set to a falsy value ("false"/"0"/"no"/"off"). |
Source
"""Fail-closed strictness seam for governance error handling (P0.3).
All governance components that catch a Prolog/infra error and must decide
whether to fail open (permissive) or fail closed (deny/require-consent) read
this flag at CALL time — never at import time — so tests and dev tooling can
opt into the permissive legacy behavior explicitly via an ``env`` mapping
instead of mutating process-wide state.
"""
from collections.abc import Mapping
from orchestrata_ultimate.core.base.traces import traces
_ENV_VAR = "ORCHESTRATA_GOVERNANCE_STRICT"
_DEFAULT = "true"
_FALSY = {"false", "0", "no", "off"}
@traces(spec="001", story="US-003", reqs=["REQ-001-US-003-008"])
def governance_strict(env: Mapping[str, str] | None = None) -> bool:
"""Return True (fail-closed) unless ``ORCHESTRATA_GOVERNANCE_STRICT`` is
explicitly set to a falsy value ("false"/"0"/"no"/"off").
Reads ``env`` (or ``os.environ`` if ``env`` is None) at call time — no
import-time reads, so process env changes and injected ``env=`` mappings
take effect immediately. Fail-closed by default (REQ P0.3).
"""
import os
source = env if env is not None else os.environ
value = source.get(_ENV_VAR, _DEFAULT)
return value.strip().lower() not in _FALSY