Handoff to Opus New Session — Pack 22 P2 rev12 Needed
Handoff to Opus New Session — Pack 22 P2 rev12 Needed
Date: 2026-05-06
From: GPT-5.5 Thinking / Incomex Hội đồng AI
To: Opus new session
Current gate: Pack 22 / P2 prompt patch, do not dispatch yet
0. Read this first
Opus, phiên trước bị mất ngữ cảnh. Không search lung tung. Đọc handoff này là đủ để tiếp tục đúng mạch.
Việc ngay bây giờ: patch P2 prompt rev11 → rev12 để tránh PASS ảo trong shell verdict. Sau khi patch xong, dừng lại chờ GPT/User final yes/no, chưa dispatch Agent.
P2 prompt file hiện tại:
knowledge/dev/laws/dieu44-trien-khai/prompts/22-p2-iu-native-create-main-functions-prompt.md
GPT review cần apply:
knowledge/dev/laws/dieu44-trien-khai/reviews/gpt-review-22-p2-main-functions-prompt-rev11-2026-05-06.md
1. Big picture — chúng ta đang làm gì?
Chúng ta không thiết kế lại hệ thống khai sinh.
Hệ thống khai sinh hiện hữu vẫn là:
fn_birth_registry_auto;- IU birth trigger + L1/L2 gates;
birth_registry;- DOT-118 / backfill;
- orphan/ghost/registry-health detectors.
Pack 22 chỉ tạo native IU creation contract nằm trên hệ thống hiện hữu:
- caller gọi
fn_iu_create(...); - function tự tạo IU + UV + anchors + hash;
- existing birth trigger tự tạo birth row;
- function verify invariants;
- không raw insert
birth_registry; - không gọi backfill;
- không tạo birth process mới.
Triết lý: mẹ chỉ sinh. Đường chính complete-or-nothing. Động cơ phụ vẫn tồn tại cho bypass/legacy/import/schema drift/sự cố, không phải để vá happy path.
2. Roadmap hiện tại
Đã xong
| Phase | Status | Ý nghĩa |
|---|---|---|
| 20B vector hygiene | PASS | Dọn context-pack khỏi KB/vector, search sạch lại |
| Pack 21 doc fix | PASS | Docs birth runtime sửa theo query-path, không hardcode số |
| 22-P0 inspection | PASS | Xác nhận chưa có native fn_iu_create; schema đủ; adapter role candidate directus |
| 22-P1 helpers | PASS | 5 helper functions installed, 14/14 tests pass, PUBLIC revoked |
P1 helpers đã có:
public.fn_content_hash(text)public.fn_iu_resolve_default(text,text,text)public.fn_iu_classify_existing(text)public.fn_iu_create_preflight()public.fn_iu_verify_invariants(text)
Đang làm
22-P2 — tạo main functions:
public.fn_iu_create_plan(...)— dry-run/native plan, no rows.public.fn_iu_create(...)— writer chính, tạo IU + first UV + anchors, birth qua trigger, verify invariants.
P2 là writer-phase thật, tạo pilot IU thật. Vì vậy prompt đã được rà rất kỹ nhiều vòng. Hiện P2 prompt ở rev11, kiến trúc đúng nhưng còn shell verdict cần vá rev12.
Sau P2
Chưa làm. Sau khi Agent chạy P2 và report PASS mới xét:
- P3 adapter / Directus/API/tool integration;
- DOT registration nếu cần;
- không nhảy Pack 2C trước review.
3. Current P2 rev11 status
P2 rev11 hiện tại đã có các điểm đúng:
- self-contained, full SQL inline;
- no
CREATE OR REPLACE; - no raw
birth_registryinsert; - no manual address substitution;
- uses bash arrays for psql;
- env defaults:
PG_CONTAINER,PG_USER,PG_DB; - no global
set -e, intentional to always report; - strict address regex;
- no bare unique-index fallback, requires real unique constraint;
fn_iu_createverifies full invariants viafn_iu_verify_invariantsbefore returningcreated;- incomplete existing states return
action_required=true,health_signal_needed=true; - auxiliary engine wording present;
- post-commit verify runs only when main SQL succeeded;
- pre-SQL init failure no longer exits early.
4. Why rev11 still needs rev12
Rev11 architecture is correct. Remaining issue is PASS ảo in shell verdict/reporting.
Specifically:
- Rev11 captures
POST_EXIT, but final verdict ignores it. If post-commit verification query errors, phase could still pass incorrectly ifPOST_COMMIT_STATUSis stale/noisy. - Function existence check after success is display-only. It should be captured as machine status.
POST_COMMIT_STATUSis not normalized. Noisy output could become an unexpected string.INIT_ERRORshould be printed as its own field.- Report must explicitly say existing incomplete states are not success.
5. Exact rev12 patch to apply
Patch file:
knowledge/dev/laws/dieu44-trien-khai/prompts/22-p2-iu-native-create-main-functions-prompt.md
Apply these 5 fixes exactly.
Fix 1 — Final verdict requires POST_EXIT=0
Find final verdict condition. It currently resembles:
if [ $INIT_EXIT -eq 0 ] && [ $PSQL_EXIT -eq 0 ] && [ "$POST_COMMIT_STATUS" = "PASS" ]; then
echo "phase_status=PASS"; echo "p3_readiness=READY"
else
echo "phase_status=FAIL"; echo "p3_readiness=BLOCKED"
fi
Change to require POST_EXIT=0:
if [ $INIT_EXIT -eq 0 ] && [ $PSQL_EXIT -eq 0 ] && [ $POST_EXIT -eq 0 ] && [ "$POST_COMMIT_STATUS" = "PASS" ] && [ "$FCHECK_STATUS" = "PASS" ]; then
echo "phase_status=PASS"; echo "p3_readiness=READY"
else
echo "phase_status=FAIL"; echo "p3_readiness=BLOCKED"
fi
Also echo:
echo "post_exit=$POST_EXIT"
Fix 2 — Capture function existence check as machine-readable status
Current rev11 runs function existence check after success but only displays it.
Add variables before the post-success check:
FCHECK_STATUS="NOT_RUN"
FCHECK_EXIT=0
FCHECK_RESULT=""
Replace display-only function check with captured check. Example:
FCHECK_STATUS="NOT_RUN"
FCHECK_EXIT=0
FCHECK_RESULT=""
if [ $PSQL_EXIT -eq 0 ]; then
set +e
FCHECK_RESULT=$("${PSQL_RO[@]}" <<'FCHECK'
WITH checks AS (
SELECT 'fn_iu_create' AS fn, to_regprocedure('public.fn_iu_create(text,text,text,text,text,text,text,text,uuid)') IS NOT NULL AS exists
UNION ALL
SELECT 'fn_iu_create_plan', to_regprocedure('public.fn_iu_create_plan(text,text,text,text,text,text,text,text,uuid)') IS NOT NULL
)
SELECT CASE WHEN bool_and(exists) THEN 'PASS' ELSE 'CRITICAL' END FROM checks;
FCHECK
)
FCHECK_EXIT=$?
FCHECK_STATUS=$(echo "$FCHECK_RESULT" | tr -d '[:space:]')
if [ "$FCHECK_STATUS" != "PASS" ] && [ "$FCHECK_STATUS" != "CRITICAL" ]; then
FCHECK_STATUS="INVALID_OUTPUT"
fi
set -uo pipefail
fi
Then in final verdict echo:
echo "fcheck_exit=$FCHECK_EXIT"
echo "fcheck_status=$FCHECK_STATUS"
If FCHECK_STATUS is not PASS, final verdict must be FAIL/P3 BLOCKED.
Fix 3 — Normalize POST_COMMIT_STATUS
After:
POST_COMMIT_STATUS=$(echo "$POST_RESULT" | tr -d '[:space:]')
Add:
if [ "$POST_COMMIT_STATUS" != "PASS" ] && [ "$POST_COMMIT_STATUS" != "CRITICAL" ]; then
POST_COMMIT_STATUS="INVALID_OUTPUT"
fi
This prevents noisy stdout or malformed output from being treated accidentally.
Fix 4 — Echo init_error as its own field
In final verdict section, add:
echo "init_error=$INIT_ERROR"
Keep existing reason output too.
Fix 5 — Report/philosophy: incomplete existing states are not success
In the report requirement/philosophy section, add explicit wording:
Existing state semantics:
- `exists_complete` = idempotent success.
- `exists_missing_birth`, `exists_missing_version`, `exists_anchor_invalid`, `exists_duplicate_version`, `exists_unknown_state` = health/remediation states, not success.
- Adapters must not treat these as successful creation.
- These states require health/remediation review; `fn_iu_create` does not call backfill or repair them.
6. Do not change these decisions
Do not undo these current design choices:
fn_iu_createmust callfn_iu_verify_invariantsinternally and raise exception ifall_passis not true.- Do not return
created_birth_missing. - Do not raw insert into
birth_registry. - Do not call backfill inside
fn_iu_create. - Do not reintroduce global
set -e. - Do not use manual placeholder substitution.
- Do not support bare unique-index fallback in P2 v1.
- Do not hardcode container/user/db; keep env defaults.
- Do not dispatch Agent after patching rev12; return for GPT/User final approval.
7. Expected output from you now
After patching rev12, reply with:
P2 rev12 done.
Applied 5 GPT fixes:
1. Final verdict requires POST_EXIT=0 and FCHECK_STATUS=PASS.
2. Function existence check captured as FCHECK_STATUS/FCHECK_EXIT.
3. POST_COMMIT_STATUS normalized to PASS/CRITICAL/INVALID_OUTPUT.
4. init_error emitted as own field.
5. Existing incomplete states documented as health/remediation, not success.
Chờ GPT final yes/no. Không dispatch.
8. Dispatch text for later, only after GPT/User approves
Do not use this yet. After approval only:
Đọc prompt từ KB rồi thực hiện:
knowledge/dev/laws/dieu44-trien-khai/prompts/22-p2-iu-native-create-main-functions-prompt.md
Prompt là single bash script. Chạy nguyên khối. ALWAYS upload report + log bất kể kết quả.
Report tại:
knowledge/dev/laws/dieu44-trien-khai/reports/22-p2-iu-native-create-main-functions-report.md
9. One-line mental model
P2 rev12 không sửa logic sinh nữa. Logic sinh đã đúng. Rev12 chỉ siết đồng hồ báo kết quả để không có PASS ảo.