lietzsche;stokes

updated 2026-11-26·3 min read

Declarative Boundary Contracts Reference

Declarative boundary rule layout (LINT-001, LINT-002, LINT-004) and cross-boundary diff remediation.

contracts/boundary_policy.yaml ties SQL schemas, Python ETL workers, and Rust edge proxies into one checkable spec without forcing you to rewrite native code into an IDL.

Stokes declarative boundary_policy.yaml view binding ClickHouse SQL, Python ETL, and Rust L7 edge proxy targets
contracts/boundary_policy.yaml: verifying 200 canonical signals across clickhouse, python, and rust.

Target Bindings in boundary_policy.yaml

Upstream Producers

  • ClickHouse Target: migrations/001_bot_signals.sql, enforced predicate AND database = currentDatabase(), 200 canonical columns with r0 and r1 shards isolated.
  • Python ETL Pipeline: services/feature-pipeline covering 6 security domains (200 features) serialized into payloads/features.json with explicit 200-item bounds.

Downstream Consumer & Invariants

  • Rust L7 Edge Proxy: crates/cloudflame-proxy allocating [FeatureDescriptor; 200] stack storage partitioned via Dual-Zone 128 + 72 select_nth_unstable_by (0 B heap).
  • Active Policy Digest: e3b0c442...b855 (schema_version: "2026.09.25", max_canonical_features: 200).

Enforced Contract Invariants

# contracts/boundary_policy.yaml
schema_version: "2026.09.25"
target_workspace: "cloudflame-l7-proxy"
max_canonical_features: 200

rules:
  - id: "LINT-004"
    assertion: "cardinality_risk_ratio = C_upstream / B_downstream <= 1.0"
    on_violation: "block_pr_merge_upstream"
    protection: "avoids 502/TryFromSliceError blackouts across edge nodes"
    heap_allocation_limit_bytes: 0
  - id: "LINT-001"
    assertion: "system.columns reflection query must declare database filter"
    on_violation: "flag_unscoped_reflection"
  - id: "LINT-002"
    assertion: "wire serialization sinks must declare explicit limit or slice clamp"
    on_violation: "reject_unbounded_payload"

Cross-Boundary Remediation Diff (stokes audit --diff)

When drift pushes the Cardinality Risk Ratio to 1.40 (280 features arriving at a 200-slot buffer), Stokes emits coordinated upstream and downstream fixes:

// services/feature-pipeline/catalog_sync.py
- query = "SELECT name, type FROM system.columns WHERE table LIKE 'events%'"
+ query = "SELECT name, type FROM system.columns WHERE database = currentDatabase() AND table = 'events'"

// crates/cloudflame-proxy/src/engine/feature_ingest.rs
- raw_features.into_boxed_slice().try_into().unwrap() // panic on #201
+ ingest_descriptors_dual_zone(&mut raw_features, &mut buffer); // 128 core + 72 adaptive
Boundary Contracts & Rules FAQ
  • What is the Cardinality Risk Ratio? upstream_columns / buffer_capacity. Values <= 1.0 guarantee safe intake; values > 1.0 (such as 280 / 200 = 1.40) cause downstream buffer overflow panics.
  • What are LINT-001 through LINT-006? LINT-001 flags unscoped system.columns queries; LINT-002 flags unbounded Python extraction loops; LINT-003 flags unbounded Protobuf repeated fields without stokes.max_items; LINT-004 flags .try_into().unwrap() on fixed arrays; LINT-005 flags heap allocations on hot paths; LINT-006 flags SELECT * wildcards.
  • How do queries trace contracts without running code? AST/regex patterns map SQL projections, Python extraction loops, Protobuf repeated fields, and Rust fixed-size arrays directly from source files.
  • How does Stokes prevent silent data corruption? It prevents blind truncation by pinning 128 core signals in Zone 0 (priority >= 200), partitioning the remaining 72 slots in Zone 1 via select_nth_unstable_by, and scoping upstream queries with AND database = currentDatabase().

See Untyped Seams Across Compilers and Channel Binding & Manifests for boundary examples.

Search wiki and portfolio

type to search across all entries.