KB-49C2

P6 — Checker/DOT Design v0.2

21 min read Revision 1
dieu38p6checkerdottext-as-codeofficial

P6 — Checker/DOT Design v0.2 for Đ38 Text as Code

Loại: Checker/DOT design note — Điều 38 Text as Code Phase: P6 (Checker Design), gắn cảm biến cho P5 + P5b schema Trạng thái: OFFICIAL v0.2 — GPT R1 (22) + R2 (12) + FINAL PASS. User PASS. Ngày soạn: 2026-04-26 | Phiên: S181 Agent soạn: Opus 4.6 (Desktop) GPT review: R1 PASS có điều kiện (22). R2 PASS có điều kiện nhẹ (12). Final PASS. Inputs: P5 v0.2, P5b v0.2, C1–C3, C1A, LSL-01, L2, L4, L5, Đ24, Đ32, Đ33, Đ35


1. Mục tiêu

P6 thiết kế checker/DOT cho P5 + P5b schema. Chưa phải code/trigger/function/cron. Mọi implementation qua gateway/migration approval (Đ33).

Registry/severity/schedule = config/governance data (NT4), seed = initial, không hardcode.

P6 chỉ thiết kế checker side (Cấp A — phát hiện). Healer (Cấp B — sửa chữa) = DOT riêng, thiết kế khi implementation, theo paired DOT principle Đ35. P6 KHÔNG chốt tên/cấp DOT cụ thể, chỉ áp dụng paired governance principle. P6 KHÔNG tự heal.


2. Phạm vi / Không làm

Trong: Checker design cho birth gate, pre-enact gate, daily DOT, drift, projection, label, APR, PG safety. Severity model, registry, scheduling, phase 1/2, coverage matrix.

Không: Code/SQL/trigger/cron thật. Sửa P5/P5b/C1–C3/LSL/L1–L5. Qdrant/KG implementation. Healer implementation.


3. Checker taxonomy + Severity model

Taxonomy: BIRTH (create/update/transition) | PRE-ENACT (transition→enacted) | INVARIANT (daily DOT) | DRIFT (daily, only-if-projection-enabled) | PROJECTION (daily, only-if-projection-enabled).

Severity: BLOCK (reject at gate) | ERROR (critical existing violation, escalate) | WARN (issue, log+nhắc) | INFO (monitoring).

SYSTEM AUTO = writer action type (compute hash, set defaults), NOT severity. Not counted as checker.

Self-healing (C2§9): Checker PHÁT HIỆN. Healer DOT riêng sửa draft objects + derived fields. Enacted: ESCALATE, KHÔNG auto-fix.

Default checker contract: Khi bảng ghi tắt, default = action: log+escalate (ERROR) hoặc log+nhắc (WARN); input: entity state from PG; output: issue list (checker_id, entity_ids, details JSONB).


4. P5 Checker set — Unit / Publication / Metadata

4.1 Birth gate

ID Mục tiêu Law Applies to Event Sev Action Input Output Ph
BG-LU-01 Address unique INV-ADDRESS-IMMUT logical_unit create BLOCK Reject canonical_address pass/fail 1
BG-LU-02 Doc_code valid P5§12, OD-P5-04 logical_unit create BLOCK Reject doc_code pass/fail 1
BG-LU-03 Parent valid+same doc C1 I5 logical_unit create BLOCK Reject parent_id,doc_code pass/fail 1
BG-LU-04 Section_type active P5 DP-4 logical_unit create BLOCK Reject section_type FK pass/fail 1
BG-LU-05 Owner present C2§6.4 logical_unit create BLOCK Reject owner pass/fail 1
BG-LU-06 Sort_order valid P5§12 logical_unit create BLOCK Reject sort_order pass/fail 1
BG-UV-01 Title present C2§6.5 unit_version create BLOCK Reject title pass/fail 1
BG-UV-02 Description C2§6.5 unit_version create BLOCK/WARN Per config desc,section_type pass/fail/skip 1
BG-UV-03 Body valid C2§6.5 unit_version create WARN Per config body,section_type pass/warn/skip 1
BG-UV-04 Required profile C2§5.3 unit_version create BLOCK/WARN Validate JSON Schema content_profile pass/fail 1
BG-UV-05 Length flag C1A§8.3 unit_version create WARN Set flag, no block draft word count length_flag 1
BG-UV-06 Provenance valid INV-PROVENANCE unit_version create WARN Verify FAC-PROV provenance pass/warn 1

