runtime-code
How code inside blaze is written: no fallbacks, allocation by lifetime, the one standard data structure per need (locks, maps, queues, channels, waits), sans-IO cores, named and bounded waits, errors that name the thing, panics that fail one job, nothing thread-bound across a fiber wait. Load before writing or reviewing Rust in blaze's crates, especially the scheduler, daemon, query engine, store
Install
Copy this folder into your Claude Code project (needs Node.js):
npx degit indexable-inc/blaze/.agents/skills/runtime-code .claude/skills/runtime-codeOr install it for every project:
npx degit indexable-inc/blaze/.agents/skills/runtime-code ~/.claude/skills/runtime-codeFile content
Made by its original authors and shared under Apache-2.0. We show it unchanged, with credit and a link to the source. Source ↗
---
name: runtime-code
description: "How code inside blaze is written: no fallbacks, allocation by lifetime, the one standard data structure per need (locks, maps, queues, channels, waits), sans-IO cores, named and bounded waits, errors that name the thing, panics that fail one job, nothing thread-bound across a fiber wait. Load before writing or reviewing Rust in blaze's crates, especially the scheduler, daemon, query engine, store or anything concurrent."
---
# Writing blaze's runtime code
<!-- Generated by `bun tools/agents/rules.ts --write` from tools/agents/rules.ts, down to the end marker; edit the rules there. AGENTS.md carries each rule as one line. -->
## no-fallback (rule 3)
No fallback, ever. When blaze can't do something it stops with an error naming what and where, never
quietly takes another path (rustc, a full link or rebuild instead of a patch, a slower backend, an
older cached result, a default guessed for a missing value). A fallback that only logs its reason is
still a fallback. A change that touches an existing fallback turns it into an error, and a bench or
test that hits one fails instead of timing the slow path.
## bump-allocate (rule 11)
Allocate by lifetime, never from the global heap by default: a collection that lives within one task
(a query run, a codegen unit, a maintainer pass) names its allocator, `Vec::new_in(frame)` /
`Box::new_in(.., frame)` from `blaze_mem::frame::current`, and longer lifetimes use the request,
revision or image allocator. A global allocation (`Vec::new`, `vec![]`, `collect` into a heap `Vec`,
`Box::new`, `to_owned`) needs `// alloc: <why>` on its line. `blaze::implicit_allocator` enforces
this, warning everywhere and denied wherever `blaze::hot` is, with `blaze::hot_alloc` for what a
call reaches.
See [docs/v2/plan/design/memory.md](../../../docs/v2/plan/design/memory.md).
## standard-structures (rule 12)
One choice per need, never a hand-rolled or std stand-in: a lock is `blaze_core::lock::{Lock,
ReadLock}` (with `Signal` for a driver thread's condition), named where it is made
(`Lock::new("store.packs", v)`), held only for a field update and never across a query call, IO or a
global allocation (`blaze::lock_held_across_slow`); raw `std::sync` and `parking_lot` locks are
banned in `.clippy.toml` outside `crates/blaze-core/src/lock.rs`, and a contended wait records who
waited behind whom into the profile's `lock_waits` (`blaze debug locks` ranks them and says what to
use instead: arc-swap or RCU for reads, papaya for a map, an atomic for an integer, a channel for a
queue, an owner for one holder); a shared map is `papaya::HashMap`; a single-owner map or set is
`blaze_hash::{HashMap<K, V, A>, HashSet<K, A>}` (foldhash with a fixed seed, its allocator named: a
frame's for a task, `Global` with a reason otherwise), with `blaze_hash::KeyHasher` for keys that
are already content hashes and `blaze_hash::Blake3Hasher` for persisted content IDs; results of
parallel items come back from `blaze_graph::par` in order, never pushed into a `Mutex<Vec>`; a queue
is `crossbeam::queue::{SegQueue, ArrayQueue}`; a channel is `crossbeam-channel`; a counter or flag
is an atomic. How a thread or fiber waits is `deadline-waits`. `BTreeMap` only where iteration order
is part of the output.
## sans-io-cores (rule 14)
Every core (a scheduler decision, a protocol, a retry or backoff policy, a lease, a maintainer's
plan) is a synchronous state machine that reads time only from an injected clock
(`advance_clock(now)`), owns no socket, file, thread, timer or sleep, and hands back decisions and
deadlines (`take_decisions`, `next_deadline`). Drivers do the IO and stay thin. A test replays a
transcript with no real clock, and a deterministic simulation test drives the core through
`blaze_core::sim::Sim` (`testing` skill): a core that does its own IO cannot be simulated, so it
cannot be proven. Protocol code is a core too: an HTTP client or server, TLS (through rustls's own
byte-in/byte-out `Connection`, never `tokio-rustls`), the daemon's wire protocol, a remote-cache or
registry client. Its interface is bytes in, bytes and events out, so any IO backend can drive it
(tokio today, io_uring on Linux later) by writing one thin driver, with no change to the core. A
dependency that ties protocol logic to one runtime (hyper's connectors, hyper-util, reqwest,
tokio-rustls) is replaced by a core and a driver, not wrapped. Persisted state is a core too: a
writer of files that must survive a crash (a manifest, a journal, a history, a store) asks for each
write, sync, rename, delete and lock as a blaze-core `Effect` and takes `Completion`s, so `Sim` sees
every one and can tear what was not synced; its durability is the order of the effects it emits,
never a direct `fsync`, `F_FULLFSYNC` or `flock`. Each core module carries `#![blaze::sans_io]` and
`#![deny(blaze::sans_io_core)]`: the lint walks every call the module makes, through workspace
functions, and refuses the clock, `std::fs`, `std::thread`, `std::net`, `std::process`, `std::env`,
OS randomness and `libc`/`rustix`/`nix`. What a core needs of its process beyond IO (its pid,
whether another process lives, symbols to name a stack) comes through a trait the driver implements,
taken as a type parameter: calls through it are the driver's, not the core's. Drivers are separate,
unmarked modules, so the exemption is by module, never by an allow on a line. A core's errors carry
the path the driver will report, and a step that waits on no effect is a typed error
(`bounded-progress`).
## every-wait-says-what (rule 15)
A thread or fiber that blocks says what it waits for: the wait opens a span naming the awaited key,
lock, channel, IO or child, and its owner when known. A wait with no name, and time on a worker
covered by no span, are bugs; the profile test fails on them.
## bounded-progress (rule 18)
Every loop that waits for progress (a solver, a fixpoint, a readiness probe, a retry) has a bound
(fuel, depth or a deadline from the injected clock) and ends in a typed outcome: done, or a failure
naming what it was doing, the goal or key, and how far it got. Never an open loop whose only exit is
success, and never a spin with no cap.
## errors-name-the-thing (rule 19)
An error names the item it is about (the function or instance with its path, the crate, the key, the
file and line) and the rule that refused it, in the message itself. "a template made against 6
references is given 7" is unfinished until it says which function and which template.
## panics-fail-one-job (rule 20)
A panic inside a job (a query, a codegen unit, a proc-macro evaluation) fails that job's units with
a typed error naming the panic and the job; the daemon keeps serving and keep-going (the default;
`--fail-fast` opts out) keeps building the rest. Formatting an error must not panic: render what
needs the database while the database is attached.
## no-wait-across-thread-locals (rule 27)
A fiber can resume on another thread after any wait, so nothing held across a wait may be tied to a
thread: no thread-local borrow, lock guard or `Rc`. Mark regions that must not wait with `NoWait`;
read thread-locals in `#[inline(never)]` functions that end before any wait.
## deadline-waits (rule 44)
A thread blocks in the kernel only through `blaze_core::wait`, which takes an absolute `Deadline` on
the injected clock (a driver's `now()`), recomputes the time left from that clock before every
system call, treats an interrupted (EINTR) or spurious return as a retry, and ends in a typed
outcome (`Waited::Ready` or `Waited::Deadline`), with fuel for a clock that does not move.
`Driver::poll` takes that `Deadline`, never a relative timeout, so no layer restarts one. The
kernel's waits (`poll`, `ppoll`, `select`, `epoll_wait`, `kevent`, `nanosleep`, `usleep`, `sleep`,
`GetQueuedCompletionStatusEx`, ...) are banned in `.clippy.toml` outside
`crates/blaze-core/src/wait*`, each with its `blaze_core::wait` replacement; io_uring waits pass a
signal mask that blocks every asynchronous signal but the stop signals. Only IO driver threads and
the pool's idle park block in the kernel: a fiber that waits, with a deadline or without, parks on
the scheduler (a key, a counter, a job, a timer on the driver's wheel), never a `Condvar`, a channel
receive, `thread::sleep` or a raw `spin_loop`; elsewhere a spin is the one bounded spin-then-park
helper. Nothing sends a signal to a pool or driver thread: the sampler reads the kernel's samples
(Linux `perf_event_open`) or stops the thread (macOS `thread_suspend`, Windows `SuspendThread`). The
DST in `crates/blaze-core/src/wait/tests.rs` interrupts every wait and checks that it ends by its
deadline, with a planted relative-timeout retry it must catch.
See [docs/v2/plan/design/deadline-waits.md](../../../docs/v2/plan/design/deadline-waits.md).
## macos-private-apis (rule 45)
On macOS, use any private or undocumented interface (Mach calls, libsystem and libdispatch
internals, `__ulock_wait2`, `kevent_qos`/`kevent_id` workloops, `sandbox_init_with_parameters`,
kperf, `thread_selfcounts`, `proc_info`, ...) where it is more efficient or more capable than the
public one, and the public one where it is the better (`os_sync_wait_on_address_with_deadline`'s
absolute deadline over `__ulock_wait2`'s relative one). Each use carries a comment naming the symbol
and why it wins, and a test that resolves the symbol at run time and fails naming it if it is gone,
so an OS update that removes it fails loudly in CI. There is no public-API fallback (`no-fallback`):
a missing symbol is an error naming it. Which are in use and which are next is in
docs/v2/plan/design/deadline-waits.md.
See [docs/v2/plan/design/deadline-waits.md#macos-private-apis-rule-macos-private-apis](../../../docs/v2/plan/design/deadline-waits.md#macos-private-apis-rule-macos-private-apis).
<!-- End of the generated rules. Hand-written notes follow. -->