KB-543F

03 — Six-Object Foundation Commit-or-Defer (Branch B)

5 min read Revision 1
registries-pivotsix-objectcommit-deferredscalar-existsbegin-rollbackinvariant-closeszero-mutation2026-05-31

title: 03 — Six-Object Foundation Commit-or-Defer date: 2026-05-31 decision: DEFERRED (no approval) — re-rehearsed GREEN, ready to commit on RG1+RG2

03 — Six-Object Foundation Commit-or-Defer (Branch B)

Because no approval exists (doc 02), this is the deferred path. The pack re-compiled GREEN under BEGIN..ROLLBACK, the invariant closes, and it is ready to commit the instant RG1+RG2 are signed. No COMMIT occurred. Canonical SQL = local pack /Users/nmhuyen/rp_gateway/sql/001..006 (SHA256 in doc 09).

The six objects

# object kind purpose
1 v_registry_leaf_set view leaf accounting universe (excludes meta/_total/all rollups; keys on composition_level+entity_type, no hardcoded CAT list)
2 v_count_integrity view per-leaf integrity; pivot_backed/pivot_count via scalar EXISTS / scalar subquery (never fan-out join)
3 v_count_drift view drift exceptions with source_model-aware classification
4 v_living_lists view each leaf as a living list + backing pivot_code or PIVOT_MISSING
5 v_registries_pivot_tree view drill graph over pivot_definitions.parent_code (data-driven)
6 fn_registries_pivot_node_substrate(text) STABLE fn leaf-panel resolver: CAT code → DB substrate + counts + pivot backing

Re-rehearsal result (live, BEGIN..ROLLBACK, GREEN)

S1 PRE six_pre=0                          (clean — nothing pre-exists)
CREATE VIEW ×5, CREATE FUNCTION ×1        (all compile)
V1 leaf            = 160
V2 invariant       = 160 / rec 2,007,256 / act 2,001,909 / net_gap +5,347 / drift 3 / unver 5 / orph 0
V3 closure         = leaf_gap 5,347 == drift_gap 5,347     ← invariant CLOSES (no double-count)
V4 coverage        = 160 leaf / 21 backed / 139 PIVOT_MISSING
V5 verdict         = FAILED  (152 ok / 3 failed / 5 unverified)   ← honest, by design
V6 class           = 152 balanced / 5 unmeasured / 1 model_a_surplus_recheck / 1 model_b_phantom_candidate / 1 model_b_unregistered_candidate
V7 tree            = 37 nodes / 37 roots / 0 parents             ← flat (drilldown unwired; see doc 05)
V8 fn006(CAT-006)  = record 309 / actual 163 / pivot_backed t / pivot_count 309
ROLLBACK
S1 POST six_post=0  fn_post=0             (clean rollback — nothing persisted)

Why scalar-EXISTS (not a join)

A LEFT JOIN pivot_definitions ON source_object fans 160 → 172 rows because several leaf tables map to multiple pivots, doubling the invariant (~1.95M → ~3.92M) — the Đ28 double-count re-entering through SQL. Scalar subqueries cannot fan out. V3 closure (5,347 == 5,347) is the proof the chosen strategy does not double-count.

Pivot key = registry_collection

The pivot-backed test keys on meta_catalog.registry_collection = pivot_definitions.source_object → 21/160 backed. The earlier split_part(source_location,':',2) under-reported (13/160).

Commit procedure (ONLY after RG1+RG2 — exact steps)

  1. Record the signed approval wording (doc 02 §E) into approval_requests/apr_approvals.
  2. Re-run BEGIN..ROLLBACK rehearsal; confirm V3 still closes (numbers will move with CAT-023 — that is expected; closure must hold).
  3. Off-peak, ONE transaction:
    BEGIN;SET LOCAL lock_timeout='3s'; SET LOCAL statement_timeout='30s'; SET LOCAL idle_in_transaction_session_timeout='60s';\i 001_create_v_registry_leaf_set.sql\i 002_create_v_count_integrity.sql\i 003_create_v_count_drift.sql\i 004_create_v_living_lists.sql\i 005_create_v_registries_pivot_tree.sql\i 006_create_fn_node_substrate.sql\i 900_verify.sql          -- must show V3 closure + objects presentCOMMIT;
    
  4. Verify: 6 objects present, V3 closes, idle_in_transaction = 0.
  5. Keep 999_rollback.sql ready (drops all 6; removes no data).

Safety properties

  • Pure read-layer over existing tables — COMMIT adds no data, DROP loses none (Đ30).
  • CREATE OR REPLACE → idempotent.
  • No base-table mutation, no trigger added, no Directus/Qdrant touch.

Status: COMMIT-READY, DEFERRED. No COMMIT performed this run.

Back to Knowledge Hub knowledge/dev/reports/architecture/registries-pivot-macro1-ratify-foundation-pivot-drilldown-2026-05-31/03-six-object-foundation-commit-or-defer.md