KB-6E56

S146-M4a — Pivot Readiness Report

31 min read Revision 1
s146pivotreadinesscodexreportcurrent-state

S146-M4a — Pivot Readiness Report

Agent: Codex Ngày: 2026-03-29 Trạng thái: CHỈ KIỂM TRA — KHÔNG SỬA GÌ

Step 0: Checkpoint Bắt Buộc

OR SSOT

Version: 1.0
Date: 2026-02-28
Status: Active

Luật 1: ĐỌC TRƯỚC KHI LÀM

Mọi Agent PHẢI đọc các tài liệu sau TRƯỚC KHI thao tác VPS:

  1. knowledge/dev/ssot/operating-rules.md
  2. knowledge/dev/ssot/vps/vps-architecture.md
  3. knowledge/dev/ssot/vps/vps-operating-rules.md
    Agent phải trích dẫn dòng cụ thể để chứng minh đã đọc.

Skills merge rule

## ⚡ MERGE RULE (web-test) — v4.68
"CI GREEN" = CHỈ 4 required checks GREEN:
MERGE NGAY khi 4 cái trên xanh.
## §0-AB CẤM --admin (v4.72)
- TUYỆT ĐỐI CẤM gh pr merge --admin hoặc bypass branch protection

Anti-patterns SSOT — đã đọc đủ 12 AP

  • AP-01: Skip Assembly Gate — Sai: Bỏ qua Step 0, code ngay.
  • AP-02: Báo cáo ảo — Sai: Báo DONE chưa verify production.
  • AP-03: Bypass branch protection — Sai: --admin khi CI fail.
  • AP-04: Filter ẩn issues — Sai: filter che giấu vấn đề.
  • AP-05: Manual deploy duplicate — Sai: deploy thủ công.
  • AP-06: Chức năng OK nhưng automation thiếu — Sai: DONE nhưng không tự động.
  • AP-07: Sửa lắt nhắt nhiều vòng CI — Sai: push từng fix lẻ.
  • AP-08: Config trước code sau — Sai: code trước, check PG/Directus sau.
  • AP-09: Làm tay thay DOT — Sai: bypass DOT.
  • AP-10: "Excluded" = giấu — Sai: dùng excluded để che vấn đề.
  • AP-11: Sáng tác Nuxt page cho collection mới — Sai: tạo page riêng thay vì PG+Directus+meta_catalog -> Nuxt tự hiện.
  • AP-12: Giám sát báo PASS nhưng số sai — Sai: scanner PASS nhưng count thực tế sai.

Assembly Gate

  • Q0 “PG đã giải quyết chưa?”
    • Trạng thái ban đầu: CHƯA BIẾT — mission này đi kiểm tra.
    • Kết quả sau kiểm tra ngày 2026-03-29: CHƯA XÁC NHẬN ĐƯỢC trực tiếp trên PG vì SSH vào VPS bị Connection refused; runtime evidence production hiện tại không cho phép kết luận “pivot system sẵn sàng cho 7 dòng”.

1. Quotes Hiến Pháp / Luật + Ý Kiến Agent

1A. Hiến pháp

Hiến pháp v3.9 | Ban hành: S105, mở rộng S106-S141 | 34 Điều Luật (Điều 0-24 + 0-B + 0-G + 0-S + 0-M + 0-L + 26-31) | +Điều 26 MỚI v3.5 BAN HÀNH (S141, Pivot Table, gộp Điều 32). +Điều 0-S/0-M/0-L (S132). +Điều 31 BAN HÀNH v1.2 (S131)
VĂN BẢN NÀY CÓ HIỆU LỰC TỐI CAO TRONG MỌI QUYẾT ĐỊNH THIẾT KẾ.

Luật 1 — SSOT
Snippet SSOT hiện hành truy xuất được:

Mỗi nội dung, mỗi tính năng, mỗi cơ chế chỉ tồn tại ở MỘT NƠI DUY NHẤT (Single Source of Truth)...

Luật 2 — Tự động hoá
Snippet SSOT hiện hành truy xuất được:

Con người chỉ ra quyết định Yes/No. MỌI THỨ KHÁC = máy làm...

Luật 3 — DOT 100%
Snippet SSOT hiện hành truy xuất được:

Mọi thao tác trên hạ tầng, schema, registry, metadata = qua DOT tool hoặc script chuẩn...

