lietzsche;stokes

updated 2026-11-26·5 min read

Untyped Seams Across Compilers

Dissection of cross-compiler boundary failures, column-vs-buffer mismatches, and the Cloudflare November 18, 2025 incident model.

The nasty outages in polyglot backends usually aren’t local syntax bugs or borrow-checker errors. Type systems catch those before anything merges. The trouble sits at the untyped seams between tiers, where an analytical database feeds a dynamic extractor that feeds a fixed-size edge buffer:

  1. Tier 1: SQL Analytics (ClickHouse DDL)

    system.columns emits 280 rows across canonical signals and internal shard replicas.

  2. Tier 2: Python Worker (ETL Extractor)

    json.dumps(features) serializes all 280 dynamic dictionary items onto the KV mesh.

  3. Tier 3: Rust Edge Proxy (Pingora L7)

    let buf: [Feature; 200] fails on slice.try_into().unwrap(), triggering TryFromSliceError and a 100% 502 blackout.

Cloudflare November 18, 2025 4-stage outage timeline comparing TryFromSliceError crash cascade against stokes verify protection
the four-stage november 18, 2025 outage model: unhardened seam drift vs. compile-time stokes verification.

Dissecting the Nov 18, 2025 Cascade

On November 18, 2025, a global edge network went down for hours across millions of domains. Nobody broke into a host and no switch died. ClickHouse simply added replica shards that bumped reflected columns from 200 to 280, a Python ETL worker packed all 280 items into a dynamic dictionary, and the Rust edge proxy panicked trying to cast a 280-element slice into a 200-slot stack array.

Every repo passed its own CI without a single warning. The SQL ALTER TABLE and reflection queries passed sqlfluff as clean ANSI SQL. The dict[str, Any] serializer passed mypy --strict, ruff, and pytest. And [Feature; 200] compiled cleanly under rustc 1.80+ and cargo clippy. The bug didn’t live in any one repo; it sat in the untyped seam between them.

Checking Column Count Against Buffer Capacity

Stokes models the seam plainly as a producer-vs-consumer bounds check: compare the maximum number of fields emitted upstream against the physical slot capacity allocated by the downstream buffer.

Whenever emitted_columns <= buffer_slots, stack allocation stays safe. Whenever emitted_columns > buffer_slots (for example, 200 canonical columns plus 40 replica columns from shard r0 and 40 from shard r1 yielding 280 total columns into a 200-slot [Feature; 200] array, or risk_ratio = 280 / 200 = 1.40), slice.try_into() fails:

if slice.len() != N {
    return Err(TryFromSliceError(()));
}

Because 280 != 200, try_into() returns Err, and .unwrap() panics on the very first payload intake. If an upstream query is completely unbounded (SELECT * or an unlimited dynamic dictionary), CI flags it immediately before production sees an OOM or crash loop.

Concrete Code Analysis: Vulnerable vs. Hardened

1. The SQL Layer (LINT-001)

Vulnerable Reflection Query

-- VULNERABLE: LINT-001 Fatal Error
-- Omits database qualification; captures shards
SELECT
    name,
    type,
    default_expression
FROM system.columns
WHERE table LIKE 'bot_signals%'
ORDER BY name ASC;

Stokes Hardened Query

-- HARDENED: Fully scoped and bounded projection
SELECT
    name,
    type,
    default_expression
FROM system.columns
WHERE database = currentDatabase()
  AND table = 'bot_signals'
ORDER BY name ASC
LIMIT 200;

2. The Python ETL Layer (LINT-002)

Python ETL: Vulnerable Reflection vs. Bounded Extraction
# VULNERABLE: LINT-002 Fatal Error
# Dynamic dictionary packing without boundary slice guard
from typing import Any
import json

def extract_features_vulnerable(db_rows: list[dict[str, Any]]) -> bytes:
    features: list[dict[str, Any]] = []
    for row in db_rows:
        col_name = row["name"]
        features.append({
            "id": hash(col_name) & 0xFFFFFFFF,
            "name": col_name,
            "priority": 0 if "shard" in col_name else 200,
        })
    return json.dumps({"signals": features}).encode("utf-8")


