GPT Review — Trigger Guard Investigation Fix Path
GPT Review — Trigger Guard Investigation Fix Path
Date: 2026-04-28
Scope: Review Claude Code Trigger Guard investigation report and Opus evaluation.
Verdict
Claude Code PASS. Choose Option A, with a safety refinement: schema-qualify public.trigger_guard_alerts and set a locked function search_path; use SECURITY DEFINER only if pre-check confirms the owner/privilege model is safe and necessary.
G6 retry remains blocked until Trigger Guard repair is completed and verified.
Evidence checked
knowledge/dev/laws/dieu38-trien-khai/reports/p9-g6-trigger-guard-incident-investigation-2026-04-28.mdrev 1.knowledge/current-state/reports/trigger-guard-v2-d26-complete.knowledge/current-state/reports/trigger-guard-d26-p3-report.knowledge/dev/reports/gpt-review-g6-run3-ddl-event-trigger-guard-fail-2026-04-28.md.
Findings
trigger_guard_alertsexists inpublicon bothdirectusandincomex_metadata.fn_evt_trigger_guard()uses an unqualifiedtrigger_guard_alertsreference.- Function is
SECURITY INVOKERand has no function-levelsearch_path. - G6 sets
search_path=p9_g6_dryrun,pg_catalog, so unqualified lookup fails. incomex_metadatahas the same search_path weakness, so it is not a healthy control for this defect.- Docs say
trigger_guard_configshould exist, but investigation did not find it; this is a separate drift to document. trigger_guard_exceptionsexists but is not read by the current function; whitelist mechanism is not active.- DOT-316 active but
last_executed=NULL; separate operational follow-up.
Law / constitutional check
| Rule | Result | Finding |
|---|---|---|
| Đ26 / Trigger Guard | BLOCK until repaired | Guard must function reliably before more DDL dry-run. |
| Đ31 System Integrity | PASS with root-fix | Fix root search_path defect, do not bypass guard. |
| Đ32 | PASS if gated | ALTER FUNCTION is production DDL and needs gate. |
| Đ33 | PASS if scoped | Repair must include pre-check, rollback, post-verify, action log. |
| Đ35 / DOT | PASS if governed | Use governed AI execution gate, not manual human psql. |
| Hiến pháp | PASS | Fix guard infrastructure, do not disable protection. |
Decision
Reject Option B as default: disabling the event trigger is a bypass and only acceptable as emergency repair, not needed here.
Reject Option C as default: hardcoding p9_g6_dryrun exception fixes the incident, not the root cause, and weakens guard semantics.
Accept Option A with refinement:
- Patch
fn_evt_trigger_guard()in bothdirectusandincomex_metadataso it referencespublic.trigger_guard_alertsexplicitly. - Add/lock function-level
search_pathtopg_catalog, publicor equivalent safe deterministic path. - Evaluate
SECURITY DEFINERduring pre-check:- If current invoker lacks INSERT on
public.trigger_guard_alertsin normal DDL contexts,SECURITY DEFINERmay be required. - If INSERT privilege is already sufficient and schema qualification fixes failure, keep
SECURITY INVOKERto minimize privilege elevation. - If using
SECURITY DEFINER, owner must be a controlled role with only necessary privileges; action log must capture owner and security posture.
- If current invoker lacks INSERT on
- Do not implement whitelist/exception changes in this gate unless strictly needed for the root fix.
- Track
trigger_guard_configmissing,trigger_guard_exceptionsunused, and DOT-316 last_executed=NULL as follow-up issues, not blockers for the search_path repair unless the pre-check shows they are required.
Required next step
Opus should draft Trigger Guard Repair Gate — Option A.
Gate requirements:
- Executor: Claude Code.
- Effort: high (production ALTER FUNCTION on both DBs).
- Scope: repair event trigger function only; no G6 retry in same gate.
- Pre-checks: both DBs, table exists, function definition hash/snapshot, owner/security/search_path, event triggers enabled, test current failure mode in a harmless controlled way if possible.
- Mutation: patch function definition / ALTER FUNCTION SET search_path;
SECURITY DEFINERonly if pre-check justifies. - Rollback: restore original function definitions/settings from snapshots; preserve event trigger enabled state.
- Post-verify: controlled DDL smoke in isolated temporary schema or harmless DDL event that triggers guard, verify alert insert succeeds and no error; rollback test artifacts.
- Action log path:
knowledge/dev/laws/dieu38-trien-khai/reports/p9-g6-trigger-guard-repair-option-a-log-2026-04-28.md. - STOP after report; no G6 retry until GPT/User review.