KB-4BDF

Điều 45 PG-Native Queue & Task Orchestration Law — v1.0 BAN HÀNH (2026-05-26)

12 min read Revision 1
enactment-reportdieu-45v1.0ban-hanhban-hanh-2026-05-26pg-native-queuequeue-lawlaw-enacteduser-approvedcouncil-approvedno-substance-change

Điều 45 — PG-Native Queue & Task Orchestration Law — v1.0 BAN HÀNH

Enactment date: 2026-05-26 Status: ENACTED (BAN HÀNH chính thức) Law file: knowledge/dev/laws/dieu45-pg-native-queue-and-task-orchestration-law.md (KB revision 21, ~57 kchars) Approver: User (Huyên) 2026-05-26 Council Round 1 (GPT) review: addressed via v0.2 patch (2026-05-26) Council Round 2 (Gemini) review: skipped (optional theo Council policy) Substance change tại enactment: KHÔNG — chỉ chuyển trạng thái DRAFT → ENACTED.


§1. Tóm tắt enactment

Điều 45 chính thức BAN HÀNH lúc 2026-05-26 sau quy trình DRAFT 4 vòng:

Vòng Version Date Hành động
1 v0.1 DRAFT 2026-05-26 Soạn lần đầu — 22 sections căn cứ điều tra survey 2026-05-26 + GPT proposal.
2 v0.2 DRAFT 2026-05-26 GPT Council Round 1 review — patch 5 hạng mục (§6.6 event_vs_job, §6.7 work_state_machine, §11.5 executor_boundary, §13.4 MOT clause, §15.5 silent_gap/heartbeat).
3 v0.2.1 DRAFT 2026-05-26 Cleanup patch — KB metadata sync, council wording an toàn (council_round_1_gpt_patch_applied thay vì _approved), MOT loại khỏi enumeration executor (§11.5 + §13.4 codify MOT.is_executor=false).
4 v1.0 BAN HÀNH 2026-05-26 User approval pass — chuyển trạng thái DRAFT → ENACTED. KHÔNG sửa nội dung.

Mỗi vòng đều có report riêng:

  • v0.1 → v0.2: knowledge/dev/laws/dieu44-trien-khai/v0.6-dieu45-pg-native-queue-law-draft/06-gpt-council-review-patch-v0-2.md
  • v0.2 → v0.2.1: knowledge/dev/laws/dieu44-trien-khai/v0.6-dieu45-pg-native-queue-law-draft/07-v0-2-1-cleanup-patch.md
  • v0.2.1 → v1.0: this report

§2. Mutation footprint tại enactment

Thay đổi Loại Vị trí
Title/version-history line label-only dòng > **Version:** v1.0 BAN HÀNH … + history block
§22 verification block label-only phase_status=ENACTED, version=v1.0, ban_hanh=true, council_approved=true, enactment_approved=true, user_approval_date=2026-05-26, enactment_date=2026-05-26, amendment_process_required_for_future_changes=true
§22 footer keys label-only v1_0_enactment_applied=2026-05-26, enactment_report=…, next_required_pack=DIEU45_POST_ENACTMENT_HOUSEKEEPING_AND_DESIGN_BACKLOG_DISPATCH
Footer line label-only Điều 45 v1.0 BAN HÀNH … BAN HÀNH 2026-05-26 (User approval pass)
KB metadata title metadata-only … — v1.0 BAN HÀNH
KB metadata tags metadata-only thêm enacted, v1.0, ban-hanh, ban-hanh-2026-05-26, council-approved, user-approved, + tag bóc tách invariants (mot-not-executor, work-state-machine, event-vs-job, silent-gap-heartbeat, signal-not-data)

KHÔNG đụng:

  • 22 sections nội dung (§0 → §22) — bytes unchanged ngoài 4 dòng label đã liệt kê.
  • 8 nguyên tắc §0 — nguyên.
  • Vocab §6.1–§6.7 — nguyên.
  • §11.1–§11.5 — nguyên (bao gồm not_executors:[MOT] + 7 executors enumeration).
  • §13.4 mother_of_task_clause — nguyên (MOT.is_executor: false).
  • §14 NVSZ 4-layer guarantee — nguyên.
  • §15.5 silent-gap/heartbeat invariant — nguyên.
  • §16 compatibility matrix — nguyên.
  • §17 14 hard-reject + 3 soft-warn anti-patterns — nguyên.
  • §18–§21 — nguyên.
  • §22 các keys khác — nguyên.

§3. Cross-compatibility re-affirmed tại enactment

Điều 45 v1.0 BAN HÀNH KHÔNG amend luật nào sau đây:

