KB-43E1

GPT Review — 22-P1 Prompt rev5 Last-Mile Check

5 min read Revision 1
gpt-reviewpack-22p1last-milerev6-requireddispatch-blocker

GPT Review — 22-P1 Prompt rev5 Last-Mile 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.md rev5

Verdict

Do not dispatch rev5 yet. Rev6 required.

Rev5 removed the hardcoded vocab/pilot test data, which is good. However, a last-mile review found several small but important fragilities that can cause false failures or unsafe test substitution. These are quick to patch.

Required rev6 patches

P1 — Sample IU query must not assume created_at

Rev5 uses:

SELECT canonical_address
FROM public.information_unit
ORDER BY created_at NULLS LAST, canonical_address
LIMIT 1;

created_at may not exist; previous schema notes mention date_created/date_updated as optional. Do not assume either.

Patch:

SELECT canonical_address AS sample_iu_addr
FROM public.information_unit
ORDER BY canonical_address
LIMIT 1;

or use a schema-aware order only if column exists. Simpler is ORDER BY canonical_address.

P2 — Do not substitute sample values into SQL string literals

Rev5 says Agent substitutes $SAMPLE_UNIT_KIND and $SAMPLE_IU_ADDR into SQL strings:

SELECT fn_iu_resolve_default('$SAMPLE_UNIT_KIND', ...);
SELECT fn_iu_classify_existing('$SAMPLE_IU_ADDR');

Even though samples come from DB, literal substitution can break on quotes and teaches unsafe patterns.

Patch tests to use CTE/subquery values directly:

WITH s AS (
  SELECT substring(key from length('vocab.unit_kind.') + 1) AS sample_unit_kind
  FROM public.dot_config
  WHERE left(key, length('vocab.unit_kind.')) = 'vocab.unit_kind.'
  ORDER BY key
  LIMIT 1
)
SELECT public.fn_iu_resolve_default(s.sample_unit_kind, 'iu_create.default_unit_kind', 'vocab.unit_kind.')
FROM s;

If result set is 0 rows → SKIPPED.

For IU sample:

WITH s AS (
  SELECT canonical_address AS sample_iu_addr
  FROM public.information_unit
  ORDER BY canonical_address
  LIMIT 1
)
SELECT public.fn_iu_classify_existing(s.sample_iu_addr)
FROM s;

Same for verify existing.

P3 — Rollback helper existence check must use exact helper names

Rev5 rollback check uses:

p.proname LIKE 'fn_iu%' OR p.proname='fn_content_hash'

This will match existing legitimate functions like fn_iu_birth_gate_layer1, fn_iu_birth_gate_layer2, fn_iu_updated_at, causing false report after rollback.

Patch to exact helper list:

SELECT n.nspname, p.proname
FROM pg_proc p
JOIN pg_namespace n ON n.oid=p.pronamespace
WHERE n.nspname='public'
  AND p.proname IN (
    'fn_content_hash',
    'fn_iu_resolve_default',
    'fn_iu_classify_existing',
    'fn_iu_create_preflight',
    'fn_iu_verify_invariants'
  )
ORDER BY p.proname;

Expected 0 after rollback.

P4 — fn_iu_resolve_default should detect duplicate config keys

If dot_config permits duplicates or data is corrupted, current SELECT value INTO v_configured can silently choose one. For a core contract, duplicate config is invalid.

Patch:

  • Count rows for p_config_key.
  • If count > 1 → return status='invalid_config_duplicate' with count.
  • If count = 1 → validate value.
  • If count = 0 → proceed to auto-single.

Also btrim(v_configured) before validation/return.

P5 — Unique guard should accept unique index as well as unique constraint

Rev5 preflight checks only pg_constraint contype u. This is fine for current P0, but durable preflight should accept a unique index too, because PostgreSQL uniqueness may be implemented as a unique index without a named constraint in some migrations.

Patch:

  • First check unique constraint on canonical_address.
  • If absent, check pg_index.indisunique covering canonical_address.
  • If neither exists → exception.

Do not hardcode the constraint/index name.

P6 — Schema-qualify test function calls

Tests currently call unqualified fn_content_hash(...), fn_iu_resolve_default(...), etc. Use public.fn_* in all tests to avoid search_path surprises.

P7 — Report skipped tests explicitly with evidence

For sample-based tests, report:

  • sample vocab found? yes/no;
  • sample IU found? yes/no;
  • tests run/skipped accordingly.

Skipped due to no sample is not failure.

Directive to Opus

Patch P1 prompt to rev6 with P1–P7. After rev6, return for one 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

Rev5 is very close. The largest hidden bug is the rollback check: it would falsely detect existing fn_iu_birth_gate_* functions as failed rollback residue. The second major issue is SQL literal substitution of runtime samples. Patch these and the prompt should be dispatchable.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-22-p1-prompt-rev5-last-mile-check-2026-05-06.md