GPT Review — 22-P3-P0 Inspection Prompt rev2
GPT Review — 22-P3-P0 Inspection Prompt rev2
Date: 2026-05-06
Reviewer: GPT-5.5 Thinking / Incomex Hội đồng AI
Reviewed:knowledge/dev/laws/dieu44-trien-khai/prompts/22-p3-p0-iu-creation-gateway-inspection-prompt.mdrev2
Verdict
Rev2 is much better, but do not dispatch yet. Rev3 required.
The 11 requested fixes were applied in substance. The prompt is still read-only and the scope is right. However, the current shell/logging pattern can still miss SQL query errors, which matters because P3-P0 is an evidence-gathering phase. If a query fails silently in the middle, Agent may produce a confident but incomplete recommendation.
What is good
- Effective table privileges via
has_table_privilegeadded. - Effective function privileges via
has_function_privilegeadded. - Directus admin roles added.
- Invariant check is scale-safe.
- Birth coverage uses entity-code join.
- Duplicate birth detection added.
- Filesystem search is bounded with timeout / rg / excludes.
dot_config.descriptionassumption removed.- Trigger order wording softened.
fn_birth_registry_autosource usesleft(prosrc,4000).- Advisory-only recommendation is explicit.
- §9 sequencing dependency is correctly called out.
Required rev3 patches
P1 — Query errors must be captured systematically, not manually by hope
Rev2 defines run_query(), but nearly all SQL blocks still call "${PSQL_RO[@]}" <<SQL | tee ... directly. That means most SQL errors are only visible in the log and are not accumulated into QUERY_ERRORS.
Patch:
- Either use
run_queryfor every SQL block; or - create a helper
run_sql <id> <label> <<'SQL' ... SQLthat captures exit code withset +e, logs output, and appends failed query id/label toQUERY_ERRORS.
Example pattern:
run_sql() {
local id="$1"; shift
local label="$1"; shift
echo "--- $id $label ---" | tee -a "$LOG_PATH"
set +e
"${PSQL_RO[@]}" 2>&1 | tee -a "$LOG_PATH"
local rc=${PIPESTATUS[0]}
set -uo pipefail
if [ "$rc" -ne 0 ]; then
QUERY_ERRORS="${QUERY_ERRORS}${id}: ${label} (exit=$rc)\n"
echo "*** QUERY ERROR $id exit=$rc ***" | tee -a "$LOG_PATH"
fi
}
Then call:
run_sql "1.1" "Table owners" <<'SQL'
...
SQL
This is the main blocker for dispatch.
P2 — Add ON_ERROR_STOP=1 to read-only psql command
Without ON_ERROR_STOP=1, psql may continue after SQL errors in multi-statement blocks and exit behavior can be misleading.
Patch:
PSQL_RO=(docker exec -i "$PG_CONTAINER" psql -v ON_ERROR_STOP=1 -U "$PG_USER" -d "$PG_DB")
This is read-only and safe.
P3 — Guard optional Directus tables before querying
The prompt assumes Directus tables exist:
directus_collectionsdirectus_permissionsdirectus_policiesdirectus_accessdirectus_rolesdirectus_fields
They likely exist here, but this inspection is meant to be robust. Add a preliminary table-existence query or make failures explicit through P1. At minimum, report errors from these queries as partial data and do not treat missing Directus metadata as “no dependency.”
P4 — Guard optional dot_tools, system_health_checks, collection_registry similarly
Some sections query optional governance tables. This is fine, but failures must be captured and interpreted as “table absent / partial evidence,” not silently ignored.
With P1 this may be enough; additionally, the report template should say missing optional tables are findings.
P5 — rg glob excludes should use recursive exclude syntax correctly
Current:
--glob '!.git' --glob '!node_modules' --glob '!backups'
This may not exclude recursive contents reliably. Prefer:
-g '!**/.git/**' -g '!**/node_modules/**' -g '!**/backups/**' -g '!**/context-pack/**' -g '!**/*.log'
Not a blocker alone, but improves performance/noise.
P6 — Invariant check on >1000 IUs should include failure count sampling label
Current >1000 path samples first 100 by address and pilot. Good. Add report instruction that this is a sample, not global proof. Agent must not claim all IUs pass when sample passes.
P7 — Add explicit final inspection status field
At final log/report, output:
if [ -n "$QUERY_ERRORS" ]; then
echo "inspection_status=PARTIAL"
else
echo "inspection_status=COMPLETE"
fi
Report should include this. Advisory recommendations with PARTIAL must mark confidence lower.
P8 — Report should include log path and scan timeout/truncation status
Rev2 logs LOG=...; report template should require:
- log path;
- grep timeout/truncation notes;
- query error count;
- inspection_status.
Directive to Opus
Patch P3-P0 prompt to rev3 with P1–P8.
Do not dispatch after patch; return for GPT/User final approval.
Hard boundaries remain
- READ-ONLY only;
- no DDL;
- no DML;
- no GRANT/REVOKE;
- no trigger creation;
- no function change;
- no DOT registration;
- no adapter;
- no cleanup;
- no IU row creation;
- no Pack 2C.
Summary
Rev2 has the right questions. Rev3 must make the evidence reliable: every SQL query needs machine-captured error handling, and the report needs an explicit COMPLETE/PARTIAL status. Otherwise Agent could produce a confident gateway recommendation with missing Directus/governance evidence.