GPT Directive to Opus — 23-P3D4C1 Staging Outbox + Worker Prompt
GPT Directive to Opus — 23-P3D4C1 Staging Outbox + Worker Prompt
Date: 2026-05-08
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Basis:
knowledge/dev/laws/dieu44-trien-khai/reviews/opus-review-23-p3d4c0-execution-pass-2026-05-08.mdknowledge/dev/laws/dieu44-trien-khai/reports/23-p3d4c0-new-piece-document-batch-notification-design-report.mdknowledge/dev/laws/dieu44-trien-khai/design/23-p3d4c0-new-piece-document-batch-notification-design.mdknowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-23-p3d4c0-execution-pass-and-revised-roadmap-2026-05-08.md
Verdict
Opus review of P3D4C0 is accepted. Agent output is accepted. No additional P3D4C0 work is required.
Proceed to draft P3D4C1 prompt. Do not dispatch implementation.
Task for Opus
Create prompt:
knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3d4c1-staging-outbox-worker-notification-implementation-prompt.md
Future execution report path:
knowledge/dev/laws/dieu44-trien-khai/reports/23-p3d4c1-staging-outbox-worker-notification-implementation-report.md
P3D4C1 is an implementation prompt review. It may include executable SQL candidates, but execution must wait for GPT/User approval.
Design direction to preserve
AI ghi dữ liệu vào PG thật nhanh
→ hot path chỉ append O(1) vào pending/outbox
→ pg_cron worker sau 90–120s gom notification
→ durable notification event
→ Directus/Nuxt chỉ đọc projection
No trigger/function on the AI interaction path may perform COUNT, JOIN, rollup, batch detection, latest_readers, vector computation, or any derived processing.
P3D4C1 prompt scope
Draft an implementation prompt that covers:
-
Preflight and prerequisites:
- verify current P3D2 trigger state remains O(1);
- verify
pg_cronstatus; - if not installed, include explicit admin/superuser step to install/enable
pg_cronfor thedirectusdatabase; - verify no existing
iu_notification_pending; - verify current notification event CHECK constraints;
- verify no existing birth notification trigger/function.
-
Minimal schema extension:
- add nullable
source_document_ref textoninformation_unit; - add nullable
import_batch_ref textoninformation_unit; - no NOT NULL backfill;
- no heavy migration over existing bodies/content.
- add nullable
-
Staging/outbox table:
- create
iu_notification_pendingas append-only hot-path table; - include unit id, canonical address, source/batch refs, actor, ref id, created_at, processed_at/status/error fields as needed;
- indexes must support pending-row pickup without adding hot-path computation;
- no body/payload content exposure.
- create
-
Birth hook:
- use
unit_version.version_seq=1as the birth marker; - create
fn_iu_notif_birth+ trigger, or equivalent sibling to existing version trigger; - hot path must be O(1): single staging insert plus at most one PK lookup for
information_unitmetadata; - do not group, count, roll up, compute latest readers, or inspect vectors in the hook.
- use
-
Event taxonomy extension:
- add
new_piece_created; - add
document_imported; - keep existing
comment_added,draft_created,version_appliedsemantics intact; - map new event types to existing
updatestream unless a stronger documented reason exists.
- add
-
Worker:
- create
fn_iu_notification_worker_tick()or equivalent PG-native worker function; - use advisory lock to prevent concurrent worker overlap;
- process only eligible pending rows older than the configurable debounce window;
- use stable grouping key from
source_document_ref/import_batch_ref; - if no stable key, emit piece-level events only;
- if stable key and count >= threshold, emit one
document_importedevent; - otherwise emit
new_piece_createdevents; - mark pending rows processed only after durable events are safely inserted;
- preserve idempotence.
- create
-
Configuration:
- add or reuse config keys for
notification.debounce_secondsdefault 90, bounded 60–300; - add or reuse config key for
notification.batch_piece_thresholddefault 2, bounded 2–50; - use existing config/DOT conventions where available.
- add or reuse config keys for
-
pg_cron schedule:
- schedule worker every approximately 2 minutes, or another justified interval consistent with 90–120s debounce;
- no external scheduler;
- no new service/tool.
-
Tests:
- birth gap is closed for new IU after worker runs;
- creator implicit self-read still applies through existing board semantics;
- single new piece produces
new_piece_created; - multiple pieces with same stable key produce one
document_importedwhen threshold met; - unrelated pieces do not incorrectly roll up;
- no body/raw payload exposed;
- hot path has no COUNT/JOIN/aggregation/rollup/latest_readers/vector;
- P3D2 existing comment/draft/version notifications still work;
- worker idempotence and retry behavior verified;
- rollback plan verified.
-
Rollback:
- unschedule pg_cron job;
- drop worker function/trigger/function/table if needed;
- restore event CHECK constraints;
- drop nullable source/batch columns only if safe and empty, otherwise document manual review;
- leave existing P3D1/P3D2 runtime intact.
Hard boundaries
- Do not dispatch implementation.
- Do not mutate PG while drafting the prompt.
- Do not mutate Directus.
- Do not write Nuxt code.
- Do not start Hermes.
- Do not involve Codex unless User explicitly approves.
- Do not create a new external tool/service/scheduler.
- Do not solve grouping in Directus or Nuxt.
- Do not expose IU body, unit_version body, raw payload, vector data, or secrets.
- Do not claim the user-facing Directus board is complete before P3D4C1 PASS and later P3D4C2 exposure.
Required report fields for future P3D4C1 execution
The P3D4C1 prompt should require at least:
phase_status=PASS|FAIL
pg_cron_available=PASS|FAIL
pg_cron_installed_or_verified=PASS|FAIL|ALREADY_PRESENT
source_document_ref_added=PASS|FAIL|ALREADY_PRESENT
import_batch_ref_added=PASS|FAIL|ALREADY_PRESENT
pending_table_created=PASS|FAIL
birth_hook_created=PASS|FAIL
event_taxonomy_extended=PASS|FAIL
worker_function_created=PASS|FAIL
cron_schedule_created=PASS|FAIL
debounce_seconds_default=90
batch_piece_threshold_default=2
hot_path_operations=<description>
hot_path_joins=0
hot_path_aggregations=0
hot_path_rollups=0
hot_path_latest_readers=0
hot_path_vector_ops=0
hot_path_expected_complexity=O(1)
worker_grouping_strategy=HYBRID
stable_key_rule=source_document_ref_or_import_batch_ref
no_stable_key_behavior=PIECE_LEVEL_ONLY
single_piece_event_verified=PASS|FAIL
batch_rollup_event_verified=PASS|FAIL
unrelated_pieces_not_rolled_up=PASS|FAIL
creator_implicit_self_read_verified=PASS|FAIL
p3d2_existing_events_regression=PASS|FAIL
no_body_content_exposed=true
no_raw_payload_exposed=true
no_directus_mutation=true
no_nuxt_code=true
no_hermes_start=true
rollback_plan=PASS|FAIL
next_required_pack=P3D4C2_DIRECTUS_NOTIFICATION_BOARD_EXPOSURE_PROMPT_REVIEW
Expected next after Opus returns prompt
GPT/User review the P3D4C1 prompt. If approved, only then dispatch implementation.