Algebraic Semantics of Governed Execution:
Monoidal Categories, Effect Algebras, and Coterminous Boundaries
May 01, 2026
We present an algebraic semantics for governed execution in which governance is axiomatized, compositional, and coterminous with expressibility. The framework, mechanized in 32 Rocq modules ( 12,000 lines, 454 theorems, 0 admitted), is built on interaction trees and parameterized coinduction.
A three-axiom GovernanceAlgebra record (safety, transparency, properness) induces a symmetric monoidal category with verified pentagon, triangle, and hexagon coherence, where every tensor composition preserves governance. An algebraic effect
system constrains the handler algebra so that only governance-preserving handlers can be constructed in the safe fragment; programs in the empty capability set provably emit only observability directives. Capability-indexed composition bundles programs
with machine-checked capability bounds, and a dual guarantee theorem establishes that within_caps and gov_safe hold simultaneously under all composition operators.
The capstone result is the coterminous boundary: within our formal model, every program expressible via the four primitive morphism constructors is governed under interpretation, and every governed program is the image of such a program. Turing completeness is preserved inside governance; unmediated I/O is excluded from the governed fragment. Governance denial is modeled as safe coinductive divergence.
The governance algebra is parametric: any system instantiating the three axioms inherits all derived properties, including convergence, compositional closure, and goal preservation. Extracted OCaml runs as a NIF in the BEAM runtime, with property-based testing (70,000+ random inputs, zero disagreements) confirming behavioral equivalence between the specification and the runtime interpreter.
AI workflow systems compose language model calls with data retrieval, code execution, and external API access. Governance of these systems currently takes two forms. Behavioral approaches (RLHF [1], constitutional AI [2], guardrails [3]) train or filter model outputs but do not address whether the system’s effects (API calls, file writes, tool invocations) pass through any governance boundary. Structural approaches enforce invariants at the execution layer, but existing formalizations either lack machine-checked proofs or do not address composition: they verify individual programs rather than establishing that governance is closed under the system’s composition operators.
This paper develops an algebraic semantics for governed execution: a framework in which governance is axiomatized as a three-property algebra, compositional under all program combinators, and, within the formalized execution model, coterminous with expressibility. The central thesis is:
Governance, when formalized as an algebraic structure over interaction trees, induces compositional properties on programs, effects, and capabilities such that the governed fragment coincides with the expressible fragment in the modeled substrate.
Prior papers in this line establish structural governance at the architectural level [4], expressive completeness via four primitives [5], and machine-checked safety proofs for the specific runtime [6]. The present paper abstracts and unifies those system-specific results into an algebraic semantics. The GovernanceAlgebra axiomatization lifts safety theorems to parametric results that hold for any system satisfying three axioms. The monoidal, effect, and capability layers explain why the system’s programs compose under governance, not just why individual programs are safe. Two companion papers address practical enforcement: [7] discharges the pure module constraint assumed by the safety theorems, replacing convention-based enforcement with WASM compilation and cryptographic purity certificates; [8] extends the governance boundary to the supply chain with dual-signature distribution provenance.
We distinguish three levels that the paper addresses:
Syntactic expressibility: a program is constructible from the four primitive morphisms (code, reason, memory, call) via composition in category \(\mathbf{Mashin}\).
Semantic governance under interpretation: interpreting a program through the governance operator \(\mathcal{G}\) yields a tree satisfying the coinductive gov_safe predicate.
Trace-level evidence: the execution trace extracted from a governed program is well-governed (every I/O event preceded by a governance check) and maps to a tamper-evident ledger.
The coterminous boundary result connects levels 1 and 2: every syntactically expressible program is semantically governed under interpretation. Level 3 is a derived consequence (Section 7).
The paper makes four contributions, each mechanized in Rocq:
GovernanceAlgebra and monoidal structure (Sections 3–4). A three-axiom parametric record from which convergence, compositional closure, and goal preservation are derived. Category \(\mathbf{Mashin}\) admits a symmetric monoidal structure with verified pentagon, triangle, and hexagon coherence. All tensor compositions preserve governance.
Governed algebraic effects (Section 5). An algebraic effect system in which the handler algebra is constrained: only handlers carrying a machine-checked safety certificate (GovernedHandler) can be constructed in the governed fragment. The No Ambient Effects theorem proves that programs in the empty capability set emit only observability directives.
Capability-indexed composition with dual guarantee (Section 6). CapMorphisms bundle programs with capability bounds verified by a trust lattice. Composition operators (sequential, tensor,
branch) preserve bounds. The dual guarantee establishes that within_caps and gov_safe hold simultaneously.
Coterminous boundary (Section 8). Within the formalized execution model, every expressible program is governed, and every governed program is the image of an expressible program. Turing completeness is preserved inside governance. Unmediated I/O is excluded from the governed fragment.
Section 7 derives trace semantics and ledger connection as consequences of the algebraic framework. Section 9 discusses mechanization and extraction to OCaml. Section 10 positions the work relative to prior results on algebraic effects, monoidal categories, and verified systems.
The individual ingredients (monoidal categories, algebraic effects, coinductive predicates, capability systems) are well-established. To our knowledge, this is the first mechanized framework combining governance-constrained interpretation, capability-bounded algebraic effects, and a coterminous expressibility/governance theorem over an interaction-tree-based execution model. The GovernanceAlgebra axiomatization is parametric: the derived theorems hold for any system satisfying three axioms, not only the concrete system we instantiate.
All formalizations use the Interaction Trees library [9], which represents programs as coinductive trees with three node types: pure values (\(\mathrm{Ret}\)), silent steps (\(\mathrm{Tau}\)), and visible events (\(\mathrm{Vis}\)). The governance pipeline transforms trees of directive events (\(\mathrm{DirectiveE}\)) into trees of governed events (\(\mathrm{GovIOE}\)). Coinductive properties are proved using the paco library [10] for parameterized coinduction.
An interaction tree \(\mathrm{itree}\;E\;R\) is a potentially infinite tree coinductively defined by three constructors: \[\begin{align} \mathrm{Ret}(r) &\quad \text{pure value of type } R \\ \mathrm{Tau}(t) &\quad \text{silent computation step} \\ \mathrm{Vis}(e, k) &\quad \text{event } e : E\;X, \text{ continuation } k : X \to \mathrm{itree}\;E\;R \end{align}\]
Interaction trees form a monad: \(\mathrm{ret}\) injects values and \(\mathbin{>\!\!>\!\!=}\) sequences computations. Interpretation via handlers \(h : \forall X.\; E\;X \to \mathrm{itree}\;F\;X\) transforms \(\mathrm{itree}\;E\;R\) into \(\mathrm{itree}\;F\;R\). Equivalence is eutt (equivalence up to taus): two trees are equivalent if they produce the same visible events and return values, ignoring silent steps.
The system’s effect signature is \(\mathrm{DirectiveE}\), an inductive type with 14 constructors covering all external capabilities:
Inductive DirectiveE : Type -> Type :=
| LLMCall : LLMCallParams -> DirectiveE LLMResponse
| HTTPRequest : HTTPRequestParams -> DirectiveE HTTPResponse
| FileOp : FileOpParams -> DirectiveE FileResult
| CallMachine : CallMachineParams -> DirectiveE CallMachineResult
| MemoryOp : MemoryOpParams -> DirectiveE MemoryResult
| DBOp : DBOpParams -> DirectiveE DBResult
| ExecOp : ExecOpParams -> DirectiveE ExecResult
| RecordStep : RecordStepParams -> DirectiveE unit
| Broadcast : BroadcastParams -> DirectiveE unit
| EmitEvent : EmitEventParams -> DirectiveE unit
| GraphQLRequest : GraphQLRequestParams -> DirectiveE HTTPResponse
| WebSocketOp : WebSocketOpParams -> DirectiveE WebSocketResult
| MCPCall : MCPCallParams -> DirectiveE CallMachineResult
| Observability : string -> DirectiveE unit.
The governed event type layers governance checks over I/O: \(\mathrm{GovIOE}= \mathrm{GovE}+ \mathrm{IOE}\), where \(\mathrm{GovE}\) carries governance stage checks and \(\mathrm{IOE}\) carries actual I/O events.
The operator \(\mathcal{G}: \mathrm{base\_handler} \to \mathrm{governed\_handler}\) wraps a base handler with governance checks. Before each I/O operation, \(\mathcal{G}\) emits a \(\mathrm{GovCheck}\) event; only if governance approves does the handler proceed. The key property is the coinductive safety predicate \(\texttt{gov\_safe}\):
Definition 1 (gov_safe). \(\texttt{gov\_safe}(a, t)\) holds coinductively for a governed tree \(t : \mathrm{itree}\;\mathrm{GovIOE}\;R\) with permission flag \(a : \mathrm{bool}\) if:
\(\mathrm{Ret}(r)\): always safe.
\(\mathrm{Tau}(t')\): safe if \(t'\) is safe.
\(\mathrm{Vis}(\mathrm{inl}_1(\mathrm{GovCheck}(s)), k)\): safe if both branches (\(k(\mathrm{true})\) with \(a := \mathrm{true}\), \(k(\mathrm{false})\) with \(a := \mathrm{false}\)) are safe.
\(\mathrm{Vis}(\mathrm{inr}_1(e), k)\): safe only if \(a = \mathrm{true}\) (governance has approved) and \(\forall x.\; \texttt{gov\_safe}(\mathrm{false}, k(x))\).
The fundamental safety theorem, proved in prior work [6]:
Theorem 1 (governed_interp_safe). For any base handler \(h\) and program \(t : \mathrm{itree}\;\mathrm{DirectiveE}\;R\), \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), t))\).
The category \(\mathbf{Mashin}\) has types as objects and Kleisli arrows \(A \to \mathrm{itree}\;\mathrm{DirectiveE}\;B\) as morphisms. Identity is \(\mathrm{ret}\), composition is monadic bind (\(\mathbin{>\!\!>\!\!=}\)). Four primitive morphism constructors generate all programs:
\(\mathrm{\small code}(f) : A \to B\) – pure computation, \(\mathrm{ret}(f(a))\)
\(\mathrm{\small reason}(\mathrm{build}, \mathrm{extract}) : A \to B\) – LLM inference
\(\mathrm{\small memory}(\mathrm{build}, \mathrm{extract}) : A \to B\) – semantic storage
\(\mathrm{\small call}(\mathrm{build}, \mathrm{extract}) : A \to B\) – machine invocation
Category laws (identity, associativity) hold up to eutt, proved in Category.v [6].
The central abstraction is a three-axiom record that captures what it means to be a governance operator.
Definition 2 (GovernanceAlgebra). A GovernanceAlgebra is a record \((\mathrm{ga\_Gov}, \mathrm{ga\_safe}, \mathrm{ga\_transparent}, \mathrm{ga\_proper})\) where:
\(\mathrm{ga\_Gov} : \mathrm{base\_handler} \to \mathrm{governed\_handler}\)
G1 (Safety): \(\forall h, R, a, t.\; \texttt{gov\_safe}(a, \mathrm{interp}(\mathrm{ga\_Gov}(h), t))\)
G2 (Transparency): Under permissive governance (all checks pass), governed interpretation is observationally equivalent to ungoverned interpretation.
G3 (Properness): Equivalent handlers produce equivalent governed handlers (eutt-preservation).
The three axioms are independent. Safety does not imply transparency: an operator could alter permitted results. Transparency does not imply safety: an operator could be transparent without wrapping I/O with governance checks. Properness is orthogonal to both.
From these three axioms, we derive:
Theorem 2 (ga_convergence). For any GovernanceAlgebra \(G\), handler \(h\), level \(n\), and program \(t : \mathrm{machine\_at\_level}\;n\;R\): \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathrm{ga\_Gov}(G, h), t))\).
This follows because \(\mathrm{machine\_at\_level}\;n\;R\) is definitionally \(\mathrm{itree}\;\mathrm{DirectiveE}\;R\) for all \(n\), so G1 applies directly. Governance holds uniformly across the meta-recursive tower.
Theorem 3 (ga_subsumption_asymmetry). For any GovernanceAlgebra \(G\):
Any program, including one whose handler incorporates content-governance logic (output filtering, alignment constraints), is governed when interpreted through \(\mathrm{ga\_Gov}\): \(\forall h, R, t.\; \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathrm{ga\_Gov}(G, h), t))\)
Unmediated I/O (a handler that performs effects without governance checks) does not satisfy gov_safe: \(\forall R, e : \mathrm{IOE}\;R, k.\; \neg\, \texttt{gov\_safe}(\mathrm{false},
\mathrm{Vis}(\mathrm{inr}_1(e), k))\)
The positive direction follows from G1. The negative direction follows from \(\texttt{bare\_io\_not\_safe}\): bare I/O nodes in the governed tree violate gov_safe because no governance check has approved
them. This is a property of the gov_safe predicate, independent of any particular operator. The asymmetry is a theorem about the formal model: structural governance (effect mediation via \(\mathcal{G}\))
provides a guarantee that output-oriented controls alone cannot replicate within this framework, because output controls do not address the governance-check structure of the interaction tree.
Theorem 4 (ga_goal_preservation). For any GovernanceAlgebra \(G\), if a program reaches value \(v\) under ungoverned interpretation, it reaches the same value under permissive governed interpretation.
This follows from G2 (transparency): permissive governance erases the governance events and preserves the base handler’s semantics.
The concrete Mashin operator \(\mathcal{G}\) instantiates the record:
Definition mashin_governance : GovernanceAlgebra :=
mk_gov_algebra Gov
governed_interp_safe (* G1 from Safety.v *)
governed_transparency (* G2 from Transparency.v *)
Gov_base_proper. (* G3 from Functor.v *)
All derived properties immediately apply to \(\mathcal{G}\). The algebra-level theorems (any_governance_algebra_subsumes, any_governance_algebra_converges,
any_governance_algebra_preserves_goals) establish these properties for any operator satisfying the three axioms.
We extend category \(\mathbf{Mashin}\) with symmetric monoidal structure.
Given morphisms \(f : A \to \mathrm{itree}\;\mathrm{DirectiveE}\;B\) and \(g : C \to \mathrm{itree}\;\mathrm{DirectiveE}\;D\), the tensor product \(f \otimes g : (A \times C) \to \mathrm{itree}\;\mathrm{DirectiveE}\;(B \times D)\) is defined as sequential-independent composition:
Definition mashin_tensor {A B C D}
(f : mashin_morphism A B)
(g : mashin_morphism C D)
: mashin_morphism (A * C) (B * D) :=
fun p =>
let (a, c) := p in
ITree.bind (f a) (fun b =>
ITree.bind (g c) (fun d =>
ret (b, d))).
The two computations share no state; \(f\)’s effects complete before \(g\)’s begin. This is not true concurrent interleaving, which would require a more complex construction (noted as future work in Section 11).
Lemma 1 (tensor_id). \(\mathrm{id} \otimes \mathrm{id} = \mathrm{id}\).
Lemma 2 (tensor_pure). \(\mathrm{\small code}(f) \otimes \mathrm{\small code}(g) = \mathrm{\small code}(\lambda(a,c).\;(f(a), g(c)))\). The pure fragment is closed under tensor.
The unit object is \(\mathrm{unit}\). Structural isomorphisms are all pure (no effects):
Associator \(\alpha : (A \otimes B) \otimes C \xrightarrow{\sim} A \otimes (B \otimes C)\)
Left unitor \(\lambda : I \otimes A \xrightarrow{\sim} A\)
Right unitor \(\rho : A \otimes I \xrightarrow{\sim} A\)
Braiding \(\sigma : A \otimes B \xrightarrow{\sim} B \otimes A\)
Each isomorphism is verified by round-trip lemmas (assoc_iso_lr/assoc_iso_rl, lunit_iso_lr/lunit_iso_rl, runit_iso_lr/runit_iso_rl, braid_iso).
Theorem 5 (Pentagon). The following diagram commutes: \[\begin{tikzcd}[column sep=small] ((A \otimes B) \otimes C) \otimes D \arrow[rr, "\alpha \otimes \mathrm{id}"] \arrow[d, "\alpha"'] & & (A \otimes (B \otimes C)) \otimes D \arrow[d, "\alpha"] \\ (A \otimes B) \otimes (C \otimes D) \arrow[dr, "\alpha"'] & & A \otimes ((B \otimes C) \otimes D) \arrow[dl, "\mathrm{id} \otimes \alpha"] \\ & A \otimes (B \otimes (C \otimes D)) & \end{tikzcd}\] Both paths yield the same morphism (up to eutt).
Theorem 6 (Triangle). \(\alpha \mathbin{;} (\mathrm{id} \otimes \lambda) = \rho \otimes \mathrm{id}\) as morphisms \((A \otimes I) \otimes B \to A \otimes B\).
Theorem 7 (Hexagon). The braiding coherence diagram commutes: \(\alpha \mathbin{;} \sigma \mathbin{;} \alpha = (\sigma \otimes \mathrm{id}) \mathbin{;} \alpha \mathbin{;} (\mathrm{id} \otimes \sigma)\).
All three proofs proceed by unfolding definitions and applying bind_ret_l repeatedly, since the structural morphisms are pure. The proofs are short (under 10 lines each) precisely because purity makes coherence computational rather than
coinductive.
Theorem 8 (tensor_governed). For any handler \(h\), morphisms \(f, g\), and input \(p\): \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), (f \otimes g)(p)))\).
Theorem 9 (ga_tensor_governed). For any GovernanceAlgebra \(G\): \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathrm{ga\_Gov}(G, h), (f \otimes g)(p)))\).
Theorem 10 (interp_tensor_distribute). Interpretation distributes over tensor: \[\mathrm{interp}(\mathcal{G}(h), (f \otimes g)(a, c)) \quad\equiv\quad \mathrm{interp}(\mathcal{G}(h), f(a)) \mathbin{>\!\!>\!\!=}\lambda b.\; \mathrm{interp}(\mathcal{G}(h), \mathrm{bind}(g(c), \lambda d.\; \mathrm{ret}(b, d)))\] Governance of the product decomposes into governance of the components.
Standard algebraic effect systems [11], [12]
define handlers that interpret effects freely: any function of the right type is a valid handler. In our framework, the governed fragment admits only handlers that carry a machine-checked proof of safety preservation. This is not merely a matter of record
packaging; it is a semantic exclusion. A handler that performs I/O without emitting governance checks cannot inhabit the GovernedHandler type, because its interpretation would produce trees violating gov_safe, and the required
proof obligation cannot be discharged.
A capability set is a characteristic function \(\mathrm{CapSet}= \mathrm{Capability} \to \mathrm{bool}\) with standard operations:
Definition cap_empty : CapSet := fun _ => false.
Definition cap_singleton (c : Capability) : CapSet :=
fun c' => cap_eqb c c'.
Definition cap_union (s1 s2 : CapSet) : CapSet :=
fun c => s1 c || s2 c.
Definition cap_full : CapSet := fun _ => true.
\((\mathrm{CapSet}, \subseteq)\) forms a bounded partial order with \(\emptyset\) as bottom and \(\mathrm{cap\_full}\) as top. Union is join: \(\cap\) is idempotent (cap_union_idem), commutative (cap_union_comm), and associative (cap_union_assoc).
Definition 3 (within_caps). The coinductive predicate \(\texttt{within\_caps}(\mathrm{caps}, t)\) holds for \(t : \mathrm{itree}\;\mathrm{DirectiveE}\;R\) if every directive event in \(t\) requires only capabilities present in \(\mathrm{caps}\) (or no capability at all):
\(\mathrm{Ret}(r)\): always within any caps.
\(\mathrm{Tau}(t')\): within caps if \(t'\) is.
\(\mathrm{Vis}(d, k)\): within caps if \(\mathrm{directive\_in\_caps}(\mathrm{caps}, d)\) and \(\forall x.\; \texttt{within\_caps}(\mathrm{caps}, k(x))\).
This uses paco1 (parameterized coinduction with one parameter) since the capability set is fixed during the coinduction.
Lemma 3 (within_caps_weaken). If \(\mathrm{caps}_1 \subseteq \mathrm{caps}_2\) and \(\texttt{within\_caps}(\mathrm{caps}_1, t)\), then \(\texttt{within\_caps}(\mathrm{caps}_2, t)\).
Lemma 4 (within_full). \(\forall t.\; \texttt{within\_caps}(\mathrm{cap\_full}, t)\).
Each primitive has a tight capability bound:
Theorem 11 (Primitive profiles).
code_within_empty: \(\texttt{within\_caps}(\emptyset, \mathrm{\small code}(f)(a))\). Pure computation needs no capabilities.
reason_within_llm: \(\texttt{within\_caps}(\{\mathrm{CapComputeLLMReason}\}, \mathrm{\small reason}(\ldots)(a))\).
memory_within_mem: \(\texttt{within\_caps}(\{\mathrm{CapMemory}\}, \mathrm{\small memory}(\ldots)(a))\).
call_within_call: \(\texttt{within\_caps}(\{\mathrm{CapMachineCall}\}, \mathrm{\small call}(\ldots)(a))\).
Theorem 12 (bind_within_caps). If \(\texttt{within\_caps}(\mathrm{caps}_1, t)\) and \(\forall r.\; \texttt{within\_caps}(\mathrm{caps}_2, k(r))\), then \(\texttt{within\_caps}(\mathrm{caps}_1 \cup \mathrm{caps}_2, t \mathbin{>\!\!>\!\!=}k)\).
The proof uses pcofix (parameterized coinduction) with case analysis on \(\mathrm{observe}(t)\). The \(\mathrm{Ret}\) case applies weakening from \(\mathrm{caps}_2\) to \(\mathrm{caps}_1 \cup \mathrm{caps}_2\). The \(\mathrm{Vis}\) case applies directive_in_caps_mono for the directive and the
coinductive hypothesis for the continuation.
Corollary 1 (seq_comp_caps). \(\texttt{within\_caps}(\mathrm{caps}_1, f(a)) \wedge (\forall b.\; \texttt{within\_caps}(\mathrm{caps}_2, g(b))) \implies \texttt{within\_caps}(\mathrm{caps}_1 \cup \mathrm{caps}_2, (f \mathbin{;} g)(a))\).
Theorem 13 (no_ambient_effects). If \(\texttt{within\_caps}(\emptyset, t)\) and \(\mathrm{observe}(t) = \mathrm{Vis}(d, k)\), then \(\mathrm{is\_observability}(d) = \mathrm{true}\).
A program within the empty capability set can only emit observability directives. It cannot perform LLM calls (llm_not_in_empty), HTTP requests (http_not_in_empty), machine calls (call_not_in_empty), or any other
effectful action. This is the algebraic characterization of the “no ambient effects” property: effect capability is not ambient but must be structurally present in the program’s capability set.
Definition 4 (GovernedHandler). A GovernedHandler is a base handler bundled with its safety proof:
Record GovernedHandler := mk_governed_handler {
gh_handler : base_handler;
gh_safe : forall R (t : itree DirectiveE R),
@gov_safe R false (interp (Gov gh_handler) t)
}.
Theorem 14 (Gov_governed). Every base handler has a governed version: \(\mathrm{Gov\_governed}(h) : \mathrm{GovernedHandler}\).
Handler equivalence (\(\mathrm{gh\_equiv}\)) is an equivalence relation (reflexive, symmetric, transitive). Both \(\mathrm{Gov\_endo}\) and \(\mathrm{Gov\_iter}\) preserve this equivalence (Gov_endo_preserves_gh_equiv, Gov_iter_preserves_gh_equiv).
Theorem 15 (composed_handlers_governed). Given two GovernedHandlers \(g_1, g_2\), for any program \(t\) and continuation \(k\): \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(g_1.\mathrm{handler}), t))\) and \(\forall r.\; \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(g_2.\mathrm{handler}), k(r)))\).
The structural difference from standard algebraic effect systems [11], [13] is that those systems impose no constraint on what a handler does with an effect. Here, the GovernedHandler record requires a proof that interpretation through \(\mathcal{G}\) satisfies gov_safe. Handlers lacking this proof cannot be used in governed composition. The handler algebra is thus closed under governance-preserving operations but excludes handlers that would
bypass governance checks.
Trust levels form a bounded total order with six elements: \[\mathrm{Untrusted} < \mathrm{Tested} < \mathrm{Evaluated} < \mathrm{Reviewed} < \mathrm{Stdlib} < \mathrm{System}\]
Definition trust_le (t1 t2 : TrustLevel) : Prop :=
trust_value t1 <= trust_value t2.
The order is reflexive (trust_le_refl), transitive (trust_le_trans), antisymmetric (trust_le_antisym), and total (trust_le_total). \(\mathrm{Untrusted}\) is the bottom
(trust_bottom), \(\mathrm{System}\) is the top (trust_top).
Join and meet are computed by comparison of trust values:
Definition trust_max (t1 t2 : TrustLevel) : TrustLevel :=
if Nat.leb (trust_value t1) (trust_value t2) then t2 else t1.
Definition trust_min (t1 t2 : TrustLevel) : TrustLevel :=
if Nat.leb (trust_value t1) (trust_value t2) then t1 else t2.
A \(\mathrm{CapMorphism}\) bundles a morphism with its capability requirement and a proof that the morphism stays within those capabilities:
Record CapMorphism (A B : Type) := mk_cap_morphism {
cm_morph : mashin_morphism A B;
cm_caps : CapSet;
cm_within : forall a, within_caps cm_caps (cm_morph a)
}.
The four primitives yield canonical CapMorphisms:
| Primitive | CapMorphism | Caps |
|---|---|---|
| \(\mathrm{\small code}(f)\) | cap_code |
\(\emptyset\) |
| \(\mathrm{\small reason}(\ldots)\) | cap_reason |
\(\{\mathrm{CapComputeLLMReason}\}\) |
| \(\mathrm{\small memory}(\ldots)\) | cap_memory |
\(\{\mathrm{CapMemory}\}\) |
| \(\mathrm{\small call}(\ldots)\) | cap_call |
\(\{\mathrm{CapMachineCall}\}\) |
\(\mathrm{cap\_seq\_compose}(f, g)\) has capabilities \(\mathrm{caps}(f) \cup \mathrm{caps}(g)\), following from bind_within_caps.
\(\mathrm{cap\_tensor}(f, g)\) has capabilities \(\mathrm{caps}(f) \cup \mathrm{caps}(g)\).
Theorem 16 (tensor_within_caps). If \(\texttt{within\_caps}(\mathrm{caps}_1, f(a))\) and \(\texttt{within\_caps}(\mathrm{caps}_2, g(c))\), then \(\texttt{within\_caps}(\mathrm{caps}_1 \cup \mathrm{caps}_2, (f \otimes g)(a, c))\).
\(\mathrm{cap\_branch}(\mathrm{pred}, f, g)\) has capabilities \(\mathrm{caps}(f) \cup \mathrm{caps}(g)\), since either branch may execute.
Theorem 17 (code_contributes_nothing). \(\mathrm{caps}(\mathrm{cap\_seq\_compose}(\mathrm{cap\_code}(f), g)) \subseteq \mathrm{caps}(g)\) and symmetrically on the right.
Theorem 18 (same_caps_no_escalation). If \(\mathrm{caps}(f) = \mathrm{caps}(g)\), then \(\mathrm{caps}(\mathrm{cap\_seq\_compose}(f, g)) \subseteq \mathrm{caps}(f)\).
Both follow from the algebraic properties of \(\cup\) on CapSets (identity and idempotence).
The function \(\mathrm{allowed\_cap\_set}(\mathrm{tl}, \mathrm{declared})\) converts a trust level and declared capability list to a CapSet:
Theorem 19. System and Stdlib trust allow all capabilities (system_allows_all_caps, stdlib_allows_all_caps). Any program runs at System trust (system_within_any). Untrusted programs access only LLM
capabilities (untrusted_only_llm).
Definition 5 (is_principal). A CapMorphism has principal capabilities if its cap set is minimal: any cap set that works must include the declared caps.
Theorem 20 (code_principal, id_principal). Code morphisms and identity have principal capabilities (\(\emptyset\) is the smallest CapSet).
Theorem 21 (cap_morphism_governed). For any CapMorphism \(\mathrm{cm}\), handler \(h\), and input \(a\): \[\texttt{within\_caps}(\mathrm{cm}.\mathrm{caps}, \mathrm{cm}.\mathrm{morph}(a)) \quad\wedge\quad \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), \mathrm{cm}.\mathrm{morph}(a)))\]
Capabilities tell you what the program can do; governance ensures it passes through governance checks before doing it. These are independent properties that hold simultaneously. The dual guarantee is preserved by tensor
(tensor_dual_guarantee) and sequential composition (seq_dual_guarantee).
The preceding sections establish governance at the program level (coinductive gov_safe on interaction trees) and the capability level (within_caps on programs). This section derives the trace-level consequences: governed
execution produces well-governed traces that map to tamper-evident ledger entries.
Execution produces a finite trace of governance and I/O events:
Inductive TraceEvent :=
| TE_GovCheck : GovernanceStage -> bool -> TraceEvent
| TE_IO : string -> TraceEvent.
The inductive relation \(\mathrm{trace\_of}(t, \mathrm{trace}, r)\) extracts a trace from a governed computation, with constructors for return (empty trace), tau (transparent), governance checks (recorded), and I/O events (recorded).
Theorem 22 (trace_of_bind). If \(\mathrm{trace\_of}(t, \mathrm{trace}_1, x)\) and \(\mathrm{trace\_of}(k(x), \mathrm{trace}_2, r)\), then \(\mathrm{trace\_of}(t \mathbin{>\!\!>\!\!=}k, \mathrm{trace}_1 \mathbin{+\!\!+} \mathrm{trace}_2, r)\).
Traces compose under monadic bind: the trace of a sequential composition is the concatenation of the component traces. The proof proceeds by induction on the derivation of \(\mathrm{trace\_of}\), using \(\mathrm{unfold\_bind}\) and \(\mathrm{bisimulation\_is\_eq}\) at each case.
Definition 6 (well_governed_trace). A trace is well-governed if every I/O event is preceded by at least one passing governance check. Formally, \(\mathrm{trace\_governed}(\mathrm{false}, \mathrm{trace})\) where the boolean tracks whether a passing check has been seen.
The empty trace is governed (well_governed_nil). A governance check preserves the property (well_governed_gov_only). A passing check followed by I/O is governed (well_governed_gov_then_io).
The LedgerConnection module, parameterized over an abstract hash type and injective hash function, connects traces to tamper-evident ledger entries. The abstraction assumes an ideal injective hash; connecting this to a concrete
cryptographic hash function (collision resistance rather than injectivity) requires additional formalization outside the scope of this paper.
Record LedgerEntry := mk_ledger_entry {
le_event : TraceEvent;
le_data : EventData;
le_prev_hash : Hash;
le_hash : Hash;
}.
Theorem 23 (trace_to_ledger_valid). For any trace, \(\mathrm{trace\_to\_ledger}(\mathrm{trace})\) satisfies \(\mathrm{ledger\_valid}\): entries are well-formed and hash-linked.
Theorem 24 (ledger_tamper_detected). If a ledger entry is well-formed and the recorded event is changed (while keeping the stored hash), the entry is no longer well-formed.
The proof follows from injectivity of the hash function and injectivity of event encoding.
Theorem 25 (ledger_complete). \(\mathrm{ev} \in \mathrm{trace} \iff \exists\, \mathrm{entry} \in \mathrm{trace\_to\_ledger}(\mathrm{trace}).\; \mathrm{le\_event}(\mathrm{entry}) = \mathrm{ev}\).
The ledger records exactly the trace events, with no omissions and no additions (trace_to_ledger_events).
Theorem 26 (governed_trace_ledger_valid). Well-governed traces produce valid ledgers.
The algebraic capstone combines all preceding results into a single record and theorem.
We define two sets relative to the formalized execution model:
\(E\) (expressible): programs constructible from the four primitive morphisms (code, reason, memory, call) via composition in category \(\mathbf{Mashin}\). These are interaction trees of type \(\mathrm{itree}\;\mathrm{DirectiveE}\;R\).
\(G\) (governed): programs \(t\) such that for all handlers \(h\), \(\texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), t))\).
The coterminous boundary theorem establishes \(E = G\): every expressible program is governed under interpretation, and every governed program is the image of an expressible program under \(\mathcal{G}\). This is a theorem about the modeled execution substrate, not a universal claim about all possible governance mechanisms or all possible programming languages.
Definition 7 (CoterminousRecord). A CoterminousRecord packages five properties:
ct_safety: \(\forall h, R, t.\; \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), t))\)
ct_nontrivial: \(\forall R, e, k.\; \neg\, \texttt{gov\_safe}(\mathrm{false}, \mathrm{Vis}(\mathrm{inr}_1(e), k))\)
ct_turing: \(\forall h, p, \mathrm{fuel}.\; \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), \mathrm{translate\_program}(p, \mathrm{fuel}, 0)))\)
ct_subsumption: Structural subsumes content (asymmetric)
ct_cognitive: \(\forall \mathrm{cap}.\; \mathrm{primitive\_realizes}(\mathrm{cap})\)
Theorem 27 (coterminous_boundary_exists). The CoterminousRecord is inhabited.
Proof. Each field is discharged by an existing theorem: ct_safety from governed_interp_safe_false, ct_nontrivial from bare_io_not_safe, ct_turing from ct_safety (register machine programs are \(\mathrm{itree}\;\mathrm{DirectiveE}\;\mathrm{unit}\)), ct_subsumption from subsumption_asymmetry, ct_cognitive from cognitive_surjection. ◻
Theorem 28 (boundary_equivalence). For any handler \(h\):
\(E \subseteq G\): every expressible program is governed.
Non-triviality: ungoverned I/O is not safe.
Turing completeness: register machine programs are governed.
The inclusion \(E \subseteq G\) says governance never fails to apply. The inclusion \(G \subseteq E\) follows from the construction: \(\mathcal{G}\) takes \(\mathrm{DirectiveE}\) programs as input; every governed program is the image of an expressible program.
Theorem 29 (gov_denial_is_conservative). \(\texttt{gov\_safe}(a, \mathrm{bind}(\mathrm{spin}, k))\) for all \(a, k\).
When governance denies a request, the computation diverges (non-termination). This is one conservative realization of denial: it produces no result at all, rather than an error value or an incorrect result. Alternative designs could model denial as an explicit error effect or a timeout; we chose divergence because it composes cleanly in the coinductive framework (a divergent sub-computation does not corrupt the enclosing computation’s safety properties) and avoids introducing a denial-specific effect constructor. The tradeoff is that divergence complicates refinement arguments and may obscure denial outcomes in practice; the runtime system detects denial via timeout rather than relying on the formal divergence semantics.
The coterminous boundary extends to traces: gov_safe_implies_governed_traces establishes that governed execution produces well-governed traces at the trace level, and gov_check_trace_governed shows that governance checks
preserve the well-governed property.
\(\mathcal{G}\) is an endofunctor (Functor.v: Gov_is_endofunctor) that wraps programs with governance. Under permissive governance (all checks pass), governed interpretation is observationally equivalent to
ungoverned interpretation (G2, transparency). The gov_permissive_preserves_expressiveness theorem confirms that governance does not reduce the set of expressible computations within the model.
Combined with the dual guarantee (Theorem 21), we obtain the complete picture:
Theorem 30 (The Governed Execution Invariant). For every program \(t\) expressible in \(\mathbf{Mashin}\) with capability profile \(\mathrm{caps}\) and handler \(h\): \[\texttt{within\_caps}(\mathrm{caps}, t) \quad\wedge\quad \texttt{gov\_safe}(\mathrm{false}, \mathrm{interp}(\mathcal{G}(h), t)) \quad\wedge\quad \mathrm{ledger\_valid}(\mathrm{trace\_to\_ledger}(\mathrm{trace}))\] Static capabilities bound what the program can do. Dynamic governance ensures every effect passes through checks. The ledger records every check with tamper evidence. These three properties hold simultaneously, for every expressible program, by construction.
The mechanization spans 36 modules ( 12,000 lines) with 454 theorems and zero admitted lemmas. Table 1 summarizes the development.
| Phase | Module | Lines |
|---|---|---|
| Foundation | Prelude, Directives, Governance, Interpreter | 663 |
| Safety | Safety | 507 |
| Structure | Category, Functor, Completeness | 1,331 |
| Trust | TrustSpec, HashChainSpec, InterpreterSpec | 1,066 |
| Cognitive | CognitiveArchitecture, Oracle, GoalDirected, Rice | 1,431 |
| Capstone | GovernedCognitiveCompleteness, Transparency, | |
| Convergence, Subsumption, ExpressiveMinimality | 1,303 | |
| Algebra | GovernanceAlgebra | 380 |
| Monoidal | MonoidalCategory | 437 |
| Effects | EffectAlgebra, EffectHandlers | 821 |
| Capability | CapabilityComposition | 645 |
| Traces | TraceSemantics, LedgerConnection | 769 |
| Boundary | CoterminousBoundary | 359 |
| Extraction | Extraction | 230 |
| Total | \(\approx\)12,000 |
The dependency structure is layered: foundation modules have no upstream dependencies within the project; each phase builds only on earlier phases. The build takes approximately 45 seconds on a modern laptop.
The gov_safe and within_caps predicates use paco (paco2 for the two-parameter gov_safe, paco1 for the one-parameter within_caps). The key insight is that the monotonicity lemma
(gov_safe_mon, within_caps_mon) enables compositional coinductive reasoning: once proved for the generating functor, the coinductive predicate inherits all properties automatically.
The pentagon, triangle, and hexagon proofs are each under 10 lines because the structural morphisms are pure: they unfold to \(\mathrm{ret}(\ldots)\), and \(\mathrm{bind}(\mathrm{ret}(x),
k)\) reduces to \(k(x)\) by bind_ret_l. Coherence is verified by computation rather than diagram chasing.
The bind_within_caps proof requires \(\mathrm{dependent\;destruction}\) on the within_capsF inversion in the \(\mathrm{Vis}\) case, because the directive type
\(X\) is existentially quantified in the tree constructor.
Modules with computational content in \(\mathrm{Type}\) or \(\mathrm{Set}\) are extracted to OCaml using Rocq’s extraction mechanism [14], [15]:
| Module | Extracted Functions |
|---|---|
| TrustSpec | capability_allowed, trust_at_least, |
capability_for_directive, cap_eqb |
|
| InterpreterSpec | interp_directive (as OCaml functor) |
| EffectAlgebra | cap_empty, cap_singleton, |
cap_union, directive_in_caps |
|
| CapabilityComposition | trust_max, trust_min, |
allowed_cap_set |
The InterpreterSpec module uses Rocq Section variables for the hash type, extracting as an OCaml functor parameterized over a hash signature. The functor is instantiated with a SHA-256 implementation.
The extracted OCaml is compiled to a shared library and linked as a NIF (Native Implemented Function) into the BEAM runtime, with a fallback to the Elixir implementation if the NIF is unavailable.
The system uses three-layer testing:
OCaml unit tests: Edge cases on extracted functions, comparing against Compute output from Rocq.
NIF round-trip tests: Exhaustive comparison between the NIF and the Elixir implementation for all trust/capability combinations.
Three-way property tests: The property-based testing framework generates 70,000+ random directive sequences and verifies agreement among: (a) the Rocq-extracted NIF, (b) the Elixir interpreter, and (c) the Elixir specification interpreter. Zero three-way disagreements across all test campaigns.
The property-based testing methodology follows s2n [16]: a formal specification in a proof assistant, extraction to executable code, and continuous comparison with the runtime implementation. The 188th random input in the original campaign discovered a real capability-tree bug [6], validating the approach.
The extracted governance kernel runs in the BEAM runtime’s directive execution path. Governed execution through a supervised process completes in 0.23 ms median, compared to 0.24 ms for direct ungoverned execution (bypassing all governance). The Rocq-extracted, formally verified code path adds no measurable overhead.1
Plotkin and Pretnar [11], [12] introduced
algebraic effects and handlers as a structured approach to computational effects, building on the algebraic theory of Plotkin and Power [17]. Subsequent work developed type systems for effect tracking: Koka’s row-typed effects [13], freer
monads [18], and dependently-typed effects in Idris [19]. Our framework differs in constraining the handler algebra itself: only handlers satisfying a governance proof obligation (GovernedHandler) can be used in governed composition. Programs interpreted through
ungoverned handlers do not satisfy gov_safe and are excluded from the governed fragment.
Mac Lane [20] established the coherence conditions for monoidal categories. Joyal and Street [21] developed the theory of braided tensor categories. Applied category theory has been used in programming language semantics [22], [23] and, more recently, as a framework for AI systems [24]. Our contribution is the combination of monoidal structure with governance safety: we verify not only coherence but also that every tensor composition is governed. The interaction tree representation makes coherence proofs computational (pure structural morphisms reduce by \(\beta\)) rather than requiring explicit diagram chasing.
seL4 [25] verified a complete OS kernel; CompCert verified a C compiler [26]; CertiKOS verified concurrent OS kernels [27]; Vellvm formalized LLVM IR semantics using interaction trees [28]. Our work is closest to Vellvm in technique (interaction trees in Rocq) but targets AI workflow governance rather than compiler/OS verification. The scale is smaller ( 12,000 lines vs. Vellvm’s \(\sim\)50,000) but covers a different domain. Amazon s2n’s continuous verification [16] inspired our specification-driven testing methodology.
The Gifford-Lucassen effect system [29], [30] introduced static tracking of computational effects. Capability-based security [31], [32] restricts access to resources via unforgeable tokens. Our capability sets function similarly to effect annotations, but with a crucial difference: the
gov_safe predicate is a runtime invariant enforced by the governance operator, not just a static type system property. The dual guarantee (Theorem 21) connects the static and dynamic views.
RLHF [1] and constitutional AI [2] govern LLM behavior via training signal. NeMo Guardrails [3] provides programmable guardrails for LLM
applications. These approaches operate on model outputs (what the model says). Our framework governs the system’s effects (what the system does). Theorem 3
establishes, within our formal model, that a content-governed handler wrapped with \(\mathcal{G}\) satisfies gov_safe, while unmediated I/O does not. The two approaches address different enforcement problems
and are complementary: content governance shapes output quality; structural governance ensures effect mediation.
Dalrymple et al. [33] propose a framework for guaranteed safe AI comprising a world model, a safety specification, and a verifier. Their framework identifies the right components but provides no mechanized formalization. Our work can be seen as supplying the algebraic semantics and machine-checked proofs for one instance of their architecture: the governance algebra is the safety specification, the interpreter is the verifier, and the governed interaction trees are the world model. The key difference is that their approach targets pre-deployment verification (proving safety before execution), while ours provides execution-time effect governance (ensuring safety structurally during execution). The approaches are complementary but address different points in the deployment lifecycle.
Song, Foo, and Chin [34] develop ESL, an expressive specification logic for verifying programs with unrestricted algebraic effects and handlers. Their work verifies that programs satisfy specifications given arbitrary handlers. Our work constrains the handler algebra itself: non-governed handlers cannot be constructed in the safe fragment (Theorem 15). The direction is reversed: they verify programs against handlers; we constrain handlers to governance. Vistrup et al. [35] develop modular program logics over interaction trees using Iris, sharing our ITree foundation but targeting shared-state concurrency and fine-grained reasoning about heap resources rather than AI governance and effect boundaries.
Session types [36] govern communication protocols via types. Like our approach, they provide structural guarantees. The difference is scope: session types govern message sequences between parties; our framework governs arbitrary effectful computation. Session types could complement our approach for inter-machine communication patterns.
Runtime verification [37] monitors execution traces against formal specifications. Our trace semantics (Section 7) formalizes the trace structure, and the ledger connection establishes tamper evidence. The key difference is that our governance is not post-hoc monitoring but structural: the gov_safe predicate is a
coinductive property of the governed program tree, guaranteed to hold before any execution begins.
We have presented an algebraic semantics for governed execution, formalized in 36 Rocq modules with 454 theorems and zero admitted lemmas. The central result is that governance, when axiomatized as a three-property algebra over interaction trees, induces compositional structure on programs, effects, and capabilities such that the governed fragment coincides with the expressible fragment in the modeled substrate. Turing completeness is preserved inside governance.
The four contributions are: (1) a parametric GovernanceAlgebra with verified monoidal structure; (2) a governed algebraic effect system where the handler algebra is closed under governance-preserving composition; (3) capability-indexed composition with the dual guarantee; (4) the coterminous boundary within the formal model.
The tensor product is sequential-independent, not truly concurrent. Concurrent interleaving would require a more complex construction (possibly using concurrent interaction trees or a process-algebraic extension). The hash chain formalization assumes an abstract injective hash function; connecting this to a concrete cryptographic hash (with collision resistance rather than injectivity) requires additional work. The extraction to OCaml NIF is one-directional: properties proved in Rocq constrain the extracted code, but the NIF wrapper (C bridge between Erlang and OCaml) is not itself verified. The three-layer testing strategy (property-based testing with 70,000+ inputs and zero disagreements, 36 conformance tests mapping to Rocq theorems, and the extraction pipeline itself) establishes the correspondence using the same methodology as seL4 and Amazon s2n.
The GovernanceAlgebra record has three axioms; whether these form a complete axiomatization (every valid governance operator satisfies them) remains open. The coterminous boundary is established for the specific four-primitive execution model; extending it to richer effect signatures or concurrent governance is future work. Denial-as-divergence is one conservative semantic choice; alternative formalizations using explicit denial effects may be preferable in settings where refinement reasoning is needed.
Mashin is a product of Mashin, Inc. The Rocq development uses the Interaction Trees library by Xia et al. [9] and the paco library by Hur et al. [10].
Table 2 lists all 36 modules with their primary theorems. All theorem names are valid Rocq identifiers that can be checked in the mechanization.
| Module | Lines | Primary Theorems |
|---|---|---|
| Prelude | 31 | (base definitions) |
| Directives | 245 | DirectiveE (14 constructors), directive_tag |
| Governance | 200 | Gov, gov_check, gov_safe |
| Interpreter | 187 | (interpreter structure) |
| Functor | 304 | Gov_is_endofunctor, Gov_factorization |
| Safety | 507 | governed_interp_safe, bare_io_not_safe |
| Convergence | 141 | governed_at_all_levels |
| Category | 343 | mashin_id, mashin_compose, category axioms |
| Completeness | 684 | governed_turing_completeness, coterminous_governance |
| TrustSpec | 364 | capability_allowed, trust_at_least (30+ lemmas) |
| HashChainSpec | 222 | (hash chain specification) |
| InterpreterSpec | 480 | interp_directive, step_result |
| Subsumption | 233 | subsumption_asymmetry, structural_subsumes_content |
| CognitiveArchitecture | 371 | cognitive_surjection |
| Oracle | 410 | oracle integration |
| GoalDirected | 272 | goal reachability |
| Rice | 378 | Rice’s theorem reduction |
| GovernedCognitiveCompleteness | 218 | governed_cognitive_completeness |
| Transparency | 320 | governed_transparency |
| ExpressiveMinimality | 391 | four primitives minimal |
| GovernanceAlgebra | 380 | ga_safe, ga_transparent, ga_proper, |
| mashin_governance, any_governance_algebra_subsumes | ||
| MonoidalCategory | 437 | pentagon, triangle, hexagon, |
| tensor_governed, interp_tensor_distribute | ||
| EffectAlgebra | 589 | bind_within_caps, no_ambient_effects, |
| code_within_empty, dual_guarantee | ||
| EffectHandlers | 232 | Gov_governed, composed_handlers_governed |
| CapabilityComposition | 645 | cap_morphism_governed, tensor_within_caps, |
| trust_le_total, cap_seq_compose | ||
| TraceSemantics | 404 | trace_of_bind, well_governed_trace |
| LedgerConnection | 365 | trace_to_ledger_valid, ledger_tamper_detected, |
| ledger_complete | ||
| CoterminousBoundary | 359 | coterminous_boundary_exists, boundary_equivalence, |
| gov_denial_is_conservative | ||
| GovernedMetaprogramming | 520 | form inspection safety, splice safety, evolution preservation, |
| reflect-modify-materialize pipeline, 12-way capstone | ||
| NetworkGovernance | 480 | compositional governance preservation, capability narrowing, |
| protocol uniformity, local-remote equivalence | ||
| TemporalPolicyEvolution | 550 | safety under restriction, provenance continuity, |
| rollback safety, monotone policy composition |
Measured on Apple Silicon (M-series), BEAM/OTP 27. \(n=50\) iterations with 5-iteration warmup.↩︎