KB-4A4F

GPT Review — 23-P3D4C1U Prompt rev1

13 min read Revision 1
gpt-reviewp3d4c1urev2-requireduniversal-eventimplementationsystem-issues

GPT Review — 23-P3D4C1U Prompt rev1

Date: 2026-05-08
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Reviewed: knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3d4c1u-universal-core-implementation-prompt.md rev1

Verdict

REV2 REQUIRED — do not dispatch rev1.

Rev1 has the correct strategic structure for P3D4C1U: universal core implementation, system_issues PoC, registry enforcement B, HYBRID pending, dot_config reuse, IU runtime untouched, worker/pg_cron, deterministic tests, and rollback.

However rev1 is not dispatch-safe. It contains several schema/SQL mismatches and semantic drifts that would likely fail execution or produce wrong events.

Accepted parts

  • Correct next pack: P3D4C1U_UNIVERSAL_CORE_IMPLEMENTATION_PROMPT_REVIEW.
  • Correct PoC domain: system_issues.
  • Correct high-level objects: event_type_registry, event_outbox, event_read, event_subscription, event_pending, event_worker_log.
  • Correct decision to reuse dot_config, not create event_config.
  • Correct hard boundary: no Directus/Nuxt/Hermes/Codex, no IU runtime change.
  • Correct hot-path target: capture trigger appends O(1) into pending only.
  • Correct need for registry trigger, worker, access functions, tests and rollback.

Dispatch blockers to patch in rev2

P1 — Schema/seed mismatch in event_subscription

Rev1 sketches event_subscription in earlier design with recipient_ref, but Step 4 seeds:

INSERT INTO event_subscription (actor_ref, event_domain, active) ...

Those columns do not match the design. Patch to one schema and use it consistently.

Required:

  • use recipient_ref, not actor_ref, for subscriptions;
  • include an active boolean column if seed uses it, or remove active from seed;
  • ensure uniqueness for ON CONFLICT DO NOTHING, e.g. unique key on (recipient_ref, event_domain, event_type, event_stream, scope_subject_table) or use explicit conflict target if nullable strategy is handled.

P2 — event_read spec mismatch

Rev1 says event_read should include read_status_source ('explicit_read'|'implicit_self'), but the referenced P3D4C0Y design used implicit self-read as computed, no row inserted.

Patch one consistent rule:

  • Preferred: no implicit self row; event_read records explicit reads only, and fn_event_unread computes implicit self-read from event_outbox.actor_ref = p_actor.
  • If read_status_source is added, explain why and adjust tests/functions.

Do not mix both.

P3 — Wrong FK/table column name in event_read

Rev1 says event_read refs event_outbox.id, but event_outbox primary key is event_id.

Patch all references to use event_outbox(event_id).

P4 — event_pending column mismatch with capture trigger

P3D4C0Y design used columns like:

event_subject_table
event_subject_ref

Rev1 capture trigger inserts into:

entity_table
entity_ref

This will fail unless the table is changed. Patch to use one naming convention consistently. Preferred universal naming:

event_subject_table
event_subject_ref

P5 — system_issues actor fields are assumed incorrectly

Rev1 capture trigger uses:

COALESCE(NEW.updated_by, NEW.created_by, 'system')

But P3D4C0Y inventory indicated actor fields are source, source_system, and resolved_by for closure, not necessarily created_by/updated_by.

Patch prompt to require agent to generate capture SQL from actual preflight columns. If created_by/updated_by do not exist, use a safe field order such as:

resolved_by for resolved/archived if present;
source_system or source for producer;
else 'system'.

No hardcoded nonexistent columns.

P6 — Registry validation trigger must validate stream match

GPT directive required validating that event_stream matches registry. Rev1 trigger checks only domain/type/active.

Patch fn_event_type_validate() to fetch registry row and verify:

NEW.event_stream = registry.event_stream

Optionally validate default severity if provided. The error should identify domain/type and expected vs actual stream.

P7 — Seed stream taxonomy is inconsistent with accepted design

