KB-3775

IU Core Event Worker — 06 Structure-ops production workflow package

3 min read Revision 1
dieu44iu-core-mvpevent-workerstructure-opsworkflowdesign-packagev0.62026-05-21

IU Core Event Worker — 06 Structure-ops production workflow package

Design package (not built this macro). The substrate already exists; this specifies the workflow that exercises it.

Substrate in place

  • iu_structure_operation — governed envelope per op (004; H4-fixed 006).
  • iu_relation — typed lineage edges; uq_iu_relation_one_active_parent.
  • iu_tree_path — materialised tree (158 rows); v_iu_tree — live recursive projection.
  • Helpers fn_iu_tree_assert_acyclic, fn_iu_tree_is_descendant (005).
  • Python: structure_ops.py (6 operation types, status transitions, STRUCTURE_OP_EVENTS), tree.py (cycle logic), idempotency.py (structure_operation_key).

Command contract — plan → apply → verify → rollback

One verb per operation type (add_new_piece, split_large_piece, merge_small_pieces, deprecate_piece, replace_piece, reparent_piece), each a four-phase governed envelope keyed by structure_operation_key:

  1. plan (dry-run) — create iu_structure_operation draftplanned; compute impact_summary (affected IUs, iu_tree_path rows that change, iu_sql_link rows hit) without mutating. Idempotent on the key.
  2. applyplannedenacted (sets enacted_at). Mutate information_unit.parent_or_container_ref / create IUs via the birth gate / set lifecycle_status; write iu_relation edges; refresh iu_tree_path for the affected subtree; emit IU events (STRUCTURE_OP_EVENTS).
  3. verify — read-only: tree acyclic, iu_tree_path == v_iu_tree for the subtree, one active contains parent per child, path_hash distinct.
  4. rollback / compensationenactedrolled_back (retains enacted_at per H4). Reverse the adjacency change; retire iu_relation edges via valid_to+relation_status; restore iu_tree_path from v_iu_tree.

dry-run / apply mode

plan leaves the op planned and writes nothing durable to the tree — that is dry-run. apply is the gated, durable step. Both honour a master gate; apply/rollback additionally require sovereign approval (mutating).

Tree maintenance

iu_tree_path is a cache of v_iu_tree. After any adjacency change, the affected unit_id and its whole subtree must be re-derived from v_iu_tree (depth, path_ids, path_addresses, path_hash). For the current flat 158-IU tree (all depth 0) every op is a depth-0/1 change; a full re-bootstrap (runtime/050 pattern) is also acceptable at this scale.

To build (next structure-ops macro)

  • SQL: fn_iu_structure_op_plan / _apply / _verify / _rollback (or a cutter_agent/iu_core/structure_ops_workflow.py driver over the existing helpers).
  • Reuse: birth gate for IU creation, fn_iu_tree_assert_acyclic for reparent, fn_iu_emit_event for STRUCTURE_OP_EVENTS — which the route worker built this macro will then consume.
  • Integration point with auto-cut: doc 07.
Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/v0.6-iu-core-event-worker-structure-ops-autocut-integration-open-goal/06-structure-ops-workflow-package.md