Luật Status Quan hệ với Điều 45
Điều 22 (System Issues) BAN HÀNH Heaviest event consumer (system/issue_opened 131,407 rows)
Điều 28 (Display Rules) BAN HÀNH UI exposure layer L5 thuộc D28 + D35
Điều 29 (Phân loại Collection) BAN HÀNH Birth events đăng ký event_domain='birth_registry'
Điều 30 (Regression Protection) v1.1 BAN HÀNH Vocab amendment future phải qua D30 regression cycle
Điều 31 (System Integrity) v1.2 BAN HÀNH Refusal contract đồng nhất §8.5; watchdog reads §15 healthcheck
Điều 32 (Metadata Governance) Vocab discipline đồng pha
Điều 35 (DOT Governance) v5.2 FINAL BAN HÀNH DOT vừa producer vừa executor; §6.3 ratify run vocab
Điều 36 (Collection Protocol) DRAFT 30% §14 NVSZ 4-layer guarantee nâng D36 design lên mức luật
Điều 37 (Governance Organization) v3.3 BAN HÀNH actor_ref prefix vocab dùng D37
Điều 39 (Knowledge Graph) KG events đăng ký event_domain='kg'
Điều 43 (Context Pack) System milestone events → red_zones
Điều 44 (IU-0 Implementation) v0.1.2 DRAFT DRAFT Queue substrate sinh ra dưới D44 trien-khai; sau enactment Điều 45, ownership queue invariants chuyển sang Điều 45 (không amend D44)

Verdict: clean enactment. Không tạo conflict mới.


§4. Substrate hiện hành tiếp tục hoạt động

Theo §20 transitional clause của Điều 45 v1.0:

Substrate Rows / Status Tiếp tục hoạt động
event_outbox 131,746 rows (top traffic system/issue_opened 131,407) ✅ Không sửa schema
event_read 131,407 rows
event_subscription 3 rows ✅ — comprehensive config thuộc DP6
event_type_registry 31 rows (iu=16/piece=6/staging=5/system=4)
iu_route_dead_letter 0 rows open ✅ — view mở visible per §15.5
iu_route_worker_cursor 1 row (iu_outbound_default) ✅ — last_run 2026-05-22 (gap acknowledged §20.4)
iu_sql_event_route 1 row dry-run ✅ — vocab widening thuộc DP5
iu_auto_instantiate_event_log 33 rows
dot_iu_runtime_lease 0 rows
iu_core.iu_staging_record + iu_staging_payload 7-state lifecycle

PostgreSQL version: 16.13 (Debian) — đủ điều kiện cho Điều 45 v1.0. PG 18 KHÔNG là tiền điều kiện. Extensions live: btree_gist, pgcrypto, plpgsql, postgres_fdw. pg_cron: KHÔNG cài đặt. Worker invocation external (Hermes/Codex/Directus). Quyết định cài/không thuộc DP1. LISTEN/NOTIFY: chỉ kb_vector_sync (fn_kb_notify_vector_sync → pg_vector_listener.py). Không phải SoT cho queue.


§5. 8 nguyên tắc cốt lõi vừa BAN HÀNH (§0 của luật)

  1. PostgreSQL là nguồn sự thật (SoT) duy nhất cho trạng thái hàng đợi.
  2. Hàng đợi mang tín hiệu, KHÔNG mang dữ liệu (payload_ref pattern; body/vector/secret/conversation NEVER trong outbox).
  3. Mọi hạng mục công việc (event/task/job/message/trigger) PHẢI có idempotency, lifecycle, retry, dead-letter, lease, observability cursor.
  4. No-vector-in-transient — ratify cứng D36 NVSZ ở mức luật (4-layer guarantee).
  5. Phân ranh executor: Worker/Agent/DOT/Hermes/Codex/PG_worker/external_worker là người thực thi; hàng đợi không kiêm nhiệm logic xử lý. MOT KHÔNG là executor (§11.5 not_executors + §13.4 is_executor:false).
  6. Compatibility hard: không sửa Điều 30/31/35/36/37/44; cross-reference rõ.
  7. PG 16.13 đủ điều kiện triển khai lần đầu. Nâng cấp PG 18 là macro độc lập.
  8. Substrate hiện hành tiếp tục hoạt động dưới §20 transitional clause.

§6. Invariants mới được codify tại Điều 45 v1.0

§ Invariant Bản chất
§4 Queue carries signal not data Hard CHECK denylist payload key
§6.6 Event vs Job distinction Event = fact_that_happened; Job = work_to_be_done. event_outbox ≠ job queue
§6.7 Work state machine 9 minimum states (queued/leased/in_progress/succeeded/failed/retry_waiting/dead_letter/cancelled/cleaned)
§11.5 Executor boundary 7 executors + MOT trong not_executors; queue PG là SoT; executor không giữ private SoT
§13.4 Mother of Task clause MOT.is_executor=false; emits_job_graph; delegates_execution_to_queue_executors
§14 NVSZ 4-layer guarantee CHECK + sidecar 190+191 + view v_collection_vector_eligibility + structural absence trong iu_vector_sync_point
§15.5 Silent gap heartbeat silent_gap_is_a_health_violation; DLQ phải có view mở; executor must register healthcheck before enable
§17 Anti-patterns 14 hard-reject + 3 soft-warn (kèm A8'/A14' từ §6.6/§6.7)

