KB-7EF1

GPT Review — 23-P3D1 Execution PASS and P3D2 Directive

10 min read Revision 1
gpt-reviewpack-23p3d1-passp3d2-directivenotificationtriggers

GPT Review — 23-P3D1 Execution PASS and P3D2 Directive

Date: 2026-05-08
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Reviewed: knowledge/dev/laws/dieu44-trien-khai/reports/23-p3d1-notification-schema-functions-report.md

Verdict

P3D1 PASS confirmed. No supplemental Agent action needed for P3D1.

Agent executed correctly. Opus review is accurate.

Accepted evidence

  • phase_status=PASS.
  • 16/16 test groups PASS.
  • ddl=OK, fn=OK, test_fail=0.
  • manual_events_cleanup=PASS.
  • p3d2_readiness=READY.
  • p23_unchanged=true, protected Pack 23 function count 10→10.
  • iu_notification_event created.
  • iu_notification_read created.
  • Named CHECK/FK constraints verified.
  • fk_notif_read_event ON DELETE CASCADE verified.
  • Six indexes verified, including partial unique uq_notif_event_type_ref.
  • fn_iu_unread(text,text,boolean,integer) created.
  • fn_iu_mark_read(uuid[],text) created.
  • Security verified: owner directus, SECURITY DEFINER, search_path pinned, PUBLIC revoked, directus execute.
  • Empty inbox behavior passed.
  • Manual event tests passed: stream filter, self-exclude/include-self, limit, mark_read duplicate/idempotency/unknown handling.
  • No trg%iu_notif% triggers created.
  • P3D1 functions do not write IU/UV.
  • Manual fake notification rows cleaned on PASS.
  • Pilot IU/draft retained for P3D2 reuse.

Notes

The PILOT-ONLY birth warnings for test/p3d1/pilot-* are expected and non-blocking. They do not affect P3D1 outcome.

The retained pilot artifacts are useful for P3D2:

  • test_addr=test/p3d1/pilot-20260508-005109
  • test_unit_id=60c0017d-4d5d-4003-a403-76e85f869557
  • test_draft_id=40381e69-12c1-42b0-965d-ce68ca7c11a8

Current state

P3D1 has installed the durable notification scaffold and read API, but notification events are not yet automatically produced. P3D2 must add triggers and event-generation tests.

Directive to Opus — create P3D2 prompt, do not dispatch

Create execution prompt:

knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3d2-notification-triggers-prompt.md

Report path:

knowledge/dev/laws/dieu44-trien-khai/reports/23-p3d2-notification-triggers-report.md

P3D2 scope

Create notification trigger functions and triggers only:

  1. Comment notification:

    • trigger function e.g. fn_iu_notif_comment();
    • trigger trg_aa_iu_notif_comment on unit_edit_comment AFTER INSERT;
    • emits comment_added / stream comment;
    • suppress system/apply comments.
  2. Draft notification:

    • trigger function e.g. fn_iu_notif_draft();
    • trigger trg_aa_iu_notif_draft on unit_edit_draft AFTER INSERT;
    • emits draft_created / stream review;
    • only when NEW.draft_status='open'.
  3. Version/apply notification:

    • trigger function e.g. fn_iu_notif_version();
    • trigger trg_aa_iu_notif_version on unit_version AFTER INSERT;
    • emits version_applied / stream update;
    • only when NEW.version_seq > 1.

Important design constraints

  • Do not modify P3D1 tables/functions.
  • Do not modify Pack 23 functions.
  • Do not modify gateway/birth triggers.
  • No LISTEN/NOTIFY in P3D2.
  • No external queue.
  • No retention/archival.
  • No global read flag.
  • Use PG durable table iu_notification_event as source of truth.

Trigger implementation guidance

  • Use AFTER INSERT triggers.
  • Use deterministic trigger names:
    • trg_aa_iu_notif_comment
    • trg_aa_iu_notif_draft
    • trg_aa_iu_notif_version
  • Use deterministic trigger function names, e.g.:
    • fn_iu_notif_comment()
    • fn_iu_notif_draft()
    • fn_iu_notif_version()
  • Trigger insert should use lightweight refs only. Do not include body text in payload.
  • Use ON CONFLICT DO NOTHING to rely on partial unique index (event_type, ref_id) for idempotency.
  • Include source values:
    • trg_aa_iu_notif_comment
    • trg_aa_iu_notif_draft
    • trg_aa_iu_notif_version
  • Payload should include lightweight refs such as:
    • unit_id
    • address
    • comment_id / draft_id / version_id
    • actor_ref

Runtime schema inspection required

Before writing trigger bodies, inspect actual columns for:

  • unit_edit_comment
  • unit_edit_draft
  • unit_version
  • information_unit

Do not assume column names blindly.

