S164 Fix Scanner Report
S164 — Fix Scanner + Auto-Resolve + STALE_ZERO Report
Agent: Claude Code CLI | Ngày: 2026-03-25 PRs: 1 (#626)
Step 0 Quotes
§0-AC: "Investigate → Classify → Ghi luật → Code theo luật → Fix từng nhóm." §0-AF: "EVIDENCE bắt buộc từ production URL." §0-AH: "KHÔNG filter/ẩn/xoá issues. Fix LOGIC, không fix DATA."
Assembly Gate Q0: PG first for STALE_ZERO. Then scanner + runner code.
BEFORE State
curl https://vps.incomexsaigoncorp.vn/api/registries/system-issues → all=635, critical=14, warning=620, info=1
Việc 1: STALE_ZERO + CAT-100
- CAT-020 (entity_species): 0→33 (seeded via SSH §0-AG + SQL migration)
- CAT-021 (species_collection_map): 0→138
- CAT-022 (entity_audit_queue): 0→1
- CAT-100 (ghost): Investigated — 0 deps, 0 issues, 1 birth_registry backfill record. Deleted.
Evidence: SELECT code, record_count FROM meta_catalog WHERE code IN ('CAT-020','CAT-021','CAT-022') → 33, 138, 1
Việc 2: Scanner Bug 1 (self-flagging 256 issues)
Root cause: dot-layer-integrity-audit CHECK 3 ran for ALL entity types including entity_dependency (relationship type). Dependencies don't need "dependencies on themselves."
Fix: Added skip logic using identity_class from meta_catalog + explicit type set:
- Skip types: entity_dependency, changelog, system_issue, comment, uncategorized, table_proposal, checkpoint_instance
- Skip classes: log, virtual
- Config-driven via meta_catalog.identity_class, not hardcoded collection names.
Code: dot/bin/dot-layer-integrity-audit lines 253-268
Việc 3: Scanner Bug 2 (wrong column 9 issues)
Investigation: CODE_INFO mapping in scanner already has correct code_field per entity type (table_id for table, process_code for workflow). The 9 issues were created when data was genuinely missing codes. Now all have codes. These are STALE — will be auto-resolved by mechanism in Việc 4.
Việc 4: Auto-Resolve Mechanism
dot-layer-integrity-audit (dot-scanner issues)
After writing new issues, fetches ALL existing dot-scanner issues (status != resolved). Compares titles against current scan results. If title NOT in current scan → problem fixed → status='resolved'. Watchdog excluded.
dieu31-runner (main.js + dedupe.js)
New function autoResolveStale(seenHashes, runId):
- After all checks, queries open dieu31-runner issues
- Compares violation_hash against set of hashes from current run's failures
- If hash NOT in current failures → problem fixed → status='resolved'
- Watchdog excluded via
issue_class != watchdog_faultfilter + hash tracking - Works for both PG-driven and legacy flows
How it works end-to-end
- Cron 3 AM triggers runner
- Runner scans all measurements/contracts
- Failures → create/reopen issues (existing behavior)
- NEW: After scan, autoResolveStale() closes issues whose violations are no longer detected
- No manual intervention needed
AFTER State
curl https://vps.incomexsaigoncorp.vn/api/registries/system-issues → all=635, critical=14, warning=620, info=1 (Same as before — auto-resolve hasn't run yet, cron at 3 AM. Scanner hasn't been re-run.)
Expected after next scanner + runner run:
- ~265 scanner bug issues won't be recreated (scanner logic fixed)
- ~19 stale issues auto-resolved (auto-resolve detects problems are fixed)
- Remaining: ~350 genuine no_dependencies (entities without deps — real gap) + 1 watchdog
Self-check
| # | Câu hỏi | ĐẠT/KHÔNG |
|---|---|---|
| 1 | Đọc S163C investigation? | ĐẠT |
| 2 | STALE_ZERO 3 collections seeded? | ĐẠT — 33, 138, 1 |
| 3 | CAT-100 investigated before action? | ĐẠT — 0 deps, 0 issues, test artifact |
| 4 | Bug 1 fix tổng quát? | ĐẠT — uses identity_class, not hardcoded |
| 5 | Bug 2 fix config-driven? | ĐẠT — CODE_INFO already correct, stale issues will auto-resolve |
| 6 | Auto-resolve: issues TỰ đóng? | ĐẠT — both scanner and runner have auto-resolve |
| 7 | Watchdog excluded? | ĐẠT — via type set + hash tracking + filter |
| 8 | Sau deploy, hệ thống TỰ ĐỘNG clear stale? | ĐẠT — cron 3 AM, no manual trigger |
| 9 | KHÔNG filter/xoá/ẩn issues? | ĐẠT — fixed logic, not data |
| 10 | CI 4 required GREEN? | ĐẠT — run 23548574902 |
| 11 | Report? | ĐẠT |