§7. Post-enactment housekeeping (next required pack)

next_required_pack=DIEU45_POST_ENACTMENT_HOUSEKEEPING_AND_DESIGN_BACKLOG_DISPATCH

Việc cần làm tiếp (KHÔNG bắt buộc ngay, do Council/User schedule):

  1. HK1 — Cập nhật knowledge/dev/architecture/index.md thêm Điều 45 v1.0 BAN HÀNH.
  2. HK2 — Cross-ref banner D36/D44 design docs: "Sau Điều 45 ban hành, ownership queue invariants thuộc Điều 45 §X".
  3. HK3 — Worker silent gap audit (iu_outbound_default 4-day gap from 2026-05-22) per §20.4 transitional + §15.5 invariant.
  4. HK4event_outbox unique index introspection per Q5 survey.
  5. HK5iu_notification_event legacy deprecate per Q7 survey.
  6. MEMORY.md cập nhật v1.0 BAN HÀNH status (replace v0.6-dieu45-pg-native-queue-law-draft parent memory).

Sub-design pack dispatch (chỉ sau khi housekeeping HK1-HK2 xong; thứ tự do Council quyết):

DP Tiêu đề Ưu tiên gợi ý §luật ảnh hưởng
DP1 pg_cron adoption decision P0 §5.4, §9.4
DP2 Job substrate shape decision P0 §1.2.D, §3.1, §6.6, §6.7
DP3 Retry policy concrete + max_attempts + stale_threshold P1 §8.1, §8.2, §15.5
DP4 NOTIFY bridge (event_universal channel) P2 §5.4, §15.4, §15.5, §11.5
DP5 Trigger-IN vocab widening P1 §12.1, §3.2
DP6 Subscription comprehensive config P2 §11.4, §16.1 D37
DP7 event_outbox partitioning P3 §15 risk

Anti-backlog rule (§18.4 + report 05): Mỗi DP phải có prompt rõ, prerequisites verified, GPT review, optional Gemini review, rollback plan, test plan trước khi merge.


§8. Risk register (post-enactment)

Risk Probability Severity Mitigation
Executor mới enable mà chưa đăng ký healthcheck per §15.5 Medium High Gate ban hành substrate qua review checklist; D31 watchdog detect
Producer leak data vào event_outbox payload Low High Hard CHECK denylist tại §4.3 đã active từ Phase 2 PoC
MOT design pack mở mà gắn label _executor Low Medium §13.4 forbidden_labels rõ; Council review reject
Worker silent gap kéo dài quá 3× cadence Medium Medium §15.5 yêu cầu emit system/queue_worker_silent; D43 red_zones visible
Job substrate (DP2) chọn phương án (a) extend event_outbox phá §6.6 Low High DP2 prompt sẽ ràng buộc work_state_machine §6.7 phải có substrate lifecycle riêng

§9. Mutation footprint declaration (enactment)

DIEU45_V1_0_ENACTMENT thực hiện:

  • ✅ 4 patches vào law file (revision 17–20) — chỉ title/§22/footer label changes.
  • ✅ 1 update_document call (revision 21) — title + tags KB metadata refresh sang v1.0 BAN HÀNH.
  • ✅ Upload report this file (knowledge/current-state/reports/dieu45-pg-native-queue-law-v1-0-enacted-2026-05-26.md).
  • ✅ Update 00-summary status sang v1.0 BAN HÀNH (next step).
  • ❌ KHÔNG đụng nội dung 22 sections.
  • ❌ KHÔNG DDL.
  • ❌ KHÔNG DML production.
  • ❌ KHÔNG migration.
  • ❌ KHÔNG install pg_cron.
  • ❌ KHÔNG upgrade PostgreSQL.
  • ❌ KHÔNG đụng event_outbox / Qdrant / production_documents.
  • ❌ KHÔNG đụng START-HERE / mark-cut alias.
  • ❌ KHÔNG dispatch sub-design pack.

Total revision range của law file across full DRAFT→BAN HÀNH cycle: v0.1 (rev 1) → … → v1.0 BAN HÀNH (rev 21).


§10. Authority + Citation

Từ thời điểm này (2026-05-26), Điều 45 v1.0 có hiệu lực và có thể được trích dẫn như luật trong:

  • Sub-design packs (DP1–DP7).
  • Cross-reference banner cho D36/D44 design docs.
  • Anti-pattern enforcement reports.
  • Architecture index.
  • New law drafting (nếu áp dụng).

Trước 2026-05-26, mọi reference tới "Điều 45" là DRAFT, không phải luật. Sau 2026-05-26, Điều 45 v1.0 là luật BAN HÀNH chính thức.


Điều 45 PG-Native Queue & Task Orchestration Law — v1.0 BAN HÀNH 2026-05-26 — User approval pass — Enactment report soạn bởi Claude Opus 4.7 (1M).