4.2 Pre-enactment gate

ID Mục tiêu Law Event Sev Action Input Output Ph
PE-PUB-01 All members enacted UV INV-ENACTED-PUB pub→enacted BLOCK Reject pm.uv.lifecycle pass/fail 1
PE-PUB-02 All members active LU INV-ENACTED-PUB pub→enacted BLOCK Reject pm.lu.lifecycle pass/fail 1
PE-PUB-03 PM consistency INV-PM-CONSISTENCY pub→enacted BLOCK Reject FK chain pass/fail 1
PE-PUB-04 Length decisions done CI-7 pub→enacted BLOCK Reject hard_limit UV pass/fail 1
PE-PUB-05 Change-set enacted C1§5.4 pub→enacted BLOCK Reject cs.lifecycle pass/fail 1
PE-PUB-06 APR approved (readiness only, does NOT approve) Đ32 pub→enacted BLOCK Reject cs.apr_ref pass/fail 1

4.3 Daily DOT invariant

ID Mục tiêu Invariant Sev Ph Dep
DOT-LU-01 Address immutable INV-ADDRESS-IMMUT ERROR 1 audit log or history
DOT-LU-02 Parent same doc C1 I5 ERROR 1
DOT-LU-03 Single parent INV-SINGLE-PARENT ERROR 1
DOT-LU-04 LU lifecycle: active+0enacted≠draft_only, draft_only+enacted=ERROR INV-RETIRE ERROR 1
DOT-UV-01 Enacted immutable INV-ENACTED-IMMUT ERROR 1 content_hash history or audit
DOT-UV-02 Duplicate enacted C1 I8 ERROR 1
DOT-UV-03 Retired UV + non-retired LU INV-RETIRE ERROR 1
DOT-UV-04 Content hash recompute P5§5.2 WARN 2
DOT-UV-05 Provenance vocab INV-PROVENANCE WARN 2
DOT-UV-06 Length flag recompute C1A§8 WARN 2
DOT-PUB-01 Enacted pub member lock P5§9.1 ERROR 1 audit log or trigger
DOT-PUB-02 Draft lọt enacted pub INV-ENACTED-PUB ERROR 1
DOT-PUB-03 PM consistency ongoing INV-PM-CONSISTENCY ERROR 1
DOT-PUB-04 Section_type deprecated P5 DP-4 WARN 2
DOT-CS-01 Snapshot immutable C1 I9 ERROR 1 audit log
DOT-CS-02 Orphan draft versions C1§7.7 INFO 2

4.4 Cross-cutting: Label / APR / PG

ID Mục tiêu Sev Ph Action Input Output Dep/Notes
DOT-LBL-01 section_type = structural SoT, verify no unregistered sync to entity_labels WARN 2 Log section_type_vocab, entity_labels sync issues If approved sync rule → check valid
DOT-LBL-02 No parallel label registry (scope: known classification sources in checker scope list) ERROR 1 Escalate classification source list violations Dep: only-if classification source list exists. If no source list → phase 2 candidate.
DOT-LBL-03 Label doc=X vs pub membership advisory INFO 2 Log entity_labels, pub_member mismatches Informational
DOT-LBL-04 component_type = structural SoT, verify no unregistered sync WARN 2 Log comp_type_vocab, entity_labels sync issues Same principle as DOT-LBL-01
DOT-LBL-05 Component entity_labels mapping exists (OD-P5b-07 deferred) INFO 2 Log component.code, entity_labels unmapped components Advisory until mapping format decided
DOT-APR-01 CS submitted has apr_ref WARN 2 Log cs.apr_ref missing refs Advisory
DOT-APR-02 Structural change has CS+APR ERROR 1 Escalate re-parent/split/merge changes, cs.apr_ref violations LSL-01§10.3
DOT-APR-03 Component create_new has approval_ref ERROR 1 Escalate reuse_decision.approval_ref missing approval L2§4.1
DOT-PG-01 No direct DDL outside migration ERROR 2 Escalate gateway audit log unauthorized DDL Status: inactive/candidate until gateway audit source exists. Cannot run without approved source.
DOT-PG-02 component_pg_ref read-only WARN 2 Log pg_ref vs pg_catalog duplicated metadata Via approved read-only path per Đ33

