QT-001 Apply DOT Harden — 05 Metadata-Driven Plan + Parity Finding
05 — Metadata-Driven Plan (Supertrack E) + Parity-Divergence Finding
Hardcoded 39-collection planning replaced by a metadata-driven planner that derives scope from collection_registry (policy=BIRTH_REQUIRED) + fn_birth_resolve_identity (eligible strategy). Live: fn_qt001_plan_all(), fn_dot_birth_qt001_plan_v2(text), snapshot qt001_plan_snapshot (refresh via fn_qt001_refresh_plan_snapshot()), views v_qt001_metadata_driven_plan, v_qt001_metadata_scope_tiers, v_qt001_plan_vs_hardcoded_diff, v_qt001_plan_no_go_guard.
Correctness vs the validated hardcoded set
For every collection the hardcoded v_birth_qt001_dryrun_result covers, the metadata planner reproduces the delta EXACTLY: v_qt001_plan_vs_hardcoded_diff shared-set mismatch = 0. The 5 Codex-validated targets reproduce 67/42/18/6/4 = 137. The planner is faithful, not a rewrite.
Live finding — the hardcoded list was incomplete AND hid a duplication hazard
Iterating all 74 BIRTH_REQUIRED collections surfaces 13 eligible / delta>0 = 779, i.e. 8 collections the hardcoded 39-list omitted. An anti-join alone is misleading, because for several of them the classified identity does NOT match the realtime trigger's actual entity_code. Consistency invariant: a backfill is safe only when existing_births = src_rows − expected_delta − unresolvable (every existing birth reconciles with a current source row under the resolved code). Divergence = existing_births − matched.
Scope tiers (v_qt001_metadata_scope_tiers)
| Tier | Collections | Δ | Meaning |
|---|---|---|---|
| TIER1_CODEX_VALIDATED | dot_domain_rules 67, apr_approvals 42, normative_relations 18, apr_action_types 6, field_type_equivalences 4 | 137 | validated + apply_safe (divergence 0) |
| TIER2_METADATA_CONSISTENT_UNVALIDATED | measurement_registry 132, law_catalog 5 | 137 | consistency-clean (divergence 0) but not independently validated |
| TIER3_PARITY_DIVERGENT_RECLASSIFY | law_dot_enforcement 272 (div 272), approval_requests 160 (div 11), law_jurisdiction 43 (div 43), table_registry 20 (div 21), governance_relations 8 (div 8), workflows 2 (div 2) | 505 | existing births do NOT reconcile → a backfill would DUPLICATE; classification must be re-mirrored to the realtime trigger before any apply |
Example: law_dot_enforcement has 272 source rows, 272 existing births, yet 272 "missing" under the classified coll::id scheme — the realtime trigger births these under a different code. Naive backfill = 272 duplicates.
Writer enforcement
fn_dot_birth_qt001_apply FAIL-CLOSES on parity divergence (RAISE) and on cross-collection collision. Demonstrated live: fn_dot_birth_qt001_apply('law_dot_enforcement', ... p_dry_run:=true) returns no_go_reason = parity_divergence. Only TIER1/TIER2 are apply_safe; TIER3 is blocked.
Guard (v_qt001_plan_no_go_guard, all pass)
plan_is_metadata_driven · plan_snapshot_present_and_fresh · metadata_reproduces_validated_137 · shared_set_zero_mismatch_vs_hardcoded(0) · validated_5_all_apply_safe(5) · writer_refuses_parity_divergence · parity_divergent_collections_flagged_not_applied(6) · unclassified_excluded_from_scope(4).