KB-1AA7

IU b/c/f Additive DOT Wrapper + Harness — Live Apply Appendix (2026-05-28)

10 min read Revision 1
iudot-commandb-c-flive-applyappendixsqltranscript

IU b/c/f Additive DOT Wrapper + Harness — Live Apply Appendix (2026-05-28)

Verbatim migration/rollback SQL, channel transcripts, and extracted JSON for IU_B_C_F_ADDITIVE_DOT_WRAPPER_AND_HARNESS_LIVE_APPLY_100000X. Companion to the main report.


A1 — Channels + artifacts

  • Write/apply: ssh contabo "docker exec -i postgres psql -U workflow_admin -d directus -v ON_ERROR_STOP=1" < /tmp/<file>.sql (stdin pipe; container /tmp ≠ host /tmp).
  • Read-proof: MCP query_pg, role context_pack_readonly, READ ONLY txn, AST-validated, statement_timeout 5s, LIMIT 500.
  • Migration /tmp/mig_bcf_dot_wrappers.sql — md5 4df7599fe385f33389fc01ac5994f2f3.
  • Rollback /tmp/rollback_bcf_dot_wrappers.sql — md5 a7b812e8964b05d7c4e469cbe80560de.
  • macOS md5 via openssl md5.

A2 — Hard Gate 0 transcripts

Container: postgres Up 5 weeks (healthy)

Write probe (BEGIN/ROLLBACK on the real target table):

 usr=workflow_admin | db=directus
BEGIN
INSERT 0 1
 catalog_in_tx = 43
ROLLBACK
 catalog_after_rollback = 42

pg_dump --schema-only: baseline 1,603,851 bytes → after apply 1,617,882 bytes (Δ +14,031 = 5 function defs).


A3 — Read-baseline / inspection queries (query_pg)

Catalog/run schema, CHECK constraints, and the fail-closed logger were read via information_schema.columns, pg_constraint, and pg_get_functiondef. Key facts:

  • dot_iu_command_catalog_category_check: category = ANY('{collection,piece,lifecycle,read,health}')
  • dot_iu_command_run_run_mode_check: run_mode = ANY('{plan,apply,verify}')
  • dot_iu_command_run_run_status_check: run_status = ANY('{planned,applied,verified,refused,failed}')
  • fn_dot_iu_command_log raises check_violation if command not in catalog once catalog is seeded (fail-closed).
  • No triggers on dot_iu_command_catalog / dot_iu_command_run; no FK run→catalog.

axis_b_tags structure (one knowledge_systems IU):

{ "topic":["topic:architecture","topic:knowledge_graph"], "unit_kind":["kind:law_unit"],
  "legal_domain":["legal_domain:knowledge_systems"], "section_type":["sectype:section"],
  "legal_document":["doc:DIEU-39","doc:knowledge/dev/laws/dieu39-knowledge-graph-law.md"] }