5. P5b Checker set — Component / BOM

5.1 Birth gate

ID Mục tiêu Law Applies to Event Sev Action Input Output Ph
BG-COMP-01 Code unique INV-COMP-NEQ-UNIT component create BLOCK Reject code pass/fail 1
BG-COMP-02 Name+spec present C3§14.1 component create BLOCK Reject name,spec pass/fail 1
BG-COMP-03 Type FK active C3§6.5 component create BLOCK Reject comp_type pass/fail 1
BG-COMP-04 Owner present C2§6.6 component create BLOCK Reject owner pass/fail 1
BG-COMP-05 Desc per config C3§14.1 component create BLOCK/WARN Per config desc pass/fail/skip 1
BG-COMP-06 Interface per config C3§14.1 component create BLOCK/WARN Per config interface pass/fail/skip 1
BG-COMP-07 Variant base valid INV-VARIANT-BASE component(var) create BLOCK Reject base_comp_id pass/fail 1
BG-COMP-08 Reuse decision (existence/authority only, NOT arch quality per L4§5.3) INV-REUSE-FIRST component(④/var) create BLOCK Reject reuse_dec_id pass/fail 1
BG-COMP-09 Approval_ref for ③④ P5b§6.4 component(③④) create BLOCK Reject approval_ref pass/fail 1
BG-CV-01 Component exists P5b§6.2 comp_version create BLOCK Reject comp_id pass/fail 1
BG-CV-02 Spec+changelog C3§14.2 comp_version create BLOCK Reject spec,changelog pass/fail 1
BG-BOM-01 Publication exists P5b§6.3 bom_entry create BLOCK Reject pub_id pass/fail 1
BG-BOM-02 Comp+version exist P5b§6.3 bom_entry create BLOCK Reject comp_id,cv_id pass/fail 1
BG-BOM-03 BOM consistency INV-BOM-CONSISTENCY bom_entry create BLOCK Reject FK chain pass/fail 1
BG-BOM-04 Comp status valid P5b§8.2 bom_entry create BLOCK/WARN Check lifecycle+gov status pass/fail 1
BG-BOM-05 Usage_type active P5b§6.3 bom_entry create BLOCK Reject usage_type pass/fail 1
BG-BOM-06 BOM uniqueness P5b DP-B2 bom_entry create BLOCK Reject unique key pass/fail 1
BG-BOM-07 Pub not enacted INV-BOM-ENACTED-LOCK bom_entry create/update/delete BLOCK Reject pub.lifecycle pass/fail 1

5.2 Pre-enactment gate (BOM)

ID Mục tiêu Law Event Sev Action Input Output Ph
PE-BOM-01 All CV active P5b§8.2 pub→enacted BLOCK Reject bom.cv.lifecycle pass/fail 1
PE-BOM-02 All comp active P5b§8.2 pub→enacted BLOCK Reject bom.comp.lifecycle pass/fail 1
PE-BOM-03 Governance allows P5b§8.2 pub→enacted BLOCK Reject comp.gov_status pass/fail 1
PE-BOM-04 BOM consistency INV-BOM-CONSISTENCY pub→enacted BLOCK Reject FK chain pass/fail 1
PE-BOM-05 Compatibility enforced P5b§11 pub→enacted BLOCK Reject compat rules+BOM violations 1
PE-BOM-06 Compatibility advisory P5b§11 pub→enacted WARN Log compat rules+BOM warnings 1

