KB-3C0E

18000x · 08 — Auto-Instantiate-From-Event Proof (sandbox BEGIN/ROLLBACK; no daemon; 5-step productization roadmap)

4 min read Revision 1
iu-corev0.618000xauto-instantiatesandbox-proofevent-drivenproductization-roadmap

18000x · 08 — Auto-Instantiate-From-Event Proof

Goal

Demonstrate the "event arrives → compose instance" flow as a sandbox BEGIN/ROLLBACK with no daemon, no cron, no worker — purely the in-TX simulation the macro explicitly authorises.

Design

  1. A _simulated_event TEMP table represents the event queue. Each row carries (template_collection_id, instance_key_suffix) — the minimum a consumer needs.
  2. A DO block walks the queue:
    • fetches v2 template piece iu_ids from iu_piece_membership
    • builds a pieces_json reusing all 5
    • calls fn_iu_compose to mint the instance
    • calls fn_iu_collection_record_template_instance for lineage
  3. The composer gate is opened inside the TX and closed before ROLLBACK — gate-toggle reversibility pattern.

Live transcript

-- simulated event
template_collection_id               | instance_key_suffix
1cd4f881-0e7f-4f7a-9133-07ce7e726d8d | auto-event-2026-05-25-001

NOTICE: composed instance 8f4724e9-1624-4344-87ab-e800b10d220b
        from template 1cd4f881-…  (minted=0, attached=5)
NOTICE: lineage recorded: digest_matches=true

             instance_collection_key              | template_collection_key | digest_matches_template |      instantiated_by
--------------------------------------------------+-------------------------+-------------------------+---------------------------
 tpl-inst:wf:onboarding/auto-event-2026-05-25-001 | tpl:wf:onboarding/v2    | t                       | iu-core-18000x-auto-event

ROLLBACK

-- post-rollback
auto_event_rows_post = 0
iu_core.composer_enabled = false

Productization path to a durable auto-instantiate

The sandbox proves the mechanism. To productize this as a real "subscribe to template.published → spawn instance" worker:

  1. Define a new event_type template.published (event_domain=template or repurpose iu domain — open question) with event_type_registry row + corresponding event_outbox CHECK constraint update (per [[feedback-event-outbox-check-vs-registry-drift]]).
  2. Emit template.published from fn_iu_collection_register_template_version (one-line hook into the existing function).
  3. Consumer: a new function fn_iu_template_auto_instantiate(p_template_id, p_instance_key_suffix, p_actor) that does the DO-block work (refactor of the sandbox).
  4. Route + worker registration in iu_outbound_route so the existing 014 route worker drives the consumer (route is internal-only — no external HTTP).
  5. Gate: a new iu_core.template_auto_instantiate_enabled config defaulting to false — durable opt-in.

None of steps 1–5 are authored in 18000x — they are listed here as the exact next-step package for ≥19000x.

Why no productization in 18000x

The sandbox PROVES the mechanism works. The constitution requires:

  • No daemon
  • No cron
  • Reversible by default
  • Discover-first before create

Productization steps 1–5 above add 1 event_type + 1 fn + 1 route + 1 gate to the surface and would push the D9 inventory higher. The sandbox proof is the discover-first deliverable; the productization itself is a separate, smaller macro.

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/v0.6-iu-core-18000x-template-versioning-bulk-scaleout-event-ops-open-goal/08-auto-instantiate-from-event-proof.md