P3D — Birth Coverage Classification Report
P3D — Birth Coverage Classification Report
Date: 2026-05-12 Mode: READ-ONLY (no DB write, no DDL, no trigger creation, no migration) Prompt:
knowledge/dev/laws/dieu44-trien-khai/prompts/p3d-birth-coverage-classification-readonly-prompt-DRAFT.mdrev2 (approved) Reviewer approval:knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-final-review-birth-b2-rev2-approved-classification-dispatch-2026-05-12.md
Phase 0 — Environment
| Item | Resolved |
|---|---|
| db_container | postgres (image postgres:16, healthy) |
| target_db | directus |
| schema | public |
| connecting role | workflow_admin (read-only usage) |
db_connection_status = RESOLVED, schema_status = RESOLVED.
Phase 1 — Table-family existence
| family | resolved | status |
|---|---|---|
| collection_registry | public.collection_registry |
EXISTS |
| birth_registry | public.birth_registry |
EXISTS |
| species_collection_map | public.species_collection_map |
EXISTS |
| information_schema.triggers | system catalog | EXISTS |
| information_schema.columns | system catalog | EXISTS |
| information_schema.table_constraints | system catalog | EXISTS |
table_family_resolution_complete = true (6/6).
Phase 2 — Concept resolution
| concept_id | resolved column | status |
|---|---|---|
| collection_key | collection_registry.collection_name |
RESOLVED |
| collection_governance_role | collection_registry.governance_role |
RESOLVED |
| collection_migration_state | collection_registry.migration_state |
RESOLVED |
| birth_collection_key | birth_registry.collection_name |
RESOLVED |
| species_map_collection_key | species_collection_map.collection_name |
RESOLVED |
Additional collection_registry columns used as supporting signals: classification, group, purpose.
concept_resolution_complete = true.
Phase 3 — Uncovered collection set
Compiled SQL:
WITH governed AS (SELECT collection_name AS cname FROM public.collection_registry),
has_trigger AS (SELECT DISTINCT event_object_table AS cname
FROM information_schema.triggers
WHERE trigger_schema='public'
AND trigger_name LIKE 'trg_birth_%'
AND event_manipulation='INSERT')
SELECT g.cname FROM governed g
LEFT JOIN has_trigger t ON t.cname=g.cname
WHERE t.cname IS NULL
ORDER BY g.cname;
total_uncovered = 136.
(Note: prior inventory reported 137 as raw 166 − 29; join-deduped count is 136 — authoritative.)
Phase 4 — Evidence (bulk gather per collection)
Compiled SQL (single bulk pass — abridged here, full version below):
WITH uncov AS (... -- as Phase 3 above
), col_stats AS (
SELECT u.cname, COUNT(*) AS col_count,
COUNT(*) FILTER (WHERE c.data_type IN ('jsonb','json')) AS jsonb_cols,
COUNT(*) FILTER (WHERE c.data_type IN ('text','character varying')) AS text_cols
FROM uncov u JOIN information_schema.columns c
ON c.table_schema='public' AND c.table_name=u.cname
GROUP BY u.cname
), pk_stats AS (
SELECT u.cname,
string_agg(c.data_type,',' ORDER BY kcu.ordinal_position) AS pk_types,
COUNT(*) AS pk_cols
FROM uncov u
JOIN information_schema.table_constraints tc
ON tc.table_schema='public' AND tc.table_name=u.cname AND tc.constraint_type='PRIMARY KEY'
JOIN information_schema.key_column_usage kcu
ON kcu.constraint_name=tc.constraint_name AND kcu.table_schema=tc.table_schema
JOIN information_schema.columns c
ON c.table_schema='public' AND c.table_name=u.cname AND c.column_name=kcu.column_name
GROUP BY u.cname
), fk_stats AS (
SELECT u.cname, COUNT(*) AS fk_count
FROM uncov u
JOIN information_schema.table_constraints tc
ON tc.table_schema='public' AND tc.table_name=u.cname AND tc.constraint_type='FOREIGN KEY'
GROUP BY u.cname
), trig_stats AS (
SELECT u.cname, COUNT(*) AS trig_count
FROM uncov u
JOIN information_schema.triggers tr
ON tr.trigger_schema='public' AND tr.event_object_table=u.cname
GROUP BY u.cname
), birth_stats AS (
SELECT collection_name AS cname, count(*) AS birth_cnt
FROM public.birth_registry GROUP BY collection_name
), spm_stats AS (
SELECT collection_name AS cname, count(*) AS spm_cnt
FROM public.species_collection_map GROUP BY collection_name
)
SELECT u.cname, ...
FROM uncov u LEFT JOIN ... -- all stats joined left
ORDER BY u.cname;
Compiled metadata pass (governance_role / migration_state / group / purpose / existence) also executed against collection_registry joined to information_schema.tables.
compiled_sql_logged = true.
Phase 5 — Classification (weighted evidence)
Algorithm applied (per spec; naming weight ≤ 0.2):
- MISSING table →
BIRTH_DEFERRED_NEEDS_REVIEW - PG view (
v_*) →BIRTH_EXEMPT_DERIVED_CACHE directus_*or_backup_*→BIRTH_EXEMPT_SYSTEM_LOG_OR_AUDIT- Name ends in
_log/_audit_log/_changelog/_audit_queueOR group=GRP-LOG →BIRTH_EXEMPT_SYSTEM_LOG_OR_AUDIT - Name =
*_runs/*_violations(run history / violation audit) →SYSTEM_LOG_OR_AUDIT - Name =
*_run_results/ name startsderived_*→BIRTH_EXEMPT_DERIVED_CACHE - group=GRP-JUNCTION OR (purpose literally contains "Junction" AND ≤6 cols with FK-like refs) →
BIRTH_EXEMPT_STRUCTURAL_JUNCTION - governance_role ∈ {governed, locked, law_artifact} + own PK + business columns →
BIRTH_REQUIRED - governance_role=observed + business schema + not in exempt bucket →
BIRTH_REQUIRED - governance_role=excluded →
BIRTH_DEFERRED_NEEDS_REVIEW(user explicitly excluded; recommend human confirmation whether to permanently exempt or include) - Else →
BIRTH_DEFERRED_NEEDS_REVIEW
5A. BIRTH_REQUIRED (43)
agent_views, ai_discussion_comments, ai_discussions, ai_tasks, apr_action_types, apr_approvals, apr_request_types, binding_registry, checkpoint_instances, checkpoint_rules, checkpoint_set_items, checkpoint_type_overrides, comments, contacts, content_requests, conversations, doc_reviews, dot_domain_rules, feedbacks, field_type_equivalences, governance_docs, help_articles, help_collections, help_feedback, inbox, knowledge_documents, label_rules, messages, navigation_items, normative_relations, nrm_approval_rules, nrm_doc_type_config, organization_addresses, organizations, os_invoice_items, os_items, os_task_files, table_proposals, task_checkpoints, task_comments, trigger_registry, universal_rule_registry, workflow_categories
Top weighted signals: governance_role ∈ {governed/locked/observed} (0.20) + own PK uuid/integer (0.15) + business text/jsonb columns (0.15). Examples already accumulating birth rows from upstream paths (knowledge_documents 2478, checkpoint_instances 121, task_comments 278, directus_fields 1532 → moved to SYSTEM by rule 3) — trigger gap is the implementation gap, not a semantic gap.
5B. BIRTH_EXEMPT_STRUCTURAL_JUNCTION (20)
block_button_groups, block_buttons, block_columns_rows, block_gallery_files, block_logocloud_logos, block_step_items, block_testimonial_slider_items, entity_labels, navigation_navigation_items, organizations_contacts, os_activity_contacts, os_deal_contacts, os_project_contacts, os_proposal_contacts, page_blocks, pages_blocks, pages_translations, post_gallery_items, species_collection_map, taxonomy_matrix
Signals: group=GRP-JUNCTION declared in collection_registry OR purpose field explicitly says "Junction" + low column count (typically ≤8) + FK-shaped refs.
Notes:
entity_labelshas 6 cols + 118,933 rows butpurpose='Junction: thực thể ↔ nhãn phân loại (M2M)'. Classified JUNCTION on semantic grounds despite GRP-REGISTRY.taxonomy_matrixsimilar — GRP-REGISTRY but purpose="Junction: nhãn ↔ chiều phân loại (matrix)".species_collection_mapis itself a junction (already excluded from governance).
5C. BIRTH_EXEMPT_SYSTEM_LOG_OR_AUDIT (11)
admin_fallback_log, directus_fields, entity_audit_queue, governance_audit_log, law_version_verification_log, lifecycle_log, measurement_log, _permissions_backup_s132c, registry_changelog, universal_rule_runs, universal_rule_violations
Signals: name suffix _log / _audit_log / _changelog / _audit_queue / _runs / _violations; OR group=GRP-LOG; OR Directus system metadata; OR backup table.
5D. BIRTH_EXEMPT_DERIVED_CACHE (4)
derived_objects_registry, universal_rule_run_results, v_registry_counts, v_registry_summary
Signals: PG view (v_*), or name starts with derived_, or _run_results (computed from _runs).
5E. BIRTH_DEFERRED_NEEDS_REVIEW (58)
Missing tables (7) — declared in collection_registry but no physical table; can't classify schema-shape, defer:
billing, blocks, help, kb_audit_log, kb_documents_history, sales, website
Special-case observed entities needing human judgement (3):
unit_version— observed/pilot but conventionally birthed viainformation_unit(not on its own); confirm with B3 contract.universal_edges— hook target table per design v3; rich edge metadata + 2,617 birth rows. Whether to add INSERT trigger or rely on edge-creation upstream needs review.workflow_step_relations— observed, GRP-WORKFLOW, 8 cols + 80 birth rows; not clearly junction or business entity.
governance_role = excluded (48) — user explicitly excluded; no automatic exempt bucket applies (not log, not junction, not cache). Recommend human review whether to permanently exempt or re-include:
block_button, block_button_group, block_columns, block_cta, block_divider, block_faqs, block_form, block_gallery, block_hero, block_html, block_library, block_logocloud, block_quote, block_richtext, block_steps, block_team, block_testimonials, block_video, categories, forms, globals, languages, navigation, os_activities, os_deals, os_deal_stages, os_email_templates, os_expenses, os_invoices, os_payments, os_payment_terms, os_projects, os_project_templates, os_project_updates, os_proposal_approvals, os_proposal_blocks, os_proposals, os_settings, os_tasks, os_tax_rates, pages, pages_blog, pages_projects, posts, redirects, seo, team, testimonials
These split into two intuitive sub-clusters that B3/contract review should formalize:
- CMS content (GRP-CMS) — likely
BIRTH_EXEMPT_DERIVED_CACHE(Antigravity-managed) or out-of-governance-scope. - Agency OS business (GRP-BUSINESS
os_*) — likely promote toBIRTH_REQUIREDonce Agency OS enters governance.
Phase 6 — Summary
| status | count | share |
|---|---|---|
| BIRTH_REQUIRED | 43 | 31.6% |
| BIRTH_EXEMPT_STRUCTURAL_JUNCTION | 20 | 14.7% |
| BIRTH_EXEMPT_SYSTEM_LOG_OR_AUDIT | 11 | 8.1% |
| BIRTH_EXEMPT_DERIVED_CACHE | 4 | 2.9% |
| BIRTH_DEFERRED_NEEDS_REVIEW | 58 | 42.6% |
| total | 136 | 100% |
True exempt total (junction + log + cache) = 35 — i.e. ~26% of uncovered collections are structurally exempt and need no trigger. B3 implementation target = 43 BIRTH_REQUIRED collections (immediate) + governance decision on the 58 deferred (split between excluded-CMS / excluded-Agency-OS / missing-tables / hook-targets).
Critical blocker notes
- 136 vs 137 discrepancy. Prior inventory's
166 − 29 = 137was a raw subtraction; the join-deduped count of uncovered collections is 136. Adjust subsequent reports accordingly. - 7 missing tables in
collection_registry(billing,blocks,help,kb_audit_log,kb_documents_history,sales,website) — registry rows exist with no physical table. Recommend separate cleanup pass (DELETE registry rows or CREATE tables) before B3. - 48
excludedcollections fell through to DEFERRED because the spec's 5-status taxonomy doesn't have an explicit "user-excluded" bucket. Two practical sub-clusters (CMS-Antigravity vs Agency-OS-business) deserve dedicated statuses or an explicit policy in the B3 contract. entity_labelsanduniversal_edgesare designated hook tables in design v3 but landed in JUNCTION and DEFERRED respectively here. Reconcile B3 contract: do hook tables need their own birth trigger, or is birth implicit when the source entity births?- Naming-only inferences avoided per spec; classifications above are driven by
collection_registry.{governance_role, group, classification, purpose}+ schema shape (column count, PK type, FK count) + species mapping + existing birth rows. Naming weight ≤ 0.2 throughout. - No mutation performed. All SQL was
SELECT-only againstdirectus.publicon VPS 38.242.240.89.
Final response status
classification_status=PARTIAL
total_uncovered=136
birth_required_count=43
exempt_junction_count=20
exempt_system_log_count=11
exempt_derived_cache_count=4
deferred_needs_review_count=58
table_family_resolution_complete=true
concept_resolution_complete=true
compiled_sql_logged=true
report_path=knowledge/dev/laws/dieu44-trien-khai/reports/p3d-birth-coverage-classification-report.md
no_mutation_performed=true
next_recommended_action=GPT_REVIEW_CLASSIFICATION_THEN_B3_TRIGGER_DESIGN
Birth Coverage Classification | rev2 executed | 2026-05-12