KB-4DFD

GPT Review — 23-P3A Execution Result and P3B Directive

10 min read Revision 1
gpt-reviewpack-23p3a-passp3b-directiveschema-onlyedit-draft

GPT Review — 23-P3A Execution Result and P3B Directive

Date: 2026-05-07
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Reviewed: knowledge/dev/laws/dieu44-trien-khai/reports/23-p3a-iu-gateway-allow-list-patch-report.md rev1
Related: knowledge/dev/laws/dieu44-trien-khai/reviews/opus-review-23-p3a-execution-result-2026-05-07.md

Verdict

23-P3A PASS. No supplemental Agent action needed.

Agent executed the approved prompt correctly. Opus review is accurate.

P3A is closed. Proceed to P3B schema-only prompt design, not immediate execution.

Evidence accepted

  • phase_status=PASS
  • p3b_readiness=READY
  • patch_status=OK
  • 11/11 tests PASS
  • Source hash changed as expected:
    • before: 68928bcdd86325955f817b03a41b4b4f
    • after: 6907fa4e5e46b5617d7dfecbd86326d7
  • fn_iu_create real pilot succeeded via named params.
  • direct IU INSERT blocked.
  • direct UV INSERT blocked by gateway.
  • direct UV UPDATE blocked by gateway.
  • future marker fn_iu_apply_edit_draft accepted in rollback test.
  • unknown marker blocked.
  • row-leak count = 0.
  • PUBLIC EXECUTE not broadened.
  • owner/SECURITY DEFINER/search_path preserved.
  • hard boundaries honored.

Runtime state after P3A

  • Gateway now allows explicit markers:
    • fn_iu_create
    • fn_iu_apply_edit_draft
  • fn_iu_apply_edit_draft does not exist yet.
  • IU/UV counts increased 5 → 6 due to retained P3A pilot. This is expected and accepted.
  • No schema edit tables exist yet.
  • P3B is unblocked.

Important process note

The Agent log says it received “tiếp tục P3B schema-only”, but P3B should not be executed until the P3B prompt is created, reviewed, and approved.

Correct next step: Opus creates P3B schema-only prompt and stops for GPT/User review.

Directive to Opus — P3B schema-only prompt design

Create prompt, do not dispatch:

knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3b-iu-edit-draft-schema-prompt.md

Report path:

knowledge/dev/laws/dieu44-trien-khai/reports/23-p3b-iu-edit-draft-schema-report.md

P3B objective

Add only the schema needed for the editorial edit layer:

  1. unit_edit_draft
  2. unit_edit_comment
  3. information_unit.sort_order
  4. any minimal dot_config policy keys needed for schema semantics

No functions yet. No gateway changes. No triggers unless absolutely required and explicitly justified.

Hard boundaries

  • No edit/apply/comment functions.
  • No changes to fn_iu_create, fn_iu_gateway_write_guard, or Pack 22 functions.
  • No trigger create/drop/enable/disable unless explicitly justified in prompt and reviewed.
  • No IU/UV row rewrite.
  • No cleanup of pilot rows.
  • No vector mutation.
  • No Pack 2C.
  • DDL must be additive only.

Required prompt structure

§0. Scope / pre-read

Agent must read:

  • knowledge/dev/laws/dieu44-trien-khai/design/23-p3-iu-proposal-merge-implementation-design.md rev5
  • knowledge/dev/laws/dieu44-trien-khai/reports/23-p3a-iu-gateway-allow-list-patch-report.md
  • knowledge/dev/laws/dieu44-trien-khai/reports/23-p2-iu-edit-merge-runtime-inspection-report.md

§1. Preflight hard gates

Include §15 compatibility/no-duplicate checks from 23-P3 rev5.

Must inspect and STOP if:

  • table unit_edit_draft already exists;
  • table unit_edit_comment already exists;
  • similar tables exist (%edit%draft%, %proposal%, %comment%) and need reconciliation;
  • information_unit.sort_order already exists with incompatible type;
  • information_unit.sort_order already exists with compatible type, in which case do not re-add it;
  • information_unit and unit_version schema changed unexpectedly from P3-P2 evidence;
  • dot_config.key unique semantics missing;
  • current role/owner/grant pattern cannot be determined.

Also capture baseline counts:

  • IU count;
  • UV count;
  • table list;
  • existing columns on IU;
  • existing constraints/indexes related to new objects if any.

§2. Proposed schema DDL — design requirements

P3B prompt should propose exact DDL, transaction-wrapped, for:

unit_edit_draft

Recommended columns:

  • id uuid PRIMARY KEY DEFAULT gen_random_uuid()
  • unit_id uuid NOT NULL REFERENCES information_unit(id)
  • canonical_address text NOT NULL
  • base_version_ref uuid NOT NULL REFERENCES unit_version(id)
  • base_version_seq integer NOT NULL
  • base_content_hash text NOT NULL
  • draft_title text NULL
  • draft_body text NOT NULL
  • draft_content_hash text NOT NULL
  • draft_status text NOT NULL DEFAULT 'open'
  • created_by text NOT NULL
  • created_at timestamptz NOT NULL DEFAULT now()
  • applied_by text NULL
  • applied_at timestamptz NULL
  • applied_version_ref uuid NULL REFERENCES unit_version(id)
  • stale_at timestamptz NULL
  • reason text NULL
  • metadata jsonb NOT NULL DEFAULT '{}'::jsonb

