GPT Handoff to Opus — Pack 23 P3C2 rev5
GPT Handoff to Opus — Pack 23 P3C2 rev5
Date: 2026-05-07
From: GPT-5.5 Thinking / Incomex Hội đồng AI
To: Opus new session
Purpose: Restore context and apply latest GPT directive for P3C2 rev5.
Status: P3C2 rev4 reviewed; rev5 patch required; DO NOT DISPATCH.
0. Start here
Opus, this is a new-session handoff. Please do not search broadly. Read these files first, in this order:
-
Current P3C2 prompt to patch:
knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3c2-iu-apply-edit-functions-prompt.md
-
Latest GPT review requiring rev5:
knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-23-p3c2-prompt-rev4-2026-05-07.md
-
P3D notification roadmap note, already accepted as roadmap:
knowledge/dev/laws/dieu44-trien-khai/design/23-p3d-notification-outbox-roadmap-note.md
-
If you need runtime context only, read the P3C1 PASS report:
knowledge/dev/laws/dieu44-trien-khai/reports/23-p3c1-iu-edit-draft-safe-functions-report.md
Avoid re-litigating earlier P3C1/P3B/P3A unless needed. The current task is only to patch P3C2 prompt rev4 → rev5.
1. Where we are
Pack 22 is complete:
fn_iu_createexists.- IU create gateway is enforced.
- Direct IU/UV writes are blocked unless a canonical writer marker is used.
- Gateway allow-list includes
fn_iu_apply_edit_draft, prepared for P3C2.
Pack 23 so far:
P3B — PASS
Created schema for editorial edit layer:
unit_edit_draftunit_edit_commentinformation_unit.sort_order
P3C1 — PASS
Created four safe functions that do not write IU/UV:
fn_iu_edit_plan(text,text,text,text)fn_iu_create_edit_draft(text,text,text,text,text)fn_iu_comment_edit_draft(uuid,text,text,text,text)fn_iu_comment(text,text,text,text,text,jsonb)
P3C1 test report:
- 21/21 tests PASS.
- IU/UV unchanged.
- Draft/comment rows retained for P3C2.
fn_iu_commentproved simple-but-safe behavior: it does not silently attach to wrong drafts.
P3C2 — current work
P3C2 will create the official write path:
fn_iu_apply_edit_draft(uuid,text,text)fn_iu_edit(text,text,text,text,text,text)wrapper
P3C2 is the dangerous layer because it inserts unit_version, updates information_unit, uses the gateway marker, and verifies invariants.
2. Current P3C2 prompt status
Current prompt:
knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3c2-iu-apply-edit-functions-prompt.md
Current version: rev4.
Rev4 already fixed major issues:
content_anchor_ref = new_uv_id::text, matching Pack 22 invariant.- Lifecycle convention is determined at function runtime, not via transaction-local GUC.
- T1 no longer calls apply twice; it uses a unit separator and captures full JSON from the same successful apply call.
- Unique
(unit_id, version_seq)requires exact count = 1. - Grantee check uses heredoc variables.
- Owner check is present.
- P3D notification roadmap is referenced.
But rev4 still has one real blocker and several small hardening gaps.
3. Latest GPT verdict on rev4
GPT verdict:
Rev4 is very close, but do not dispatch yet. Rev5 small patch required.
Main blocker:
- T16 source check for
fn_iu_apply_edit_draftcurrently includes|| true, so it cannot fail properly.
This must be fixed before Agent execution.
4. Required P3C2 rev5 patch
Patch only the following seven items. Do not expand scope.
1. BLOCKER — fix T16 apply source check
Current rev4 effectively does this:
echo "$T16_AP" | grep -q "t" && ! echo "$T16_AP" | grep -q "t|t" || true
Because of || true, T16 apply source check can never fail.
Replace with exact parsed fields:
T16_AP=$("${PSQL[@]}" -t -A -F "$US" <<'SQL'
SELECT
prosrc ~* 'app\.canonical_writer' AS has_marker,
prosrc ~* 'insert\s+into\s+(public\.)?unit_version' AS has_uv_insert,
prosrc ~* 'update\s+(public\.)?information_unit' AS has_iu_update,
prosrc ~* 'delete\s+from\s+(public\.)?(information_unit|unit_version)' AS has_delete
FROM pg_proc
WHERE proname='fn_iu_apply_edit_draft'
AND pronamespace='public'::regnamespace;
SQL
)
T16_AP_MARKER=$(echo "$T16_AP" | cut -d"$US" -f1)
T16_AP_UV_INSERT=$(echo "$T16_AP" | cut -d"$US" -f2)
T16_AP_IU_UPDATE=$(echo "$T16_AP" | cut -d"$US" -f3)
T16_AP_DELETE=$(echo "$T16_AP" | cut -d"$US" -f4)
if [ "$T16_AP_MARKER" = "t" ] && \
[ "$T16_AP_UV_INSERT" = "t" ] && \
[ "$T16_AP_IU_UPDATE" = "t" ] && \
[ "$T16_AP_DELETE" = "f" ]; then
echo "T16_APPLY=PASS"
else
echo "T16_APPLY=FAIL marker=$T16_AP_MARKER uv_insert=$T16_AP_UV_INSERT iu_update=$T16_AP_IU_UPDATE delete=$T16_AP_DELETE"
TEST_FAIL=$((TEST_FAIL+1))
fi
Keep wrapper check, but fail if wrapper forbidden paths are true.
2. T16 apply must verify expected official write paths
The apply function must have:
- gateway marker present;
INSERT INTO unit_versionpresent;UPDATE information_unitpresent;- no DELETE from
information_unit/unit_version.
This is included in the patch above.
3. Preflight must require two open drafts
P3C2 needs both DRAFT_A and DRAFT_B:
- A is applied.
- B becomes
stale_base.
Rev4 can skip T6/T9 if B is missing. That weakens the stale-base evidence.
Patch preflight:
[ -n "$DRAFT_A_ID" ] || { PREFLIGHT_STATUS="FAIL"; echo "FAIL: no DRAFT_A"; }
[ -n "$DRAFT_B_ID" ] || { PREFLIGHT_STATUS="FAIL"; echo "FAIL: no DRAFT_B for stale-base test"; }
Do not create DRAFT_B inside P3C2. If missing, STOP and request a separate reviewed helper step.
4. Initialize final variables
In setup add:
NEW_UV_ID=""
NEW_SEQ=""
T11_UV=""
T1_FULL=""
T1_INV=""
P3C1_HASHES_AFTER=""
This avoids unset/empty report artifacts when preflight or function creation fails.
5. Validate interpolated test values
Before running tests, add validation:
UUID_RE='^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
[[ "$DRAFT_A_ID" =~ $UUID_RE ]] || { PREFLIGHT_STATUS="FAIL"; echo "FAIL: DRAFT_A_ID invalid UUID"; }
[[ "$DRAFT_B_ID" =~ $UUID_RE ]] || { PREFLIGHT_STATUS="FAIL"; echo "FAIL: DRAFT_B_ID invalid UUID"; }
[ -n "$TEST_ADDR_A" ] || { PREFLIGHT_STATUS="FAIL"; echo "FAIL: TEST_ADDR_A empty"; }
case "$TEST_ADDR_A" in
*"'"*) PREFLIGHT_STATUS="FAIL"; echo "FAIL: TEST_ADDR_A contains single quote" ;;
esac
Place this in preflight after draft/address selection and before any raw shell interpolation into SQL.
6. Report security metadata clearly
Final report should include:
function_owner_verified=$FN_OWNER
function_security=SECDEF_search_path_pg_catalog_public_public_execute_absent_grantees_ok
This is in addition to T15.
7. Preserve P3D roadmap exact fields
Keep these exact final report lines:
notification_roadmap=knowledge/dev/laws/dieu44-trien-khai/design/23-p3d-notification-outbox-roadmap-note.md
next_required_pack=P3D_NOTIFICATION_OUTBOX_BEFORE_HERMES_PRODUCTION
5. Hard boundaries
Do not violate these:
- No dispatch.
- No table DDL.
- No trigger/gateway changes.
- No vector mutation.
- No cleanup.
- No notification log implementation in P3C2.
- No Pack 2C.
This task is prompt patch only.
6. After patch
After applying rev5:
-
Save the patched prompt at:
knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3c2-iu-apply-edit-functions-prompt.md
-
Return a concise summary:
- rev5 done;
- list seven fixes;
- confirm no dispatch.
-
Stop for GPT/User final review.
7. Design reminders
- The philosophy remains: simple but safe. AI/Agent should not need to remember the process, and the system must not silently do the wrong thing.
- P3C2 official writes must only happen in
fn_iu_apply_edit_draft. fn_iu_editis a wrapper; it must not directly write IU/UV.- Notification/log/Hermes work is deferred to P3D.
- P3D will have separate lightweight comment-event and update-event logs, probably populated by PG triggers later.
8. Do not re-open already settled decisions
Do not revisit unless new evidence appears:
content_anchor_refmust benew_uv_id::text.- lifecycle convention is self-determined at runtime inside apply.
unit_version.lifecycle_statuscurrent unique convention is expected to be used.- P3C1 functions must remain unchanged; T17 verifies this.
- Official test rows are retained. No destructive cleanup.