- Engine Version (
ENGINE_VERSION):2.0.0 - Normalization Policy Version (
NORMALIZATION_POLICY_VERSION):1.0.0 - Operator Semantics Version (
OPERATOR_SEMANTICS_VERSION):1.1.0 - Financial Context Policy Version (
FINANCIAL_CONTEXT_POLICY_VERSION):1.0.0 - Temporal Policy Version (
TEMPORAL_POLICY_VERSION):1.0.0 - Supported Replay Engine Versions (
SUPPORTED_REPLAY_VERSIONS):{"2.0.0"}
-
Typed Financial Context (
FinancialContext): Enforces explicit compatibility checks acrosscurrency,metric(e.g.turnover,net_worth),financial_year(e.g.FY2023-24),averaging_period(e.g.3_year_avg), andis_base_unit. -
No Context Bypasses: Failed financial context parsing or mismatched currencies/metrics/periods strictly return
REVIEW_REQUIREDwith canonical reason codes (CURRENCY_MISMATCH,FINANCIAL_CONTEXT_MISMATCH,MISSING_FINANCIAL_CONTEXT). Financial values never fall back to context-free numeric comparison. -
Scale Independence: Rule units (
rule.unit) are resolved independently and never imposed on observed input values. Observed scales are derived strictly from explicit input representations or input metadata. -
Strict Representation Flags: Representation flags (
is_base_unit,normalized,is_normalized) use strict boolean parsing ("true","false",True,False). Malformed flags (e.g."maybe") are rejected withMALFORMED_NUMBER. -
Single Scale Application & Base-Unit Protection: Explicit scales (e.g.
"5 Crore") are scaled to base units exactly once. Already-normalized base-unit inputs (is_base_unit=Trueor50000000 INR) are not multiplied again. -
Contradictory Scale & Unsupported Scale Detection: Conflicting scales between raw input text and metadata (e.g.
"5 Crore"with metadataunit="Lakh") and unsupported unit scales in metadata returnREVIEW_REQUIREDwithUNIT_MISMATCH. -
Exact Numeric Bounds:
Decimalarithmetic enforces string length$\le 100$ , total digits$\le 38$ , and exponent bounds$[-30, 30]$ . Floats, booleans,NaN,Inf, and corrupt comma structures are rejected.
- Pure Functional Clock: Zero
datetime.now()calls or placeholder timestamps inside pureComplianceEngine.evaluate()and historical reconstruction. - Evaluation Clock Context: Time-dependent rules (
EXPIRES_AFTER,MIN_YEARS_EXPERIENCE_FROM_DATE, relative timestamps) require an explicitevaluation_timestamp(derived from recordedrun.started_atin UTC). Missing clock context fails closed withUNKNOWN(MISSING_EVALUATION_CLOCK) andevaluated_at=None. - Nullable Evaluated At:
RuleEvaluationRead.evaluated_atis truthfully nullable (datetime | None = None) across canonical schemas and OpenAPI contracts. - Three-Tier Classification:
DATE_ONLY: Calendar date comparisons (YYYY-MM-DD) without time-of-day or timezone offsets (correct across leap years).AWARE_DATETIME: ISO-8601 timestamps normalized to UTC prior to comparison.NAIVE_DATETIME: Local timestamps without timezone offsets.
- Ambiguity & Mismatch Handling:
- Comparing
NAIVE_DATETIMEagainstAWARE_DATETIMEreturnsUNKNOWNwithAMBIGUOUS_TIMEZONE. - Comparing
DATE_ONLYagainst datetimes returnsUNKNOWNwithTEMPORAL_CONTEXT_MISMATCH.
- Comparing
- Boolean Validation: Strict parsing of boolean metadata (
True,False,"true","false",1,0). Malformed strings (e.g."maybe") returnUNKNOWNwithINVALID_APPLICABILITY_POLICY. - Requirement-Scoped Exemption Authority: Exemption determinations must be scoped strictly to:
- The specific approved requirement (
rule.id) - The current bidder (
bidder_id) - The approved exemption policy (
rule.metadata_json) - The evidence or authorized manual determination supporting it (
evidence_ids,decision_id,document_id)
- The specific approved requirement (
- No Silent or Global Exemptions: Global boolean flags (
is_exempt=True,exemption_approved=True) alone are strictly rejected. Unverified exemption eligibility returnsUNKNOWNwithUNVERIFIED_EXEMPTION_ELIGIBILITY. - Contributing Evidence Preservation: When an exemption is granted (
NOT_APPLICABLE_EXEMPTION), contributing evidence references are preserved inRuleEvaluationRead.evidence_ids. - Categorical Bidder Context: Bidder type/category must come from authorized context. Missing bidder category is NOT treated as a categorical mismatch.
- Mandatory Exemption Protection:
optional_missing_policycannot override an explicitly applicable mandatory requirement. Missing evidence on mandatory requirements always evaluates toUNKNOWN(MISSING_EVIDENCE).
- Canonical Rule Hashing: Rules hash (
canonical_rule_hash) is computed via SHA-256 over deterministic JSON representations of rule attributes (clause,field,operator,expected_value,unit,mandatory,requirement_type) and semantic policy metadata (applicability,currency,financial_year,metric,averaging_period,optional_missing_policy), while strictly omitting transient database IDs and timestamps. - Historical Reconstruction:
ComplianceEngine.reconstruct_historical_evaluation()retrieves and validates recorded evaluations from the authoritative stored snapshot (input_snapshot_json) rather than re-executing historical rules or claiming full semantic replay across disparate engine versions. Evaluations missing from stored snapshots returnHISTORICAL_EVALUATION_NOT_FOUNDwithout fabricating missing evidence. Incompatible historical versions returnREVIEW_REQUIREDwithHISTORICAL_VERSION_UNSUPPORTED.
- Durable Active-Lock Coordination:
OperationLockServiceprovides atomic mutual exclusion per(resource_type, resource_id, operation)using database-level unique constraints (uq_active_operation_locks_resource) and PostgreSQL row-level locks (SELECT ... FOR UPDATE). - Scoped Lock Release:
release_lock()strictly requires the caller'sjob_idand releases only the lock owned by that specific operation. Missing or mismatched owner identifiers are rejected (ValueError/False). - Fail-Closed Ambiguous Recovery: Stale locks with missing or unverified background jobs fail closed with HTTP 409 (
OPERATION_LOCK_RECOVERY_REQUIRED). Locks are only automatically reconciled when the previous job has definitively terminated in a terminal state (COMPLETED,REVIEW_REQUIRED,FAILED). - Monotonic Sequence Allocation:
JobEventServiceallocates deterministic, sequentialseqnumbers per job under database row locks (SELECT id FROM processing_jobs WHERE id = :job_id FOR UPDATE), preventing duplicate or unordered event stream cursors.
- Idempotency Scoping:
IdempotencyServiceenforces unique scopes on(principal_id, resource_type, resource_id, operation, key)with SHA-256 payload fingerprint verification. Concurrent identical requests return HTTP 409 (OPERATION_IN_PROGRESS) and replay cachedCOMPLETEDresponses once finished.
| Validation Tier | Scope & Target | Execution Environment | Status |
|---|---|---|---|
| PostgreSQL Migration Validation | Full Alembic migration upgrade (head), downgrade, re-upgrade, and drift check against SQLAlchemy declarative models. |
CI live PostgreSQL 16 service container & disposable databases. | Verified (Head: 9f5627b30055) |
| Dedicated PostgreSQL Concurrency Suite | 7 live race-condition & concurrency tests in test_postgresql_compatibility.py (same-key deduplication, different-key mutual exclusion, DB unique constraint enforcement, multi-threaded monotonic sequence allocation under FOR UPDATE, rollback isolation, fail-closed ambiguous recovery, terminal reconciliation). |
CI live PostgreSQL 16 service container against disposable TEST_POSTGRES_URL prepared via Alembic. |
7 tests skipped locally, verified in CI |
| Backend Test Suite | 241 unit and integration tests covering compliance engine, numeric context, temporal semantics, applicability, risk engine, verification adapters, RBAC policies, error envelopes, and API endpoints. | Local development and CI SQLite in-memory/file fallback. | 241 passed, 7 skipped |
| OpenAPI Contract Validation | Byte-for-byte schema export and drift verification against contracts/openapi.json. |
CI OpenAPI drift check step. | Verified (cd9eacd10475a8de6293e991dbf62e81750d0990d0a3ff485ab6f4b9c08f941e) |
- Current Alembic Head:
9f5627b30055(9f5627b30055_add_idempotency_records.py) - Verified via
python -m alembic headsandpython -m alembic currentagainst disposable database instances.