Điều 7 Khoản 1 — PG trước nhất
Tôi không truy xuất được nguyên văn current Điều 7 Khoản 1 bằng MCP search trong phiên này. Câu gần nhất tôi xác minh được từ SSOT hiện hành là từ knowledge/dev/architecture/dieu33-postgresql-law-draft.md:

PG là nền tảng DUY NHẤT. Mọi thứ đứng trên PG. PG sai = tất cả sai.
PG = NƠI ENFORCE TẤT CẢ LUẬT. Application logic chỉ ĐỌC kết quả PG đã enforce.

Điều 13 — Danh mục sống / Mô hình A vs B
Phần nội dung truy xuất được nguyên văn từ knowledge/dev/architecture/index.md:

**Mô hình A — Registry IS the source (ưu tiên):**
Thực thể được TẠO TRONG registry → hệ thống đọc từ registry → UI hiện.
- **Đây là mô hình tốt nhất.** Tạo record = xuất hiện. Không cần sync.
**Mô hình B — Source tách rời → auto-sync vào registry:**

Nhận xét về đánh số Điều: prompt gọi đây là “Điều 13”. Tôi xác minh được nội dung Mô hình A/B là có thật trong SSOT hiện hành, nhưng không xác minh được số điều current qua tool search hôm nay. Đây là một điểm lệch tài liệu cần ghi nhận thẳng.

1B. Điều 26 — Luật Registries & Đếm

# ĐIỀU 26 MỚI: LUẬT REGISTRIES & ĐẾM — Draft v3.5
## MT2: ĐẾM LUÔN ĐÚNG BY DEFINITION (COUNT trực tiếp, không cache)
## MT3: SCALE BẰNG DOT, KHÔNG BẰNG CODE

Bài toán 2 — pivot_definitions + pivot_count()

## BÀI TOÁN 2: PIVOT TABLE + MA TRẬN — "TRÍCH XUẤT"
### pivot_definitions schema

Các field xuất hiện nguyên văn trong luật:

  • code
  • name
  • source_object
  • filter_spec
  • group_spec
  • metric_spec
  • registry_group
  • composition_level
  • species
  • parent_code
  • display_order
  • is_active
  • cache_tier
  • superseded_by
  • normalized_signature

pivot_count() parse JSON → build WHERE: An toàn. DOT validate dễ. Audit rõ ràng.

Điều 26 gắn với Danh mục sống

pivot_definitions, templates, registry_groups, VIEWs = managed registries (Điều 13 Danh mục sống).

DOT tools

# §V. DOT TOOLS: 4 SỬA CŨ + 3 MỚI = 7

Tuy nhiên, trong phần luật truy xuất được hôm nay, không có danh sách enumerate đủ 7 tên tool. Evidence runtime/local hiện tại chỉ xác nhận chắc chắn 2 tool pivot-specific đang tồn tại và đăng ký:

  • dot-pivot-declare
  • dot-pivot-health

Mission status theo report cũ

  • Mission 1: Pivot CHẠY — report ghi Status: MERGED + DEPLOYED
  • Mission 2: DOT Khai Báo Pivot — report ghi Status: MERGED + DEPLOYED
  • Mission 3: VIEW Cross-Table — report ghi Status: MERGED + DEPLOYED
  • Mission 3.5: Automation Hardening — report ghi Status: MERGED + DEPLOYED

Status theo kiểm tra ngày 2026-03-29

  • Mission 1: definitions đang có thật.
  • Mission 2: 2 DOT pivot tools đang có thật và đã đăng ký.
  • Mission 3: grouped pivot API hiện trả rows: [] cho cả PIV-101PIV-103, nên phần “VIEW cross-table chạy thật” không được chứng minh bởi runtime hiện tại.
  • Mission 3.5: cron/trigger chỉ có claim trong report cũ, không SSH verify được hôm nay.

1C. Điều 0-B và Species

Điều 0-B

| Chứa gì | → Lớp | Badge |
| Chỉ chứa hạ nguyên tử (metadata, field values) | → Lớp nguyên tử (Atom) |
| Chứa nguyên tử, KHÔNG có quy trình/logic | → Lớp phân tử (Molecule) |
| Chứa phân tử + nguyên tử + CÓ quy trình/logic | → Lớp hợp chất (Compound) |
| Hợp chất đã chuẩn hoá, tái sử dụng | → Lớp vật liệu (Material) |
| Vật liệu đang chạy cho đối tượng cụ thể | → Lớp sản phẩm (Product) |
| Toàn bộ mảng kinh doanh | → Lớp công trình (Building) |