P3D4C0Y accepted event types included:

  • issue_opened: stream alert;
  • issue_resolved: stream update;
  • issue_archived: stream update;
  • red_zone_violation: stream alert.

Rev1 seed uses:

  • issue_resolved as alert;
  • issue_archived as health.

Patch seed to match P3D4C0Y unless agent produces a clear new justification. Default should be:

issue_opened=alert
issue_resolved=update
issue_archived=update
red_zone_violation=alert

P8 — Red-zone event is seeded but never emitted

Rev1 capture trigger only emits issue_opened, issue_resolved, issue_archived. It never emits red_zone_violation.

Patch to decide one of:

  • emit red_zone_violation on INSERT/UPDATE when severity is critical and inclusion criteria match, while avoiding duplicate noise; or
  • remove red_zone_violation from Phase 2 seed/tests.

Preferred: include it only if semantics are distinct and idempotent. For example, red_zone_violation may fire for severity='critical' with a separate idempotency key, but avoid double notification noise by routing/board grouping or by making issue_opened severity-aware instead.

P9 — Duplicate event/idempotency semantics need tightening

Rev1 has both issue_opened and red_zone_violation possible for the same INSERT, and two unique indexes in design can conflict with legitimate status transitions.

Patch the prompt to require an explicit idempotency design:

  • status transition events should be unique per (domain,type,subject_ref) or per (domain,type,subject_ref, status_value);
  • repeated UPDATE to same status must not create duplicates;
  • red_zone_violation must have a clear unique key and de-noise policy;
  • worker conflict handling must distinguish inserted vs already existed.

P10 — pg_cron install step is too optimistic

Rev1 says:

CREATE EXTENSION IF NOT EXISTS pg_cron;

Patch with robust preflight:

  • check pg_available_extensions;
  • check existing pg_extension;
  • check privilege/admin context;
  • if extension requires shared_preload_libraries/restart/config and is unavailable, STOP with preflight_pg_cron=NOT_AVAILABLE or BLOCKED;
  • no external scheduler fallback.

P11 — Cron schedule must be idempotent

Rev1 says schedule every 2 minutes but does not specify duplicate-job protection.

Patch:

  • query cron.job for existing job name;
  • if existing and command matches, report ALREADY_PRESENT;
  • if existing but different, STOP or require explicit unschedule/reschedule path;
  • never create duplicate cron jobs.

P12 — SECURITY DEFINER/search_path/permissions need hardening

Rev1 function examples use:

SECURITY DEFINER SET search_path = public

Patch functions to use a safer pinned search path, e.g. SET search_path = pg_catalog, public, and require:

  • owner verified, likely directus;
  • revoke public execute where appropriate;
  • grant only intended roles if needed;
  • no secret exposure.

P13 — event_type_registry trigger should be idempotently created/replaced

CREATE TRIGGER is not idempotent. Prompt should require:

  • preflight check existing trigger;
  • drop/recreate only if exact controlled path; or
  • use DROP TRIGGER IF EXISTS ... inside a transaction after verifying target table;
  • report trigger status CREATED|ALREADY_PRESENT|REPLACED|FAIL.

Same applies to system_issues capture trigger and cron job.

P14 — Tests insert into system_issues may require mandatory columns

Rev1 says test INSERT into system_issues, but does not specify required columns. This may fail or create invalid production-looking issues.

Patch tests to:

  • use actual preflight schema to construct pilot rows;
  • tag all pilot rows with unique marker, e.g. p3d4c1u_test_<timestamp> in a safe code/source field;
  • cleanup pilot rows/events/pending/read rows on PASS, or document retained rows if cleanup is unsafe;
  • avoid deleting real system_issues rows.

P15 — Tests for subscription conflict with fallback broadcast rule

Rev1 T10 says actor not subscribed to domain is filtered out. But earlier design has fallback broadcast when no subscription matches.

Patch to define routing semantics clearly:

  • If any subscriptions exist for a domain, only matching subscribers receive events; or
  • fallback broadcast only applies when no subscription rows exist for that domain/event class.

Tests must match the chosen rule.

P16 — Access functions must avoid heavy board aggregation if not needed for PoC