Expected likely mappings from current packs:

  • unit_edit_comment.unit_id
  • unit_edit_comment.author_ref or equivalent actor field
  • unit_edit_comment.comment_kind or equivalent kind field
  • unit_edit_draft.unit_id
  • unit_edit_draft.created_by
  • unit_edit_draft.draft_status
  • unit_version.unit_id
  • unit_version.version_seq
  • information_unit.id
  • information_unit.canonical_address

If actual column differs, adapt based on runtime inspection and report the mapping.

System comment suppression

For comment trigger, suppress system/apply comments.

Preferred logic:

  • if comment_kind='system' or author_type='system', do not emit comment_added.
  • if runtime uses different fields/values, inspect and adapt.

Reason: apply already emits version_applied; system comments should remain audit trail but not duplicate inbox noise.

Preflight STOP unless

  • P3D1 tables exist.
  • P3D1 functions exist with exact signatures.
  • P3D1 protected indexes/constraints exist.
  • Pack 23 protected function count = 10 and hashes captured.
  • Existing notification trigger/function names do not already exist, unless idempotent verification path is explicitly designed.
  • Source tables exist.
  • Required source columns are discovered.
  • Policy is still require_review.
  • Owner/grantee pattern discovered.

Tests required

  1. Trigger functions created with expected names/signatures.
  2. Triggers created on the correct source tables with expected names.
  3. No Pack 23 function hash changes.
  4. P3D1 function hashes unchanged.
  5. Comment event test:
    • create a normal/free-flow comment via fn_iu_comment or exact lower-level function;
    • verify exactly one comment_added event created;
    • verify event_stream='comment', source='trg_aa_iu_notif_comment', correct unit/address/ref/actor.
  6. System comment suppression test:
    • cause or insert a system/apply comment if safe, or use reviewed direct insert only if function path unavailable;
    • verify no comment_added event for system comment.
  7. Draft event test:
    • create draft via fn_iu_save(..., mode='draft');
    • verify exactly one draft_created event created;
    • verify event_stream='review' and actionable inbox shows it for another actor.
  8. Version/apply event test:
    • apply that draft via fn_iu_apply_edit_draft;
    • verify exactly one version_applied event created;
    • verify version_seq > 1.
  9. Birth exclusion test:
    • create a new IU via fn_iu_save;
    • verify no version_applied event for version_seq=1.
  10. Actionable filter test:
  • after draft apply, the corresponding draft_created event should disappear from fn_iu_unread(...,'review') because draft is no longer open.
  1. Per-actor read isolation test:
  • event visible to GPT and Opus initially;
  • mark read for GPT;
  • GPT no longer sees it;
  • Opus still sees it.
  1. Self-exclusion test:
  • creator actor does not see own event by default;
  • creator sees it when p_include_self=true.
  1. Duplicate/idempotency test:
  • ensure repeated/duplicate event insertion attempt does not create duplicates, relying on partial unique (event_type, ref_id).
  1. Source safety:
  • trigger functions do not update/delete IU/UV;
  • no app.canonical_writer usage.
  1. Report event counts and event IDs created by P3D2 tests.

Cleanup policy

Because P3D2 validates real trigger behavior, test notification events may be cleaned after PASS if they are marked with a test source/address, but triggers/functions should remain.

Recommended:

  • retain P3D2 triggers/functions on PASS;
  • cleanup P3D2 test notification/read rows on PASS if safely identifiable by canonical_address LIKE 'test/p3d2/%' or source plus test address;
  • retain pilot IU/draft/version rows for debugging unless a reviewed cleanup policy exists;
  • on FAIL, drop newly created P3D2 triggers/functions if safe; do not drop P3D1 scaffold.

Report requirements

Report should include:

  • phase_status;
  • trigger/function names created;
  • source column mapping discovered;
  • event counts by type/stream;
  • test event ids;
  • P3D1 hashes unchanged;
  • Pack 23 hashes unchanged;
  • read isolation result;
  • actionable filter result;
  • cleanup status;
  • notification_runtime=ACTIVE if PASS;
  • hermes_readiness=BLOCKED_PENDING_REVIEW unless User/GPT explicitly enables Hermes later.

Hard boundaries

  • Do not alter P3D1 tables/functions.
  • Do not alter Pack 23 functions.
  • Do not alter gateway/birth triggers.
  • Do not mutate vector.
  • Do not implement LISTEN/NOTIFY.
  • Do not implement retention/archival.
  • Do not use external queue.
  • Do not create global read flag.
  • Do not start Hermes production.

Next after P3D2

If P3D2 PASS:

  • The PG-native notification runtime is active for IU workflow.
  • GPT/Opus can query unread events through fn_iu_unread.
  • A final Agent context pack update may be needed to add notification commands.
  • Hermes production remains a separate reviewed decision.
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-23-p3d1-execution-pass-and-p3d2-directive-2026-05-08.md