⇒ axis_b_tags is keyed by tag_kind; the wrapper looks up tag_kind from iu_metadata_tag_registry (tag prefixes like doc:/kind:/sectype: differ from the kind name) and tests membership with the @> containment operator (channel-robust; ?/jsonb_exists are mangled by the read channel's parameter parser, but @> is correct and equivalent for array membership).


A4 — Migration SQL (verbatim, abridged to structure)

Single TX. Full body in /tmp/mig_bcf_dot_wrappers.sql.

\set ON_ERROR_STOP on
BEGIN;
-- guard: current_database()='directus'; catalog=42; none of the 5 names pre-exist (else RAISE)
CREATE OR REPLACE FUNCTION public.fn_iu_filter_axis_b(p_tag_key text DEFAULT NULL, p_sample_limit int DEFAULT 10) RETURNS jsonb LANGUAGE sql STABLE AS $$ ... $$;
CREATE OR REPLACE FUNCTION public.fn_iu_filter_axis_c_subtree(p_root uuid, p_sample_limit int DEFAULT 100) RETURNS jsonb LANGUAGE sql STABLE AS $$ ...uses public.fn_iu_subtree(p_root)... $$;
CREATE OR REPLACE FUNCTION public.fn_iu_sql_link_validate_all() RETURNS jsonb LANGUAGE sql STABLE AS $$ ...public.fn_iu_sql_link_validate(l.id)... $$;
CREATE OR REPLACE FUNCTION public.fn_iu_sql_link_resolve_all() RETURNS jsonb LANGUAGE sql STABLE AS $$ ...v_iu_sql_link_resolved + cross-check vs direct fn... $$;
CREATE OR REPLACE FUNCTION public.fn_iu_bcf_harness_run(p_actor text DEFAULT 'iu_bcf_harness', p_b_tag_key text DEFAULT 'legal_domain:knowledge_systems', p_c_root uuid DEFAULT 'cb211ee6-2b61-496e-b191-ef502ea28345', p_b_expected_iu int DEFAULT 16, p_c_expected_nodes int DEFAULT 8) RETURNS jsonb LANGUAGE plpgsql VOLATILE AS $$ ...calls 4 wrappers; logs 5 rows via public.fn_dot_iu_command_log; returns bundle... $$;
INSERT INTO public.dot_iu_command_catalog(command_name,category,mutating,reversible,target_functions) VALUES
 ('dot_iu_filter_axis_b','read',false,true,ARRAY['fn_iu_filter_axis_b']),
 ('dot_iu_subtree','read',false,true,ARRAY['fn_iu_filter_axis_c_subtree','fn_iu_subtree']),
 ('dot_iu_sql_link_validate','read',false,true,ARRAY['fn_iu_sql_link_validate_all','fn_iu_sql_link_validate']),
 ('dot_iu_sql_link_resolve','read',false,true,ARRAY['fn_iu_sql_link_resolve_all','fn_iu_sql_link_validate']),
 ('dot_iu_test_harness_run','read',false,true,ARRAY['fn_iu_bcf_harness_run']);
-- post-check: catalog=47, 5 new functions present (else RAISE)
COMMIT;

b consistency fragment (the core of fn_iu_filter_axis_b detail branch):

(SELECT count(*) FROM matched m JOIN iu_three_axis_envelope e ON e.unit_id=m.iu_id
  WHERE (e.axis_b_tags -> (SELECT tag_kind FROM sel_kind)) @> to_jsonb(p_tag_key)) AS denormalized_consistent

c integrity fragment (the core of fn_iu_filter_axis_c_subtree): the six counts (orphan_dangling_parent, self_parent_cycle, self_in_ancestors_cycle, root_with_nonzero_depth, depth0_with_parent_stale, stored_depth_parent_mismatch) are the same SELECTs as proof appendix C5, embedded as global_integrity.


A5 — Apply transcript

Dry-run (COMMIT→ROLLBACK):

BEGIN
DO
CREATE FUNCTION  (×5)
INSERT 0 5
DO
ROLLBACK
post: catalog=42 runs=45

Real apply:

BEGIN
DO
CREATE FUNCTION  (×5)
INSERT 0 5
DO
COMMIT

Object diff:

catalog rows (new 5): dot_iu_filter_axis_b|read|f|t|{fn_iu_filter_axis_b}
                      dot_iu_subtree|read|f|t|{fn_iu_filter_axis_c_subtree,fn_iu_subtree}
                      dot_iu_sql_link_validate|read|f|t|{fn_iu_sql_link_validate_all,fn_iu_sql_link_validate}
                      dot_iu_sql_link_resolve|read|f|t|{fn_iu_sql_link_resolve_all,fn_iu_sql_link_validate}
                      dot_iu_test_harness_run|read|f|t|{fn_iu_bcf_harness_run}
functions: fn_iu_bcf_harness_run=volatile; fn_iu_filter_axis_b/_c_subtree/sql_link_validate_all/resolve_all=stable

A6 — Harness runs (workflow_admin)

SELECT public.fn_iu_bcf_harness_run(); ×2 → extracted pipe-delimited verdict|b|b_iu|b_consist|c|c_nodes|c_maxdepth|f|f_resolved|f_total|f_vieweqdirect:

Run #1: PASS|PASS|16|true|PASS|8|2|PASS|3|3|true
Run #2: PASS|PASS|16|true|PASS|8|2|PASS|3|3|true

Audit breakdown (actor='iu_bcf_harness', after 2 runs):

dot_iu_filter_axis_b      | verified | 2
dot_iu_sql_link_resolve   | verified | 2
dot_iu_sql_link_validate  | verified | 2
dot_iu_subtree            | verified | 2
dot_iu_test_harness_run   | verified | 2
dot_iu_command_run total  : 55  (baseline 45, Δ+10)

A7 — Read-only parity (context_pack_readonly calling the STABLE wrappers)

SELECT (fn_iu_filter_axis_b('legal_domain:knowledge_systems')->>'iu_count'),
       (fn_iu_filter_axis_b('legal_domain:knowledge_systems')->'axis_b_consistency'->>'consistent'),
       (fn_iu_filter_axis_c_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')->>'node_count'),
       (fn_iu_filter_axis_c_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')->>'max_relative_depth'),
       (fn_iu_filter_axis_c_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')->'global_integrity'->>'orphan_dangling_parent'),
       (fn_iu_filter_axis_c_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')->'global_integrity'->>'depth0_with_parent_stale'),
       (fn_iu_sql_link_validate_all()->>'total_links'),
       (fn_iu_sql_link_validate_all()->>'resolved_true'),
       (fn_iu_sql_link_resolve_all()->>'all_view_eq_direct');

16 | true | 8 | 2 | 0 | 23 | 3 | 3 | true

Identical to both harness runs and to the pure read-only proof (b=16/consistent, c=8/depth-2/0-orphan/23-stale, f=3/3/view==direct). The read-only role executing these confirms the four wrappers are SELECT-only/STABLE.


A8 — Row-count matrix (before → after)

information_unit        216 -> 216   Δ0
iu_three_axis_envelope  216 -> 216   Δ0
iu_metadata_tag         536 -> 536   Δ0
iu_tree_path            199 -> 199   Δ0
iu_relation              60 ->  60   Δ0
iu_sql_link               3 ->   3   Δ0
iu_split_set              0 ->   0   Δ0
iu_merge_set              0 ->   0   Δ0
event_outbox        149095 -> 149095 Δ0
iu_route_attempt         68 ->  68   Δ0
iu_outbound_route        15 ->  15   Δ0
dot_iu_command_catalog   42 ->  47   Δ+5  (additive DOT pairs)
dot_iu_command_run       45 ->  55   Δ+10 (audit footprint, 2 runs × 5)

A9 — Rollback SQL (verbatim, structure)

\set ON_ERROR_STOP on
BEGIN;
DELETE FROM public.dot_iu_command_run WHERE actor='iu_bcf_harness'
  AND command_name IN ('dot_iu_filter_axis_b','dot_iu_subtree','dot_iu_sql_link_validate','dot_iu_sql_link_resolve','dot_iu_test_harness_run');
DELETE FROM public.dot_iu_command_catalog
  WHERE command_name IN ('dot_iu_filter_axis_b','dot_iu_subtree','dot_iu_sql_link_validate','dot_iu_sql_link_resolve','dot_iu_test_harness_run');
DROP FUNCTION IF EXISTS public.fn_iu_bcf_harness_run(text,text,uuid,integer,integer);
DROP FUNCTION IF EXISTS public.fn_iu_sql_link_resolve_all();
DROP FUNCTION IF EXISTS public.fn_iu_sql_link_validate_all();
DROP FUNCTION IF EXISTS public.fn_iu_filter_axis_c_subtree(uuid,integer);
DROP FUNCTION IF EXISTS public.fn_iu_filter_axis_b(text,integer);
-- assert catalog=42 and 0 new functions, else RAISE
COMMIT;

Reverts to exact baseline: catalog 42, command_run 45, 0 new functions. Existing fn_iu_subtree/fn_iu_sql_link_validate/fn_dot_iu_command_log untouched.

Back to Knowledge Hub knowledge/dev/reports/architecture/iu-b-c-f-additive-dot-wrapper-and-harness-live-apply-appendix-2026-05-28.md