cognitum-gate-kernel
A no_std WASM kernel for the Anytime-Valid Coherence Gate - a real-time permission system that decides "Is it safe to act right now, or should we pause or escalate?" The coherence gate provides formal safety guarantees for autonomous agent actions through continuous monitoring and evidence accumulation.
Think of it like a smoke detector for AI agents: it continuously monitors system coherence, can keep listening forever, and the moment it has enough evidence of instability, it triggers. Unlike traditional gating systems, you can stop the computation at any time and still trust the decision - that's what makes it "anytime-valid." The gate doesn't try to be smart; it tries to be safe, calm, and correct about permission.
The gate uses three stacked filters that must all agree before permitting an action: (1) Structural - graph coherence via dynamic min-cut to detect fragile partitions, (2) Shift - distribution monitoring to detect when the environment is changing, and (3) Evidence - e-value accumulation for sequential hypothesis testing with formal Type I error control. Every decision outputs a signed witness receipt explaining why.
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic usage - create a worker tile, ingest graph deltas, tick, and get the report:
use ;
// Initialize a worker tile (ID 42 in the 256-tile fabric)
let mut tile = new;
// Ingest graph deltas (edge additions, removals, weight updates)
tile.ingest_delta; // Add edge 0->1, weight 1.0
tile.ingest_delta; // Add edge 1->2, weight 1.5
tile.ingest_delta; // Complete the triangle
// Process one tick of the kernel
let report = tile.tick;
// Check the coherence state
println!;
println!;
println!;
// Get the witness fragment for global aggregation
let witness = tile.get_witness_fragment;
println!;
256-Tile WASM Fabric
The coherence gate runs on a distributed fabric of 256 tiles, with TileZero acting as the central arbiter:
+-------------------------------------------------------------------------+
| 256-TILE COGNITUM FABRIC |
+-------------------------------------------------------------------------+
| |
| +-------------------------------------------------------------------+ |
| | TILE ZERO (Arbiter) | |
| | | |
| | * Merge worker reports * Hierarchical min-cut | |
| | * Global gate decision * Permit token issuance | |
| | * Witness receipt log * Hash-chained eventlog | |
| +-------------------------------+-----------------------------------+ |
| | |
| +--------------------+--------------------+ |
| | | | |
| v v v |
| +----------------+ +----------------+ +----------------+ |
| | Workers | | Workers | | Workers | ... |
| | [1-85] | | [86-170] | | [171-255] | |
| | | | | | | |
| | Shard A | | Shard B | | Shard C | |
| | Local cuts | | Local cuts | | Local cuts | |
| | E-accum | | E-accum | | E-accum | |
| +----------------+ +----------------+ +----------------+ |
| |
+-------------------------------------------------------------------------+
Worker Tile Responsibilities
Each of the 255 worker tiles maintains a local shard with:
- CompactGraph (~42KB): Vertices, edges, adjacency lists with union-find connectivity
- EvidenceAccumulator (~2KB): Hypothesis tracking and sliding observation window
- Delta buffer (1KB): Circular buffer for incoming graph updates
- Total: ~46KB per tile, fitting within the 64KB WASM memory budget
Worker tiles perform:
- Ingest deltas - Edge additions, removals, weight updates, observations
- Process ticks - Deterministic tick loop updates local state
- Produce reports - 64-byte cache-aligned reports with coherence metrics
- Emit witness fragments - Boundary information for global aggregation
TileZero Arbiter Role
TileZero collects reports from all worker tiles and:
- Merges reports into a reduced supergraph
- Applies three filters: structural, shift, and evidence
- Issues decisions:
Permit,Defer, orDeny - Signs permit tokens with Ed25519
- Maintains receipt log with hash-chained audit trail
Data Flow
+-------------------+
| Graph Updates |
| (Edges, Weights) |
+---------+---------+
|
v
+---------------------------------------------------------------+
| WORKER TILES [1-255] |
| |
| Delta --> CompactGraph --> Connectivity --> WitnessFragment |
| --> EvidenceAccum --> LogEValue |
| |
+---------------------------+-----------------------------------+
|
TileReports (64 bytes each)
|
v
+---------------------------------------------------------------+
| TILEZERO ARBITER |
| |
| Structural Filter: global_cut >= min_cut_threshold? |
| Shift Filter: shift_pressure < max_shift_threshold? |
| Evidence Filter: e_aggregate in [tau_deny, tau_permit]? |
| |
| +-------> PERMIT (proceed autonomously) |
| DECISION --+-------> DEFER (escalate to human) |
| +-------> DENY (block the action) |
| |
+---------------------------+-----------------------------------+
|
v
+-------------------+
| PermitToken |
| (signed + TTL) |
+-------------------+
|
v
+-------------------+
| WitnessReceipt |
| (hash-chained) |
+-------------------+
CompactGraph Internals
The CompactGraph structure is optimized for cache-efficient access on WASM:
// Cache-line aligned
// Total: ~42KB
Key optimizations:
#[inline(always)]on all hot-path accessors- Unsafe unchecked array access after bounds validation
- Union-find with iterative path compression (no recursion)
- Branchless flag manipulation for partition sides
E-Value Accumulator Math
The evidence accumulator uses fixed-point log2 representation for numerical stability:
pub type LogEValue = i32; // log2(e-value) * 65536
// Pre-computed threshold constants (avoid runtime log)
pub const LOG_E_STRONG: LogEValue = 282944; // log2(20) * 65536
pub const LOG_E_VERY_STRONG: LogEValue = 436906; // log2(100) * 65536
pub const LOG_LR_CONNECTIVITY_POS: LogEValue = 38550; // log2(1.5) * 65536
pub const LOG_LR_CONNECTIVITY_NEG: LogEValue = -65536; // log2(0.5) * 65536
E-value composition (multiplicative):
log(e1 * e2) = log(e1) + log(e2)
This enables efficient sequential evidence accumulation with saturating addition:
self.log_e_value = self.log_e_value.saturating_add;
Anytime-valid property: Because e-values are nonnegative supermartingales with E[E_0] = 1, the decision is valid at any stopping time:
P_H0(E_tau >= 1/alpha) <= alpha
TileReport Structure (64 bytes, cache-line aligned)
Memory Layout (~41KB per tile)
| Component | Size | Notes |
|---|---|---|
| Graph shard | 42 KB | 256 vertices, 1024 edges, 32-degree adjacency |
| Evidence accumulator | 2 KB | 16 hypotheses, 64-observation window |
| Delta buffer | 1 KB | 64 deltas @ 16 bytes each |
| TileState overhead | 1 KB | Metadata, status, counters |
| Total per worker | ~46 KB | Fits in 64KB WASM page |
| Total 255 workers | ~11.5 MB | |
| TileZero state | ~1 MB | Supergraph + receipt log head |
| Total fabric | ~13 MB |
Example 1: Network Security Gate
Protect network device configuration changes with coherence gating:
use ;
use ;
async
Example 2: Config Change Approval
Gate infrastructure changes based on dependency graph stability:
use ;
Example 3: Multi-Agent Coordination
Coordinate multiple agents through the coherence gate:
use ;
use HashMap;
Custom Update Rules for E-Process
Extend the evidence accumulator with custom likelihood ratio functions:
use ;
/// Custom e-value update for domain-specific hypothesis testing
/// Financial anomaly detection e-process
SIMD Optimization Hooks
For high-throughput scenarios, inject SIMD-optimized paths:
Distributed Coordination with ruvector-raft
Integrate with RuVector's Raft consensus for distributed gate deployment:
use ;
/// Distributed coherence gate with Raft consensus
;
Hardware Integration (Cognitum Chip)
For deployment on dedicated Cognitum ASIC/FPGA:
//! Hardware abstraction layer for Cognitum coherence gate chip
use ;
use TileReport;
/// Hardware register interface
/// Hardware-accelerated tile driver
Extending the Witness Receipt Format
Add custom fields to witness receipts for domain-specific auditing:
use ;
use ;
/// Extended witness receipt with compliance fields
API Reference
Full API documentation is available on docs.rs/cognitum-gate-kernel.
Key Types
| Type | Description |
|---|---|
TileState |
Main worker tile state containing graph, evidence, and delta buffer |
Delta |
Tagged union for graph updates (edge add/remove, weight update, observation) |
TileReport |
64-byte cache-aligned report produced after each tick |
WitnessFragment |
16-byte fragment for global min-cut aggregation |
CompactGraph |
~42KB fixed-size graph shard with union-find connectivity |
EvidenceAccumulator |
Hypothesis tracking with sliding window and e-value computation |
WASM Exports
When compiled for WASM, the kernel exports:
void ;
int32_t ;
int32_t ;
int32_t ;
uint8_t ;
void ;
uint32_t ;
Claude-Flow Integration
Using as SDK
The coherence gate integrates with Claude-Flow for multi-agent coordination:
import from '@claude-flow/core';
import from '@ruvector/cognitum-gate';
const flow = ;
// Initialize coherence gate
const gate = ;
// Register gate with flow
flow.;
// Gate evaluates agent actions before execution
flow.;
MCP Plugin Configuration
Configure the gate as an MCP server:
Example Swarm Coordination
Coordinate a research swarm with coherence gating:
import from '@claude-flow/core';
const config = ;
const flow = ;
// Gate tracks agent interactions as graph edges
flow.;
// Research tasks are gated
await flow.;
MCP Tools
The gate exposes three MCP tools:
// Request permission for an action
permit_action({
action_id: "cfg-push-001",
action_type: "config_change",
context: { agent_id: "ops-agent", target: "router-1" }
}) -> { decision: "permit", token: "...", valid_until_ns: ... }
// Get witness receipt for audit
get_receipt({ sequence: 1847394 }) -> {
decision: "deny",
witness: { structural: {...}, predictive: {...}, evidential: {...} },
receipt_hash: "..."
}
// Replay decision for debugging
replay_decision({ sequence: 1847394, verify_chain: true }) -> {
original_decision: "deny",
replayed_decision: "deny",
match_confirmed: true
}
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.