KB-1E88

S178 Fix 25 Self-Healing Loop Investigation

7 min read Revision 1
s178fix25d22self-healinginvestigation

S178 Fix 25 — Self-Healing Loop Investigation (Đ22 §1)

Timestamp: 2026-04-21T08:XX:XX UTC Scope: Điều tra CHỈ — không sửa. Trả lời 7 câu về vì sao vòng lặp tự chữa lành không tự phát hiện 41 findings của A10.

TL;DR

Vòng lặp gãy ở bước ② (LIỆT KÊ → system_issues).

  • CẢ 2 executor hiện có (dot-dot-health, dot-context-pack-verify.sh) đều có log_issue()STUB — chỉ log_warn, không INSERT vào system_issues.
  • PG function fn_log_issue KHÔNG tồn tại.
  • Generic HC executor Đ22 §4.3 chưa được viết.
  • Không có logic wire auto_fix_action (bước ③ detect_and_fix), không có re-check (bước ④).

Kết quả: 3 HC mới của A10 (HC-REG/SCHEMA/TRIGGER) dù có thể chạy detect query thành công, cũng sẽ không ghi issue, không auto-fix, không verify — đúng như kỳ vọng vì cơ sở hạ tầng Đ22 mới chỉ có khung.


Câu 1 — Generic HC executor (Đ22 §4.3): CÓ tồn tại không?

KHÔNG.

  • grep -l 'is_active.*true.*system_health_checks' trên /opt/incomex/dot/bin/: chỉ trả về dot-dot-health — nhưng script này filter jurisdiction='NRM-LAW-35-V5P2' (line 420), KHÔNG phải generic.
  • Không script nào query WHERE is_active=true KHÔNG filter jurisdiction.
  • dot_tools registry: không có entry cho generic executor (chưa kiểm tra trực tiếp nhưng không có source file).

Evidence: dot-dot-health:420: WHERE is_active = true AND jurisdiction = '${JURISDICTION}'.

Câu 2 — Cron có chạy không?

Partial.

Executor Cron Log evidence
dot-dot-health 0 3 * * * (daily 3AM UTC) /var/log/incomex/dot-health.log (đang chạy)
dot-context-pack-verify.sh Không có cron N/A
Generic Đ22 §4.3 executor Script không tồn tại → không có cron N/A

Evidence: crontab -l của root — chỉ có dot-dot-health, không thấy verify.sh hay generic.

Câu 3 — fn_log_issue: STUB hay thật?

STUB 100%.

dot-dot-health

# /opt/incomex/dot/bin/dot-dot-health:54-58
log_issue() {
  ...
  log_warn "log_issue STUB: severity=${severity} category=${category} summary=\"${summary}\""
}

dot-context-pack-verify.sh

# /opt/incomex/dot/bin/dot-context-pack-verify.sh:74-79
# Đ22 stub — fn_log_issue sẽ implement khi Đ22 triển khai (TD-S178-31)
log_issue() {
  ...
  log_warn "log_issue STUB: severity=${severity} category=${category} summary=\"${summary}\""
}

Comment tự thừa nhận: TD-S178-31 — Đ22 chưa triển khai.

Vòng lặp gãy ở bước ② (detect xong, warn ra stderr, không ghi DB).

Câu 4 — fn_log_issue PG function có trong DB?

KHÔNG.

SELECT proname FROM pg_proc WHERE proname = 'fn_log_issue';
-- 0 rows

Functions gần giống có trong DB (không phải logger):

  • run_audit_to_issues — unrelated (audit→issues converter)
  • gen_code_system_issues — trigger sinh ISS-NNNN code
  • refresh_registry_count_issues, fn_registry_health, verify_framework_health — các healthcheck PG khác
  • fn_guard_system_issues_insert, fn_gov_validate_health_dot — guards

Không có function tên fn_log_issue (hay tương đương) để script bash gọi.

Bước ② gãy ngay cả khi bash stub được viết lại, vì API PG chưa tồn tại.

Câu 5 — detect_and_fix flow có wired không?

KHÔNG.

grep 'check_kind\|detect_and_fix\|auto_fix_action' trên 2 script → 0 matches.

Schema system_health_checks CÓ cột check_kindauto_fix_action với CHECK constraint ràng buộc. Nhưng:

  • Không executor bash nào đọc 2 cột này.
  • Không có dispatcher để map auto_fix_action='auto_attach_trigger' → shell/SQL action.

Bước ③ (XỬ LÝ) chưa tồn tại.

Câu 6 — Re-check (bước ④) có tồn tại không?

KHÔNG.

grep 're-check\|verify.*after.*fix\|recheck' → 0 matches trong cả 2 executor.

Bước ④ (XÁC NHẬN) chưa tồn tại.

Câu 7 — system_issues nào từ HC executor?

0 rows.

SELECT source, issue_type, severity, count(*) FROM system_issues
WHERE source ILIKE '%health%' OR source ILIKE '%hc%' OR issue_type ILIKE '%hc%'
GROUP BY 1,2,3;
source issue_type severity count
dot-apr-health apr_phantom_applied info 1
dot-collection-health collection_onboarding_gap warning 280

Hai source có "health" đều là executor riêng (dot-apr-health, dot-collection-health), KHÔNG phải Đ22 system_health_checks executor. Chúng tự log thẳng từ SQL/script riêng, không qua system_health_checks registry.

Top 14 source của system_issues (1806 rows): không có dot-dot-health, không có dot-context-pack-verify, không có generic HC executor.

Xác nhận vòng lặp Đ22 §1 chưa bao giờ hoạt động end-to-end.


Sơ đồ vòng lặp — bước nào ✅ / ❌

① NHẬN DIỆN (detect query)              ✅  (SQL trong system_health_checks OK, A10 đã chạy thủ công OK)
   ↓
② LIỆT KÊ (log_issue → system_issues)   ❌  STUB, fn_log_issue không tồn tại
   ↓
③ XỬ LÝ (auto_fix_action dispatch)      ❌  Không có logic wire
   ↓
④ XÁC NHẬN (re-check)                    ❌  Không có
   ↓
⑤ CẢI TIẾN                               ❌  Không đạt được

Chỉ bước ① hoạt động. Bốn bước sau đều là khung rỗng.

Generic Đ22 §4.3 executor status

  • File: không tồn tại
  • Cron: không có
  • Đăng ký dot_tools: không (script chưa viết)
  • Tech debt ticket: TD-S178-31 (đã ghi trong comment của verify.sh)

Khuyến nghị (không thực hiện ở lần này)

  1. Viết PG function fn_log_issue(severity, source, issue_type, entity_type, entity_code, summary, details) → INSERT system_issues.
  2. Thay log_issue STUB trong 2 script hiện có bằng cuộc gọi psql -c "SELECT fn_log_issue(...)".
  3. Viết dot-health-dispatch (generic Đ22 §4.3 executor) query is_active=true không filter jurisdiction, dispatch theo executor_type (builtin/sql/function).
  4. Implement dispatcher cho auto_fix_action (map → shell action).
  5. Thêm bước re-check sau auto-fix.
  6. Add cron cho verify.sh (Đ43 §5.8) và dot-health-dispatch.

Files referenced

  • /opt/incomex/dot/bin/dot-dot-health (line 54-58, 420, 487, 498)
  • /opt/incomex/dot/bin/dot-context-pack-verify.sh (line 11, 74-79, 773-783)
  • Table system_health_checks (schema correct; 3 HC mới A10 đã seeded)
  • Table system_issues (1806 rows, 0 từ Đ22 HC executor)