KB-7B3F
00 — Overview, Gate0, Reuse-First Verdict (Registries-Pivot OS Agency: Count-Integrity / Orphan-Phantom / Label / Pin)
5 min read Revision 1
architectureregistries-pivotcount-integrityorphanphantomlabelpinread-onlyzero-mutation2026-05-31verified
title: 00 — Overview, Gate0, Reuse-First Verdict date: 2026-05-31 status: read-only · zero substrate mutation · design + read-only rehearsal only macro: REGISTRIES_PIVOT_OS_AGENCY_COUNT_INTEGRITY_ORPHAN_PHANTOM_LABEL_PIN_REHEARSAL
00 — Overview, Gate0, Reuse-First Verdict
This pack answers the two addenda to the Registries-Pivot macro:
- Make Registries-Pivot the automatic PG reflection screen for the whole system — not just a report: layer, species/composition/group, total/plus/minus, orphan, phantom, verification, drift, warning, next action — every count pivot-backed or explicitly
PIVOT_MISSING. - Add the accounting invariant, orphan/phantom definitions + scanner, dynamic count>1 child-layer rule, auto-label/grouping (50 = MAX ungrouped ceiling, not a trigger-on-50), pin/ghim, notification/cleanup trigger contract, and no-hardcode tests.
Operating discipline (binding this session)
- Zero substrate mutation. All findings are read-only
query_pgoverdirectus.public. No DDL/DML; no Directus/Qdrant writes. KB document upload is the deliverable channel only. - Never author ahead of results (the recurring failure mode in prior sessions: tables/pivots fabricated before the delayed MCP batch flushed). Every number below is traced to a live result captured this session; nothing is asserted from memory.
- Reuse-first. Classify every capability REUSE / EXTEND / WRAP / NEW. The headline finding is that most of what the addenda ask for already exists in PG and the work is wiring + reconciliation + two small NEW registries, not a rebuild.
Gate0 baseline (live 2026-05-31, matches prior session — no drift since 2026-05-30)
pivot_definitions= 37 (active 35);meta_catalog= 169;pivot_results= 126.pivot_count('PIV-001')=169 ·('PIV-019')=980,221 ·('PIV-007')=309.
Reuse-first verdict (one-line summary; details in docs 01–10)
| Capability the addenda need | Live anchor (verified) | Verdict |
|---|---|---|
| Count engine | pivot_count / pivot_query / pivot_matrix, pivot_definitions(37), pivot_results(126), refresh_meta_catalog_from_pivot |
REUSE |
| Per-category accounting columns | meta_catalog.{record_count, actual_count, orphan_count, baseline_count, active_count, species_count, last_scan_date, composition_level, layer} |
REUSE |
| Orphan scanner backend | fn_refresh_orphan_col / _dot / _species (+ trg_fn_refresh_orphan_*), check_registry_coverage, Đ19 Orphan Scanner, Đ26 orphan def v3.9 |
REUSE |
| New-object scanner | fn_birth_onboarding_full_scan (+_hc), birth_registry(980,221) |
REUSE |
| Label / taxonomy / grouping | label_rules(38, has skip_wide_warning), taxonomy(58)/taxonomy_facets(10, has max_labels_per_entity)/taxonomy_matrix(36), entity_labels(718,744), species_collection_map(164), collection_groups(9), Đ24 Label Law v1.3 |
REUSE / EXTEND |
| Drill-down hierarchy field | pivot_definitions.parent_code exists but NULL on all 37 rows |
EXTEND (wire) |
| Notification / cleanup target | system_issues(179,074; types incl. thiếu_quan_hệ, thiếu_mã_định_danh, apr_phantom_applied, hardcode_violation, sai_lệch_dữ_liệu), event_outbox, event_type_registry, Đ23 §4.2 inverse-check |
REUSE |
| No-hardcode enforcement | system_issues types hardcode_violation / `hc_finding_sql |
builtin |
| Phantom definition | apr_phantom_applied (1, de-facto) + CAT-PHA (frontend gap-math, Đ28 violation); no law article |
LAW_DEFINITION_GAP → propose |
| Accounting-invariant reconciliation (total = counted + orphan + phantom) as one pivot/view | none | NEW (propose v_count_integrity + PIV-500) |
| Grand-total system pivot | none (PIV-019 = birth only) | PIVOT_MISSING |
| Pin / ghim | no pin/favorite/watchlist table | NEW (propose-only) |
Pack contents
- 01 — Orphan / Phantom / Unmanaged / Unmonitored / Ghost: definitions + scanner mapping
- 02 — Accounting invariant: design + read-only detection rehearsal (real numbers)
- 03 — Dynamic child-layer drill-down algorithm + node data contract
- 04 — Auto-label / grouping policy (50 = MAX ceiling) + list contract
- 05 — Pin / ghim policy (NEW, propose-only)
- 06 — Notification / cleanup trigger contract
- 07 — New-object scanner
- 08 — No-hardcode tests + every-count-pivot-backed
- 09 — Consolidated node/list data contract
- 10 — Acceptance gates (updated per both addenda) + REUSE/EXTEND/NEW table
- 11 — Self-review + live-evidence appendix (SQL + raw results)
Headline integrity result (doc 02)
count_integrity_status = FAILED today: 10 drift rows in meta_catalog, 7 phantom-side (record>actual), 3 orphan-side (actual>record). This is surfaced, not hidden — exactly the behaviour the invariant mandates.