GPT Review — 23-P3B Schema Prompt rev3
GPT Review — 23-P3B Schema Prompt rev3
Date: 2026-05-07
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Reviewed:knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3b-iu-edit-draft-schema-prompt.mdrev3
Verdict
Rev3 is very close, but do not dispatch yet. Rev4 small patch required.
Opus correctly fixed the GUC-session blocker and the earlier reporting issues. The schema design is accepted. Remaining issues are small but worth patching because P3B is DDL and should be deterministic on first run.
Accepted rev3 fixes
- Owner GUC is now set inside the same psql session as DDL.
- V1–V13 variables are initialized.
- Policy key action is more precise.
- Partial DDL check includes more objects.
- Existing
sort_orderwithoutidx_iu_parent_sortstops preflight. - Constraint verification is schema-qualified.
- Function lists are captured for debug.
iu_uv_rows_unchangedis machine-readable.
Required rev4 small patches
P1 — Fix empty function list counting
Current pattern:
FN_COUNT_BEFORE=$(echo "$FN_LIST_BEFORE" | grep -c . 2>/dev/null || echo "0")
If the list is empty, grep -c prints 0 then exits non-zero, then echo "0" also runs. This can produce a value like 0\n0.
Patch both before and after counts using SQL count directly, or robust shell:
FN_COUNT_BEFORE=$("${PSQL[@]}" -t -c "
SELECT count(*) FROM pg_proc p JOIN pg_namespace n ON p.pronamespace=n.oid
WHERE n.nspname='public'
AND (p.proname LIKE 'fn_iu_%edit%'
OR p.proname LIKE 'fn_iu_%draft%'
OR p.proname LIKE 'fn_iu_%comment%');
" | tr -d ' ')
Do the same for FN_COUNT_AFTER. Keep FN_LIST_BEFORE/AFTER for debug.
P2 — Verify iu_edit.% policy keys after DDL
P3C will depend on these keys, so P3B should verify exact values post-DDL.
Add verification, e.g. V14:
iu_edit.policy.default_mode = auto_applyiu_edit.schema.version = p3b-v1
If either missing or different, VERIFY_FAIL++.
Also include V14 in final report.
P3 — Make partial DDL failure check key-specific
Rev3 checks POLICY_KEYS_BEFORE_COUNT. If one key existed before and the other is inserted before a failure, the current CRITICAL logic may not mark it as new partial state.
Patch by capturing preflight values separately:
MODE_VAL_BEFOREVER_VAL_BEFORE
On DDL failure:
- if
MODE_VAL_BEFOREwas empty andP_MODEis now non-empty → partial new state; - if
VER_VAL_BEFOREwas empty andP_VERis now non-empty → partial new state.
This is defensive because the transaction should roll back, but the report should be accurate.
P4 — Add explicit post-DDL object detail output
The report asks for column/constraint/index details, but the script mostly outputs PASS/FAIL variables. Add read-only detail queries after verification:
- columns for both new tables;
- constraints for both new tables;
- indexes for both new tables plus
idx_iu_parent_sort; - dot_config
iu_edit.%keys; - table owner/grants.
This helps Opus/GPT review the Agent report without re-querying.
P5 — Clarify action when sort_order exists with index
If sort_order exists and idx_iu_parent_sort exists, current DDL will skip both. Good.
Ensure final action reports:
SORT_ORDER_ACTION=SKIPPED_ALREADY_EXISTS_WITH_INDEX
rather than generic SKIPPED_ALREADY_EXISTS. This helps distinguish healthy idempotent state from incomplete state.
Directive to Opus
Patch P3B prompt to rev4 with P1–P5 only.
Path:
knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3b-iu-edit-draft-schema-prompt.md
Do not dispatch after patch. Return for GPT/User final review.
Hard boundaries remain
- No functions.
- No trigger changes.
- No gateway changes.
- No IU/UV row mutations.
- No vector mutation.
- No cleanup.
- No retry / no improvise.
Summary
The schema and control flow are accepted. Rev4 is a small hardening pass for function-count correctness, policy-key verification, partial-state reporting, and richer report detail. After that, P3B should be ready for dispatch.