KB-73FB

GPT Review — P2B-P1 IU Pilot Insert Prompt rev1

6 min read Revision 1
gpt-reviewpack2bp2b-p1iu-pilotrev2-required

GPT Review — P2B-P1 IU Pilot Insert Prompt rev1

Date: 2026-05-05 Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI Reviewed: knowledge/dev/laws/dieu44-trien-khai/prompts/19-p2b-p1-iu-pilot-insert-and-birth-fire-prompt.md rev1

Verdict

Direction PASS, but rev2 required before dispatch.

The prompt follows the correct high-level approach:

  • one IU + one UV only;
  • one transaction;
  • schema-first payload;
  • vocab lookup before INSERT;
  • no DOT-119/schema/function changes;
  • no cleanup execution.

However, because this is the first real IU row creation, a few details must be tightened.

Required rev2 patches

B1 — Do not gate on total birth count +1

§4.6 currently says:

total_birth: +1 vs baseline

This repeats the live-table count problem. birth_registry is live. Total birth count may drift due to unrelated activity.

Patch:

  • Keep total_birth as audit/drift only.
  • Hard invariants should be IU-specific:
    • IU count: baseline 0 → 1
    • UV count: baseline +1
    • IU birth count: baseline 0 → 1
    • UV birth count: unchanged
  • If total_birth is not +1, report drift, but do not mark failure unless evidence shows P2B-P1 caused unexpected extra birth rows.

B2 — Vocab selection must derive actual allowed token from key suffix

L1 checks keys like:

  • vocab.unit_kind.<value>
  • vocab.section_type.<value>

The prompt says “choose value from query result,” but dot_config.value may be descriptive config rather than the allowed token.

Patch vocab query to expose both key and token:

SELECT key, value,
       CASE
         WHEN key LIKE 'vocab.unit_kind.%' THEN replace(key, 'vocab.unit_kind.', '')
         WHEN key LIKE 'vocab.section_type.%' THEN replace(key, 'vocab.section_type.', '')
         WHEN key LIKE 'vocab.publication_type.%' THEN replace(key, 'vocab.publication_type.', '')
       END AS vocab_token
FROM dot_config
WHERE key LIKE 'vocab.unit_kind.%'
   OR key LIKE 'vocab.section_type.%'
   OR key LIKE 'vocab.publication_type.%'
ORDER BY key;

Agent must use vocab_token for unit_kind and primary_section_type_ref, not blindly value.

B3 — Content hash function must be preflighted

Prompt uses:

encode(sha256(v_body::bytea), 'hex')

This may or may not exist depending on installed functions/extensions. Preflight must check available hash function, or use a known available one.

Add preflight:

SELECT to_regprocedure('digest(text,text)') AS digest_text,
       to_regprocedure('digest(bytea,text)') AS digest_bytea,
       to_regprocedure('sha256(bytea)') AS sha256_bytea;

Preferred execution:

  • If digest(text,text) or digest(bytea,text) exists, use: encode(digest(v_body, 'sha256'), 'hex')
  • Else if sha256(bytea) exists, use: encode(sha256(v_body::bytea), 'hex')
  • If none exists, STOP/report; do not invent hash.

To keep prompt simple, Opus may choose the function confirmed by preflight and insert exact SQL.

B4 — Post-verify must validate entity_code against actual IU id

§4.3 says expected format information_unit::<iu_uuid>, but prompt should require explicit join/check.

Add query:

SELECT iu.id,
       br.entity_code,
       ('information_unit::' || iu.id::text) AS expected_entity_code,
       br.entity_code = ('information_unit::' || iu.id::text) AS entity_code_ok
FROM information_unit iu
JOIN birth_registry br
  ON br.collection_name='information_unit'
 AND br.entity_code = 'information_unit::' || iu.id::text
WHERE iu.canonical_address='pilot.iu0.test-001';

Expected: exactly 1 row and entity_code_ok = true.

B5 — Cleanup SQL draft order must respect FK cycle

Current cleanup draft deletes UV before nulling IU anchors. That may fail because IU version_anchor_ref points to UV.

Patch draft order:

-- CLEANUP (DO NOT RUN unless approved)
BEGIN;
UPDATE information_unit
SET version_anchor_ref=NULL, content_anchor_ref=NULL
WHERE canonical_address='pilot.iu0.test-001';

DELETE FROM unit_version
WHERE unit_id IN (
  SELECT id FROM information_unit WHERE canonical_address='pilot.iu0.test-001'
);

DELETE FROM birth_registry
WHERE collection_name='information_unit'
  AND entity_code IN (
    SELECT 'information_unit::' || id::text
    FROM information_unit
    WHERE canonical_address='pilot.iu0.test-001'
  );

DELETE FROM information_unit
WHERE canonical_address='pilot.iu0.test-001';
COMMIT;

Still draft only, not executed.

B6 — If transaction commits but post-verify fails, do not continue

The prompt says STOP generally, but add explicit rule:

  • If COMMIT succeeds but any post-verify invariant fails, upload report immediately with state snapshot and cleanup draft. Do not attempt a second insert, repair, or cleanup.

Directive to Opus/Ocus

Patch P2B-P1 prompt to rev2:

knowledge/dev/laws/dieu44-trien-khai/prompts/19-p2b-p1-iu-pilot-insert-and-birth-fire-prompt.md

Apply B1–B6 above. Do not dispatch yet.

After rev2, GPT/User can review for dispatch.

Hard boundaries remain:

  • no schema changes;
  • no trigger/function changes;
  • no DOT-119 changes;
  • no raw birth_registry insert;
  • no cleanup execution;
  • no second IU row;
  • no Pack 2C/vector/outbox/Qdrant;
  • no Directus exposure;
  • no P3/HC.
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-p2b-p1-iu-pilot-insert-prompt-rev1-2026-05-05.md