updated 2026-11-26·5 min read
Cloudflame Benchmark & Incident Reproduction
Local three-tier reproduction of the Cloudflare November 18, 2025 outage across ClickHouse SQL, Python ETL, and a Rust edge proxy.
I originally named the patient codebase Dirichlet (crates/dirichlet-proxy), then renamed it Cloudflame before submission so anyone reading the hackathon demo could tell right away what incident it was modeling. On November 18, 2025, an upstream ClickHouse metadata change tripped a fixed-size stack buffer panic inside L7 edge proxies and took global traffic offline for hours, even though every repo passed its own local linter cleanly. The Cloudflame testbed reproduces that exact three-tier cascade locally across SQL, Python, and Rust so Stokes has a concrete target to test against.

Three-Tier Testbed Architecture
- Tier 1: Analytical SQL (cloudflame/migrations/)
001_bot_signals.sql declares 200 canonical signals; 002_shard_definitions.sql adds events_r0 and events_r1 (40 operational metadata columns each), causing system.columns to emit 280 rows.
- Tier 2: Python ETL (cloudflame/services/feature-pipeline/)
catalog_sync.py runs SELECT name, type FROM system.columns WHERE table LIKE 'events%'. extractor.py packs unknown shard columns with priority = 0 into data/payloads/features_drift.json (280 items).
- Tier 3: Rust L7 Proxy (cloudflame/crates/cloudflame-proxy/)
Pingora-style reverse proxy allocates [FeatureDescriptor; 200] on the stack and calls incoming[..].try_into().unwrap(), triggering TryFromSliceError.
Step-by-Step Incident Crash Reproduction
- Step 1Baseline State (Risk = 1.00, Healthy)
ClickHouse holds 200 canonical features, Python emits 200 items, and Rust ingests into 200 stack slots.
- Step 2Shard Expansion Migration Applied
002_shard_definitions.sql creates events_r0 and events_r1. sqlfluff passes 100% of DDL syntax checks.
- Step 3Unbounded Schema Extraction
catalog_sync.py matches 280 rows via LIKE 'events%' and packs features_drift.json. mypy, ruff, and unit tests pass.
- Step 4Edge Ingestion & Worker Thread Panic
feature_ingest.rs calls incoming[..].try_into().unwrap() on 280 elements into a 200-slot array.
- Step 5Core Panic Stack Trace
worker-0 panics with called Result::unwrap() on an Err value: TryFromSliceError(()).
- Step 6Cascading Fleet Blackout
Sibling worker threads crash together, supervisor restarts hit crash-loop backoff on features_drift.json, health probes fail, and edge traffic drops with HTTP 502/504.
Dual-Zone Remediation
Blindly truncating features (raw_slice[..200]) risks dropping core security rules, so stokes-rust pairs stokes-sql catalog qualification (AND database = currentDatabase()) with Dual-Zone In-Place Partitioning inside the existing 200-slot [FeatureDescriptor; 200] stack buffer:
| Memory Zone | Capacity | Priority Envelope | Behavior Under Drift |
|---|---|---|---|
| Zone 0: Core Reserved | 128 Slots (1,024 B) | Core security rules (priority >= 200) | Pinned first; immune to eviction |
| Zone 1: Adaptive | 72 Slots (576 B) | Dynamic / adaptive signals | Partitioned in-place via select_nth_unstable_by |
| Total Stack Capacity | 200 Slots (1,600 B) | Active packet descriptors | Fits in 25 contiguous 64-byte cache lines (0 B heap) |
When ClickHouse temporarily emits 280 features (200 canonical + 80 priority = 0 shard columns), Zone 0 keeps the core security rules, Zone 1 keeps the top 72 adaptive features via select_nth_unstable_by, and the 80 zero-priority shard columns are shed in-place without touching the heap.
Dual-Zone Partitioning & ArcSwap LKG Rollback (Rust)
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_count: usize,
pub shed_shadow_count: usize,
}
pub fn ingest_descriptors_dual_zone(
source: &mut [FeatureDescriptor],
out: &mut [FeatureDescriptor; MAX_ACTIVE_FEATURES],
) -> DualZoneIngestionReport {
let mut core_count = 0;
for i in 0..source.len() {
if source[i].priority >= 200 && core_count < CORE_RESERVED_SLOTS {
source.swap(core_count, i);
core_count += 1;
}
}
let remaining = MAX_ACTIVE_FEATURES - core_count;
let adaptive = &mut source[core_count..];
if adaptive.len() > remaining {
adaptive.select_nth_unstable_by(remaining, |a, b| b.priority.cmp(&a.priority));
}
let take = source.len().min(MAX_ACTIVE_FEATURES);
out[..take].copy_from_slice(&source[..take]);
DualZoneIngestionReport {
active_count: take,
shed_shadow_count: source.len().saturating_sub(MAX_ACTIVE_FEATURES),
}
}pub struct ConfigMesh {
active_config: arc_swap::ArcSwap<ConfigState>,
lkg_config: arc_swap::ArcSwap<ConfigState>,
}
impl ConfigMesh {
pub fn rollback_to_lkg(&self) {
let lkg = self.lkg_config.load();
self.active_config.store(lkg);
}
}Whenever incoming payloads exceed 200 items (source.len() > MAX_ACTIVE_FEATURES), select_nth_unstable_by partitions Zone 1 in-place in O(N) expected time so core security signals never get evicted.
What Was Actually Measured
On the 16-item window micro-benchmark in ingest_benchmark.rs (in_place_select_nth_boundary_16 vs heap_allocated_vec_boundary_16), in-place select_nth_unstable_by ran in 7.66 ns (0 B heap) versus 29.74 ns for a heap Vec. On full-struct deserialization in CONFORMANCE.md, bounded stack deserialization measured 213.09 ns versus 134.19 ns for heap Vec<Feature> (0.6x, slower on raw deserialization, trading raw throughput for 0 B heap allocations):
| Benchmark Dimension | Unhardened Cloudflame Baseline | Hardened with Dual-Zone Partitioning |
|---|---|---|
| Response to 280-Feature Payload | Immediate Core Panic (Exit 1) | Zero panics; 200 slots kept |
16-Item Slice Partition (ingest_benchmark.rs) | N/A | 7.66 ns (select_nth_unstable_by vs 29.74 ns heap) |
Full-Struct Deserialization (CONFORMANCE.md) | 134.19 ns (Vec<Feature> heap) | 213.09 ns (0 B heap, bounded stack) |
| Descriptor Footprint (200 Items) | 17,600 B (275 cache lines at 88 B/item) | 1,600 B (25 contiguous cache lines at 8 B/item) |
| Zone 0 Core Signal Retention | 0% (Proxy dead) | 100% Retained |
See Untyped Seams, Panic Resilience, and Verification Latency & Memory Benchmarks for related details.