Stage 1 Report 05 — Birth Register Foundation
Stage 1 — 05 fn_birth_register Foundation (Supertrack E)
Function
fn_birth_register(p_collection text, p_row jsonb, p_dry_run boolean DEFAULT true, p_dot_origin text DEFAULT NULL) RETURNS jsonb. The single shared register path for realtime and future QT-001.
Flow: fn_birth_policy_decision → (EXEMPT/DEFERRED → skipped; not REQUIRED → blocked) → fn_birth_resolve_identity → (no entity_code → blocked) → exists-precheck on birth_registry.entity_code → (exists → skipped/idempotent) → if dry_run → would_register (NO write) → else INSERT … ON CONFLICT (entity_code) DO NOTHING. Insert columns mirror the live gateway: entity_code, collection_name, species_code, composition_level, dot_origin, born_at=now(), governance_role=COALESCE(…,'excluded'), certified=false.
Properties: idempotent (exists-precheck + ON CONFLICT on the unique key entity_code); p_dry_run defaults TRUE (accidental call writes nothing); skips EXEMPT/DEFERRED managed birth; transaction-safe; single-row only — NOT a bulk backfill.
BEGIN..ROLLBACK rehearsal (live, fully rolled back, net 0)
| Step | Call | Result | birth_registry |
|---|---|---|---|
| c0 | — | — | 1,210,851 |
| T1 | register('agents', {id:…}, dry_run=true) | would_register | 1,210,851 |
| T2 | register('entity_labels', …, dry_run=false) | skipped (policy_exempt) | 1,210,851 |
| T3 | register('agents', {id:…}, dry_run=false) | registered | 1,210,852 (+1) |
| T4 | register('agents', {id:…}, dry_run=false) again | skipped (already_exists, idempotent) | 1,210,852 (no double) |
| T5 | register('nope', …, false) | blocked (collection_not_registered) | — |
| T6 | register('billing', …, false) | skipped (policy_deferred) | — |
| — | test row shape | entity_code agents::__STAGE1_RBK_TEST__, governance_role governed, certified f, status born |
— |
| ROLLBACK | — | — | 1,210,851 (0 leaked) |
Proves: real write works; idempotency coalesces duplicates; policy is enforced even with p_dry_run=false (EXEMPT/DEFERRED skip, UNKNOWN block); fully transaction-safe with zero net mutation.
Views
v_birth_register_readiness— per BIRTH_REQUIRED collection: policy_decision, identity_status, register_readiness (register_path_ready when REQUIRED + ELIGIBLE) → 31 ready / 43 blocked.v_birth_register_idempotency_guard— 7/7 PASS (default_is_dry_run, idempotent_on_conflict_present, exists_precheck_present, exempt_dryrun_skips, deferred_dryrun_skips, unknown_dryrun_blocks, unclassified_required_blocks).v_birth_register_dryrun_matrix— EXEMPT(admin_fallback_log)→skipped(policy_exempt) · DEFERRED(billing)→skipped(policy_deferred) · REQUIRED_COLUMN(agents)→would_register · REQUIRED_UNCLASSIFIED(agent_views)→blocked(identity_blocked_unclassified) · UNKNOWN→blocked(not_registered). Querying these views performs NO writes (all default/explicit dry-run; EXEMPT/DEFERRED/UNKNOWN short-circuit before insert).