Agent Prompt DRAFT — Phase 5C2-R1 DIEU-35 Pilot Migration Execution — TAC→Information Unit — 2026-05-14
Agent Prompt DRAFT — Phase 5C2-R1 DIEU-35 Pilot Migration Execution — TAC→Information Unit — 2026-05-14
Status: DRAFT — NOT DISPATCHED / NOT APPROVED FOR EXECUTION Mode if approved: BOUNDED WRITE EXECUTION — 36-row DIEU-35 pilot only Requires before dispatch: explicit User GO + GPT final approval of this prompt
0. Mission
Execute Phase 5C2-R1: migrate exactly 36 live TAC DIEU-35 units into native information_unit / unit_version using the canonical fn_iu_create writer, preserving TAC as canonical UI source and producing rollback keys.
This prompt is currently a draft for review only. Do not execute unless User and GPT explicitly approve dispatch.
1. Controlling evidence
Read first:
- GPT R0 mapping review:
knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-phase5c2-r0-readonly-mapping-artifact-approve-r1-prompt-draft-2026-05-14.md - R0 mapping report:
knowledge/dev/laws/dieu44-trien-khai/reports/p3d-phase5c2-r0-readonly-mapping-artifact-report.md - R0 mapping JSON artifact:
knowledge/dev/laws/dieu44-trien-khai/artifacts/p3d-phase5c2-r0-dieu35-mapping-artifact.json - R0 design:
knowledge/dev/laws/dieu44-trien-khai/design/p3d-phase5c2-resume-tac-to-information-unit-migration-plan.md - Agent current-position investigation:
knowledge/dev/laws/dieu44-trien-khai/reports/agent-readonly-investigation-iu-current-position-before-next-design-2026-05-14.md - IU create gateway README:
knowledge/dev/laws/dieu44-trien-khai/readme/iu-create-gateway-readme.md - Birth Rev3 contract:
knowledge/dev/laws/dieu44-trien-khai/design/p3d-birth-system-b2-contract-design-rev3.md
2. Non-negotiable boundaries
Allowed if and only if this prompt is explicitly approved for dispatch:
Create exactly 36 information_unit rows for DIEU-35.
Create exactly 36 unit_version rows through fn_iu_create.
Create exactly 36 birth_registry rows via existing trg_birth_information_unit.
Patch identity_profile/content_profile/provenance only for the newly captured rows.
Write rollback-key artifacts to KB + VPS log before COMMIT.
Still forbidden:
No DDL.
No schema changes.
No trigger/function changes.
No birth-system changes.
No direct INSERT into information_unit or unit_version.
No UPDATE/DELETE of TAC source tables.
No UI cutover.
No Nuxt/Directus/config changes.
No vector/Qdrant mutation or reindex.
No event_outbox/IU event emission work.
No bulk migration beyond DIEU-35 36 rows.
No touching existing 12 pilot/test IU rows.
No pattern matching deletes.
No migration of DIEU-28 or DIEU-32.
No automatic fix of source content anomalies.
3. Required execution structure
The Agent must execute in these stages and stop on failure.
Stage 0 — Authorization checkpoint
Before connecting to PG, confirm the dispatch context includes explicit approval:
USER_GO=YES
GPT_FINAL_APPROVAL=YES
PROMPT_PATH=knowledge/dev/laws/dieu44-trien-khai/prompts/agent-phase5c2-r1-dieu35-pilot-migration-execution-prompt-DRAFT.md
If either approval is missing, STOP and produce a no-execution report.
Stage 1 — Read-only preflight
Run SELECT-only checks and write them to the final report.
Required gates:
- TAC tables exist.
- DIEU-35 exists.
- DIEU-35 member count = 36 live.
- render_order contiguous 0..35.
- owner NULL count = 0.
- body NULL count = 0.
- Collision count with existing
information_unit.canonical_address= 0. - Existing IU rows count and IDs captured before migration.
fn_iu_createsignature exists and returns jsonb.fn_content_hashexists.- Gateway mode = enforced.
- Allowed marker values include
fn_iu_createandfn_iu_apply_edit_draft. - Edit policy default =
require_review. trg_birth_information_unitexists oninformation_unit.species_collection_mapprimary IU mapping exists.- Required vocab seeds exist:
vocab.publication_authority.incomex_councilvocab.publication_type.lawvocab.unit_kind.law_unit- all
vocab.section_type.<source section_type>for DIEU-35.
birth_registrycurrent count forcollection_name='information_unit'captured.- TAC table pre-counts captured for 4 TAC tables.
- Soft-flag row
D38-DIEU35-S8-P3with body_char_count=1 detected and reported as source-preservation flag, not blocker.
If any hard gate fails, STOP before BEGIN.
Stage 2 — Prepare transaction inputs
Build a 36-row in-memory mapping from live TAC source, equivalent to R0 artifact.
Do not use stale R0 JSON as the only source of truth. Use R0 as plan of record, but source rows must be live-read immediately before transaction.
For each source row, prepare:
p_canonical_address = tac_logical_unit.canonical_addressp_title = tac_unit_version.titlep_body = tac_unit_version.bodyp_actor = 'agent:p3d-phase5c2-r1'p_unit_kind = 'law_unit'p_section_type = tac_logical_unit.section_typep_owner_ref = tac_logical_unit.ownerp_publication_type = 'law'p_parent_ref = NULL- planned identity_profile patch per R0 design §5.3
- planned content_profile patch per R0 design §5.4
Stage 3 — Transaction execution
Open one transaction.
For each of 36 rows, in render_order order:
- Call canonical writer only:
SELECT public.fn_iu_create(
p_canonical_address := :canonical_address,
p_title := :title,
p_body := :body,
p_actor := 'agent:p3d-phase5c2-r1',
p_unit_kind := 'law_unit',
p_section_type := :section_type,
p_owner_ref := :owner,
p_publication_type := 'law',
p_parent_ref := NULL
);
-
Parse returned JSONB to capture at minimum:
- IU id
- UV id / version id
- canonical_address
- status
- any warnings/errors
-
If returned status is not successful/created/expected idempotent success, ROLLBACK and STOP. Do not continue.
-
Patch only the newly created/captured IU row's
identity_profileusing exact captured IU id or canonical_address, with allowed gateway marker:
SET LOCAL "app.canonical_writer" = 'fn_iu_apply_edit_draft';
UPDATE information_unit
SET identity_profile = COALESCE(identity_profile, '{}'::jsonb) || :identity_profile_patch::jsonb,
doc_code = 'DIEU-35',
sort_order = :src_render_order,
section_type = :src_section_type,
section_code = :src_section_code
WHERE id = :captured_iu_id;
- Patch only the newly created/captured UV row's
content_profileand provenance, with allowed gateway marker still local:
SET LOCAL "app.canonical_writer" = 'fn_iu_apply_edit_draft';
UPDATE unit_version
SET content_profile = COALESCE(content_profile, '{}'::jsonb) || :content_profile_patch::jsonb,
provenance = 'tac:DIEU-35:' || :src_unit_version_id::text
WHERE id = :captured_uv_id;
Notes:
- If gateway rejects these updates, ROLLBACK and STOP.
- Do not update any TAC table.
- Do not update existing pilot/test IU rows.
- Do not enrich
birth_registryELD columns; leave placeholder behavior as Rev3 defines.
Stage 4 — Capture rollback keys before COMMIT
Before COMMIT, collect exact keys:
captured_iu_ids uuid[]captured_uv_ids uuid[]captured_iu_entity_codes text[]where format isinformation_unit::<iu_uuid>- source
src_logical_unit_id,src_unit_version_id,canonical_address,render_ordermapping
Write rollback keys to BOTH:
- KB:
knowledge/dev/laws/dieu44-trien-khai/reports/p3d-phase5c2-r1-dieu35-rollback-keys-<utc>.md
- VPS log file:
/opt/incomex/logs/p3d-phase5c2-r1-dieu35-<utc>.log
If either write fails, ROLLBACK and STOP.
Stage 5 — In-transaction validation before COMMIT
Run V-1..V-7 before COMMIT.
V-1 row accounting:
captured_iu_count=36
captured_uv_count=36
source_count_live=36
V-2 render fidelity:
identity_profile.rendering.render_ordermultiset = 0..35.
V-3 content hash fidelity:
- each captured UV
content_hash = fn_content_hash(body). - compare with source
tac_unit_version.content_hashwhere source non-null.
V-4 authority:
- all captured IU
identity_profile.publication_authority_ref = incomex_council.
V-5 birth coverage:
- 36 birth rows exist for captured IU entity codes.
- all
species_code = information_unit_atom. - all
composition_level = atom. - 0 NULL species.
V-6 TAC source untouched:
- 4 TAC table counts equal preflight counts.
V-7 IU invariants:
- If
fn_iu_verify_invariantsis safe to execute as read-only, run per captured canonical_address and require PASS. - If safety is uncertain, do not execute and mark
V-7=SKIPPED_SAFETY_UNKNOWN, then ROLLBACK unless GPT/User pre-approved skipping it. Default: require PASS or rollback.
If V-1..V-7 PASS, COMMIT. If any FAIL, ROLLBACK.
Stage 6 — Post-COMMIT validation
After COMMIT, run V-8..V-10.
V-8 gateway integrity:
trg_aa_iu_gateway_write_guardandtrg_aa_uv_gateway_write_guardstill attached.- no marker leakage in a fresh session.
V-9 pre-existing 12 pilot/test rows untouched:
- compare pre-captured IDs, canonical_addresses, version_anchor_ref if practical.
V-10 rollback key artifact presence:
- KB rollback key document exists.
- VPS log contains rollback key block.
Also verify:
- final IU row count = pre_count + 36.
- final UV row count = pre_count + 36.
- final
birth_registryIU count = pre_count + 36. - TAC table counts unchanged.
- UI cutover not performed.
- Qdrant untouched.
If post-COMMIT validation fails, execute exact-key rollback only, then report failure and rollback evidence.
4. Soft-flag handling
The row below is a source-content soft-flag, not a blocker:
render_order=26
canonical_address=D38-DIEU35-S8-P3
body_char_count=1
R1 must:
- migrate the source body exactly if execution proceeds;
- report this row in
source_soft_flags; - not repair, infer, expand, normalize, or skip it;
- state that semantic repair, if any, is a separate content workflow.
5. Required reports
Create these KB reports:
- Execution report:
knowledge/dev/laws/dieu44-trien-khai/reports/p3d-phase5c2-r1-dieu35-pilot-migration-execution-report.md
- Rollback keys report, only if transaction reaches key-capture stage:
knowledge/dev/laws/dieu44-trien-khai/reports/p3d-phase5c2-r1-dieu35-rollback-keys-<utc>.md
If execution stops before BEGIN, create only the execution report with execution_started=false.
6. Required final response fields
phase5c2_r1_execution_status=PASS|FAILED_ROLLED_BACK|BLOCKED_BEFORE_BEGIN|FAILED_POST_COMMIT_ROLLBACK_FAILED
user_go_confirmed=true|false
gpt_final_approval_confirmed=true|false
execution_started=true|false
commit_performed=true|false
rollback_performed=true|false
rollback_success=true|false|not_applicable
source_count_live=<N>
created_iu_count=<N>
created_uv_count=<N>
created_birth_count=<N>
pre_existing_iu_untouched=true|false|unknown
tac_source_untouched=true|false|unknown
render_fidelity_pass=true|false|unknown
content_hash_fidelity_pass=true|false|unknown
birth_coverage_pass=true|false|unknown
gateway_integrity_pass=true|false|unknown
soft_flag_rows=[D38-DIEU35-S8-P3]
ui_cutover_performed=false
vector_work_performed=false
bulk_migration_performed=false
rollback_keys_report_path=<path or none>
execution_report_path=knowledge/dev/laws/dieu44-trien-khai/reports/p3d-phase5c2-r1-dieu35-pilot-migration-execution-report.md
next_recommended_action=GPT_OPUS_REVIEW_R1_EXECUTION_REPORT
7. Important warning
This prompt is a DRAFT. Do not run it from KB unless the user and GPT explicitly approve execution.
R1 is the first real TAC→IU write step. Treat failure conservatively: rollback and report. Do not improvise.