updated 2026-11-26·4 min read
Boundary Graphs vs. Whole-Program Taint Analysis
Why interprocedural taint analysis stalls in CI and how sparse boundary graphs check producer counts against fixed buffers.
Whole-program taint analysis (CodeQL, Semgrep) slows down fast in polyglot CI because tracing data from ClickHouse DDL through Python frameworks like Pydantic or SQLAlchemy means building O(N^3) pointer-alias graphs over millions of library lines. That takes minutes per CI run, trips constantly on reflection and dynamic dicts, and adds heavy overhead if you shift it into runtime eBPF probes.
Stokes ignores internal helper arithmetic altogether. It strips away everything outside boundary files and builds a small directed graph over just the schemas, serialization sinks, and fixed buffers, running locally with zero production overhead.
| Dimension | Whole-Program Taint Analysis | Stokes Sparse Boundary Graphs |
|---|---|---|
| Algorithmic Model | Context-Free Language (CFL) reachability over all AST nodes | Extracts only boundary schemas, serialization sinks, and fixed buffers |
| Complexity Class | O(N^3) across application, framework, and library code | O(V + E) over a small boundary graph |
| CI Scope | Full cross-library call graph per run | Boundary files only, no containers or rustc |
| False Positive Rate | Confounded by reflection, decorators, and dynamic dicts | Deterministic on declared buffer bounds |
| Runtime Overhead | 15% to 40% throughput loss if shifted to eBPF/bytecode probes | Exactly 0 ns (zero binary instrumentation) |
How Boundary Graphs Trace Column Counts
Stokes extracts boundary declarations into a directed graph connecting upstream schemas to downstream buffers across three node types:
- Schema Nodes (
ClickHouse/SQL): Tables and views, each tracking how many columns an active query emits. - Transport Channels (
Python/KV/Protobuf): Serialization sinks (json.dumps(), Kafka topics, KV keys) forwarding reflected fields. - Intake Buffers (
Rust/C++): Fixed-capacity allocations such as[Feature; N], recording their slot limitN.
For each downstream buffer, Stokes walks backwards to reachable upstream schemas, sums their emitted column counts, and compares that total against the buffer’s slot capacity (flagging CI whenever total_emitted > buffer_slots and printing the exact file chain from SQL query to .try_into().unwrap()):
- Upstream Schema Nodes (200 + 80 columns)
bot_signals DDL (200 columns) and shard_r0 DDL (80 internal columns) both match an unscoped reflection query.
- Wire Transport Node
Python ETL worker serializes all 280 reflected fields into an unbounded KV payload.
- Consumer Buffer Node (200 slots)
Rust proxy stack buffer allocates 200 slots. Comparing 280 emitted columns against 200 slots trips CI immediately (risk_ratio = 1.40).
Sparse Extraction Without Native Build Overhead
TreeSitterLoader ships .scm query definitions alongside compiled Python regex patterns (_PATTERNS) as its out-of-the-box fallback when native .so grammars aren’t installed, so CI runners only inspect boundary declarations and skip the rest of the codebase.
Tree-sitter S-Expression Queries (.scm) for SQL, Python, and Rust
;; SQL: Extract catalog reflection queries missing database = currentDatabase()
(select_statement
(from_clause
(table_expression
(table_identifier) @catalog_table
(#match? @catalog_table "^(system\\.)?(columns|tables)$")))
(where_clause
(binary_expression
left: (column_identifier) @filter_col
operator: "="
right: (string_literal) @table_name)) @where_clause
(#not-has-child? @where_predicate
(binary_expression
left: (column_identifier) @db_col
(#match? @db_col "^database$")))) @unscoped_reflection_error;; Python: Extract unbounded feature extraction loops
(function_definition
name: (identifier) @fn_name
(#match? @fn_name "extract_features|serialize_signals")
body: (block
(for_statement
left: (identifier) @item
right: (identifier) @source_collection
body: (block
(expression_statement
(call
function: (attribute
object: (identifier) @target_list
attribute: (identifier) @method
(#eq? @method "append"))
arguments: (argument_list
(dictionary) @payload_dict))))))) @unbounded_payload_append;; Rust: Extract fixed-size stack conversions with unwrap or expect
(call_expression
function: (field_expression
value: (call_expression
function: (field_expression
value: (_) @source_slice
field: (field_identifier) @try_into_fn
(#eq? @try_into_fn "try_into")))
field: (field_identifier) @unwrap_fn
(#match? @unwrap_fn "^(unwrap|expect)$"))) @fatal_slice_unwrapWhy the Graph Pass Stays Fast
Because the boundary graph typically holds a handful of schema and buffer nodes rather than an entire application call graph, Stokes skips containers and full compiler passes (rustc, mypy), parses only boundary files, normalizes declarations into SHA-256 digests, and checks stokes.lock in one pass.
Projection Consumption Isolation
Naive contract gates get stuck in constant false-positive lockouts: adding an internal analytics column breaks downstream proxy CI even though the proxy never reads that column. Stokes isolates unconsumed columns from the consumer boundary digest:
Tracked Projected Columns (200)
Explicitly queried fields (SELECT ja4_hash, ip_reputation, ...) are tracked by Stokes and included in the consumer boundary contract.
Unconsumed Offline Columns (5)
Internal metrics on the same ClickHouse table (bot_signals at 205 total columns) are isolated from the gate and ignored without CI failure.
CI fails only when a consumed column changes or when an unconstrained wildcard (SELECT * or unscoped system.columns reflection) is introduced. See Projection Isolation for how explicit field masks restrict reflected columns and Channel Manifests for manifest binding.