KB-1665
Handoff S178 Fix 25 → Phiên sau (A+1→A+7 vòng lặp tự chữa lành)
6 min read Revision 1
handoffs178-fix25self-healingfn-log-issuegeneric-executordieu22
Handoff S178 Fix 25 → Phiên sau
Phiên: S178 Fix 25 | Ngày: 2026-04-21 HP: v4.6.3 (14 NT) | Đ22: v1.2 | Đ35: v5.2 | Đ43: v1.2 FINAL rev 6
§0. TÓM TẮT 1 CÂU
Xây xong phòng giám sát trung tâm (system_health_checks 19 rows, 2 executor refactored, parity PASS). Camera soi ra 41 vấn đề cũ. Nhưng dây điện từ camera đến chuông chưa nối (fn_log_issue STUB, PG function không tồn tại, generic executor chưa xây, auto-fix chưa wire). Vòng lặp Đ22 §1 gãy từ bước ②. Phiên sau: nối dây A+1→A+7.
§1. ĐÃ LÀM (Fix 25)
Hạ tầng HC thống nhất — A1→A10 ✅
- CREATE TABLE
system_health_checks(19 rows: NRM-LAW-43=10, NRM-LAW-35-V5P2=15 gồm DOT-H1..H14+H10, NRM-LAW-36=2, NRM-LAW-22-V1P1=1) - Migrate Đ43 H1-H9+H11 từ
context_pack_health_checks(parity 10=10, 0 mismatch ✅) - 3 SQL detect queries upload KB (hc-trigger, hc-reg, hc-schema)
dot_config.hc_trigger_autofix_enabled = 'false'- Jurisdiction map: dùng enacted codes (NRM-LAW-XX-VxPx), không literal LAW-XX
Refactor 2 executor — A8b+A8c ✅
dot-context-pack-verify.sh→ đổi querysystem_health_checks WHERE jurisdiction='NRM-LAW-43'(1 dòng). Dry-run PASS 10/10 checks.dot-dot-healthv1.0→v2.0.0 generic executor (~490 dòng). Copy pattern verify.sh §9. 0 hardcode SQL. Dry-run PASS 15/15 checks. Seed 9 rows DOT-H1..H9 theo Đ35 §8.1 + H10.
Điều tra vòng lặp tự chữa lành ✅
| Bước Đ22 §1 | Trạng thái | Vấn đề |
|---|---|---|
| ① NHẬN DIỆN | ✅ | Detect query hoạt động |
| ② LIỆT KÊ | ❌ | fn_log_issue = STUB. PG function KHÔNG TỒN TẠI. 0 rows HC trong system_issues. |
| ③ XỬ LÝ | ❌ | Không có dispatcher đọc auto_fix_action |
| ④ XÁC NHẬN | ❌ | Không có re-check |
| ⑤ CẢI TIẾN | ❌ | — |
Thêm: dot-dot-health trên cron ✅ (0 3 * * *). verify.sh KHÔNG trên cron ❌. Generic executor Đ22 §4.3 KHÔNG TỒN TẠI.
Dọn dẹp ✅
- Git VPS: 7 commits dọn stale Fix16-22. .gitignore (secrets/, backup/, context-pack/). 2 repo clean.
- TD-S178-25 + TD-S178-26 ghi sổ nợ (rev 399).
§2. QUYẾT ĐỊNH KỸ THUẬT
| # | Quyết định | Lý do |
|---|---|---|
| 1 | Jurisdiction dùng enacted codes NRM-LAW-XX-VxPx | FK normative_registry |
| 2 | Đ35 codes prefix DOT- (DOT-H1..H14) | Tránh trùng H1-H9 Đ43 |
| 3 | dot-dot-health filter LAW-35 (đúng Đ35 §8.1) | Đ22 generic executor là DOT KHÁC |
| 4 | fn_log_issue spec tại Đ35 §4.1B | Code PG đầy đủ trong luật |
§3. SAI LẦM + BÀI HỌC
| Sai | Bài học |
|---|---|
| Soạn prompt xong mới rà NT | ĐỌC LUẬT TRƯỚC, soạn SAU |
| Đề xuất ghi nợ TD cho hardcode | Hardcode = vi phạm NT2/NT4/NT13 → fix ngay |
| Nhầm Đ22 executor với dot-dot-health | 3 executor khác nhau: Đ22 ALL, Đ35 LAW-35, Đ43 LAW-43 |
| Nhảy vào đăng ký 27 bảng | Fix gốc = sửa vòng lặp, không fix ngọn |
| Quên git commit trong prompt | Đã ghi memory: git BẮT BUỘC cuối mọi prompt |
§4. PHIÊN SAU — A+1→A+7
Vấn đề gốc
Camera có, dây chưa nối, chuông không kêu.
7 bước
| # | Việc | Effort | Chi tiết |
|---|---|---|---|
| A+1 | Deploy fn_log_issue() PG |
Medium | Spec: Đ35 §4.1B. Signature(source,severity,category,summary,entity_code). SECURITY DEFINER, workflow_admin. |
| A+2 | Thay STUB trong 2 script | Low | dot-dot-health + verify.sh: hàm log_issue() → gọi PG fn_log_issue() |
| A+3 | Build generic executor Đ22 §4.3 | High | DOT mới. Query ALL is_active=true. Dispatch 3 types. Pattern verify.sh. |
| A+4 | Wire detect_and_fix | Medium | Đọc auto_fix_action. HC-TRIGGER: Appendix A2 PL/pgSQL. Guard: autofix_enabled. |
| A+5 | Wire re-check | Low | Sau fix → chạy lại detect → confirm |
| A+6 | Cron + register | Low | Đăng ký dot_tools + crontab |
| A+7 | Verify e2e | Medium | Detect→system_issues→auto-fix→re-check. 41 findings tự xuất hiện. |
Dependency
A+1 → A+2 → A+3 → A+4 → A+5 → A+6 → A+7
Tài liệu ĐỌC TRƯỚC
| Tài liệu | Path KB |
|---|---|
| Đ35 v5.2 (fn_log_issue spec) | knowledge/dev/laws/dieu35-dot-governance-law.md rev 9 |
| Đ22 v1.2 (generic executor + HC-TRIGGER) | knowledge/dev/laws/law-22-self-healing.md rev 5 |
| Phụ lục Fix24 (Appendix A2 auto-attach code) | knowledge/current-state/reports/phu-luc-trien-khai-du-thao-ssot-hc-fix24.md |
| Báo cáo điều tra | knowledge/current-state/reports/s178-fix25-self-healing-investigation.md |
| Mẫu executor | VPS /opt/incomex/dot/bin/dot-context-pack-verify.sh |
§5. ROADMAP SAU A+7
A+1→A+7 ← BẮT ĐẦU ĐÂY
↓
A11 (DROP bảng cũ, sau 23/4)
↓
B1→B4 (Phase C backfill 1314 entity)
↓
C1→C2 (test agent lạ + chống phá)
§6. HẠ TẦNG
- DB:
docker exec postgres psql -U directus -d directus - SSH:
contabo, key~/.ssh/contabo_vps - Scripts:
/opt/incomex/dot/bin/ - Git:
cd /opt/incomex && git add -A && git commit+/opt/incomex/dot
§7. NGUYÊN TẮC
- Đọc luật TRƯỚC soạn prompt
- Fix gốc, không fix ngọn
- Git BẮT BUỘC cuối mọi prompt CLI
- 3 executor khác nhau: Đ22 generic ALL, Đ35 LAW-35, Đ43 LAW-43
- Prompt mục tiêu mở: mục tiêu + tiêu chí đo + ràng buộc luật