5.3 Daily DOT invariant

ID Mục tiêu Invariant Sev Ph Dep
DOT-COMP-01 Max 1 active CV INV-COMP-SINGLE-ACTIVE ERROR 1
DOT-COMP-02 Retired+active version INV-COMP-RETIRED-NO-ACTIVE ERROR 1
DOT-COMP-03 Lifecycle vs governance INV-LIFECYCLE-GOV ERROR 1
DOT-COMP-04 Variant base ongoing INV-VARIANT-BASE ERROR 1
DOT-COMP-05 Reuse decision complete INV-REUSE-FIRST ERROR 1
DOT-COMP-06 target_comp_id rules P5b§6.4 WARN 2
DOT-COMP-07 Comp_type deprecated P5b§6.7 WARN 2
DOT-COMP-08 Gov_status deprecated P5b§6.8 WARN 2
DOT-COMP-09 Code format OD-P5b-02 WARN 2
DOT-COMP-10 pg_ref validity INV-CATALOG-NEQ-PG WARN 2 Approved read path Đ33
DOT-COMP-11 Content hash P5b§6.2 WARN 2
DOT-BOM-01 Version mismatch P5b§8.3 WARN 2
DOT-BOM-02 Retired/forbidden in BOM P5b§8.2 ERROR 1
DOT-BOM-03 Enacted BOM lock INV-BOM-ENACTED-LOCK ERROR 1 Audit log or trigger
DOT-BOM-04 BOM consistency ongoing INV-BOM-CONSISTENCY ERROR 1
DOT-BOM-05 Compatibility enforced P5b§11 ERROR 1
DOT-BOM-06 Compatibility advisory P5b§11 WARN 2
DOT-BOM-07 Component orphan C3§17 INFO 2
DOT-CSX-01 FK exclusivity INV-CSM-SINGLE-FK ERROR 1
DOT-CSX-02 Subject/action vocab P5b§4.1 WARN 2

6. Vector / KG projection checkers

Only-if-projection-enabled. Nếu Qdrant/KG chưa implemented, tất cả = defer/skip.

ID Mục tiêu Invariant Sev Ph Condition Action Input Output
DOT-VEC-01 Chunk in 1 UV INV-CHUNK-SINGLE-UV ERROR 1* projection on Escalate chunk manifest violations
DOT-VEC-02 Chunk in 1 CV INV-COMP-CHUNK-CV ERROR 1* projection on Escalate chunk manifest violations
DOT-VEC-03 Sync status drift P5§10.2 WARN 2 projection on Log sync_status stale list
DOT-VEC-04 Payload vs PG INV-PG-SOT-VECTOR WARN 2 projection on Log Qdrant vs PG mismatches
DOT-VEC-05 Chunk count P5§10.5 WARN 2 projection on Log count vs manifest mismatches
DOT-VEC-06 Stale vectors P5§10.2 WARN 2 projection on Log superseded/retired stale list
DOT-VEC-07 KG projection-only INV-KG-PROJ-ONLY ERROR 1* KG on Escalate KG write audit auth violations

*Phase 1 if enabled at pilot. Defer if not.


7. Phase 2: Golden path checkers

ID Mục tiêu Invariant Sev Event Action Input Output Dep
DOT-GP-01 Active GP version lock INV-GP-VERSION-LOCK ERROR Daily Escalate gp_member.cv_id NULL + gp active unlocked members GP tables exist
DOT-GP-02 GP adherence C3§17 WARN Daily Log pub BOM vs GP required missing components GP tables exist
DOT-GP-03 GP version mismatch C3§17 WARN Daily Log gp_member.cv vs latest active outdated refs GP tables exist

8. Coverage matrix

8.1 P5 invariants (15) → checkers

