22-P2 — IU Native Create Main Functions Report (rev12 execution)
22-P2 — IU Native Create Main Functions Report
Date: 2026-05-06 04:50:33 UTC | Prompt: rev12 | Status: PASS Phase: P2 (Main Functions: fn_iu_create + fn_iu_create_plan) Executor: Claude Code agent on VPS 38.242.240.89 (postgres container)
Final Verdict
| Field | Value |
|---|---|
| init_exit | 0 |
| init_error | (empty) |
| sql_exit | 0 |
| post_exit | 0 |
| post_commit_status | PASS |
| fcheck_exit | 0 |
| fcheck_status | PASS |
| diagnostics_exit | 0 |
| phase_status | PASS |
| p3_readiness | READY |
All five conditions met (INIT_EXIT=0, PSQL_EXIT=0, POST_EXIT=0, POST_COMMIT_STATUS=PASS, FCHECK_STATUS=PASS).
Addresses (this run)
- PILOT:
pilot.p2.20260506-045033.e0ae7ec5 - PLAN1:
test.p2.plan.4c6b47b2 - PLAN2:
test.p2.plan.1c8a49ec
Pilot row retained (no cleanup per boundary).
Preflight JSON
{"status": "pass", "fk_name": "fk_iu_version_anchor", "fk_initially_deferred": true}
FK fk_iu_version_anchor is INITIALLY DEFERRED — the function does not need to issue SET CONSTRAINTS DEFERRED.
Schema Sanity Checks (all passed inside SQL)
- Helpers present: fn_content_hash, fn_iu_resolve_default, fn_iu_classify_existing, fn_iu_create_preflight, fn_iu_verify_invariants — all
to_regprocedurenon-null. - No prior conflict: 0 pre-existing fn_iu_create / fn_iu_create_plan.
- Column types match expected: all 16 columns across information_unit + unit_version validated (uuid/text/jsonb/int4 as expected).
- Unique constraint on information_unit.canonical_address: count=1 ✅.
- FK information_unit→unit_version (deferrable): count=1, no duplicate name ✅.
- No address collision at start (pilot/plan1/plan2 absent).
Functions Created
proname | owner | prosecdef | provolatile
fn_iu_create | directus | t | v
fn_iu_create_plan | directus | t | s
- Both SECURITY DEFINER, owner
directus. fn_iu_createis VOLATILE (writes);fn_iu_create_planis STABLE (read-only plan).search_pathpinned topg_catalog,public.
Permissions
routine_schema | routine_name | grantee | privilege_type
public | fn_iu_create | directus | EXECUTE
public | fn_iu_create_plan | directus | EXECUTE
REVOKE ALL ... FROM PUBLICapplied for both.- 0 PUBLIC grants verified post-revoke.
- ADAPTER not blocked (directus role exists).
Plan Tests (all passed)
- Valid plan →
status='plan_ok'✅ - NULL inputs →
status='invalid_input'✅ - Existing address →
would_create=false✅ - Plan rows count = 0 (plans never insert) ✅
- Both functions compiled (count=2) ✅
Pilot 3-Layer Verify (all PASS)
- fn_iu_create internal invariant verify (RAISE EXCEPTION on failure inside transaction): result returned
birth_verified=true,invariants_verified=true→ no exception, COMMIT proceeded. - Pilot post-create verify (in-transaction, before COMMIT, via fn_iu_verify_invariants): all_pass=true.
- Post-COMMIT verify (separate read-only psql session):
{"all_pass": true, "i1_iu_exists": true, "i2_uv_linked": true, "i5_uv_birth_ok": true, "i4_birth_exists": true, "i3_anchors_exact": true}
Birth row written for information_unit::<iu_id> (count=1).
Idempotent re-call: fn_iu_create(pilot_addr, 'X', 'X', 'a') → status='exists_complete'. Row count still 1 (no duplicate).
Birth Gate Warnings (non-blocking)
WARNING: Birth gate L1 PILOT-ONLY: P-pub1 missing — production sẽ BLOCK
WARNING: Birth gate L1 PILOT-ONLY: P-pub2 missing — production sẽ BLOCK
These are PILOT-ONLY warnings (advisory) — birth registry insert succeeded. Will become errors in production gate; outside P2 scope.
publication_type Semantics
fn_iu_resolve_default called with sentinel '__no_default__' → only 'explicit' accepted. NULL or empty publication_type passes through unchanged (not added to identity_profile). Verified in code path:
IF p_publication_type IS NOT NULL AND btrim(p_publication_type)!='' THEN
v_pt:=public.fn_iu_resolve_default(p_publication_type,'__no_default__','vocab.publication_type.');
IF v_pt->>'status'!='explicit' THEN RAISE EXCEPTION ...
Counts (before / after pilot create)
| Table | Before | After |
|---|---|---|
| information_unit | 1 | 2 |
| unit_version | 1 | 2 |
| birth_iu | 1 | 2 |
| birth_total | 81211 | 81212 |
Net: +1 IU, +1 UV, +1 birth_iu, +1 birth_total. Idempotent re-call did not increment.
Existing-State Semantics (rev12 Fix 5 — affirmed)
exists_complete= idempotent success ✅ (verified by re-call test).exists_missing_birth | exists_missing_version | exists_anchor_invalid | exists_duplicate_version | exists_unknown_state→ returned withaction_required=true, health_signal_needed=true. Treated as health/remediation states, NOT successful creation. fn_iu_create does NOT call backfill/repair.
Main / Auxiliary Boundary
- fn_iu_create = main engine, complete-or-nothing canonical create path.
- Auxiliary engines (DOT-118, birth health checks, repair/backfill, orphan remediation) are out of scope for fn_iu_create.
Hard Boundaries — Honored
- ❌ No raw birth INSERT
- ❌ No OR REPLACE on functions
- ❌ No ASSERT
- ❌ No manual substitution / cleanup
- ❌ No global
set -e(intentional — report always uploads) - ❌ No bare unique-index (canonical_address has named unique constraint)
- ❌ No
created_birth_missingstatus - ❌ No early exit before report upload
- ❌ No DOT registration / adapter / default seed / Pack 2C
- ❌ No retry / no auto SQL fix
- ❌ Pilot row NOT cleaned up (retained)
Log Excerpt (full SQL log)
See companion log file uploaded at:
knowledge/dev/laws/dieu44-trien-khai/reports/22-p2-iu-native-create-main-functions-log.md
Key lines:
- L19:
PREFLIGHT_JSON={"status": "pass", "fk_name": "fk_iu_version_anchor", "fk_initially_deferred": true} - L34-35:
CREATE FUNCTION× 2 - L45-46:
WARNING: Birth gate L1 PILOT-ONLY(advisory) - L48:
NOTICE: ALL PASS: pilot.p2.20260506-045033.e0ae7ec5 - L61:
COMMIT - L64: post_commit_status =
PASS, full verify_json all-true.
P3 Readiness
READY. All gates green. Next phase (P3) may proceed per Pack 22 controlling plan.
22-P2 rev12 execution | 2026-05-06 04:50:33 UTC | phase_status=PASS | p3_readiness=READY