fn_event_board with read_count and latest_readers is not hot path, so allowed, but it increases implementation risk.

Patch to make Phase 2 minimal:

  • implement fn_event_unread and fn_event_mark_read first;
  • fn_event_board can be minimal or deferred unless required for tests;
  • if board includes read_count/latest_readers, ensure it is read-path only and indexed, not trigger/worker path.

P17 — v_event_unified should remain deferred/optional unless tested safely

Rev1 says optional but includes future cross-domain query. Patch to make clear:

  • no dependency on v_event_unified for P3D4C1U PASS;
  • do not touch IU tables/functions;
  • if created, it must be read-only view only and must not change IU behavior.

P18 — Rollback must protect real system_issues and event data

Rollback section says drop tables after row-count checks, but must be explicit:

  • never delete real system_issues rows;
  • if event_outbox has non-test events, do not drop automatically;
  • if cron/trigger has been active beyond test scope, require manual review before dropping durable events;
  • cleanup only test-tagged rows automatically.

P19 — Report fields should include exact statuses from prior directive

Rev1 verification is concise but should include fields required by GPT directive, including:

phase_status=PASS|FAIL|CRITICAL|BLOCKED
preflight_system_issues=PASS|FAIL
preflight_dot_config=PASS|FAIL
preflight_pg_cron=AVAILABLE|INSTALLED|NOT_AVAILABLE|FAIL
preflight_iu_snapshot=PASS|FAIL
event_type_registry_created=PASS|FAIL|ALREADY_PRESENT
event_outbox_created=PASS|FAIL|ALREADY_PRESENT
event_read_created=PASS|FAIL|ALREADY_PRESENT
event_subscription_created=PASS|FAIL|ALREADY_PRESENT
event_pending_created=PASS|FAIL|ALREADY_PRESENT
event_worker_log_created=PASS|FAIL|ALREADY_PRESENT
dot_config_keys_seeded=PASS|FAIL|ALREADY_PRESENT
event_type_seed_count=4
registry_enforcement=B
registry_validate_trigger_created=PASS|FAIL|ALREADY_PRESENT
system_issues_capture_trigger_created=PASS|FAIL|ALREADY_PRESENT
hot_path_joins=0
hot_path_aggregations=0
hot_path_rollups=0
hot_path_latest_readers=0
hot_path_vector_ops=0
pg_cron_scheduled=PASS|FAIL|SKIPPED_WITH_REASON|ALREADY_PRESENT
rollback_executed=NO_ON_SUCCESS|YES_ON_FAIL|USER_APPROVED_DRILL
next_required_pack=P3D4C2U_DIRECTUS_DOT_READONLY_EXPOSURE_PROMPT_REVIEW|REVISION_REQUIRED|BLOCKED

P20 — Next pack name should be universal, not old P3D4C2

Rev1 says:

next_required_pack=P3D4C2_DIRECTUS_UNIVERSAL_BOARD_EXPOSURE

Patch to:

P3D4C2U_DIRECTUS_DOT_READONLY_EXPOSURE_PROMPT_REVIEW

or equivalent with U to mark universal branch.

Directive to Opus

Patch the prompt to rev2 at:

knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3d4c1u-universal-core-implementation-prompt.md

Do not dispatch after patch. Return for GPT/User review.

Hard boundaries unchanged

  • No PG mutation during prompt patch.
  • No Directus mutation.
  • No Nuxt code.
  • No Hermes/Codex dispatch.
  • No external scheduler/tool/service.
  • No change to existing iu_notification_* runtime.
  • No old IU-specific P3D4C1 resume.
  • No body/raw payload/vector/secret/personal data exposure.
  • No activity-log creep.

Summary

P3D4C1U rev1 is structurally correct but not production-dispatch safe. Rev2 must fix concrete SQL/schema mismatches, registry stream validation, seed taxonomy, red-zone emission semantics, pg_cron robustness, idempotent trigger/cron creation, security-definer hardening, routing test semantics, and data-safe test/rollback handling.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-23-p3d4c1u-prompt-rev1-2026-05-08.md