Invariant Checker(s) Type
INV-UNIT-SOT Architectural (2 tables) No runtime checker
INV-ENACTED-IMMUT DOT-UV-01 Active
INV-ADDRESS-IMMUT BG-LU-01, DOT-LU-01 Active
INV-PUB-NO-INLINE Architectural (pub_member design) No runtime checker
INV-LABEL-NEQ-MEMBER Architectural (separate tables) No runtime checker
INV-ENACTED-PUB PE-PUB-01/02, DOT-PUB-02 Active
INV-CHUNK-SINGLE-UV DOT-VEC-01 Conditional (projection)
INV-NO-PARALLEL-REG DOT-LBL-02 Active (conditional dep)
INV-SECTION-NOT-LABEL DOT-LBL-01 Active
INV-SINGLE-PARENT DOT-LU-03 Active
INV-BIRTH-GATE All BG-* Active
INV-PG-SOT-VECTOR DOT-VEC-04 Conditional (projection)
INV-RETIRE DOT-LU-04, DOT-UV-03 Active
INV-PM-CONSISTENCY PE-PUB-03, DOT-PUB-03 Active
INV-PROVENANCE BG-UV-06, DOT-UV-05 Active

15/15 covered. 3 architectural + 10 active + 2 conditional.

8.2 P5b invariants (19) → checkers

Invariant Checker(s) Type
INV-COMP-NEQ-UNIT BG-COMP-01 Active
INV-CATALOG-NEQ-PG DOT-COMP-10, DOT-PG-02 Active
INV-BOM-NEQ-MEMBER Architectural No runtime
INV-BOM-NEQ-REF Architectural No runtime
INV-REUSE-FIRST BG-COMP-08/09, DOT-COMP-05 Active
INV-COMP-NO-AUTH Governance/policy No runtime
INV-VARIANT-BASE BG-COMP-07, DOT-COMP-04 Active
INV-COMP-NO-TREE Architectural No runtime
INV-BOM-ENACTED-LOCK BG-BOM-07, DOT-BOM-03 Active
INV-GOLDEN-PG Architectural (phase 2) No runtime
INV-COMP-LABEL-D24 DOT-LBL-02, DOT-LBL-05 Active
INV-COMP-SINGLE-ACTIVE DOT-COMP-01 Active
INV-COMP-RETIRED-NO-ACTIVE DOT-COMP-02 Active
INV-LIFECYCLE-GOV DOT-COMP-03 Active
INV-KG-PROJ-ONLY DOT-VEC-07 Conditional (KG)
INV-BOM-CONSISTENCY BG-BOM-03, PE-BOM-04, DOT-BOM-04 Active
INV-COMP-CHUNK-CV DOT-VEC-02 Conditional (projection)
INV-GP-VERSION-LOCK DOT-GP-01 Phase 2
INV-CSM-SINGLE-FK DOT-CSX-01 Active

19/19 covered. 5 architectural + 11 active + 2 conditional + 1 phase 2.


9. Checker registry + DOT scheduling

Registry fields (concept): checker_id, name, invariant_ref, law_ref, applies_to, trigger_event, severity, phase, enabled (config NT4), dependencies, last_run, last_result JSONB.

Output storage: system_issues nếu tồn tại/xác nhận; hoặc checker_results candidate (P7 decision). Không chốt trước verify.

Naming: {TYPE}-{DOMAIN}-{SEQ} (BG/PE/DOT + LU/UV/PUB/CS/COMP/CV/BOM/CSX/LBL/APR/VEC/PG/GP + 01–99).

Schedule tiers: Birth gate = event-driven. Pre-enact = event-driven. Daily critical = 1x/day ERROR. Daily standard = 1x/day WARN. Weekly = 1x/week INFO. Implementation options (PG-native, agent cron, etc.) = P7 decision, not P6.


10. Checker I/O contract

Input: Target scope (delta default, full scan weekly critical), config (severity, enforcement mode), reference data (vocab, rules).

Output per run: checker_id, run_at, result, affected_entities, details JSONB, escalation_list.

