KB-2249

P3D Pack 1 Phase 4B — Discovery Prompt rev5 Patch Report

4 min read Revision 1
p3dpack1phase4bdiscoveryrev5patch-report

P3D Pack 1 Phase 4B — Discovery Prompt rev5 Patch Report

Date: 2026-05-11 Author: Opus 4.7 Directive: gpt-directive-opus-p3d-pack1-phase4b-discovery-prompt-rev5-introspect-first-2026-05-11.md


1. Status flags

phase4b_discovery_prompt_rev5_status=PATCHED
truly_introspect_first=true
every_subquery_independent=true
column_detection_before_use=true
parent_column_detection=true
universal_edges_fallback=true
no_hardcoded_column_assumption=true
requires_GPT_User_review_before_dispatch=true

2. Paths

Artifact Path Rev
Discovery prompt (rev5) ...prompts/p3d-pack1-phase4b-readonly-species-composition-registry-discovery-prompt.md 5
This report ...reports/p3d-pack1-phase4b-discovery-prompt-rev5-patch-report.md 1

3. Top 5 structural changes from rev4

  1. Every sub-query is independent. Helper function run_query wraps each call with 2>&1 || echo "FAILED". No heredoc groups multiple queries. One failure → log + continue.

  2. Column detection via detect_col and col_exists helpers. Before any schema-sensitive query, bash detects the actual column name from candidates. Example: TAC_PARENT=$(detect_col tac_logical_unit parent_ref parent_id parent_or_container_ref container_ref) — tries 4 candidates, uses the first that exists, skips the query if none found.

  3. SELECT * for data dumps. D1.1, D2.1, D3.1, D4.1/D4.2 use SELECT * — no column names needed, agent reads headers from output. Schema-sensitive queries (filtered, grouped, joined) gate their columns first.

  4. universal_edges fallback. If source_collection/target_collection not detected → fallback: to_jsonb(universal_edges)::text ILIKE '%information_unit%'. Labelled as fallback evidence, not primary.

  5. D8 parent detection. tac_logical_unit parent column detected from candidates (parent_ref, parent_id, parent_or_container_ref, container_ref). Used dynamically in bash variables for recursive CTE nesting depth query. No assumed column names. Same pattern for information_unit parent column.

4. Column detection inventory

Table Columns detected via detect_col Candidates tried
entity_species parent, depth parent_id/parent_ref/parent_species_id, depth/tree_depth/level
species_collection_map collection_name collection_name/name/table_name
collection_registry collection_name, governance_role, species_code collection_name/name/table_name, governance_role/role, species_code
birth_registry collection_name, species_code, composition_level collection_name, species_code, composition_level
entity_labels entity_code, facet_code entity_code/code/entity_ref, facet_code/facet/label_facet
universal_edges source_collection, target_collection, edge_type source_collection/source_table/from_collection, target_collection/target_table/to_collection, edge_type/relation_type/type
tac_logical_unit parent, section_type parent_ref/parent_id/parent_or_container_ref/container_ref, section_type/type
information_unit parent parent_or_container_ref/parent_ref/parent_id/container_ref

Columns like composition_level in entity_species and species_code in entity_species are verified via col_exists before use in GROUP BY/DISTINCT queries.

5. What was preserved from rev4

  • All D0-D8 block purposes unchanged
  • Legal alignment header and law references preserved
  • Compliance matrix connection preserved
  • candidate_not_approved labelling preserved
  • Report requirements expanded (D8 containment, column detection results, failed sub-queries)
  • No-hardcode contract preserved
  • Hard boundaries preserved

6. Confirmation

phase4b_discovery_prompt=REV5_READY_FOR_GPT_REVIEW
agent_dispatch_allowed=false_until_GPT_USER_REVIEW
next_action=GPT_REVIEW_DISCOVERY_PROMPT_REV5
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/reports/p3d-pack1-phase4b-discovery-prompt-rev5-patch-report.md