GPT Review — 22-P1 Prompt rev7 Hidden Schema Risk Check
GPT Review — 22-P1 Prompt rev7 Hidden Schema Risk Check
Date: 2026-05-06 Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI Reviewed:
knowledge/dev/laws/dieu44-trien-khai/prompts/22-p1-iu-native-create-helper-functions-prompt.mdrev7
Verdict
Do not dispatch rev7 yet. Rev8 required.
Rev7 fixed the major scale issues, but a hidden schema-risk pass found several places where helper functions read columns that preflight does not verify, and one unique-index query may fail depending on PostgreSQL catalog typing.
Required rev8 patches
P1 — Preflight must cover every table/column the helpers read
Rev7 fn_iu_create_preflight() verifies IU/UV columns but helpers also read:
public.birth_registry.collection_namepublic.birth_registry.entity_codepublic.collection_registry.collection_namepublic.collection_registry.birth_code_strategypublic.dot_config.keypublic.dot_config.valuepublic.information_unit.lifecycle_statusiffn_iu_classify_existingreturns it
Patch either:
- add these columns to preflight required checks; or
- remove optional reads such as
lifecycle_statusfrom helper outputs.
Preferred:
- add
birth_registry,collection_registry, anddot_configrequired column checks; - add
information_unit.lifecycle_statusonly if the helper continues to return it.
A durable helper layer must verify all schema fields it depends on.
P2 — Unique index check should not use array_length(i.indkey,1)
pg_index.indkey is int2vector, not a normal SQL array. The expression:
array_length(i.indkey,1)=1
may fail or be version-dependent.
Patch unique-index fallback to use catalog fields designed for this:
EXISTS (
SELECT 1
FROM pg_index i
JOIN pg_attribute a
ON a.attrelid = i.indrelid
AND a.attnum = i.indkey[0]
WHERE i.indrelid = 'public.information_unit'::regclass
AND i.indisunique
AND i.indpred IS NULL
AND i.indnkeyatts = 1
AND a.attname = 'canonical_address'
)
If there is concern about int2vector subscript base, Agent should test it read-only in preflight or use pg_get_indexdef(i.indexrelid) as diagnostic evidence. Do not rely on array_length for indkey.
P3 — Avoid optional lifecycle_status unless it is a contract column
Rev7 fn_iu_classify_existing returns:
'lifecycle_status', v_iu.lifecycle_status
But lifecycle_status is not in required IU columns. This can break if schema changes.
Patch:
- either add
lifecycle_statusto the required IU contract columns; or - remove it from the JSON result.
For P1 helper layer, lifecycle_status is not necessary for classifying birth/version/anchor state. Preferred: remove it from output to reduce coupling.
P4 — Preflight name conflict should include argument signatures if future overloads are possible
Rev7 stops on any same-name helper in public. This is safe but may block future overloads. For P1 first install this is acceptable.
Add a note:
- current P1 intentionally blocks any same-name public helper to avoid overload ambiguity;
- future overloads require a separate design pack.
This prevents Agent from trying to work around conflicts.
P5 — Test expectation for verify_existing must classify diagnostic as P2 blocker, not P1 rollback
Rev7 says diagnostic OK, but report should explicitly put verify_existing diagnostic issues into P2 readiness blockers/warnings. This avoids silently proceeding after installing helpers when sample data is inconsistent.
Patch report requirement:
- if
verify_existingreturnsall_pass=falseor issue, P1 can still COMMIT helper DDL; - but
P2 readinessmust mark blocker/warning and require GPT/User review before mainfn_iu_createexecution design.
Directive to Opus
Patch P1 prompt to rev8 with P1–P5. Then return for final yes/no approval.
Hard boundaries remain
- helper function DDL only;
- no row DML;
- no table/index/constraint DDL;
- no DOT adapter;
- no default seeding;
- no retry/improvise on failure.
Summary
Rev7 is close but still assumes some schema fields without verifying them. At million-object scale, helpers must not fail because an unverified optional field disappeared or because catalog syntax is version-sensitive. Patch rev8 before dispatch.