Species / “lớp thứ 7”

Species ≠ nguyên tử. Species = meta-entity phân loại, đứng NGOÀI 6 lớp cấu tạo.
Registries UI = 7 chiều (6 lớp + 1 meta-layer species).
KHÔNG CÓ composition_level riêng. Field composition_level trong entity_species = lớp CỦA CÁ THỂ.
Trước: 6 lớp cấu tạo. Giờ: 6 + 1 meta-layer species.

1D. Ý kiến agent — vênh / thiếu / mâu thuẫn

  1. Vênh lớn nhất giữa luật và runtime: Điều 26/Điều 13 nói metadata-driven, tạo record = tự hiện; nhưng runtime hiện tại có pivot_definitions rồi mà pivot-query cho PIV-101PIV-103 vẫn trả rows: []. Tức là “có định nghĩa” chưa thành “tự hiện”.
  2. Luật 2 / Luật 3 nói automation + DOT 100%, nhưng 2 DOT pivot tools hiện tại vẫn là manual SSH CLI. Không có evidence runtime nào chứng minh “thêm 1 pivot mới” là chỉ INSERT metadata rồi máy tự lo hết.
  3. Điều 26 cover 6 lớp ở mức grouped, nhưng không có 1 pivot dedicated cho từng lớp. Hiện có PIV-101PIV-106 group theo composition_level, không phải 6 dòng định nghĩa riêng.
  4. Species chưa nối thẳng vào pivot_definitions: field species tồn tại trong schema luật, nhưng 27/27 rows hiện tại đều species = null. Species law có, pivot law có, nhưng bridge giữa hai thứ này hiện chưa thấy trong runtime definitions.
  5. Điều 29/Species nói 7 chiều, nhưng endpoint composition hiện chỉ trả atom/molecule/compound/meta; không có material/product/building species counts trong output live ngày 2026-03-29.
  6. Đánh số điều bị lệch/truy xuất không đầy đủ: prompt yêu cầu quote Điều 7 Khoản 1 và Điều 13; tôi xác minh được nội dung PG-first và Model A/B, nhưng không xác minh được chính xác current numbering bằng tool search hôm nay. Đây là lệch tài liệu cần dọn.

2. Kết Quả Chạy Thử PG / Runtime

2A. SSH vào VPS để chạy SQL trực tiếp

Lệnh read-only đã thử:

ssh -i ~/.ssh/contabo_vps root@38.242.240.89 "hostname; whoami"

Kết quả nguyên văn:

ssh: connect to host 38.242.240.89 port 22: Connection refused

Hệ quả: tôi không thể chạy trực tiếp các SQL user yêu cầu trên PG hôm nay:

  • SELECT ... FROM pivot_definitions
  • SELECT pivot_count(...)
  • SELECT proname FROM pg_proc ...
  • SELECT prosrc FROM pg_proc ...
  • SELECT refresh_meta_catalog_from_pivot()
  • crontab -l, journalctl, pg_trigger

Vì vậy, phần dưới đây là runtime evidence thay thế từ Directus MCP + production API public + source trong repo. Chỗ nào là inference từ source repo, tôi đánh dấu rõ.

2B. pivot_definitions — current state quan sát được qua Directus

Tổng số rows hiện tại: 27
Active: 26
Inactive: 1 (PIV-020)

Relevant rows cho 6 lớp + species:

