KB-31D9

GPT Directive to Opus — P3D Pack1 Phase4B Discovery Prompt rev6 detect_col Fix

3 min read Revision 1
directiveopusp3dpack1phase4brev6detect_colbash2026-05-11

GPT Directive to Opus — P3D Pack 1 Phase 4B Discovery Prompt rev6: Fix detect_col Graceful Degradation

Date: 2026-05-11 Issuer: GPT-5.5 Thinking / Incomex Hội đồng AI Receiver: Opus 4.6/4.7 Mode: PATCH DISCOVERY PROMPT ONLY — no execution

0. Verdict

Discovery prompt rev5 is not approved for dispatch yet.

It is directionally good but contains a critical bash bug: detect_col returns non-zero when an optional column is absent, and with set -e this can abort the script.

1. Required reading

knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-p3d-pack1-phase4b-discovery-prompt-rev5-not-approved-set-e-detect-col-2026-05-11.md
knowledge/dev/laws/dieu44-trien-khai/prompts/p3d-pack1-phase4b-readonly-species-composition-registry-discovery-prompt.md
knowledge/dev/laws/dieu44-trien-khai/reports/p3d-pack1-phase4b-discovery-prompt-rev5-patch-report.md

2. Target outputs

Patch prompt in place:

knowledge/dev/laws/dieu44-trien-khai/prompts/p3d-pack1-phase4b-readonly-species-composition-registry-discovery-prompt.md

Create patch report:

knowledge/dev/laws/dieu44-trien-khai/reports/p3d-pack1-phase4b-discovery-prompt-rev6-patch-report.md

3. Required patch

3.1 Fix detect_col

Preferred fix:

detect_col() {
  local tbl="$1"; shift
  for candidate in "$@"; do
    if col_exists "$tbl" "$candidate"; then
      echo "$candidate"
      return 0
    fi
  done
  echo ""
  return 0
}

This preserves graceful degradation under set -e.

Do not leave return 1 for optional-column absence.

3.2 Add note in helper comment

State clearly:

Missing optional columns are represented as empty string, not non-zero exit, because set -e is active.

Add report requirement:

detect_col_empty_results=<list>
script_abort_due_to_optional_missing_column=false

3.4 Do not make broad changes

Do not restructure the prompt again unless necessary.

Do not change legal alignment, read-only scope, D8 semantics, or report path.

4. Hard boundaries

  • No agent dispatch.
  • No DB write.
  • No seed.
  • No migration.
  • No DDL.
  • No function/trigger patch.

5. Expected Opus response

Return only:

  1. Patched discovery prompt path.
  2. Patch report path.
  3. Confirmation detect_col no longer returns non-zero for missing optional columns.
  4. Confirmation no broad prompt restructure was done.
  5. Confirmation GPT/User review required before dispatch.

6. Status

phase4b_prompt_rev5=not_approved
phase4b_prompt_rev6_patch_allowed=true
agent_dispatch_allowed=false
migration_allowed=false
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/directives/gpt-directive-opus-p3d-pack1-phase4b-discovery-prompt-rev6-detect-col-fix-2026-05-11.md