Design constraints/checks:

  • draft_status IN ('open','applied','stale_base','withdrawn')
  • btrim(created_by) <> ''
  • btrim(draft_body) <> ''
  • draft_title IS NULL OR btrim(draft_title) <> ''
  • canonical_address non-empty
  • optional check: status/timestamp consistency if simple and safe

Indexes:

  • (unit_id, draft_status, created_at DESC)
  • (canonical_address, draft_status, created_at DESC)
  • (base_version_ref)
  • (applied_version_ref) partial/normal as appropriate
unit_edit_comment

Recommended columns:

  • id uuid PRIMARY KEY DEFAULT gen_random_uuid()
  • draft_id uuid NOT NULL REFERENCES unit_edit_draft(id)
  • unit_id uuid NOT NULL REFERENCES information_unit(id)
  • author_ref text NOT NULL
  • author_type text NOT NULL
  • comment_body text NOT NULL
  • comment_kind text NOT NULL DEFAULT 'general'
  • created_at timestamptz NOT NULL DEFAULT now()
  • resolved_at timestamptz NULL
  • resolved_by text NULL
  • parent_comment_id uuid NULL REFERENCES unit_edit_comment(id)
  • target_path text NULL
  • metadata jsonb NOT NULL DEFAULT '{}'::jsonb

Design constraints/checks:

  • author_type IN ('user','agent','system')
  • comment_kind IN ('general','review','change_request','approval','system')
  • btrim(author_ref) <> ''
  • btrim(comment_body) <> ''
  • resolved_by IS NULL OR btrim(resolved_by) <> ''

Indexes:

  • (draft_id, created_at)
  • (unit_id, created_at)
  • (comment_kind, created_at) if justified
  • parent comment index if threading is expected later
information_unit.sort_order

Recommended:

  • ALTER TABLE information_unit ADD COLUMN sort_order integer NULL;
  • no immediate NOT NULL;
  • no immediate unique constraint;
  • add index only if justified for render hot path now.

GPT recommendation for P3B prompt: add the column, but defer index unless Agent can justify it cheaply. If adding index, use normal btree on (parent_or_container_ref, sort_order) if this matches runtime type.

§3. Ownership / permissions

P3B must preserve Directus/Pack 22 pattern:

  • identify table owner pattern first;
  • new tables should be owned by the same operational owner, likely directus, but do not hardcode without preflight;
  • no PUBLIC table privileges unless existing convention demands it;
  • Agent should report grants.

If directus owns current IU/UV and execution role is directus, note owner/grant state in report.

§4. dot_config policy keys

Only seed minimal keys if useful and non-conflicting. Candidate keys:

  • iu_edit.policy.default_mode = auto_apply
  • iu_edit.schema.version = p3b-v1
  • iu_edit.comment.append_only = true
  • iu_edit.draft.status_values = open,applied,stale_base,withdrawn

Do not over-seed. If uncertain, leave to P3C functions.

§5. Transaction and rollback

Prompt must run DDL in a transaction where possible.

If failure occurs:

  • transaction rollback should leave no partial schema;
  • report must say whether tables/columns exist after failure;
  • no retry/improvise.

§6. Post-DDL verification tests

Required:

  • unit_edit_draft exists with expected columns/types;
  • unit_edit_comment exists with expected columns/types;
  • sort_order exists with expected type or compatible pre-existing status;
  • constraints/checks exist;
  • indexes exist if created;
  • FK references resolve;
  • JSONB defaults are '{}'::jsonb;
  • no IU/UV count change;
  • P3A gateway allow-list still present;
  • fn_iu_create still exists and was not touched;
  • no new functions created.

§7. Report requirements

Report must include:

  • phase_status PASS/FAIL/CRITICAL;
  • p3c_readiness READY/BLOCKED;
  • preflight result;
  • DDL applied list;
  • table/column/constraint/index verification;
  • owner/grants;
  • IU/UV count before/after;
  • boundaries honored;
  • whether any objects were skipped because already existed.

P3B design cautions for Opus

  1. Keep P3B schema-only. Do not sneak in helper functions.
  2. Do not create triggers on draft/comment tables in Phase 1 unless absolutely justified.
  3. Do not add strict NOT NULL/unique constraints beyond what Phase 1 functions can satisfy.
  4. Keep schema extensible with JSONB metadata but core hot fields as columns.
  5. Draft/comment direct writes are discouraged by policy; permission hardening can be Phase 2 unless P3B can do it safely.

Expected Opus response

Opus should create the P3B schema-only prompt and stop for GPT/User review.

Do not dispatch.

Summary

P3A is complete. The gateway now has the future keyhole for fn_iu_apply_edit_draft. P3B should add only the editorial schema layer, carefully and additively, without touching the verified create/gateway infrastructure.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-23-p3a-execution-result-and-p3b-directive-2026-05-07.md