KB-4ABA

Codex Reports Live Refresh Factory — Progress and Evidence

5 min read Revision 1
codexreportslive-refreshtable-factorydirectuspgprogress2026-07-10

Mission — Khuôn Reports đọc số thực và Làm mới dữ liệu sống

Ngày bắt đầu: 2026-07-10
Trạng thái: ĐÃ SỬA VÀ VERIFY LOCAL — CHỜ OWNER GATE, CHƯA PUSH / CHƯA CI / CHƯA DEPLOY

Checkpoint Desktop

  • Vĩnh viễn: sửa cơ chế phân loại nguồn và luồng dựng từ repository; không vá từng trang hoặc sửa tay on-box.
  • Nhầm: khuôn/server chỉ cho phép table_id; SQL chỉ lấy từ table_registry; gateway read-only; kiểm tra tự động ngăn route/nginx bị bỏ khỏi artifact dựng.
  • 100% tự động: một khai báo metadata phải đủ để trang mới chọn đúng nguồn và nút Làm mới luôn re-query nguồn sống.
  • Data flow: bảng gốc PG → Directus → Nuxt; số tính toán PG → read-only report gateway → Nuxt.
  • Một việc: làm cho toàn bộ khuôn Reports và mọi bản đúc từ khuôn luôn đọc dữ liệu mới nhất khi Làm mới.

Luật đã đọc

  • .claude/skills/incomex-rules.md — 36 mục, 8 bước.
  • knowledge/dev/ssot/vps/vps-operating-rules.md — v1.0, revision 2.
  • knowledge/dev/laws/constitution.md — v4.6.3, revision 44.
  • knowledge/dev/ssot/table-module/index.md — Table Module SSOT v4.1, revision 11.
  • Thiết kế Reports rev2 và Runbook Reports MVP 2A.
  • Điều 41 vận hành mã VPS — bản tìm được qua KB là v0.5.1 DRAFT; không viện dẫn như luật ban hành.

5 câu thiết kế sản phẩm

  1. Mô hình tổng thể: table_registry là metadata SSOT; renderer chung tự chọn Directus hoặc live gateway.
  2. Quy trình khép kín: metadata → route chung → fetch nguồn → refresh → đối chiếu số → scanner hồi quy.
  3. Công cụ đầy đủ: cần validator/static test cho registry/route/nginx và smoke test UI/API.
  4. Môi trường: repository local là nơi chuẩn bị thay đổi; production VPS chỉ đọc khảo sát cho tới Owner gate.
  5. Nguyên tắc vàng: metadata > code; không tạo logic business hoặc page riêng theo từng collection.

TODO và evidence

  • Chụp hiện trạng source tree, Git và file bị .gitignore chặn.
  • Đọc khuôn DirectusTable, composable, host pages và live route.
  • Truy vấn read-only toàn bộ table_registry production.
  • Phân loại 100% trang: base table / live SQL / snapshot sai.
  • So sánh số API/UI với PG production.
  • Diff nginx repository với nginx live; xác định pipeline deploy.
  • Giao Codex CLI khảo sát độc lập và review bằng evidence.
  • Chốt thiết kế sửa gốc.
  • Sửa local repository, thêm guardrail/test; không push/deploy.
  • Test local và self-review hai mũ.
  • Trình Owner gate trước push/CI/deploy.
  • Sau gate: deploy chuẩn và verify production hai vòng.
  • Cập nhật OR/TD/handoff và hoàn tất báo cáo.

Evidence hiện có

  • Production registry snapshot (read-only): 28 dòng chưa archive; 7 route /reports* gồm Home, PG Census, 4 Balo và Loại.
  • Production paired verifier: cả 7 route Reports đều PASS đối chiếu API/Directus với PostgreSQL: Balo function 654, table 383, trigger 410, view 699, Loại 42, Home 6, PG 12.
  • Production UI before deploy: Playwright reports-live.spec.ts hiện 0/3; sau khi bấm Làm mới không phát sinh request live cho Home/PG và không re-query Directus cho Balo. Đây là lỗi khuôn đang chạy trên VPS, không phải lỗi số PG.
  • Production live sample: tbl_report_pg trả source=pg:table_registry.view_sql:tbl_report_pg, count=12, table=385, sequence=151; Balo table trả directus_count=383 = pg_count=383.
  • ⚠️ Production header before deploy: response đang thiếu Cache-Control: no-store; bản local đã thêm header này ở live route và cache: 'no-store' ở UI fetch.
  • Local artifact: pnpm run typecheck PASS; pnpm run build PASS; Playwright reports-live.spec.ts PASS 3/3 (Home refresh, PG live refresh, Balo Directus refresh).
  • Static guard: scripts/integrity/check-reports-factory.sh PASS; YAML CI/deploy parse PASS; pg runtime dependency is declared so SSR output is self-contained.
  • ⚠️ Non-Reports scope: 2/28 registry rows (tbl_registry_changelog, tbl_registry_collections) trả 403 qua public UI proxy; đây là quyền đọc của nhóm /knowledge, không thuộc 7 route Reports và chưa tự ý ghi quyền production.
  • ⏸️ Owner gate: chưa push, chưa chạy CI/deploy, chưa ghi production DB. Deploy workflow đã thêm nginx -t, Reports gateway health check và guard route; lỗi route sẽ làm deploy fail trước khi báo healthy.