[
  {
    "code": "PIV-101",
    "name": "Danh mục theo Lớp",
    "source_object": "meta_catalog",
    "composition_level": "molecule",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": [
        {
          "op": "=",
          "field": "status",
          "value": "active"
        }
      ]
    },
    "group_spec": {
      "groups": [
        {
          "alias": "level",
          "field": "composition_level"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  },
  {
    "code": "PIV-102",
    "name": "Danh mục theo Loại quản lý",
    "source_object": "meta_catalog",
    "composition_level": "molecule",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": [
        {
          "op": "=",
          "field": "status",
          "value": "active"
        }
      ]
    },
    "group_spec": {
      "groups": [
        {
          "alias": "identity",
          "field": "identity_class"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  },
  {
    "code": "PIV-103",
    "name": "Loài theo Lớp",
    "source_object": "entity_species",
    "composition_level": "atom",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": []
    },
    "group_spec": {
      "groups": [
        {
          "alias": "level",
          "field": "composition_level"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  },
  {
    "code": "PIV-104",
    "name": "DOT Tools theo Nhóm",
    "source_object": "dot_tools",
    "composition_level": "atom",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": [
        {
          "op": "=",
          "field": "status",
          "value": "published"
        }
      ]
    },
    "group_spec": {
      "groups": [
        {
          "alias": "category",
          "field": "category"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  },
  {
    "code": "PIV-105",
    "name": "Collections theo Phân loại",
    "source_object": "collection_registry",
    "composition_level": "molecule",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": []
    },
    "group_spec": {
      "groups": [
        {
          "alias": "classification",
          "field": "classification"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  },
  {
    "code": "PIV-106",
    "name": "Danh mục: Lớp × Loại quản lý",
    "source_object": "meta_catalog",
    "composition_level": "molecule",
    "species": null,
    "registry_group": "cross-table",
    "is_active": true,
    "filter_spec": {
      "filters": [
        {
          "op": "=",
          "field": "status",
          "value": "active"
        }
      ]
    },
    "group_spec": {
      "groups": [
        {
          "alias": "level",
          "field": "composition_level"
        },
        {
          "alias": "identity",
          "field": "identity_class"
        }
      ]
    },
    "metric_spec": {
      "metrics": [
        {
          "func": "count",
          "alias": "total",
          "field": "*"
        }
      ]
    }
  }
]

Trả lời câu hỏi 2A

  • Có entry đếm theo 6 lớp không?
    • , nhưng ở dạng grouped pivot, không phải 6 định nghĩa riêng:
    • PIV-101meta_catalog group by composition_level
    • PIV-106meta_catalog group by composition_level × identity_class
    • PIV-103entity_species group by composition_level
  • Có entry đếm species không?
    • , nhưng chỉ gián tiếp qua entity_speciesPIV-103.
    • Field species trong pivot_definitions hiện null cho toàn bộ 27 rows.
  • Nếu hỏi “có pivot riêng đếm atom / molecule / compound / material / product / building không?”
    • KHÔNG. Hiện chỉ có grouped pivot, không có 1 pivot riêng cho từng lớp.
  • Nếu hỏi “filter_spec của atom có đúng không?”
    • KHÔNG có pivot atom-specific để đánh giá.
    • PIV-101 không phải “managed atom count”; nó chỉ lọc status = 'active', nên về logic không khớp với bài toán:
      WHERE composition_level = 'atom'  AND identity_class = 'managed'  AND status = 'active'
      
    • Nói cách khác: definition hiện tại chưa encode đúng bài toán “managed atom active” mà prompt yêu cầu đối chiếu.

2C. pivot_query / pivot_count path — runtime evidence hiện tại

PIV-101 live API

curl -sS "https://vps.incomexsaigoncorp.vn/api/registry/pivot-query?code=PIV-101"

Kết quả nguyên văn:

{"definitions":1,"results":[{"code":"PIV-101","name":"Danh mục theo Lớp","source_object":"meta_catalog","group_spec":{"groups":[{"alias":"level","field":"composition_level"}]},"metric_spec":{"metrics":[{"func":"count","alias":"total","field":"*"}]},"composition_level":"molecule","rows":[]}],"timestamp":"2026-03-29T03:55:25.494Z"}

PIV-103 live API

curl -sS "https://vps.incomexsaigoncorp.vn/api/registry/pivot-query?code=PIV-103"

Kết quả nguyên văn:

{"definitions":1,"results":[{"code":"PIV-103","name":"Loài theo Lớp","source_object":"entity_species","group_spec":{"groups":[{"alias":"level","field":"composition_level"}]},"metric_spec":{"metrics":[{"func":"count","alias":"total","field":"*"}]},"composition_level":"atom","rows":[]}],"timestamp":"2026-03-29T03:59:03.375Z"}

Composition endpoint live

curl -sS "https://vps.incomexsaigoncorp.vn/api/registry/composition"

Kết quả nguyên văn:

{"byLevel":{"atom":{"speciesCount":16,"collectionCount":65},"compound":{"speciesCount":6,"collectionCount":30},"molecule":{"speciesCount":11,"collectionCount":50},"meta":{"speciesCount":1,"collectionCount":1}},"totalSpecies":35,"cachedAt":"2026-03-29T03:52:10.828Z"}

Kết luận runtime cho pivot path

  • PIV-101 có definition nhưng rows: [].
  • PIV-103 có definition nhưng rows: [].
  • Trong khi đó production vẫn có byLevel data ở endpoint composition.
  • Vì vậy, definition tồn tại ≠ grouped pivot path đang trả kết quả.
  • Tôi không thể chạy SELECT pivot_count('PIV-XXX')COUNT(*) trực tiếp trên PG do SSH block, nên phần so sánh pivot_count vs COUNT thật chưa verify được theo đúng cách user yêu cầu.

2D. refresh_meta_catalog_from_pivot() — source và virtual rows

Live PG source (SELECT prosrc): KHÔNG lấy được vì SSH bị block.

Repo source gần nhất truy xuất được trong sql/s170b_pivot_directus.sql
Lưu ý: đây là source trong repo, KHÔNG phải dump trực tiếp từ production PG hôm nay.

CREATE OR REPLACE FUNCTION refresh_meta_catalog_from_pivot()
RETURNS TABLE(cat_code TEXT, old_count INT, new_count BIGINT, changed BOOLEAN)
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
DECLARE
  r RECORD;
BEGIN
  FOR r IN
    SELECT mc.code AS cat_code, mc.record_count AS old_count, pc.count_value AS new_count
    FROM pivot_count() pc
    JOIN pivot_definitions pd ON pd.code = pc.code
    JOIN meta_catalog mc ON mc.registry_collection = pd.source_object
    WHERE pd.is_active = true
  LOOP
    IF r.old_count IS DISTINCT FROM r.new_count THEN
      PERFORM set_config('app.allow_meta_update', 'true', false);
      UPDATE meta_catalog
      SET record_count = r.new_count,
          active_count = r.new_count,
          last_scan_date = NOW()
      WHERE code = r.cat_code;
    END IF;

    cat_code := r.cat_code;
    old_count := r.old_count;
    new_count := r.new_count;
    changed := (r.old_count IS DISTINCT FROM r.new_count);
    RETURN NEXT;
  END LOOP;

  PERFORM set_config('app.allow_meta_update', 'false', false);
END;
$$;

Theo source repo, function này update field nào?

  • record_count
  • active_count
  • last_scan_date

Không thấy update

  • orphan_count
  • virtual summary fields khác

Virtual rows hiện tại

[
  {
    "code": "CAT-ALL",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "atom"
  },
  {
    "code": "CAT-BLD",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "building"
  },
  {
    "code": "CAT-CMP",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "compound"
  },
  {
    "code": "CAT-MAT",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "material"
  },
  {
    "code": "CAT-MOL",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "molecule"
  },
  {
    "code": "CAT-PRD",
    "registry_collection": null,
    "identity_class": "virtual",
    "composition_level": "product"
  }
]

Suy luận có đánh dấu rõ là inference từ repo source + Directus data

  • Vì function join bằng mc.registry_collection = pd.source_object
  • Và vì CAT-ALL/MOL/CMP/MAT/PRD/BLD đều có registry_collection = null
  • Nên repo source hiện tại không thể update các virtual rows này qua join đó
  • Đây là vênh rất mạnh với kỳ vọng “6 lớp + species” nếu Registries 2 định reuse virtual rows

Current raw-counts của virtual rows

[
  {"code":"CAT-ALL","name":"Tổng nguyên tử","identity_class":"virtual","composition_level":"atom","record_count":34321},
  {"code":"CAT-MOL","name":"Tổng phân tử","identity_class":"virtual","composition_level":"molecule","record_count":766},
  {"code":"CAT-CMP","name":"Tổng hợp chất","identity_class":"virtual","composition_level":"compound","record_count":326},
  {"code":"CAT-MAT","name":"Tổng vật liệu","identity_class":"virtual","composition_level":"material","record_count":55},
  {"code":"CAT-PRD","name":"Tổng sản phẩm","identity_class":"virtual","composition_level":"product","record_count":0},
  {"code":"CAT-BLD","name":"Tổng công trình","identity_class":"virtual","composition_level":"building","record_count":0}
]

2E. Automation / health — runtime evidence

Health endpoint

curl -sS "https://vps.incomexsaigoncorp.vn/api/registry/health"

Kết quả nguyên văn:

{"collections":[{"collection_name":"birth_registry","noi_chua":21186,"noi_sinh":0,"gap":21186,"status":"ORPHAN"},{"collection_name":"dot_tools","noi_chua":152,"noi_sinh":435,"gap":-283,"status":"PHANTOM"},{"collection_name":"approval_requests","noi_chua":165,"noi_sinh":6,"gap":159,"status":"ORPHAN"},{"collection_name":"system_issues","noi_chua":765,"noi_sinh":890,"gap":-125,"status":"PHANTOM"},{"collection_name":"pivot_definitions","noi_chua":27,"noi_sinh":0,"gap":27,"status":"ORPHAN"},{"collection_name":"meta_catalog","noi_chua":152,"noi_sinh":174,"gap":-22,"status":"PHANTOM"},{"collection_name":"entity_dependencies","noi_chua":142,"noi_sinh":160,"gap":-18,"status":"PHANTOM"},{"collection_name":"tasks","noi_chua":10,"noi_sinh":13,"gap":-3,"status":"PHANTOM"},{"collection_name":"taxonomy","noi_chua":55,"noi_sinh":57,"gap":-2,"status":"PHANTOM"},{"collection_name":"measurement_registry","noi_chua":-1,"noi_sinh":1,"gap":-1,"status":"ORPHAN"},{"collection_name":"checkpoint_types","noi_chua":31,"noi_sinh":32,"gap":-1,"status":"PHANTOM"},{"collection_name":"law_catalog","noi_chua":-1,"noi_sinh":0,"gap":-1,"status":"ORPHAN"},{"collection_name":"agents","noi_chua":6,"noi_sinh":6,"gap":0,"status":"KHOP"},{"collection_name":"checkpoint_sets","noi_chua":2,"noi_sinh":2,"gap":0,"status":"KHOP"},{"collection_name":"collection_registry","noi_chua":145,"noi_sinh":145,"gap":0,"status":"KHOP"},{"collection_name":"taxonomy_facets","noi_chua":6,"noi_sinh":6,"gap":0,"status":"KHOP"},{"collection_name":"modules","noi_chua":5,"noi_sinh":5,"gap":0,"status":"KHOP"},{"collection_name":"ui_pages","noi_chua":37,"noi_sinh":37,"gap":0,"status":"KHOP"},{"collection_name":"entity_species","noi_chua":35,"noi_sinh":35,"gap":0,"status":"KHOP"},{"collection_name":"table_registry","noi_chua":20,"noi_sinh":20,"gap":0,"status":"KHOP"},{"collection_name":"workflow_change_requests","noi_chua":3,"noi_sinh":3,"gap":0,"status":"KHOP"},{"collection_name":"workflows","noi_chua":2,"noi_sinh":2,"gap":0,"status":"KHOP"},{"collection_name":"workflow_steps","noi_chua":70,"noi_sinh":70,"gap":0,"status":"KHOP"}],"totals":{"khop":11,"orphan":5,"phantom":7,"totalGap":21828},"cachedAt":"2026-03-29T03:55:26.480Z"}

system-issues

curl -sS "https://vps.incomexsaigoncorp.vn/api/registry/system-issues"

Kết quả nguyên văn:

{"totals":{"all":112,"critical":1,"warning":111,"info":0,"group_count":2},"cachedAt":"2026-03-29T03:56:07.982Z"}

Dual-trigger check

Trigger Loại Có? Chạy thật? Evidence
Cron refresh scheduled Theo report cũ: CÓ KHÔNG XÁC NHẬN ĐƯỢC SSH block, không đọc được crontab/log
Cron health scheduled Theo report cũ: CÓ KHÔNG XÁC NHẬN ĐƯỢC SSH block, không đọc được crontab/log
PG trigger on pivot_definitions change on-demand Theo report cũ: CÓ KHÔNG XÁC NHẬN ĐƯỢC SSH block, không query được pg_trigger
Runtime accuracy verification correctness THIẾU KHÔNG dot-pivot-health H7 không so COUNT(*) thật

Kết luận phần automation

  • Tôi không thể xác nhận cron/trigger đang chạy thật vì SSH/ref log bị chặn.
  • Nhưng public health hiện tại không cho thấy hệ đang khỏe:
    • pivot_definitions = ORPHAN với gap = 27
    • meta_catalog = PHANTOM với gap = -22
    • tổng totalGap = 21828

3. DOT Tools Đánh Giá

3A. Tồn tại local

ls/repo inspection cho thấy có 2 tool pivot-specific:

  • dot/bin/dot-pivot-declare
  • dot/bin/dot-pivot-health

dot_tools registry hiện tại

[
  {"code":"DOT-113","name":"dot-pivot-declare","category":"pivot","status":"published"},
  {"code":"DOT-114","name":"dot-pivot-health","category":"pivot","status":"published"}
]

3B. Đánh giá từng tool

Tiêu chí dot-pivot-declare dot-pivot-health
Chức năng Tạo pivot_definitions single mode hoặc auto từ meta_catalog Health check H1-H7 cho pivot_definitions + pivot_count()
Mode --single (--source= --name= --filter= --group= --level=) KHÔNG
Mode --batch (--auto-from-meta-catalog) , nhưng là quét toàn bộ hệ, không phải batch per-pivot
Mode --dry-run KHÔNG KHÔNG
Idempotent — duplicate check theo source_object + filter_spec, auto mode có ON CONFLICT DO NOTHING Read-only mode thì an toàn; --fix có sửa H4/H5. Duplicate H6 chỉ warn, không fix
TỰ ĐỘNG chạy được không? KHÔNG — là CLI phải gõ tay, SSH thẳng vào VPS KHÔNG — là CLI phải gõ tay; chỉ có thể thành “tự động” nếu cron gọi
Có trong cron / trigger tự động? Không có evidence runtime Theo report cũ: cron daily 4AM; hôm nay không SSH verify được
Có trong dot_tools? DOT-113 DOT-114

3C. H7 / AP-12 — điểm vênh quan trọng

Trong source local dot-pivot-health, phần H7: Count cross-check ghi comment:

# H7: Count cross-check — pivot_count() vs direct COUNT(*) for no-filter pivots

Nhưng query thực tế chỉ cảnh báo khi:

AND pr.count_value < 0;

không hề tính COUNT(*) trực tiếp trên source table để so chéo. Dòng output còn hardcode chuỗi:

SELECT pr.code || ': pivot=' || pr.count_value || ' vs direct=mismatch'

nhưng không có direct count thật trong query.

Kết luận: dot-pivot-health hiện không chứng minh được accuracy. Nó có thể báo PASS/WARN mà không biết số thật có lệch hay không. Đây là đúng anti-pattern AP-12.

3D. Đánh giá theo nguyên tắc automation

  1. Nếu user muốn thêm 1 pivot mới
    Quy trình hiện thấy được là: chạy dot-pivot-declare bằng tay hoặc insert metadata bằng đường khác. Tôi không có evidence runtime cho đường “INSERT pivot_definitions → mọi thứ tự chạy → meta_catalog tự update → Nuxt tự hiện” ở production ngày 2026-03-29.
  2. Nếu data thay đổi
    Theo report cũ thì cron refresh mỗi 10 phút. Theo runtime hôm nay, tôi không xác nhận được cron/log; hơn nữa health endpoint còn có gap lớn. Vì vậy tôi không thể kết luận “counting tự cập nhật ổn”.
  3. Scale test
    Về mặt khai báo, pivot_definitions + JSON spec có ý đồ scale bằng metadata. Nhưng runtime grouped pivot hiện rows: [], DOT health chưa so direct count thật, và chỉ có 2 tool pivot-specific đăng ký. Tôi chưa thấy bằng chứng đủ mạnh để nói hệ đang scale tốt cho 500 collections.

4. 6 Câu Trả Lời + Kết Luận

4A. Pivot system CHẠY ĐƯỢC cho 7 dòng (6 lớp + species) chưa?

CHƯA.

Thiếu/chưa chứng minh được:

  • PIV-101 live API trả rows: []
  • PIV-103 live API trả rows: []
  • Không SSH verify được pivot_count() / pivot_query() / cron / trigger
  • species field trong pivot_definitions hiện null toàn bộ
  • Virtual rows có sẵn nhưng repo source refresh hiện không join tới được

4B. pivot_definitions đã có entry nào liên quan 6 lớp + species?

CÓ, nhưng chưa ở dạng “7 dòng dedicated”.

  • PIV-101meta_catalog by composition_level
  • PIV-103entity_species by composition_level
  • PIV-106meta_catalog by composition_level × identity_class

Chưa có:

  • 1 pivot riêng cho từng lớp atom/molecule/compound/material/product/building
  • 1 pivot dedicated cho species meta-layer qua field species

Nếu mục tiêu là 7 dòng runtime-ready đúng nghĩa, current definitions chưa đủ.

4C. Automation đầy đủ chưa?

CHƯA.

  • INSERT pivot_definitions → meta_catalog tự update?
    • Theo report cũ:
    • Theo kiểm tra hôm nay: KHÔNG XÁC NHẬN ĐƯỢC
  • Data thay đổi → counting tự update?
    • Theo report cũ: cron */10
    • Theo kiểm tra hôm nay: KHÔNG XÁC NHẬN ĐƯỢC
  • Thiếu automation chắc chắn nhìn thấy:
    • accuracy cross-check thật (COUNT(*) vs pivot)
    • đường refresh cho virtual rows
    • evidence log/trigger live hôm nay

4D. meta_catalog virtual rows (CAT-ALL/MOL/CMP/MAT/PRD/BLD) hiện thế nào?

[
  {"code":"CAT-ALL","name":"Tổng nguyên tử","identity_class":"virtual","composition_level":"atom","status":"active","record_count":34321},
  {"code":"CAT-MOL","name":"Tổng phân tử","identity_class":"virtual","composition_level":"molecule","status":"active","record_count":766},
  {"code":"CAT-CMP","name":"Tổng hợp chất","identity_class":"virtual","composition_level":"compound","status":"active","record_count":326},
  {"code":"CAT-MAT","name":"Tổng vật liệu","identity_class":"virtual","composition_level":"material","status":"active","record_count":55},
  {"code":"CAT-PRD","name":"Tổng sản phẩm","identity_class":"virtual","composition_level":"product","status":"active","record_count":0},
  {"code":"CAT-BLD","name":"Tổng công trình","identity_class":"virtual","composition_level":"building","status":"active","record_count":0}
]

Quan trọng:

  • registry_collection của cả 6 dòng này đều null
  • Nếu Registries 2 muốn reuse chúng, phải có đường refresh/read phù hợp
  • Theo repo source hiện truy xuất được, refresh_meta_catalog_from_pivot() không join tới được 6 dòng này

4E. Giữa hiến pháp/luật và thực tế — vênh gì?

  • Luật nói Tạo record = xuất hiện, nhưng live pivot-query hiện rows: []
  • Luật nói DOT 100%, nhưng 2 DOT pivot tools hiện là manual CLI qua SSH
  • Luật species nói 7 chiều, nhưng live composition endpoint chỉ thấy atom/molecule/compound/meta
  • pivot_definitions có field species, nhưng runtime rows hiện tại đều null
  • Report cũ nói automation dual-triggered, nhưng hôm nay không SSH verify được; ngược lại health endpoint còn gap lớn
  • Legal numbering/quote retrievability đang lệch: nội dung có, nhưng current article numbering không truy xuất sạch bằng tool

4F. Toàn bộ blockers trước khi làm 7 dòng

Loại Blocker Mức
PG Không SSH được vào VPS (Connection refused), nên không verify trực tiếp pivot_count(), pivot_query(), refresh, pg_trigger, cron logs Critical
PG Grouped pivot live PIV-101PIV-103 trả rows: [] Critical
PG Repo source refresh hiện không cover virtual rows vì registry_collection = null High
DOT dot-pivot-health H7 không so COUNT(*) thật, nên PASS/WARN không chứng minh correctness High
DOT Chỉ thấy 2 pivot-specific tools đang đăng ký; luật nói 7 tools nhưng runtime không enumerate đủ Medium
Automation Cron/trigger chỉ có claim trong report cũ; không verify live được High
Directus Health endpoint báo pivot_definitions ORPHAN, meta_catalog PHANTOM, totalGap = 21828 Critical
Directus system_issues hiện 112 issues (1 critical, 111 warning) High
Nuxt Nếu Nuxt/endpoint dựa vào grouped pivot result, 7 dòng sẽ không ra vì API đang trả rows: [] High

Kết luận 1 câu: CHƯA SẴN SÀNG. Definitions có, report cũ nói LIVE, nhưng runtime ngày 2026-03-29 cho thấy grouped pivots đang trả rows: [], virtual rows chưa có đường refresh được chứng minh, species chưa nối đủ, và verification PG/automation bị chặn bởi SSH.