KB-5A8F rev 2

P2B-INV — Birth Pipeline Inventory Prompt

6 min read Revision 2
birth-pipelineinventoryinvestigationread-only

P2B-INV — Birth Pipeline Inventory (Read-Only Investigation)

Date: 2026-05-05 | Status: PROMPT rev2 | Scope: READ-ONLY Mục tiêu: Tìm TẤT CẢ cơ chế khai sinh ĐÃ CÓ trên VPS + KB. Không thiết kế mới.


§0. Mission

Điều tra toàn diện birth pipeline đang chạy trên VPS. Trả lời 8 câu hỏi cuối report (§4). Không thiết kế gì mới. Chỉ tìm và báo cáo.


§1. Read-list bắt buộc TRƯỚC KHI vào VPS

Đọc trên KB theo thứ tự:

  1. knowledge/ops/processes/birth-process-v1.md
  2. knowledge/dev/architecture/birth-registry-law.md
  3. knowledge/dev/laws/law-04-birth-process.md
  4. knowledge/dev/laws/dieu44-trien-khai/reports/dot119-repair-p2-script-rewrite-report.md
  5. knowledge/dev/laws/dieu44-trien-khai/reports/iu-birth-trigger-install-18c-report.md
  6. knowledge/dev/laws/dieu44-trien-khai/reports/19-p2b-p1-iu-pilot-insert-and-birth-fire-report.md
  7. knowledge/dev/laws/dieu44-trien-khai/reviews/iu-birth-philosophy-and-p2b-p1-interpretation-2026-05-05.md

Sau đó search KB/history cho: QT-001, QT-002, birth-first, backfill birth_registry, orphan, ghost, fn_birth_registry_auto, dot-birth-trigger-setup, DOT-119


§2. Connection

docker exec -i postgres psql -U directus -d directus

§3. Queries — chạy lần lượt

Q1: DOT tools trên disk (toàn bộ)

ls -la /opt/incomex/dot/bin/
grep -RInE 'birth_registry|fn_birth_registry_auto|trg_birth_|orphan|ghost|backfill|retrofit|reconcile' /opt/incomex 2>/dev/null | head -300

Q3: Birth triggers với trigger definition

SELECT tgname, tgrelid::regclass AS table_name, tgfoid::regproc AS function,
       pg_get_triggerdef(oid) AS trigger_def
FROM pg_trigger
WHERE tgname LIKE 'trg_birth_%' AND NOT tgisinternal
ORDER BY table_name, tgname;

Q4: Birth functions — full source

SELECT proname, pg_get_functiondef(oid)
FROM pg_proc
WHERE proname LIKE '%birth%'
   OR proname LIKE '%registry_auto%'
   OR proname LIKE '%orphan%'
   OR proname LIKE '%ghost%'
ORDER BY proname;

Q5: Health/registry functions

SELECT proname, pg_get_functiondef(oid)
FROM pg_proc
WHERE proname LIKE 'fn_registry%'
   OR proname LIKE 'fn_health%'
   OR proname LIKE '%reconcile%'
ORDER BY proname;

Q6: Birth registry schema

SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name='birth_registry'
ORDER BY ordinal_position;

Q7: system_health_checks — schema first, then query

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name='system_health_checks'
ORDER BY ordinal_position;

Sau đó query health checks theo columns thật (không assume column names):

SELECT * FROM system_health_checks
WHERE <adapt columns> ILIKE '%birth%'
   OR <adapt columns> ILIKE '%orphan%'
   OR <adapt columns> ILIKE '%ghost%'
   OR <adapt columns> ILIKE '%registry%'
ORDER BY 1;

Q8: dot_tools registry (disk và registry có thể lệch)

SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name='dot_tools'
ORDER BY ordinal_position;

Sau đó query theo columns thật, filter birth/registry/orphan/ghost related.

SELECT key, value FROM dot_config
WHERE key LIKE '%birth%' OR key LIKE '%backfill%' OR key LIKE '%orphan%' OR key LIKE '%ghost%'
ORDER BY key;

Q10: DOT tool source inspection

Với MỖI tool birth/backfill/orphan/ghost/registry/health/scan/reconcile tìm được ở Q1+Q2:

/opt/incomex/dot/bin/<tool> --help 2>&1 | head -30
head -80 /opt/incomex/dot/bin/<tool>
grep -nE 'birth|backfill|orphan|ghost|registry|trigger|health|scan|reconcile|ON CONFLICT|birth_registry' /opt/incomex/dot/bin/<tool>

Q11: Cron/scheduled tasks

crontab -l 2>/dev/null | grep -iE 'birth|backfill|orphan|health|ghost|reconcile'
ls /opt/incomex/dot/cron/ 2>/dev/null
cat /opt/incomex/dot/cron/* 2>/dev/null | head -80

Q12: Birth coverage hiện trạng

SELECT collection_name, count(*) AS birth_rows
FROM birth_registry
GROUP BY collection_name
ORDER BY count(*) DESC;
SELECT t.tgrelid::regclass::text AS table_name, count(br.*) AS birth_rows
FROM pg_trigger t
LEFT JOIN birth_registry br ON br.collection_name = t.tgrelid::regclass::text
WHERE t.tgname LIKE 'trg_birth_%' AND NOT t.tgisinternal
GROUP BY t.tgrelid::regclass::text
ORDER BY table_name;

§4. Report format

Upload tại: knowledge/dev/laws/dieu44-trien-khai/reports/p2b-inv-birth-pipeline-inventory-report.md

Report PHẢI trả lời trực tiếp 8 câu hỏi:

  1. Kênh chính khai sinh hiện là gì? (tool/function/trigger nào, QT-002 hay cơ chế khác)
  2. Động cơ phụ/backfill hiện là gì? (tool nào, QT-001 hay cơ chế khác)
  3. Khi động cơ phụ chạy thì warning/health signal nào báo?
  4. Orphan detector nào đang có? (entity không birth)
  5. Ghost detector nào đang có? (birth không entity)
  6. Tool/function/trigger nào phụ trách từng vai trò?
  7. Hardcode còn lại ở đâu, nếu có?
  8. Cái gì runtime-active, cái gì chỉ là document/design?

Mỗi câu trả lời phải ghi rõ:

  • Found on VPS runtime (file, function, trigger đang chạy)
  • Found in KB/history only (documented nhưng chưa implement)
  • Runtime-active vs documented/design only

Report sections bổ sung:

  • DOT tools listing (disk + registry, ghi lệch nếu có)
  • Birth triggers (31 triggers, table, function, definition)
  • Functions source summary
  • Health checks registered
  • Cron/scheduled
  • Birth coverage (collections × birth rows)
  • KB/history search results

§5. Hard boundaries

  • ❌ NO mutation — read-only
  • ❌ NO design — chỉ báo cáo hiện trạng
  • ❌ NO new tools/scripts
  • ❌ KHÔNG đề xuất thiết kế mới
  • ❌ KHÔNG đề xuất tool mới

P2B-INV prompt rev2 | 2026-05-05 | Full inventory birth pipeline. Read-only. 8 câu hỏi bắt buộc.