# HARDENED: Bounded extraction with static capacity ceiling
MAX_CANONICAL_FEATURES: int = 200

def extract_features_hardened(db_rows: list[dict[str, Any]]) -> bytes:
    features: list[dict[str, Any]] = []
    for row in db_rows:
        col_name = row["name"]
        features.append({
            "id": hash(col_name) & 0xFFFFFFFF,
            "name": col_name,
            "priority": 0 if "shard" in col_name else 200,
        })

    features.sort(key=lambda f: f["priority"], reverse=True)
    bounded_features = features[:MAX_CANONICAL_FEATURES]
    return json.dumps({"signals": bounded_features}).encode("utf-8")

3. The Rust Ingress Proxy Layer (LINT-004)

Blindly slicing raw_slice[..200] drops arbitrary security features if an upstream query adds extra columns, so the hardened Rust path partitions by priority first via Dual-Zone select_nth_unstable_by (keeping 128 core slots with priority >= 200 in Zone 0 and the top 72 adaptive signals in Zone 1):

Rust Proxy: Fatal try_into().unwrap() vs. Dual-Zone Partitioned Intake
// VULNERABLE: LINT-004 Fatal Error
use std::convert::TryInto;

#[derive(Clone, Copy, Debug)]
pub struct Feature {
    pub id: u32,
    pub priority: u8,
}

pub fn ingest_packet_features(raw_slice: &[Feature]) -> [Feature; 200] {
    // Panics with TryFromSliceError if raw_slice.len() == 280
    raw_slice.try_into().unwrap()
}

// HARDENED: Dual-Zone in-place priority partitioning (128 core + 72 adaptive = 200 slots)
pub const CORE_RESERVED_SLOTS: usize = 128;
pub const ADAPTIVE_SLOTS: usize = 72;
pub const MAX_ACTIVE_FEATURES: usize = CORE_RESERVED_SLOTS + ADAPTIVE_SLOTS;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(C, align(8))]
pub struct FeatureDescriptor {
    pub id: u32,
    pub priority: u8,
    pub is_shadow: bool,
    pub _pad: [u8; 2],
}

pub struct DualZoneIngestionReport {
    pub active_features: [FeatureDescriptor; MAX_ACTIVE_FEATURES],
    pub active_count: usize,
    pub shed_shadow_count: usize,
}

pub fn ingest_descriptors_dual_zone(raw_slice: &mut [FeatureDescriptor]) -> DualZoneIngestionReport {
    let mut buffer = [FeatureDescriptor {
        id: 0,
        priority: 0,
        is_shadow: false,
        _pad: [0; 2],
    }; MAX_ACTIVE_FEATURES];

    // Zone 0: pin high-priority core rules (priority >= 200) first
    let mut core_end = 0;
    for i in 0..raw_slice.len() {
        if raw_slice[i].priority >= 200 && core_end < CORE_RESERVED_SLOTS {
            raw_slice.swap(core_end, i);
            core_end += 1;
        }
    }

    // Zone 1: quickselect highest-priority adaptive signals into remaining slots
    let remaining_slots = MAX_ACTIVE_FEATURES - core_end;
    let tail = &mut raw_slice[core_end..];
    if tail.len() > remaining_slots {
        tail.select_nth_unstable_by(remaining_slots, |a, b| b.priority.cmp(&a.priority));
    }

    let take_count = raw_slice.len().min(MAX_ACTIVE_FEATURES);
    buffer[..take_count].copy_from_slice(&raw_slice[..take_count]);

    DualZoneIngestionReport {
        active_features: buffer,
        active_count: take_count,
        shed_shadow_count: raw_slice.len().saturating_sub(MAX_ACTIVE_FEATURES),
    }
}

Continue to Panic vs. 100% Error Rate & Dual-Zone Resilience for the zero-drop runtime memory model, or Cloudflame Case Study for the full incident reproduction.

Search wiki and portfolio

type to search across all entries.