jonnify·echd /echd/bus/one-bus/the-braced-keyspace

echd — Echo on Encore · E3.1 · dive

The Braced Keyspace

Four rules hold the wire together, and all four are enforced at the key, not asserted in review — one braced root, branded ids, declared keys, one clock.

Vision · real substrate

echd speaks in the present tense over a build ladder. Every module, verb, key, and port named on this page is real; the composition into one standing platform is the vision the ladder builds.

§1

The dive

docs/echo_mq/emq.design.md:27-98,375

Every family writes into one keyspace, and that keyspace is governed by four rules that never bend. A queue's keys all live under one braced root, emq:{q}:, so {q} is a hash tag and the whole queue lands in a single slot. The ids on it are branded JOB snowflakes, gated at the one place a raw string could become a key. Every Lua script touches only the keys handed to it in KEYS[]. And every lease is stamped by the server's own TIME, never a caller's wall clock. Braced, branded, declared, clocked — four rules, one wire.

The reason to name them together is that they fail together. Drop the braces and a cluster scatters a queue's keys across slots, so no single script can move a job atomically. Skip the gate and an unbranded string slips in as a key, and the type is no longer the check. Derive a key inside a script instead of declaring it, and the slot check cannot see it. Read a caller's clock and two workers disagree about whether a lease expired. None of these is a style preference; each is a way the wire breaks, and one of them already did.

§2

The master invariant, drawn

hover a rule
Four rules, one wire · braced · branded · declared · clocked · hover to read
emq:{q}: — one braced root · a queue's keys share one hash slot JOB — branded, gated at the key builder · the brand is the check KEYS[n] — every Lua key declared · an ARGV base is not a root TIME — the server's clock on every lease · never the caller's break one and the wire breaks — so all four are pinned at the key
One braced root. Every key a queue touches lives under emq:{q}: — the braces make {q} the hash tag, so on a cluster the queue's keys land in one slot and a single Lua script can span them atomically. One queue, one slot, one script.
One branded type. Ids on the bus are branded JOB snowflakes, minted once and gated at the key builder — the one place a raw string could become a key is the one place the brand is checked. The type is not documentation; it is the boundary.
Every Lua key declared. A script reaches only the keys passed in KEYS[], or a key derived from a declared KEYS root. A base handed through ARGV and joined inside the script is invisible to the slot check — the emq.2.1 F-1 finding — and forbidden.
One clock. Wherever a lease is set, extended, or read, the timestamp is the server's own TIME, never a caller's wall clock. Two workers cannot disagree about whether a lease has expired, because neither of them is the one keeping time.

Hover or focus a rule to read it; click to pin. Without scripting, all four read in sequence.

§3

The rule that hid on one node

docs/echo_mq/emq.design.md:80-98

Three of the four rules announce themselves the moment they are broken. The fourth is the dangerous one, because it can be broken and still pass every test on a single-node Valkey. A Lua script is allowed to touch a key only if that key is declared in KEYS[], or built from a declared KEYS root. It is tempting to hand the script a base string through ARGV and join the rest of the key inside the script — it works, the tests are green, and nothing complains. On a cluster it is a latent break: the server routes a script by the slots of its declared keys, and a key assembled from an ARGV base was never declared, so the script can be sent to a node that does not own the key it silently touches.

This is the emq.2.1 F-1 finding, and it is why the invariant is stated as every Lua key declared, not most. A gate that runs only on one node cannot see the break — the single node owns every slot — so the rule cannot be a test you run; it has to be a discipline you keep at the point the key is built. That is the through-line of all four rules: the braces, the brand, the declaration, and the clock are enforced where a key or a lease is constructed, so that correctness does not depend on a reviewer noticing or a cluster being present to fail.

§4

The rule

one line to carry

The keyspace rule — every key braced, every id branded, every Lua key declared, every lease on the server's clock. The invariant lives in the key builder, not the code review: three of the four rules break loudly, but the fourth — an ARGV base treated as a declared root — hides on a single node and takes the cluster down, so the wire pins all four where keys are made.

§5

Doors

where the invariant is proven
§6

References

sources · related

Sources

Related