recon_gen.common.spine.semantic_lock_json

AZ.1 — JSON serialization for the semantic lock dict.

Phase AZ replaces the byte-locked seeds (~28 MB across 3 dialects) with per-(instance, dialect) JSON semantic locks gated on the violation SET rather than SQL bytes. This module is the serialization seam: semantic_lock(conn, ALL_INVARIANTS) returns dict[str, frozenset[Violation]]; lock_to_json renders the canonical JSON shape AZ.0 designed.

Per AZ.0’s “JSON-string equality is the gate contract” — the loader doesn’t reconstruct Violation objects. The test serializes the live emit through lock_to_json + compares the output string against the on-disk file byte-for-byte.

See docs/audits/az_0_semantic_lock_schema.md for the full design + the validation table showing the semantic lock catches every real violation-set change AY.5 caught + drops every byte-only false positive.

Functions

lock_to_json(lock, *, instance, dialect, ...)

Render a semantic lock dict to the canonical JSON shape.

recon_gen.common.spine.semantic_lock_json.lock_to_json(lock, *, instance, dialect, canonical_anchor)[source]

Render a semantic lock dict to the canonical JSON shape.

Deterministic + byte-stable across runs: invariant names sorted alphabetically; violations within each invariant sorted by (kind, sorted-identity-repr); identity keys sorted alphabetically per entry.

Empty invariants land as empty arrays (not omitted) so diffs surface “X used to fire, doesn’t now” clearly.

Parameters:
  • lock (dict[str, frozenset[Violation]]) – dict[invariant_name, frozenset[Violation]] — exactly what semantic_lock(conn, ALL_INVARIANTS) returns.

  • instance (str) – the L2 instance name (e.g., “spec_example”) — lands in scenario_fingerprint.instance for mismatch detection.

  • dialect (Dialect) – the SQL dialect — lands in scenario_fingerprint.dialect.

  • canonical_anchor (date) – the canonical lock date — lands in scenario_fingerprint.canonical_anchor.

Return type:

str

Returns:

A JSON string with indent=2, terminating newline. Suitable for direct write-to-disk + byte-equality test.