Self-healing: Checker DETECTS. Healer DOT (paired Đ35) FIXES draft + derived. Enacted: ESCALATE. P6 không thiết kế healer.


11. Phase 1 minimum

Chốt: Birth gate + pre-enact = bắt buộc trước P7 pilot. Daily ERROR = minimum smoke set trước pilot start, full ERROR rollout trong pilot.

Category Candidate count Checkers
Birth gate ~30 BG-LU-01→06, BG-UV-01→06, BG-COMP-01→09, BG-CV-01→02, BG-BOM-01→07
Pre-enactment ~12 PE-PUB-01→06, PE-BOM-01→06
Daily ERROR ~25 DOT-LU-01→04, DOT-UV-01→03, DOT-PUB-01→03, DOT-CS-01, DOT-LBL-02*, DOT-APR-02→03, DOT-COMP-01→05, DOT-BOM-02→05, DOT-CSX-01
Vector (if enabled) ~3 DOT-VEC-01, 02, 07

*DOT-LBL-02: phase 1 only-if classification source list exists. If no source list → phase 2 candidate.

Phase 1 total: ~67 candidate checkers. System-auto writer logic NOT counted.


12. Phase 2

Deferred WARN/INFO: DOT-UV-04→06, DOT-PUB-04, DOT-CS-02, DOT-COMP-06→11, DOT-BOM-01/06/07, DOT-CSX-02, DOT-LBL-01/03/04/05, DOT-APR-01, DOT-PG-01(inactive)/02, DOT-VEC-03→06.

Golden path: DOT-GP-01 (ERROR), DOT-GP-02/03 (WARN).

Future: Version-specific compatibility, non-pub assembly BOM, cross-doc change-set.


13. Open decisions

Code Câu hỏi Phase
OD-P6-01 Output: system_issues or checker_results? P7
OD-P6-02 Delta vs full scan? P7
OD-P6-03 Birth gate implementation (PG-native vs app)? P7 option. P7
OD-P6-04 DOT scheduling implementation? P7 option. P7
OD-P6-05 Healer DOT design (paired Đ35)? Post-P6
OD-P6-06 Checker registry storage? P7

14. Constitutional check

Law Verdict Notes
NT1/NT13 PASS PG SoT. Drift: PG wins. Projection conditional.
NT2 PASS Machine-enforceable. BLOCK = máy chặn.
NT4 PASS Registry/severity/schedule = config.
NT8 PASS BOM/compat/reuse checkers.
NT11 PASS pg_ref read-only via approved path.
Đ24 PASS section_type/comp_type = structural SoT. No parallel registry (conditional dep).
Đ32 PASS APR readiness only.
Đ33 PASS Design only. pg_catalog via approved path. DOT-PG-01 inactive until source.
Đ35 PASS Paired principle. Checker only. Healer separate. No specific DOT names.
P5/P5b PASS Bám invariants. Registry/schedule = operational governance, not content invariant.

15. PASS criteria

# Criterion Status
1 15/15 P5 invariants covered ✅ §8.1
2 19/19 P5b invariants covered ✅ §8.2
3 Taxonomy + severity rõ ✅ §3
4 Full + default checker contract ✅ §4–7
5 No duplicate IDs
6 Checker only, healer separate (Đ35) ✅ §1
7 Phase 1/2 candidate counts + rõ ✅ §11–12
8 Vector/KG conditional ✅ §6
9 Dependencies noted
10 Birth gate per L4 (existence, not arch quality)
11 APR = readiness only
12 Constitutional PASS ✅ §14
13 No code/SQL/trigger
14 No sửa P5/P5b
15 GPT + User

P6 có sửa P5/P5b không? KHÔNG.

Block P7? Birth (~30) + pre-enact (~12) bắt buộc. Daily ERROR smoke set (~25) trước pilot.

Defer? WARN/INFO (~30+), golden path (3), vector/KG nếu chưa enabled.


P6 v0.2 | OFFICIAL | S181 | 2026-04-26 | Opus 4.6 GPT: R1(22) + R2(12) + FINAL PASS | User: PASS