GPT Review — 23-P3D1 Execution PASS and P3D2 Directive
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_eventcreated.iu_notification_readcreated.- Named CHECK/FK constraints verified.
fk_notif_read_eventON 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-005109test_unit_id=60c0017d-4d5d-4003-a403-76e85f869557test_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:
-
Comment notification:
- trigger function e.g.
fn_iu_notif_comment(); - trigger
trg_aa_iu_notif_commentonunit_edit_commentAFTER INSERT; - emits
comment_added/ streamcomment; - suppress system/apply comments.
- trigger function e.g.
-
Draft notification:
- trigger function e.g.
fn_iu_notif_draft(); - trigger
trg_aa_iu_notif_draftonunit_edit_draftAFTER INSERT; - emits
draft_created/ streamreview; - only when
NEW.draft_status='open'.
- trigger function e.g.
-
Version/apply notification:
- trigger function e.g.
fn_iu_notif_version(); - trigger
trg_aa_iu_notif_versiononunit_versionAFTER INSERT; - emits
version_applied/ streamupdate; - only when
NEW.version_seq > 1.
- trigger function e.g.
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_eventas source of truth.
Trigger implementation guidance
- Use AFTER INSERT triggers.
- Use deterministic trigger names:
trg_aa_iu_notif_commenttrg_aa_iu_notif_drafttrg_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 NOTHINGto rely on partial unique index(event_type, ref_id)for idempotency. - Include
sourcevalues:trg_aa_iu_notif_commenttrg_aa_iu_notif_drafttrg_aa_iu_notif_version
- Payload should include lightweight refs such as:
unit_idaddresscomment_id/draft_id/version_idactor_ref
Runtime schema inspection required
Before writing trigger bodies, inspect actual columns for:
unit_edit_commentunit_edit_draftunit_versioninformation_unit
Do not assume column names blindly.
Expected likely mappings from current packs:
unit_edit_comment.unit_idunit_edit_comment.author_refor equivalent actor fieldunit_edit_comment.comment_kindor equivalent kind fieldunit_edit_draft.unit_idunit_edit_draft.created_byunit_edit_draft.draft_statusunit_version.unit_idunit_version.version_seqinformation_unit.idinformation_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'orauthor_type='system', do not emitcomment_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
- Trigger functions created with expected names/signatures.
- Triggers created on the correct source tables with expected names.
- No Pack 23 function hash changes.
- P3D1 function hashes unchanged.
- Comment event test:
- create a normal/free-flow comment via
fn_iu_commentor exact lower-level function; - verify exactly one
comment_addedevent created; - verify
event_stream='comment',source='trg_aa_iu_notif_comment', correct unit/address/ref/actor.
- create a normal/free-flow comment via
- 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_addedevent for system comment.
- Draft event test:
- create draft via
fn_iu_save(..., mode='draft'); - verify exactly one
draft_createdevent created; - verify
event_stream='review'and actionable inbox shows it for another actor.
- create draft via
- Version/apply event test:
- apply that draft via
fn_iu_apply_edit_draft; - verify exactly one
version_appliedevent created; - verify
version_seq > 1.
- apply that draft via
- Birth exclusion test:
- create a new IU via
fn_iu_save; - verify no
version_appliedevent for version_seq=1.
- create a new IU via
- Actionable filter test:
- after draft apply, the corresponding
draft_createdevent should disappear fromfn_iu_unread(...,'review')because draft is no longer open.
- 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.
- Self-exclusion test:
- creator actor does not see own event by default;
- creator sees it when
p_include_self=true.
- Duplicate/idempotency test:
- ensure repeated/duplicate event insertion attempt does not create duplicates, relying on partial unique
(event_type, ref_id).
- Source safety:
- trigger functions do not update/delete IU/UV;
- no
app.canonical_writerusage.
- 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=ACTIVEif PASS;hermes_readiness=BLOCKED_PENDING_REVIEWunless 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.