lietzsche;stokes

updated 2026-11-26·9 min read

Introduction & Overview

Cross-boundary contract checker for SQL, Python, Protobuf, and Rust pipelines, built solo for an IBM Bob 2.0 hackathon.

Stokes came out of an IBM Bob hackathon, only the second or third hackathon I had joined, I think, and got its name mainly so I wouldn’t ship yet another generic two-word AI project title (Stokes’ theorem connects boundary behavior to interior guarantees, albeit mostly here as a cool name). Anyway, building it solo meant I forgot to prepare slides until late, spent roughly ten hours filming and editing the demo video, and found out the hard way that per-person credit limits give a six-person team 6x the runway of a solo builder rather than one fixed pool per team.

That budget ceiling shaped how the repo was split: solo participants got 40 Bobcoins (versus 240 for a 6-person squad), and the first session alone burned 27.18 Bobcoins getting the core AST scanner, five language workers, and test suite off the ground. Ergo, I built the MCP bridge, the Cloudflame testbed, and the web demo shell with external tooling so the remaining Bobcoins could stay on the core engine.

In multi-language stacks, each repo can look clean on its own: sqlfluff passes the SQL, mypy passes the Python, and rustc compiles the edge proxy, yet the moment a schema migration emits 280 columns into a 200-slot stack buffer, production panics with TryFromSliceError. Stokes catches that boundary drift in CI and over MCP before anything ships.

Stokes landing view showing curl install command, CI check summary, and MCP integrations for Claude Code, Cursor, Windsurf, and IBM Bob
stokes workspace overview: curl installer, static ci check, and mcp integration.

How Untyped Seams Break in Production

Across a three-tier microservice pipeline, each compiler signs off on its own piece while a runtime collision builds across the wire:

  1. Tier 1: SQL Analytics (ClickHouse DDL)

    migrations/004_stats.sql emits 280 columns across canonical and shard tables. sqlfluff reports PASS.

  2. Tier 2: Feature Extractor (Python Worker)

    services/etl/worker.py reflects and serializes all 280 items into a dynamic KV mesh payload. mypy reports PASS.

  3. Tier 3: Reverse Proxy (Rust Edge)

    crates/proxy/src/intake.rs decodes into a fixed stack buffer [Feature; 200]. rustc reports PASS, but production panics with TryFromSliceError.

Why Compilers Miss Boundary Drift

Multi-tier pipelines usually split data contracts across three layers that never share a type system. ClickHouse, PostgreSQL, or Snowflake run DDL migrations and expose columns through virtual introspection tables like system.columns or information_schema. Python, Node.js, or Go workers query that catalog metadata, pack dynamic dictionaries, and push payloads onto Redis, Kafka, or distributed KV stores. At the edge, L7 reverse proxies in Rust (Pingora) or C++ (Envoy) decode those payloads straight into fixed-size stack arrays to skip heap allocations and keep packet intake off the allocator.

When an upstream team adds shard replica tables or new feature flags, the downstream proxy crashes on deserialization even though every repo passes local CI, simply because sqlfluff, mypy, and rustc each only inspect their own files and never see what sits downstream.

Stokes bridges that gap by pulling interface signatures out of isolated source files and linking producer counts directly to downstream buffers.

How the Checker Runs

Stokes runs the same boundary graph in two places, without spinning up Docker containers or invoking rustc:

Static CI Gate

Runs as a zero-dependency Python CLI in CI (stokes verify --strict). It probes for native Tree-sitter bindings if installed, falls back to compiled regex rules (_PATTERNS) out of the box, checks emitted column counts against buffer slots, and verifies normalized AST digests against stokes.lock.

MCP Bridge & Patch Generation

Streams boundary shapes, buffer limits, and schema constraints over JSON-RPC 2.0 (stokes mcp) to IBM Bob 2.0, Claude Code, Cursor, and Windsurf. Also emits Dual-Zone stack layouts (128 core + 72 adaptive slots via select_nth_unstable_by) through stokes codegen.

Because it skips containers and full compiler passes, a local check finishes well under a tenth of a second on small workspaces, with zero code injected into the compiled proxy binary.

Checking Column Counts Against Buffer Slots

The core check Stokes enforces at every boundary is plain: does the upstream producer ever emit more fields than the downstream array or struct can hold? Internally the engine tracks upstream_count / buffer_capacity (reported as risk_ratio in CLI output), failing CI whenever emitted columns exceed buffer slots or an unscoped reflection loop leaves the wire length unbounded:

ConditionBuffer CheckOperational Outcome
Within BoundsEmitted fields <= buffer capacity (risk_ratio <= 1.0)Safe stack allocation; no slice length mismatch.
Overflow DriftEmitted fields > buffer capacity (e.g. 280 > 200, risk_ratio = 1.40)Direct .try_into().unwrap() is guaranteed to panic in production.
Unbounded WireUnscoped SELECT * or reflection without limitsUnbounded payload growth and OOM / crash risk.

Core Diagnostic Rules

Stokes enforces five primary rules across mixed boundaries (plus LINT-006 for wildcard projections in Projection Isolation):

Rule CodeSeverityTrigger ConditionRoot Cause & Failure Mode
LINT-001FATALsystem.columns without database = currentDatabase()Ingestion of replica shard tables (r0, r1), inflating column projection count.
LINT-002FATALDynamic dictionary serialization without slice guardsUnbounded feature reflection loop bypasses Python type check, overflowing downstream buffers.
LINT-003WARNINGUnbounded repeated Protobuf fieldMissing [(stokes.max_items) = N] option lets upstream producers send arbitrary slice lengths.
LINT-004FATALDirect .try_into().unwrap() on fixed stack bufferImmediate TryFromSliceError panic or 502 drop when upstream cardinality exceeds capacity N.
LINT-005WARNINGHeap allocations on microsecond intake hot pathCache line evictions degrading packet evaluation latency.

Parallel Language Workers

Inside the CLI, Stokes splits scanning across five focused Python workers coordinated over an asyncio.Queue (and 4-byte length-prefixed binary frames for external IPC):

  • stokes-sql: Catches unqualified system.columns queries and wildcard catalog reflections.
  • stokes-proto: Flags unbounded repeated fields without stokes.max_items bounds.
  • stokes-python: Spots unguarded dictionary append loops and missing slice ceilings.
  • stokes-rust: Flags .try_into().unwrap() calls on fixed stack buffers and heap allocations.
  • stokes-verify: Runs the 10,000-case IEEE-754 float fuzz battery and Criterion regression checks.

Demo Video, Sprites & Zundamon TTS

For the hackathon submission video, I wanted that brisk sketched-avatar style from SoiriLab on YouTube, so my girlfriend drew the whole sprite set from scratch (right down to the whiteboard prop and pixel sunglasses). For the voiceover, I figured out how to set up a local Zundamon TTS model myself and learned pretty quickly just how loud my laptop fans can scream running a local neural voice model nonstop during an edit (gosh, if only I could get a new laptop).

I would link the finished video here too, I guess, except lablab rebranded to Starfield Labs and removed my submission once the hackathon ended (or something like that), and I’m honestly too lazy to re-upload it on YouTube when I wasn’t even that proud of how it came out anyway.

Documentation Map

Continue to Architecture Vision or Quickstart & CLI Guide to run Stokes locally.

Search wiki and portfolio

type to search across all entries.