Operational semantics

This document specifies what Hale programs do when they run. Where grammar.ebnf says what's syntactically valid and types.md says what's meaningfully valid…

Reference material, synced from the compiler repo’s spec/. The guide is the gentler path in.

This document specifies what Hale programs do when they run. Where grammar.ebnf says what’s syntactically valid and types.md says what’s meaningfully valid, this document says what happens at runtime.

The semantics are described informally (engineering-grade prose), not as formal small-step rules. Formal operational semantics are deferred to v1+; the framework’s substrate-invariance claim is not blocked on full formalization.

Program startup

Section titled “Program startup”
  1. The runtime initializes:
    • Region allocator, schedulers (one per CPU core; cooperative within each), bus router, lifecycle dispatcher.
    • Establishes the runtime root locus as the implicit parent of main’s implicit locus.
  2. Bus topics with bindings { Topic: ...; } entries in the main locus are registered against their declared transports. Topics without a binding stay same-process via the cooperative queue.
  3. fn main() is invoked.

Function call

Section titled “Function call”

A fn name(args) -> ret { body } invocation:

  1. Caller passes args by value.
  2. Implicit locus is allocated for the function’s scope.
  3. Body executes statement-by-statement.
  4. Locally bound handles are bound to local names.
  5. Anonymous-child loci with ongoing-work surface attach to the implicit locus.
  6. On return value;, control flows back to caller. Before return, the implicit locus drains and dissolves (waits for all children to finish; depth-first cascade per F.4).

Receiver calls on text values

Section titled “Receiver calls on text values”

For x of type String, StringView or std::str::ByteView, a call x.f(args) is the call std::str::f(x, args); for x of type Bytes, BytesView or BytesMut, it is std::bytes::f(x, args) (GH #2068, F.59). It applies when that fn is public and takes a value of x’s type first (v.find("\n", 0) on a ByteView is std::str::find(v, "\n", 0)):

fn main() {
let raw = " Key = Value ";
let (k, v) = raw.cut("=") or { return; };
println(k.trim().lower(), "|", v.trim());
let b = std::bytes::from_string("hale");
println(b.at(0) or -1);
}

Implicit Int → Float widening at call sites

Section titled “Implicit Int → Float widening at call sites”

When a function parameter has type Float and the call-site argument has type Int, codegen inserts an implicit sitofp widening at the call site. The same rule fires at let-binding type ascriptions: let nf: Float = self.n; where self.n: Int succeeds. The widening is one-way only — Float → Int narrowing remains explicit, and Decimal never participates in implicit cross-type conversion. Phase 2c. See F.23 in spec/design-rationale.md and the Phase 2c entry in spec/stdlib.md.

Expressions — if and block tails

Section titled “Expressions — if and block tails”

A { ... } block whose last item is an expression without a trailing ; carries that expression as its value. In expression position (let-RHS, fn-call argument, if-arm body) the value is consumed; in statement position (loop body, Stmt::If / Stmt::Match block) the trailing expression is evaluated for side effects and the value is discarded — semantically equivalent to having added the ;. A call there is the call statement, a builtin’s or a fn’s that returns nothing included: if c { println("x") } and a statement match‘s arm P -> { println("x") } build as if c { println("x"); } does. An if, a match (an if let included) or a block there is the statement of that shape, its own arms’ tails statements in turn: a value-shaped trailing if c { println("a") } else { println("b") } (below) ending a body that returns nothing is that if statement. (GH #2016; until then the check passed these and the build refused the call as having no binding.)

A fn-shaped body (free fn, locus method) with a declared return type treats its trailing expression as an implicit return: fn double(n: Int) -> Int { let d = n * 2; d } returns d (2026-08-11 — previously the typechecker accepted this form and codegen rejected it as a fall-through). The tail is checked as that return is: against the return type (a fallible body’s success type), a set’s member flowing into the set, an Int widening to a Float (2026-11-15 — previously the check judged only a Decimal tail’s scale, and the build refused a tail of another type, a member included, with no place). A fallible locus method’s tail is its return as every other body’s is. A body with no declared return type keeps statement-position semantics: the tail is evaluated for side effects. So does a () fallible(E) body’s, an or included (fn fwd() -> () fallible(E) { touch() or fail err } lowers as the statement touch() or fail err;; GH #2005). The same body’s last statement is its value when it is a match, an if or a block: its arms and tails carry the value down, each leaf a return (§ “Definite return”, below).

Such a body returns nothing, so a return in it carries no value: a return <expr>; in a fn with no -> T (a fallible fn’s success type is then ()) or in a lifecycle hook (birth, run, accept, drain, …) is a type error at the value, a call with no value of its own included (return touch() or fail err; in a () fallible(E) fn: write the call as a statement, then return;). fn main is the exception: its return n; is the process exit code (§ “Process exit”).

main.hl:1:66: type error: `return` carries a value, but this body
returns nothing: a fn with no `-> T`, or a lifecycle hook, which
never returns a value. Declare the return type (`fn f() -> T`),
or write `return;`.

if cond { ... } else { ... } is dual-position:

The two positions are distinguished by shape, not syntactic context (WS3.2). A trailing if — the last item of a block, with no ; — becomes that block’s tail expression when it is value-producing: every arm (then, else, and each else if) must end in a trailing expression. This is what lets an if nest as a block value:

let x = if a { if b { p } else { q } } else { r };
// \__ then-arm block whose tail is the inner if __/

The inner if is the then-arm block’s tail, so the outer if’s then-value is the inner if’s value. A trailing if that is not value-producing (no else, or an arm with no tail) stays a statement — it has no value to carry, and forcing it into the value path would leave a tail-less arm with nothing to yield.

else if chains carry through the value path — ElseBranch::ElseIf recurses and the innermost arm’s tail feeds the phi at the outermost merge.

Phase 2b introduced if-as-expression; WS3.2 (2026-06-11) made a value-producing trailing if compose as a block tail. See F.24 in spec/decisions.md and the Phase 2b entry in spec/stdlib.md.

match is dual-position too (Gap C, 2026-07-17):

An enum-constructor pattern’s values are each a binding, _ or a literal: a nested pattern there (Op::Pair((a, b))) is a type error at the nested pattern; bind the value and match or read the binding in the arm.

.Variant patterns (GH #2069, F.58). Against a value whose type is an enum (directly, through an alias, or a generic enum’s instantiation), a pattern may name a variant with a leading dot:

type Outcome = enum { Result(Int), Refused(String), Pending };
fn index_or(o: Outcome, fallback: Int) -> Int {
return match o {
.Result(n) -> n,
.Refused(_) | .Pending -> fallback,
};
}

The checker resolves each .V against the type it gave the scrutinee and records the variant; lowering reads that record rather than naming the enum again, and in a generic body each specialization resolves the pattern against its own instantiation.

A variant’s pattern names all of its values or none: E::V (and .V) with no parentheses matches the variant whatever it carries, and one with parentheses names each value the variant declares. A count that differs (Job::Work(1, 2) against Work(Int), .Rest(x) against a variant that carries nothing) is a type error at the pattern (“the variant `Work` carries 1 value, and this pattern names 2”). Until GH #2069 the check passed it and the build refused it.

A pattern’s bindings are locals of their arm (its guard and its body), each of the type of what it binds: a bare binding is of the scrutinee’s type, a variant’s value of the variant’s declared field type (a set member’s of the member’s type), a tuple pattern’s part of the element’s type. A binding is typed at its uses as any other local is, so with type S = enum { A, B(Int) }, S::B(v) -> { let t: String = v; … } is a type error at v. An or-pattern’s bindings are the first alternative’s (every alternative binds the same names at the same types, below). Until GH #2016 a binding was entered untyped, and that let passed both the check and the build.

A literal in a pattern is a value of the type it is matched against, compared as lowering compares them (an identity’s or a range’s scrutinee is its Int): match n { "a" -> … } over an Int, or the 2 of (1, 2) against an (Int, String), is refused at the literal (“this pattern is of type `String`, and the value matched is of type `Int`”). A quantity literal in a pattern is the quantity it is in an expression, converted into the scrutinee’s denomination: match d { 1min -> … } over a Duration matches sixty seconds. A Decimal literal takes the scrutinee’s scale. The values in an enum constructor’s pattern (Fee::Flat(2.50d)) are matched against the variant’s declared types the same way.

Or-patterns (GH #1995 E2). An arm’s pattern may be two or more alternatives separated by |; the arm matches when one of them does:

type CtlError = enum { Invalid(String), NotFound(String), NotReady(Int) };
fn problem(e: CtlError) -> String {
return match e {
CtlError::Invalid(p) | CtlError::NotFound(p) -> p,
CtlError::NotReady(h) -> f"not ready: {h}",
};
}
fn usage(verb: String) -> String {
return match verb {
"assign" | "unassign" -> verb + " <name>",
"close" -> "close <name>",
_ -> "unknown",
};
}

The body is lowered once: each alternative’s test branches to the arm’s one guard or body block, its bindings merged there.

Matching strings. A String scrutinee matches string-literal patterns by value ("assign" | "unassign" -> …). A ladder of three or more if tests comparing one String place with literals, chained with else if or as consecutive if statements, is the same decision, and --warn-string-match (on hale check or hale verify) warns at its first test with the match it reads as. The advisory is off by default for every verb, hale verify included, and never reports stdlib source.

Scrutinee-less form. match { cond -> body, else -> body } omits the scrutinee and tests guards directly:

let tier = match {
n < 10 -> "small",
n < 100 -> "medium",
else -> "large",
};

Arms are tried in written order and the first whose condition is true wins. else is the catch-all and carries no condition.

This is sugar, desugared at parse into the guarded form it replaces — match { c -> b, else -> d } is match true { _ if c -> b, _ -> d }. Everything downstream sees an ordinary match, so both positions, block arm bodies, the trailing comma rule, and the all-guards-false fallthrough above behave identically.

The form exists because first-match-wins over conditions is common where dispatch is a ladder of tests rather than a shape match, and the scrutinee in that case is a value the author invents only to ignore.

match { is not ambiguous with matching on a block expression: that shape is written match (…) { … }.

if let and let … else (GH #1995 E3). Two spellings of a two-arm match, for the test of one pattern:

type Side = enum { Buy, Other(String) };
type Outcome = enum { Result(Int), Refused(String) };
fn note(side: Side) -> String {
if let Side::Other(raw) = side { "other: " + raw } else { "buy" }
}
fn index_of(o: Outcome) -> Int {
let Outcome::Result(index) = o else {
return -1;
};
return index * 2;
}

if let is the enum counterpart of or { return …; }, and it introduces no Option (F.52). No keyword is added.

Definite return

Section titled “Definite return”

A body with a declared return type (a fn, a locus method, a fallible fn with a success type) returns a value on every path that reaches its end.

The result position. Its tail is its value (above), and when its last statement is a match, an if or a block, that statement is the value: every arm of the match (an expression arm, or a block arm’s own result position), the if’s then-block, each else if and its else, and a block’s tail or last statement in turn. A leaf in result position is checked as the return it is, against the return type (“this is the body’s value (its last statement’s arm or tail): expected `String`, got `Int`”), and lowered as one, for every result type:

fn word(n: Int) -> String {
match n { 1 -> "one", _ -> "other" }
}
fn sign(n: Int) -> Int {
if n > 0 { return 1; } else if n < 0 { -1 } else { 0 }
}

A leaf that leaves (return, fail, …) is unchanged. A trailing match stays a statement in the grammar, and a trailing if some arm of which has no tail stays one too (§ “Expressions — if and block tails”); in a body that returns a value, the result position is what makes them its value.

Reaching the end. A path leaves without reaching the end when it meets return, fail, break, continue, terminate or violate; an if with an else each of whose branches leaves; a match each of whose arms leaves (F.18 makes it exhaustive); a block that leaves; a while true loop no break leaves (a break inside a nested loop leaves that loop, not this one); or a statement whose value is a match, an if … else or a block expression that leaves on every path. Any other statement can complete, and the body can reach its end when its last statement can, or when it is empty. Such a body is a type error at the declaration’s name, naming the path as a secondary location:

main.hl:1:4: type error: fn `sign` returns `Int`, and its body can reach
its end without a value: this `if` has no `else`, so when its condition
is false the body ends after it. Return a value on that path, or end the
body with its value (a tail expression, or a `match`, an `if … else` or
a block whose every arm ends in one)
note: the path that reaches the end without a value at main.hl:2:5

The paths it names: an if with no else, and an if let with none (GH #1995); a while loop whose condition can be false, and a for loop; the break that leaves a while true; an arm or block whose last statement completes; an empty body, block or arm. The judgment is the program’s shape, not its values: while n > 0 { return n; } can finish as far as it is concerned, and a call that never returns (std::process::exit) is a call that completes. Until GH #1940 the check passed such a body and the build refused it as falling through, with no file or line; a tail match was refused the same way.

Expression statements

Section titled “Expression statements”

An expression followed by ; is a statement only when evaluating it does something: a call (a fn, a method, a builtin — its value, if any, is discarded), a locus literal (an instance built in statement position, § “Locus instantiation”), or an or over a fallible call. Any other expression — an arithmetic or comparison, a name, a field read, an index, a literal — only computes a value and discards it, and is a type error at the expression:

main.hl:1:24: type error: this expression's value is unused: a
statement that only computes a value does nothing. Bind it
(`let v = ...;`), assign it (`self.f = ...;`), pass it to a call, or
delete the statement.

A block’s trailing expression with no ; is not a statement and is not judged here (§ “Expressions — if and block tails”). Before this rule the checker accepted a + 2; and the backend refused it with no file or line.

Expressions with no value

Section titled “Expressions with no value”

A call to a fn that returns nothing, an or on a () fallible(E) call (push(self.marks, t) or { }, write_file(p, s) or discard), and an if / match / block with no tail value produce no value: their type is (), and there is no () value to bind, store or compute with. Such an expression is a statement or nothing. Where a place takes the type of what it is given rather than checking it against a declared one — a let (with or without an annotation), a tuple or array element, an operand, a generic fn’s argument — the check refuses it at the expression:

main.hl:7:20: type error: let `full` needs a value, and this
expression produces none (its type is `()`): a call to a fn that
returns nothing, an `or` on a `() fallible(E)` call, or an `if` /
`match` / block with no tail value. Write it as a statement of its
own (`call() or { ... };`), or give it a value to produce.

A place with a declared type (a parameter, a field, a condition, a return) already refused () as a type mismatch. Until 2026-10-13 the others checked clean and the build refused them with no file or line.

Operators and their operand types

Section titled “Operators and their operand types”

== != < > <= >= and the arithmetic, bitwise and logical operators apply to these operands (both of one type; an Int widens into a Float, F.23):

Operand Operators
Int (an identity’s and a range’s are the unit dialect’s, spec/units.md) + - * / %, & | ^ << >>, unary - ~, every comparison
Float + - * /, unary -, every comparison
Decimal<S> + - * / %, unary -, every comparison (one scale)
U64 + - * / % (checked and unsigned: an overflow or a division by zero is a violation), & | ^ ~, << >> by an Int count from 0 to 63, every comparison (unsigned); no unary -; an integer literal operand is a U64, and nothing else mixes in (spec/types.md § U64)
I32, U32, I16, U16, I8, U8 + - * / % (checked at the width: an overflow, a division by zero, or a signed minimum divided by or negated through -1, is a violation), & | ^ ~, << >> by an Int count below the width (>> arithmetic on a signed one), every comparison (signed or unsigned as the type is), unary - on a signed one; an integer literal operand is the other’s type, and operands never widen (spec/types.md § Fixed-width integers)
U256, I256 + - * / % (checked: an overflow or a division by zero is a violation), & | ^ ~, << >> by an Int count, unary - (an I256’s only), every comparison; never mixed with another type (spec/types.md § U256 and I256)
Duration, Time, a quantity, a point the unit dialect’s algebra (spec/units.md)
Bool == !=, && ||, unary !
String + (concatenation; String + <printable> renders the other side), every comparison
an enum == !=: the tag, then each payload by its own == (a nested enum’s included), so only when every payload type of every variant has ==; a generic enum’s instance by its payloads with its arguments in place (Value<P> compares only when P does)
Bytes, a struct, a tuple, an array, a bounded, a locus, an interface none

Anything else is refused at the operator, naming the operand and what its type has: “`<` does not apply to `Bool`: a `Bool` has `==`, `!=`, `&&`, `||` and `!`”. A compound assignment (x += v) is its operator’s: b += true on a Bool is refused the same way. A struct, tuple or array is compared or combined through its parts, and so is an enum one of whose payloads is one (“`==` does not apply to `E`: its variant `B` carries `Inner`, whose variant `X` carries a struct (`P`), which has no `==` …”; until 2026-10-17 the check passed it and the build refused it, “match on TypeRef not supported”, and an enum payload of an enum was refused at the build even when it compared). Until 2026-10-13 the check held only that the two sides were one type, and the build refused true < false, p == q of two structs, b"a" + b"b" and !n with no file or line.

String slicing

Section titled “String slicing”

A range in an index’s brackets slices a String by byte offset and yields a new String holding a copy of those bytes:

Form Bytes Same as
s[lo..hi] lo up to, not including, hi std::str::substring(s, lo, hi)
s[lo..=hi] lo through hi s[lo..(hi + 1)]
s[lo..] lo to the end s[lo..len(s)]
s[..hi] the start up to, not including, hi s[0..hi]
s[..=hi] the start through hi s[0..(hi + 1)]
s[..] every byte (a copy) s[0..len(s)]

The bounds are Int expressions, evaluated left to right after the receiver, and the receiver is evaluated once in every form: next_line()[4..] calls next_line once, as a closed slice does. Bounds clamp and never fail: a start below 0 is 0, a bound past the end is the end, and an end before the start gives "". Offsets are bytes, not characters, so a slice can cut a multibyte UTF-8 character in two; std::str::cp_at and cp_size walk code points.

A bound is left out only inside an index’s brackets (GH #1995): a bare 3.. or ..3 anywhere else, for i in 0.. included, is a parse error. ..= needs its end (s[lo..=] is refused). An open form is the closed form it reads as before anything checks or lowers it, so hale check and the build accept exactly the same open slices as closed ones. Only a String slices: a range index on an array, a bounded, Bytes or a view is refused at the check (spec/types.md § What the compiler cannot compile yet; std::bytes::slice copies a range of bytes, std::str::slice a range of a ByteView).

Each slice measures the receiver and copies the bytes (O(n) + O(hi - lo), spec/stdlib.md § Linear byte scanning), so walking a long string by re-slicing its tail is quadratic; a text source (§ Text sources, below) or a ByteView walks it in one pass (spec/styleguide.md S16).

An index that is not a range (s[i]) is refused at the check: one position of a String could mean a byte or a character, and Hale picks neither. The refusal names both ways to say which: “`s[i]`: a `String` has no element to index, since one position could mean a byte or a character. Read bytes through a view (`let v = std::str::bytes_view(s);` then `std::str::byte_at(v, i)` …), or slice the text (`s[i..(i + 1)]`, `s[i..]`)”. Until GH #1995 the check passed it and the build refused it (“indexing a non-array value”).

A byte read that way is an Int (0..=255), and a byte literal names one by its character: b'/' is 47, so std::str::byte_at(v, i) == b'/' reads as the test it is (GH #1995, spec/tokens.md § Integer literals). A byte literal is an integer literal in every respect: it types as Int, folds in a constant, and matches in an arm’s pattern, or-patterns included (b'a' | b'A' -> …). It is the lexer’s, so hale check and the build accept exactly the same ones, and refuse the same ones (no byte, several bytes, a non-ASCII character) at the literal.

Text sources

Section titled “Text sources”

std::str::split(s, sep), std::str::lines(s) and std::str::words(s) are for sources: each names the parts of a text for a for loop to visit, one per iteration (GH #1995). They are not values. Hale has no sequence value for them to return, which is also why std::str::split_into writes into storage the caller owns.

fn main() {
let row = "id,name,,note";
for field in std::str::split(row, ",") {
println("[" + field + "]");
}
for line in std::str::lines("first\r\nsecond\n") {
println(line);
}
for w in std::str::words(" any amount of space ") {
println(w);
}
}
Source The parts
split(s, sep) The text between occurrences of sep, empty parts included, as split_into writes them: "a,,b," is a, an empty part, b, an empty part. "" is one empty part, and s with no sep in it is s. An empty sep gives no parts.
lines(s) The text between \ns, each without one \r before its \n (or before the end of the text). A final \n starts no line: "a\r\nb\n" is a, b. "" is no lines, and "\n" is one empty line.
words(s) The runs of bytes that are not ASCII whitespace (space, tab, LF, vertical tab, form feed, CR). There is never an empty word, so "" and " " are no words.

Before anything checks it, the loop is rewritten as one while over a view of s (hale_syntax::str_sources, in the desugar sequence every entry point runs). The checker, the analyses and lowering see that loop, so hale check and hale build accept the same programs, and a diagnostic in the body points where the body was written.

A source starts a chain (§ Element chains, GH #1995 S2). A call of a source of its own arity, followed by a stage or a terminal, is an element chain whose elements are the parts, each it for its turn:

fn main() {
let text = "id,name,,note";
println(std::str::split(text, ",").filter(len(it) > 0).count()); // 3
let longest = std::str::words("pear fig banana").max(len(it)) or "";
println(longest); // banana
}

The parts are the loop’s, by the same scan: the chain’s stages and terminal are the loop’s body, the arguments are evaluated once, and break, continue and return in an each block act as in the loop. Every stage and terminal applies, and on a source every terminal is recognized with no stage before it (std::str::words(s).count()), since the receiver is the standard library’s call and no facade of a program’s can be hiding behind it. first, find, min and max answer the part they picked, and an empty selection fails with the IndexError an empty vec’s does, so or supplies the fallback. A chain over a source keeps no list of the parts: like the loop, it makes one String per part, for that iteration, and min and max keep the best part’s offsets (and its key), not the part.

A source used as anything other than a loop’s iterand or a chain’s source is refused at the check, with the ways to keep the parts: “`std::str::split` is a `for` source and a chain’s source, not a value: write `for part in std::str::split(s, sep) { … }`, or a chain over it (`std::str::split(s, sep).filter(…).count()`). Hale has no sequence value to return; to keep the parts, write them into storage you own with `std::str::split_into(s, sep, v)` or a chain’s `into(v)`”. So is a call with the wrong number of arguments (“`std::str::lines(s)` takes 1 argument, got 2”), and an argument that is not a string, at the argument (“`std::str::split(s, sep)`: `sep` takes a `String`, not a `Int`”).

A for over a String itself is refused at the check: “`for` over a `String`: a string is not a sequence. Iterate `std::str::split/lines/words`, or a `bytes_view` by index”. Until GH #1995 the check passed it and the build refused it (“for-loop iterator must be an array”).

Binary data — Bytes and conversion

Section titled “Binary data — Bytes and conversion”

Bytes is the binary-safe sibling of String. Same single-pointer ABI; the underlying blob is [i64 len][u8 data[len]]. The i64 len prefix means embedded NUL bytes survive, unlike String’s strlen-based view.

Producing a Bytes:

Consuming a Bytes:

All returned Bytes values from the path-call surface are anchored in the lazy global payload arena, so callers can stash the pointer past the call site without m49 deep-copy plumbing.

Rendering values as text

Section titled “Rendering values as text”

println, print, to_string, String + x, and f-string interpolation all render through one rule. The set of types that rule accepts is called the printable set.

A type is printable when it is:

Three exclusions are load-bearing rather than incidental:

Rendering is defined recursively, with two rules about the nesting:

Rendering has no user-visible ordering or allocation guarantees beyond producing the text above; results are owned by the caller’s arena like any other constructed String. A StringView renders as its text, copied as std::str::clone copies it, so the String that to_string(view), "x=" + view or f"{view}" produces does not follow the builder the view reads (2026-10-05, F.40 phase 4: before it, only println and print rendered a view, and the other three passed the check and were refused at build).

The checker and lowering read one definition of this rule (hale_types::printable): the checker refuses a value outside the set at its span, and lowering renders a record only when every field is printable, as the checker does.

Declared templates: @display (RFC #2035, decisions F.54)

Section titled “Declared templates: @display (RFC #2035, decisions F.54)”

A record, or an enum’s variant, may declare the text its values render as for people:

@display("${dollars}.{cents:0>2} {currency}")
type Money { dollars: Int; cents: Int; currency: String; }
type Side = enum {
@display("buy") Buy,
@display("other: {0}") Other(String),
Unlisted(Int),
};

{x:?}, the structural form. The format-spec kind ? renders a value by the structural rule above whatever its template, at every depth: a nested value with a template of its own renders structurally too. A String inside a composite is quoted and a composite over 32 elements truncated, as always. It is what a test failure, a log of internals or a debugger wants, and it exists for every printable value. An assertion of std::test that renders a value shows both forms when they differ; today’s assertions take Bool, Int, String and Float, which have no template.

Format specs

Section titled “Format specs”

f"{expr:spec}" renders expr under spec instead of under the default rule. The grammar is in spec/tokens.md. Ordering is fixed: the value is rendered first (honouring precision or a hexadecimal kind, both of which need the value) and the text is padded second (width, fill, align).

An absent alignment resolves from the value’s type — numeric values pad on the left, everything else pads on the right — so a column of figures lines up on the ones place and a column of names lines up on the first letter without either being asked for.

Grammatical errors in a spec are reported by the parser; spec/value mismatches (hexadecimal of a String, a precision on an Int) are reported by the typechecker. Neither reaches codegen.

Locus instantiation

Section titled “Locus instantiation”

LocusName { params }:

  1. Compute params (overrides applied to declared defaults). self resolves lexically: inside a default expression — including the field inits of a nested locus literal written in that default — self.X reads the locus being instantiated (earlier-declared siblings only; a default that reads a later-declared sibling, or its own param, is a type error at the read, since defaults run in declaration order). Inside an override expression, self belongs to the code that wrote the literal — the enclosing method’s locus, or the enclosing params block when the literal itself sits in a default (F.4 call-site rule). This holds regardless of where the instantiation executes (fn main, a params-init, or another locus’s method body — 2026-07-14 fix). For a locus placed pinned, the defaults, and every locus nested under it with its whole instantiation, are computed on the locus’s own thread, and the literal completes once they are; an override is still evaluated where the literal is, except a locus it builds as the field’s value, which is part of the pinned subtree (runtime.md § “Placement classes”, m27 + m28a). For a field placed on cooperative(pool = X) the same holds on X’s worker, as the first job of that field: its defaults and every locus nested under it are computed there, and the literal completes once they are (the pool side of m27 + m28a); the field’s own birth() still runs where the literal is.
  2. The nearest enclosing ancestor that declares accept(c: I) for the child’s type — the type itself, or an interface the type satisfies (see “An interface accept” below) — is the owner (innermost-wins — interest-based ownership / accept bubbling; see below and runtime.md). Its accept(c) runs once the child’s region exists and its params are built, before the child’s birth(), and it cannot reject (runtime.md § “Lifecycle obligations”, line 5). With no accepting ancestor the child is a transient throwaway (no owner).
  3. Region allocated as a sub-region of the owner’s region (the accepting ancestor — not necessarily the direct parent); size determined by projection class.
  4. Bus subscriptions wire up, before birth(), so that birth() may publish to its own subscriptions; delivery to the locus becomes eligible once birth() (and its birth_check) has completed, and what was published to it before waits, in order (runtime.md § “Lifecycle obligations”, line 6). A cooperative locus’s subscriptions that take no key wire up as soon as its region exists, before its params are built, so what its params’ children publish to it while they are born or run waits for it too (2026-10-12); a keyed one waits for the params its key reads, a pinned locus’s and an accepted child’s for step 2’s accept, and one bound to an shm_ring (its reader calls the handler outside the window) for the params too. A publish made before its subscriber is built at all reaches no subscription of it; hale check warns where it can see one in a body.
  5. birth(args) runs synchronously.
  6. Its fn members are reachable for invocation.
  7. If run declared, scheduled to run on the locus’s scheduler. For a locus placed pinned or on a cooperative pool other than main, “scheduled” means handed to that thread or worker and the instantiation returns immediately. For a locus that runs inline on the main thread — the default placement, and an explicit cooperative(pool = main) — run() executes synchronously here, and step 8 does not happen until it returns. See § Birth order is load-bearing.
  8. Expression returns the locus handle.

The instance before its params. Step 1 can already reach the locus being built: a default’s child is instantiated inside the literal (its run() inline, step 7), and an I{} it births bubbles to this locus when this locus is the accepting ancestor. So the locus’s own state is initialized before step 1, as soon as its region exists, before anything can reach it: its accepted children (self.children, empty), its restart, quarantine and drain state, its failure route and its owner link. Nothing later in the instantiation resets it. A child accepted during step 1 stays in self.children and is torn down with the locus, like any other accepted child. The params themselves follow step 1’s order: a field is its value once its turn comes, whatever an accept wrote to it before.

Accept bubbling. The owner in step 2 need not be the direct parent. An I{} instantiated anywhere in a subtree bubbles to the nearest enclosing ancestor that declares accept(I) (innermost-wins); resolution is entirely static (the closed-world instantiation graph fixes every owner edge at compile time). The owner may live in a different tower or on a different pool: a cross-pool owner is served by an async handoff over the bus, so a cross-pool I{} is fire-and-forget — it may only appear as a bare statement, and using the instance as a value is rejected at compile time. So is a value use where the enclosing locus runs both on the owner’s thread and off it (its birth is a same-tower allocation in some instances and a cross-pool post in others, chosen at a bare statement): the typechecker refuses it at the literal, naming the instances and their threads. The rule holds at every expansion of a default, since a default is lowered where it is expanded, not where it is written. The typechecker rejects it at the literal: in a member body (a closure’s assertion included), under the locus whose body it is; in a params default, under each locus that builds the defaulting locus and leaves that field to its default (the default is expanded there, and a default is a field’s value, never a bare statement). A fn’s or a locus method’s argument default is judged per invocation: each call that leaves the argument out expands the default in the caller, under the caller’s locus, and is rejected at the call when the default builds a cross-pool I{} there; a call that supplies the argument expands nothing, and a caller on the owner’s thread is not rejected. Chains of defaults of either kind are followed. A const’s value and a type’s field default are expanded at every use, under whichever locus uses them, so one that builds an I{} some locus would post is rejected at the position. See runtime.md “Interest-based ownership (accept bubbling).”

A cross-pool child is born on the owner’s thread from a marshaled copy of its params, and nothing of it runs on the far side but that birth: each param must be a type the spawn marshals (a scalar of Int, Float, Bool, Decimal, Duration and Time, a String, a Bytes, a struct whose fields the bus carries, a fixed array of those), and the child keeps params, an optional birth, drain or dissolve, and a contract, never a non-empty run(), bus subscriptions, closures, capacity slots or an accept of its own. hale check refuses a child that breaks either, once, at the first literal the bubble plan posts across (“cross-pool spawn `Ship{ }`: it is born on `World`’s thread from a marshaled copy of its params, and hale can’t compile this child that way yet: its param `t` is `(Int, Int)`, a tuple, …”); the build refused it after a passing check (GH #1942).

An interface accept. accept(c: I) may name an interface (spec/types.md § Interface types). It accepts every locus that satisfies I — conformance as a coercion into I judges it, error channels included — and nothing else. Resolution is static, like every owner edge: every locus is born from a literal of a concrete type, so the clause stands for one concrete accept(c: L) per locus L it admits, and the ownership relation holds those concrete edges. There is no runtime type test and no dispatch through a vtable:

Whether the owner is on another pool is a fact of each instance of the enclosing locus, not of its type: a locus nested under a root field placed off main runs on that field’s thread, and one type can have instances on several threads. The owner is resolved once, for every instance; the delivery is chosen per instance. When some instances of the enclosing locus run on the owner’s thread and others do not, and the owner is a main locus, a bare I{}; is born in the owner’s region where the enclosing instance runs on the owner’s thread, and handed off where it does not. Where that choice cannot be made — a value use of the literal, or an owner with more than one instance, which has no single thread to hand off to — the literal is refused at compile time, naming every instance of the enclosing locus and the thread it runs on. A resolved owner is never dropped for a transient birth.

Birth order is load-bearing

Section titled “Birth order is load-bearing”

A parent births its params fields in declaration order, one at a time, and step 7 above runs an inline locus’s run() synchronously. Composing those two rules: a params field whose run() does not return prevents every field declared after it from being born at all.

Not merely from running — from being born. The later locus’s birth() never executes, so the subscriptions it registers, the sockets it binds, and the children it accepts never come into existence. Nothing fails and nothing is logged; the process completes what looks like a normal boot and then sits idle. This is the single most expensive way to misread a Hale program, and the symptom points nowhere near the cause — it typically presents as “my handler never fires”, which sends you looking at the bus.

main locus App {
params {
server: Server = Server { }; // run() { while true { ... } }
metrics: Metrics = Metrics { }; // NEVER BORN
}
}

Only the blocker’s placement matters. Moving the later field off the main thread does not rescue it — the instantiation itself runs inline on main, so even a pinned sibling declared after a blocking field waits. The four placements behave as:

Placement of the blocking field Blocks later births?
default (no placement entry) yes
cooperative(pool = main) yes
cooperative(pool = io) (any non-main pool) no — run() is posted to a worker
pinned no — run() gets its own thread

Two remedies, both sound: declare the non-returning field last, or place it off the main thread. The compiler warns whenever it can prove the shape — a terminal while loop with no break/return/terminate, in a field that runs inline on main, with at least one field declared after it. The proof is deliberately conservative, so a loop the compiler cannot prove non-terminating is not reported: absence of the warning is not a guarantee of correct ordering.

This rule is why a child’s run() is the wrong place to put work that must happen after its siblings exist. The main locus’s run() is the right place — it begins only after params-init completes, so by then every child has been born.

Dissolve timing rules

Section titled “Dissolve timing rules”

Five shapes, three timings (m82 — “locus all the way down”; expression position generalized from receivers to every position by GH #711 / #812).

Who reclaims a locus is decided before any code is emitted. One pass over the program gives every locus-producing expression — a literal, a proven-fresh factory call, and each branch, arm and element of an or, a carrier or a composite separately — the owner the rules below name, and lowering reads that decision rather than making one as it goes. An instantiation the pass left undecided is refused, so the rules here hold by construction rather than by the order things happen to be lowered in (spec/decisions.md F.39).

Multiple deferred dissolves in the same scope fire in reverse instantiation order at scope exit (LIFO), matching the F.4 depth-first cascade. The reason: a later-created locus may depend on an earlier-created one, so the later one must dissolve first.

Whichever of the four shapes applies, the timing is the timing of the whole owned tree, not of one level of it. A locus held as another locus’s param field never has a teardown of its own — its instantiation is parent-owned, and the owner’s teardown cascades into it (F.29). That cascade runs to the leaves: a grandchild’s drain(), its dissolve() body, its capacity slots and its arena are the owner’s responsibility just as a child’s are, at exactly the moment the owner’s timing fires. Every level’s arena is destroyed, none outlives the owner, and the count of live arenas a finished program leaves behind is zero. “Constructed by the owner” covers both spellings of construction: a nested literal (Mid { leaf: Leaf { } }) and a factory call whose result the field takes (Mid { leaf: make_leaf() }, in the diverging-or spelling too, and as a param default). A field the owner did NOT construct (Mid { leaf: shared }, an external handle passed in; or a call that hands back a locus somebody else built) is excluded at whatever depth it appears, and is torn down once by its real owner, at its owner’s timing.

An array or a tuple of loci is the same tree. A param holding an array or a tuple of a locus type (cs: [C; 2] = [C { }, C { }], t: (C, D) = (C { }, D { }), or the same written at the owner’s literal) holds each element its initializer builds as a parent-owned child: built in the owner’s arena, drained before the owner in declaration order with element order inside, torn down after the owner’s dissolve() body in the same order, each reclaimed once — whatever the owner’s placement. An element written into the field later (self.cs[i] = c) is not the owner’s: the element it replaces, while still one the literal built, is reclaimed at the store, and the instance written in is left to its own owner. A locus literal written into an element (self.cs[i] = C { }, self.t.0 = C { }, h.cs[i] = C { } through a handle), or a literal of the whole array or tuple written over the field (self.cs = [C { }, C { }]), is the reassignment of a locus field, element by element: the element it replaces reclaimed while the owner owns it, the new one built in the owner’s arena as its child and torn down with the owner, not with the method that wrote it. A whole array or tuple written from anywhere else (self.cs = xs) leaves the instances written in to their owners. The value is read before the store, and an element the owner owns is reclaimed once the field no longer holds it: one written back in (self.cs = [self.cs[1], self.cs[0]]) stays the owner’s, at its new place. The owner tracks every element, whatever the array’s length, and a path to the owner is evaluated once (ls[next()].cs[0] = C { } calls next once). The placement table holds a row per element (cs.0, t.1), and the lifecycle plan owes each one its teardown, in element order. A name handed whole (cs: shared) is a borrow, as above. A param written without a type takes its default literal’s (cs = [C { }, C { }] is cs: [C; 2], t = (C { }, 1) is t: (C, Int), n = [1, 2] is n: [Int; 2]): an array of one type’s literals, a tuple of literals, a locus or record literal.

A locus handed back inside a tuple or an array (fn both(w: W) -> (H, W) { return (H { w: w }, w); }) is owned by whatever holds the aggregate (GH #1569): a param holding it (p: (H, W) = both(W { })) holds each part the fn built, and each argument handed back as a part, as its children, exactly as one built from a literal; a binding leaves them to the frame, which tears them down at its flush (each iteration’s in a loop, before the next builds its own); a call whose result is discarded has them torn down at the statement, in order, then the arguments they kept. An argument a part keeps in a field (H { w: w }) goes with the last part keeping it, so every part that keeps it is torn down first. A builder that keeps an argument in a literal nested in the locus it returns (K { a: H { w: w } }) gives it to that nested holder. A tuple’s parts of other types (fn mk2() -> (W, Int) { return (W { }, 1); }) change none of this: each locus part the fn builds is owned as a factory’s direct return is, and so is each one a call through a fn value hands back, or a fn handing back such a call’s result (fn apply(f: fn() -> (W, Int)) -> (W, Int) { return f(); }). A param holding a tuple with a locus part (t: (W, Int) = (W { }, 5)) holds it as an array or a tuple of loci holds its elements.

What the field is DECLARED as does not change any of this. A param typed by a contract — an interface the child satisfies (params { j: Counter = Churner { } }) — holds a parent-owned child exactly as a locus-typed param does, and the cascade reaches it and everything under it. Which locus satisfies the contract is a per-instantiation choice: an impl written at the literal overrides one written as the param’s default, and the child torn down is the one that was actually constructed. Both spellings of construction reach a param typed by a contract: Queries { j: make_churner() } is the same transfer as Queries { j: Churner { } }. The child reclaimed is the impl that was actually built rather than the one the param’s default names (GH #895), and the or spellings transfer here exactly as they do into a locus-typed param — the diverging ones, where the factory’s result is the only value the field can hold, and or <substitute>, where the field owns whichever branch ran.

A locus literal written as a call’s argument is an expression-position temporary of the frame unless the callee keeps it (GH #1566): a free fn that hands the argument back unchanged (fn id(w: W) -> W { return w; }) makes it the call’s value, owned wherever the call’s value is (Routes { w: id(W { }) } is Routes { w: W { } }), and a fresh factory that keeps it in a field of the locus it builds and returns (fn mk(w: W) -> Routes { return Routes { w: w }; }, or through a let bound to that literal) makes it that field’s child, torn down with the returned locus — when the returned locus is held by a field, a placement or a binding. Which fns do either is read from their bodies: the parameter named nowhere but in the value handed back. Before, such an argument was reclaimed when the frame that built it ended, while the locus the call built still held it.

A locus literal written inside the initializer of a param that cannot hold a locus is not an ownership transfer, because there is no field for the owner to cascade from. In Lonely { n: Queries { }.total() } the Queries literal is an ordinary expression-position literal, owned by the enclosing fn’s scope and reclaimed by its scope-exit flush, exactly as it would be written on a line of its own.

A deferred dissolve is scoped to the enclosing fn, not to the enclosing block — the slot a let binds lives until the fn exits, including after the loop that bound it, while the name is the block’s: a let is visible from its statement to the end of its block, and a let that reuses a parameter’s or an outer let’s name inside a block shadows it there and there only (GH #1132) — but a locus created in a loop is reclaimed when its slot is reused, and only the last one at scope exit. Control arriving at the same instantiation a second time is the end of the previous instance’s life: it is torn down there, with the same drain → dissolve → arena reclaim the scope-exit flush runs, before the new one takes its place. This holds for every spelling — let h = L { };, a fresh literal used as a value, a let bound to a locus-returning factory, and a let whose RHS is an if / match / block or an ascribed array or tuple, where the reclaim is per ARM and per ELEMENT because that is where the value is built — so a loop’s residency is one instance per site, not one per iteration. Ownership follows the binding, not the name: a let that shadows a binding the fn hands back is a binding of its own, reclaimed like any other, and only the binding a return resolves to where it is spelled — or a binding whose value flows into it — passes to the caller (GH #1140). A locus that ESCAPES the iteration is unaffected, because it never had a slot here to begin with: a literal written directly as another locus’s param field is parent-owned, and so are an accept’d child and a locus the fn returns. A handle the loop passes in to an owner (Keeper { held: h }) keeps its own slot and is reclaimed here — the owner’s cascade steps over a field it did not construct, as it always did (F.29).

Each instantiation reclaims its own previous instance, where it stands, so within one iteration the reclaims run in instantiation order — the reverse of the LIFO order the scope-exit flush uses. Two loci bound in the same iteration are independent; a dissolve() body that reads a sibling handle it does not own sees the sibling’s next instance.

Every exit path flushes independently, and a return takes nothing away from the others. A fn — fn main included — may leave through an early return, through a later return, or by falling off the end. Each of those paths dissolves everything the fn owns at that point, in reverse instantiation order, and the paths do not interact: a return in the middle of a body does not shorten the set the fall-through exit dissolves. So in

fn main() {
let a = Noisy { tag: "a" };
if bad_usage { return 2; } // dissolves `a`, then exits 2
let b = Noisy { tag: "b" };
} // dissolves `b`, then `a`

the guarded exit dissolves a, and the ordinary exit — the one taken when the guard does not fire — dissolves b and then a. A locus bound only inside the branch that returns is listed on the other paths too but was never instantiated there, so those paths skip it: it dissolves exactly once, on the one path that built it. return f() evaluates f before any teardown begins, and a locus f itself bound is dissolved by f’s own exit (GH #789).

terminate

Section titled “terminate”

terminate; ends the current locus’s lifecycle from inside one of its own methods — the locus analogue of return (which ends a fn). It is only valid inside a locus method body. It does not free anything directly: it sets the locus’s __drain_requested latch and exits the current method like return;. When the method’s run() coro completes with the latch set, the runtime runs the locus’s normal drain → dissolve → arena reclaim — i.e. terminate invokes the declarative teardown early; it is never a manual free.

Its purpose is per-child reclamation on completion for an accept’d child whose lifetime is its own flow rather than its parent’s. An accept’d child on a daemon parent is otherwise reclaimed only when the parent dissolves (never, for a daemon), so per-connection children accumulate. A connection child whose run() is a recv/park loop ending on EOF can terminate; (or just return; once run-completion-reclaim for declared flows lands) so its arena is reclaimed the moment its flow ends, while the parent and the rest of the program keep running. Reclamation is idempotent (the arena-destroy latch), so a terminate that races the parent’s eventual dissolve is torn down exactly once.

The reclaim runs on the coro’s own pool worker, after run() returns, while the locus’s arena is still valid — never seizing a still-executing frame. (A child that terminates mid-run() exits run() immediately, like return; code after terminate in the same method does not execute.)

Validity (typecheck). terminate; in a free function is a typecheck error — there is no enclosing locus whose lifecycle to end. It is accepted in any locus method body (lifecycle method or member fn).

From a bus handler. terminate; is no longer limited to run(). A subscriber can end its own life from inside a bus handler (e.g. on_close receives a shutdown message and calls terminate;). The reclaim runs when the handler returns — the dispatch path checks the __drain_requested latch after each handler and runs the spine on the handler’s own worker. This is the resident-subscriber analogue of the connection child that terminates from its run() recv loop. A handler that violates sets the same latch and is reclaimed the same way — unless its owner still holds it (below).

A child reclaimed this way may still be named by its owner — a param field (c: Child = Child { }) keeps its handle. Both halves of the owner’s teardown cascade — the drain walk and the dissolve walk — test the child’s arena-destroy latch (__arena, slot 0 of a struct that lives in the owner’s arena) before the per-child body, and step over a child already reclaimed: its drain() and dissolve() do not run twice, and its own children, which lived in its freed arena, are not visited again (GH #1036).

A failed child its owner holds is kept (GH #1069). terminate is a child ending its own life; a failure is not. A child whose run() or handler failed — a violate, a failed birth_check — and that its supervisor did not restart (it absorbed the failure, quarantined the child, or spent restart(c) for N) stops: its run() has returned, and on the wrapper paths that would have reclaimed it its bus subscriptions are dropped. But while anything still holds it — a param field, a binding, a value the enclosing expression uses — its memory stays until that owner’s teardown, where its drain() and dissolve() run once. The owner’s handle therefore always names a live child: self.c.why after an absorbed failure reads what the child last stored. Only a child nothing else reclaims tears itself down when it fails: an accept’d child (its owner’s tracker expects it gone) and a bare statement literal (its statement’s own teardown then steps over it, on the same latch).

A child that fails from a bus handler is recovered as one that fails from run() is (GH #2028). When the handler returns and no run() of the child is running, the supervisor’s decision is carried out there: a restart(c) lowers the drain latch, re-runs birth() (the birth-epoch closures and birth_check with it) and then run(), and puts back the subscriptions; an absorb stops the child, as above. When the handler ran inside the child’s run() (at a yield or the drain its body ends with), a held child stops at once and the rest is decided once run() returns, as for a failure run() raised. Until GH #2028 neither happened after a handler’s failure.

A held child stops as it fails: its subscriptions are dropped where the failure is raised, before the handler or run() it was raised in goes on, and well before the supervisor has decided (the failure is delivered on the owner’s thread, and the child’s thread runs its other work while it waits). So nothing published after the failure reaches the failed child — a publish whose topic fails on no subscriber takes its or, as for any stopped child — even while the handler that failed is still running; until GH #2091 the stop came when that handler returned, and a delivery published in answer to what the handler said after its failure (a std::api receiver’s server error) could reach the failed child, or be dropped at the stop unannounced. A restart the supervisor then decides takes that stop back: the restarted child has every subscription it had before it failed, so a bound receiver restarted after the call it was executing returned is served again (spec/api.md § Receiver failure and generations).

A delivery queued for the child before it stopped, and not yet begun, is dropped unrun when its turn comes, unless a restart has put the child back by then, in which case the restarted child is delivered it. A dropped delivery is announced to nobody, except that a std::api receiver’s stop (and a quarantine that ends a receiver still live) tells each exposure bound to it that its incarnation is gone, as its dissolve() does, so the calls it was handed and had not started are answered unavailable rather than never (GH #2098).

release(c) and flow children

Section titled “release(c) and flow children”

release(c: Child) { ... } is the death-side bookend, symmetric to accept(c: Child). Declaring it on a parent has two effects:

  1. It marks Child a flow. A flow child is reclaimed when its run() completes — a plain return (or running off the end of run()), no explicit terminate; required. This is the connection model: run() is the connection’s flow (a recv/park loop that returns on EOF), and the child’s arena is reclaimed the moment that flow ends. A child whose type is NOT declared in any parent’s release is a resident: its run() returning means “ready” (it lives on as a subscriber), and it is reclaimed only when the parent dissolves. The same run()-returns event thus means “reclaim me” for a flow and “ready” for a resident — disambiguated by the parent’s declaration, never guessed.
  2. It fires on each completion. When a flow child completes (via run-completion OR terminate;), the runtime calls parent.release(owner, child) — after the child drains, before it dissolves — so the parent observes the completion and reads the child’s final settled state (the mirror of accept(c), which reads it fresh). release is policy only: it does not free. The owner is the accept’ing parent, recorded at accept time; release does not fire if a flow-typed locus is instantiated outside an accept context (no owner).

release(c: I) naming an interface makes every locus that satisfies I a flow, as accept(c: I) accepts each, and is compiled once per such type (§ Locus instantiation, “An interface accept”). The clause must name the same type as the locus’s accept (the validity rule below).

Several parent types may accept the same child type; each child carries its accept’ing owner AND that owner type’s release fn (stored at accept dispatch), so the body that fires is the actual owner’s own, never another parent type’s (2026-09-05, GH #526 F.6: the reclaim spine used to pick the first declared release(c: T) program-wide). Where more than one owner type tracks T (two concrete owners, or an interface owner beside another), the child also carries the accepting owner’s children tracker, so a completed flow leaves the tracker of the owner that accepted it, never none (the removal used to be skipped there, and the tracker grew without bound under churn). Whether T is a flow remains a type-wide fact: if any parent declares release(c: T), every T reclaims on run-completion, and an owner that declares no release simply has no bookend called.

Whether T is a flow is decided over the whole program, imported seeds and the standard library’s own loci included (a stdlib owner’s release, the TCP substrate’s connections on an async_io pool, reclaims its children as a user owner’s does), and a clause on a locus that is never instantiated counts all the same. hale check --flows reports every flow type with each release(c: T) clause that makes it one, by its declaring locus, file and line, as the declaring seed spells it, never a mangled symbol (GH #736), and an interface’s clause with the loci it admits; a qualified type is the whole path, so a local Stream is never mistaken for std::io::tcp::Stream. It is an opt-in report, never a diagnostic, since a release declaration is legitimate. It lists the program’s own clauses: a stdlib child type is internal to the stdlib locus that owns it, and is not listed.

Three ends, kept apart. A flow ends by completing: its run() returns (or it terminates), and it is reclaimed on the spot, its owner’s release firing between its drain and its dissolve. A resident never completes that way — its run() returning means “ready” — and ends one of two other ways: by its own terminate;, typically from a bus handler (the handler returns, then it drains and dissolves; no release fires, for none names its type), or in its owner’s dissolve cascade, which tears it down before the owner’s slots and arena are freed. A resident that disappears when its run() returns is a flow by some clause elsewhere; the report above names it.

A resident and what a handler hands it. A payload delivered to a handler, and any container the handler builds while it runs, belong to that dispatch and are reclaimed when the handler returns. A child born from the handler that must keep them copies them in its own birth() — cloning Strings, rebuilding rows — into storage it owns; holding the handler’s pointers past the dispatch is a use after free. The transfer rule is: a value is copied at the store; a locus is borrowed, and a borrow must outlive its holder. A String, a row or a payload’s field handed to a resident is copied into the resident’s own storage as it is stored, so the resident reads it after the handler has returned. A container that is a locus (a @form(vec) the handler built) handed to a resident by name is a borrow, and the checker refuses it at the argument, in check, build, run and test alike, naming this rule (GH #712, decided by the table under “A borrow outlives its holder”); the working shape is the copy in birth() above, which is sound because a borrow read only in birth() lives no longer than the instantiation.

release has the same shape as accept — one typed child param — and the same fn signature (parent_self, child_self).

Validity (typecheck). A release(c: T) with no matching accept(c: T) on the same locus is a typecheck error: a locus that never accepts a T child can never release one, so the declaration is dead (almost always a wrong child type or a forgotten accept).

Parent-dissolve reclaim. When a parent that accepts children dissolves, it reclaims each accept’d child it still tracks — running the child’s full teardown (drain → dissolve → arena reclaim) before the parent’s own arena (which backs the children’s subregions) is freed. A parent that accepts tracks every child it accepted, whether or not any of its methods iterates self.children, because this cascade is what the tracker exists for; and the cascade runs on every path that dissolves the parent — graceful shutdown, a reclaimed flow, and a mid-life reassignment of the field that holds it — so a child’s bus subscriptions are deregistered before the memory they point at is freed, never left to receive into whatever reuses it. The order within the parent’s teardown is children first, then the parent’s own capacity slots, then its arena: a child may hold a slot borrowed from the parent (as_parent_for), and a borrowed slot is never destroyed by the child. This is what makes the “resident reclaimed only when the parent dissolves” rule above observable: a resident’s dissolve() body (fd close, flush) runs at the parent’s graceful shutdown, rather than the child being silently swallowed by the parent’s wholesale arena free. Flow children that already self-reclaimed mid-life are no longer tracked, so they are not torn down twice; the per-child teardown is idempotent regardless (an __arena-null latch). The cascade is single-threaded-safe: cooperative pool workers are joined before the dissolve cascade runs at program exit, so no worker can be mid-dispatch to a child being reclaimed. (A parent reclaims only children it tracks — i.e. one whose body iterates self.children; a dispatcher that accepts but never iterates holds no per-child handle and relies on flow/terminate reclaim.)

Locus method dispatch

Section titled “Locus method dispatch”

Methods on loci may not return locus values. This is the load-bearing rule for locus method dispatch in Hale. The compiler rejects any fn member of a locus whose declared return type (or fallible-payload type) names a user-declared locus.

Why this rule

Section titled “Why this rule”

Five design principles converge on the same constraint, which is why the rule is shaped this narrowly:

These aren’t five rules layered on top of each other — they’re five lenses pointing at one structural error. The compiler enforces it once.

The factory train wreck

Section titled “The factory train wreck”

The motivating violation is the cross-tower factory pattern:

locus Counter {
store: Store; // borrowed reference back to caller's state
key: String;
fn inc() { self.store.touch(self.key); }
}
locus Registry {
fn counter(name: String) -> Counter { // ← rejected
return Counter { store: self.store, key: name };
}
}
// caller:
self.reg.counter("ticks").inc(); // would leak per call

The counter() method declaration is the rejection site. The diagnostic names three canonical alternatives:

Expose entries bind what the locus declares: an expose entry must bind a real params field or fn member at a matching type (M3 stage 4); an entry named like a method is checked against its declared return.

  1. Parent-child + contract reads. Counter becomes an accepted child of Registry; Registry reads counter state through the contract:

    locus Counter {
    params { name: String; value: Int = 0; }
    contract { expose value: Int; }
    fn inc() { self.value = self.value + 1; }
    }
    locus Registry {
    accept(c: Counter) { /* default registration */ }
    fn inc(name: String) {
    // iterate self.children, find the matching counter,
    // call c.inc(). Vertical method dispatch on owned
    // child — friend access, no LoD violation.
    }
    }
  2. Bus topic (mediator). Counters publish events; Registry subscribes:

    topic Inc { name: String };
    Counter::Inc { name: "ticks" } -> Inc;

    Closed-world rewrite (when its preconditions hold) collapses the bus round-trip to a direct dispatch — same cost as delegation, without the typed-handle loss.

  3. Delegation. Registry exposes the operation directly:

    self.reg.inc("ticks");

    Loses the typed handle but doesn’t allocate. Acceptable when the caller has only a few counters to touch.

Owned-child + contract is the canonical “B’s data feeds A” shape

Section titled “Owned-child + contract is the canonical “B’s data feeds A” shape”

When locus A needs to read and update derived state computed from its own input, the canonical pattern is B as an owned-child field of A, with the update going through a vertical command (self.b.compute(...)) and reads going through a vertical contract exposure or method call on the child:

locus Segment {
params { /* accumulator state */ }
fn clear() { /* reset */ }
fn push(t: Float, v: Float) { /* update */ }
fn slope() -> Float { /* compute */ }
fn intercept() -> Float { /* compute */ }
}
locus LeadingEdge {
params {
// ring buffer fields
seg: Segment = Segment { }; // owned-child field
}
fn fit() { // command, returns nothing
self.seg.clear();
// replay ring contents into self.seg
}
fn slope() -> Float { // query, returns data
self.fit();
return self.seg.slope(); // vertical method on owned child
}
}

The 54-geom-leading-edge example fixture demonstrates this shape end-to-end. The earlier “factory return” form (fn fit() -> Segment) was the pattern this rule rejects.

What’s not rejected

Section titled “What’s not rejected”

The rule fires only on fn members of a locus. It does not catch:

Migration

Section titled “Migration”

There is no opt-out annotation. The rule is the language’s structural axiom for locus methods — programs that violate it are mis-designed, and the diagnostic names the canonical alternatives. Migrating from the factory shape to one of the three alternatives is a refactor, not a switch flip.

The runtime m90 routing (see § Method-returning-locus heap allocation below) survives only to cover the few remaining shapes where a locus value transits through the m90 path indirectly (e.g., interface returns from free fns). With factory methods stopped at the declaration site, the dominant trigger of the m90 leak goes away by construction.

Method-returning-locus heap allocation (m90)

Section titled “Method-returning-locus heap allocation (m90)”

When a fn or a method declares -> Some (or a tuple, an array or an interface that holds a Some) and instantiates a Some in its body, the instance’s struct cannot live in the callee’s frame: a stack slot is dangling the moment the fn returns, so the first read after the return sees still-valid memory and the second sees overwritten state. The struct is allocated outside the frame, and both the eager dissolve and the deferred-frame push are suppressed at the instantiation site; the locus moves to the caller, whose binding, holder or statement owns it (§ “Ownership”, GH #1569). This covers both return Some { ... }; and let s = Some { }; ...; return s;, and the locus literals the returned instance’s params build.

The struct goes back at the end of the instance’s reclaim (GH #1570). It comes from the runtime’s returned-struct allocator (lotus_returned_struct_alloc) and is released at its reclaim’s ReleaseStruct step, the last one: after the latch, the cancel of its queued runs, the wait for its admitted runs (a deferred reclaim releases when its runs end) and its arena’s release. A loop over a factory therefore holds what is alive, not what was ever built: a discarded mkw(i);, a let w = mkw(i); and a call through a fn value each leave memory flat, however many locus types the loop hands back. A released struct is listed for reuse by a later struct of the same size, on a list of its own size (every size reachable, none scanned past a cap), and never returned to the operating system, as an accepted child’s struct is: a stale teardown path reading the instance’s __arena latch still reads memory the process owns, and finds it null. Where chunk recycling is off (LOTUS_NO_CHUNK_POOL, the default under a sanitizer, GH #816) each struct is allocated and freed on its own, so a read after the release is a sanitizer report.

Which instances came from the allocator is decided per site and is not a property of the type, since a literal of the same type in a frame or a field lives elsewhere; the allocator records what it handed out and the release answers only for those. Codegen emits the release only in the reclaim of a type some fn’s or method’s declared return type names (through a tuple, an array or an interface it satisfies) or that is a locus field of one; a program that returns no locus from a fn emits nothing new. A literal of a type outside that set (a generic fn’s T) and the program-lifetime literals codegen builds for bindings { } transports, adapters and codecs keep the program-lifetime payload arena. Deferred bloom (#1553), where a fn returns its plan and the locus is born at the consuming position, is the direction; this allocator is what the struct does until then.

@sealed and a revealed secret

Section titled “@sealed and a revealed secret”

A @sealed locus confines its params: only its own methods read them (spec/verification.md § “Secrets”, GH #436). A parameter’s default reads them as the caller that leaves it does, since that is where it is evaluated: a default that reaches a sealed field is refused unless every call that leaves it is inside the sealed locus. A value of a sealed generic locus’s specialization (Box<Int>) is that locus: its params are confined the same. A generic body reads a field of a parameter type as each specialization binds it: self.inner.key with inner: T is refused when a specialization binds T to a sealed locus, and so is a chain of fields of any depth reaching one, a field typed as another generic applied to the parameters included (self.h.s.key with h: Holder<T> and Holder<A>’s s: A). std::secret::Credential is sealed, and its reveal() / reveal_text() are the one named way its material leaves as a Bytes or String — a raw token or password has to leave as text to be put on a wire at all. The checker holds every reveal to that one use, on the path hale check, build, run and test share. A revealed secret is consumed in the statement that reveals it:

The check fails closed: a receiver whose type it cannot see (a pattern binding, a call’s result, an alias) is taken to be a Credential, a call it cannot follow keeps what it is handed, and a reveal outside the bodies it walks (a contract, a closure, a claims block) is refused.

// the header line is the wire write: one statement
return std::http::request(std::http::ClientRequest {
method: "POST", url: u,
headers: "Authorization: Bearer " + std::secret::Credential { vault: "api-key" }.reveal_text(),
body: b
}) or raise;

A @secret parameter is a declared consumer, so the rule holds inside its fn as well: the parameter may reach only a wire write, a comparison, or another @secret parameter, through the same composition, and the checker verifies that body. A chain of them ends at the wire — write_str(@secret s) → write(@secret b) → std::io::tls::send_bytes(fd, b) — each hop one statement. A one-way derivation is not a consumer: a hash, an HMAC, a PBKDF2 of a password is password-equivalent — a SCRAM client key authenticates exactly as the password does — so a derived value carries the secret on like any other composition, and binding it is refused the same way.

For a tool that reads a secret from a file rather than a wire, Credential.write_private(path) writes it on the sealed side, with nothing revealed: path is a new file, created mode 0600 by openat(2) itself, in a directory the effective user owns with no group or world access, outside any git work tree (spec/stdlib.md § std::secret). The rule follows a value, not a file: once written, the file is the tool’s to read, and a program that reads it back itself holds the secret in the open. Making the private directory, handing the path to the tool and removing both afterwards are the caller’s.

Four sites wait on one change, pq taking a Credential for the Postgres DSN and its SCRAM exchange: dna::role_password, dna::ReferenceInfrastructure.knowledge_database, pq::salted_password and pq::compute_client_final are allowed by qualified name and by the body that was reviewed — the checker pins each declaration’s text, wherever the seed is and under whatever alias it is imported — each finding in them a warning naming that deferral. A fifth site, or one of the four with anything changed in its body, is refused.

Capacity slot lifecycle and dispatch (F.22)

Section titled “Capacity slot lifecycle and dispatch (F.22)”

A locus’s capacity { pool X of T; heap Y of T; ... } block declares slots 1..N — additional storage disciplines beyond slot 0 (the locus’s own Arena, implicit). Slot order in the declaration is significant.

Slot lifetime ordering

Section titled “Slot lifetime ordering”

Slot init runs at instantiation, in declaration order, after slot 0 (arena) is set and before the locus’s own field initializers run:

  1. Slot 0 (arena) — fresh lotus_arena_create(), or a sub-region of the parent’s arena if the parent’s projection class is Chunked / Recognition and accepts this locus.
  2. For each declared slot in declaration order: call lotus_pool_create(size_of(T), 8) or lotus_heap_create( size_of(T), 8). Store the returned allocator pointer in the slot’s __slot_<name>: ptr field.
  3. Locus’s user fields (params + their defaults / overrides).
  4. Synthetic flags (__restart_count, __quarantined, etc.).

Slot destroy runs at dissolve, in reverse declaration order, before slot 0:

  1. Drain + dissolve closures + user drain() / dissolve().
  2. For each slot in reverse declaration order: call lotus_pool_destroy(allocator) or lotus_heap_destroy( allocator).
  3. Slot 0 arena destroyed via lotus_arena_destroy(arena).

Reverse-order destroy matches F.4’s reverse-instantiation cascade rule for let-bound loci; the same principle applies to slots within a locus.

Slot restrictions (v1)

Section titled “Slot restrictions (v1)”
  1. Slot element type must be a value-shape, not a LocusRef. Loci have lifecycle; cell recycling (Pool.release) or individual free (Heap.free) would orphan the locus. Use accept(c: Child) for locus membership; slots are for value-shaped types. Enforced at typecheck (with a span-targeted diagnostic) and again at codegen as defense in depth.
  2. Slot pointers don’t cross the bus. Structurally enforced: slot names aren’t typeable identifiers, so they cannot appear as bus payload struct fields. No runtime check is needed; the type system makes the case unreachable.
  3. Duplicate slot names rejected. Two slots sharing a name (even across separate capacity { ... } blocks on the same locus, though v1 grammar admits only one block per locus in practice) fail at both typecheck and codegen.

Method-shaped slot dispatch

Section titled “Method-shaped slot dispatch”

The user-facing surface is self.<slot>.<method>(args). The parser and typechecker both recognize self.<slot> as a slot reference rather than a missing field; the codegen intercepts the method-call shape and routes directly to the matching C primitive:

Slot kind acquire / borrow release / return
pool X of T self.X.acquire() -> Cell<T> (no args) self.X.release(c) (one Cell arg)
heap Y of T self.Y.alloc() -> Cell<T> (no args) self.Y.free(c) (one Cell arg)

Calling a pool method on a heap slot (or vice versa), or any other method on a slot, is a type error at the method name that names the right methods for the slot kind:

main.hl:7:38: type error: pool slot `entries`: method `alloc` is not
available (`alloc` is a heap slot's) — use `acquire()` to borrow a
cell and `release(cell)` to return it

The Cell<T> cell type is documented in types.md; struct cells support cell.field read/write (v1.x-2) and Cell<T> carries slot-of-origin so cross-slot release is a type error at the cell (v1.x-5). Primitive cells (Cell<Int> etc.) still reject field access, at the field name — direct load/store through a primitive Cell handle (e.g. *cell) is the natural next surface but no current workload demands it.

Slot access outside a method-call receiver position (e.g., let x = self.entries; to hold a slot handle as a value) is not supported at v1 — slots have no value-level CodegenTy that survives outside the dispatch path. Codegen errors with “no field on locus self” if the standalone access slips past typecheck. v1.x can lift this if a workload demands first- class slot-handle values.

Slot 0 parent-override

Section titled “Slot 0 parent-override”

When a locus is accepted by an owner (the accepting ancestor — see “Accept bubbling,” not necessarily the direct parent) whose projection class is Chunked or Recognition, the child’s slot 0 (arena) is allocated either as a sub-region of the owner’s arena (Chunked, via lotus_arena_create_subregion) or out of the owner’s recpool (Recognition with the matching sub-mode, via lotus_recpool_fixed_acquire / lotus_recpool_slab_acquire). The child is freed wholesale when the owner dissolves. Rich-class owners do not sub-region-allocate; accepted children get their own top-level arenas. When bubbling crosses a pool, the child is born in — and reclaimed by — the owner’s thread via an async bus handoff (runtime.md). See memory.md Per-projection-class allocation table.

F.22 names this as “projection class governs parent-override of slot 0.” Slot 1..N parent-override (pool entries of Int as_parent_for Child;) shipped via v1.x-4 (surface) + v1.x-4b (runtime mechanic, commit d50ab79): the borrow-mask __slot_borrowed_mask field carries one bit per slot, set when the slot was borrowed from a parent’s matching slot at accept time; the dissolve pass skips destroy on borrowed slots so the parent retains ownership of the underlying allocator. The child’s slot takes the parent’s allocator, so it is declared with the same name, the same kind (pool or heap) and the same cell type; each mismatch is a type error at the as_parent_for clause’s locus name.

Lifecycle method invocation

Section titled “Lifecycle method invocation”

birth()

Section titled “birth()”

Runs once, synchronously, after region allocation and before the locus is “live” for any other purpose. A failure during birth (a birth-epoch closure or birth_check) is a ClosureViolation: the region is kept, and the parent’s on_failure(c, ClosureViolation { ... }) runs at that epoch, held while the parent’s params are open, so the handler can read the child and restart it (runtime.md § “Lifecycle obligations”, line 8). There is no StructuralFailure.

accept(c)

Section titled “accept(c)”

Runs after child c’s region is allocated and its params are built, and before its birth(). Receives c with its params set (not its running state). Its result is not read: accept admits the child and cannot reject it; an admission interface is separate work (runtime.md § “Lifecycle obligations”, line 5).

After accept returns, the child registers in self.children (per F.11).

A locus declares at most one accept (single-accept-type per parent, types.md F.11). A second accept clause is a typecheck error naming both clauses; the first clause remains the locus’s accept type. The one clause may name an interface, accepting every locus that satisfies it (§ Locus instantiation, “An interface accept”). A parent that must own two child types gives one of them a different owner. (2026-09-04, GH #525: a second clause used to overwrite the first silently.)

accept’s param (and release’s) names a child: a locus type, or an interface the child’s locus satisfies (§ “Locus instantiation”). A param of any other type — a primitive, a type — is a typecheck error at the param’s type:

main.hl:1:44: type error: `accept(c: Int)`: `accept()` takes a locus
or an interface: it adopts a child, so its param names the child's
locus type (or an interface that locus satisfies), and `Int` is
neither. A value is not a child: pass it to the child as a param when
the child is built.

Before this rule the check accepted such a param and the backend refused it with no source location.

run()

Section titled “run()”

Runs continuously until drain is requested or run returns naturally. Cooperative — yields at every bus dispatch, every time::sleep, every explicit yield point. The scheduler may run other loci while this run is yielded.

If run() returns naturally, the locus exits run-state and proceeds to drain.

A locus that declares no run() has an empty one: the two spellings are the same program (GH #735, 2026-09-22). In particular a flow child — a type some parent releases — is reclaimed when its empty run completes, right after its birth, whether the empty run() { } is written or omitted; it does not live until its owner’s exit because the hook was left out. A resident is unaffected: an empty run means “ready” either way.

A violate in run(), or a closure that fails there, is a ClosureViolation, delivered to the parent’s on_failure(c, ClosureViolation { ... }) at that point (runtime.md § “Lifecycle obligations”, lines 8 and 9). run() has no panic.

drain()

Section titled “drain()”

Runs once, when the locus is asked to drain. Drain cascades depth-first (per F.4): drain runs on all children first, synchronously; then runs on self.

During drain:

Default drain: no-op (just transitions state from running to drained).

dissolve()

Section titled “dissolve()”

Runs once, after drain completes, in this order (runtime.md § “Lifecycle obligations”, line 10):

Default dissolve: free region.

on_failure(c, err)

Section titled “on_failure(c, err)”

Runs when a child of self fails: a ClosureViolation, or, for main’s bindings, a transport’s loss. Receives the child handle and the typed error.

The handler may:

Default on_failure: bubble(err). The runtime root’s default is process exit with stack trace.

Which handler runs. A locus may declare one on_failure per child type — on_failure(a: Alpha, err: ClosureViolation) beside on_failure(b: Beta, err: ClosureViolation), a stdlib locus such as std::http::Server included. Every handler takes the same error type, so the failing child’s own locus type is what selects one: an Alpha’s failure runs the Alpha handler and only it, whatever order the handlers are declared in. A child whose type has no handler on its parent gets the default. A second handler for a child type that already has one is an error: the first declared is the one a failing child reaches, so the second could never run, and hale check refuses it where it stands, pointing at the first.

Which locus is the parent. A child locus held in a param field is supervised by the locus that holds it, whichever way the literal is written: as the field’s default in the parent’s params { }, or at the call site in the parent’s literal (App { b: Boom { why: w } }), in any branch of an if or match that the field’s value names, and one level at a time through nesting (App { w: Wrap { b: Boom { } } } — Boom’s parent is Wrap). Where the holder itself is built does not matter: let s = Sup { }; inside another locus’s method gives Sup’s default child to Sup, not to the method’s locus (GH #1074). An override expression is otherwise lowered in the caller’s context (self.x in it reads the caller), but the literal it builds belongs to the parent. A locus built elsewhere and passed in by name — a let binding, a factory’s return — keeps the route of the place it was built: the locus whose method body built it, or none from a free fn or fn main.

When it runs: never before the parent’s params are settled. A child can fail while its parent is still setting params — a cooperative child’s run() executes inside that loop (§ Birth order is load-bearing) and a pinned child’s thread starts in it. The failure is held and delivered once the parent’s last param is stored, before the parent’s birth(); several are delivered in the order they arrived, on the thread settling the parent. So a handler always reads params that hold their values, and nothing it writes is overwritten by a default stored after it. The failing child outlives its held failure: a child whose run() has already ended — a cooperative child’s returns right after its violate — is reclaimed only after its handler has run, so the handler’s c is always a live child.

The rule holds the handler back, not the children. The other reading — every param settled before any child runs — would undo § Birth order is load-bearing: a later param’s default may read what an earlier child computed (total: Int = self.loader.count after loader’s inline run() filled it), and that only works because the children are born, and inline ones run, one at a time in declaration order.

A restart requested from a held handler takes effect when the handler returns, in the same delivery step: on the parent’s thread for a cooperative child (the one settling the parent, which the child was running on), on the child’s own thread for a pinned one — that thread waits for the handler’s decision rather than deciding by timing — and on its pool for a child placed on a worker pool, whose birth ran on the pool’s worker: the restart is posted there as the child’s run, so the re-run birth() and the run() after it execute where the first ones did, never on the thread settling the parent (whose own run() would otherwise wait behind a child run() that never returns). The child the handler restarts is the one it was handed, kept alive for it. A birth-epoch failure is held like any other: a child whose birth failed does not start run() until its handler has returned, and then starts it, restarts, or stays quarantined as the handler decided.

A handler may replace a sibling whose own failure is still outstanding (self.b = Kid { … } in the handler for a, with b’s failure not yet delivered): the field holds the new child at once, the replaced child’s failure is still delivered to the owner, after the running handler returns (handlers never run inside one another), and the replaced child is kept for that handler and reclaimed right after it.

The reclaim wins. A decision about a child the handler has replaced, or whose owner’s reclaim reached it while its failure was outstanding, is not performed: restart(c) and restart_in_place(c) on such a child leave it as if the handler had returned without asking, so it is reclaimed once, after its handler, and no birth() or run() of it starts again, while the new child in the field is untouched. (An owner’s teardown that reaches the child through a pool join before its reclaim does not refuse it yet: spec/runtime.md § “Lifecycle obligations”, “Restart during drain”.)

One failure cannot wait and is delivered at once: a dissolve-epoch closure’s, because the child’s region is released right after.

The bracket costs a locus nothing unless it declares on_failure and holds a locus-typed field or computes a default; one that does pays two uncontended lock round trips per instantiation.

Reassigning a locus-typed field (WS1#4)

Section titled “Reassigning a locus-typed field (WS1#4)”

Assigning a fresh locus literal to a locus-typed field — self.<field> = SomeLocus { … }; — is a lifecycle transition, not a value store. It is lowered break-before-make:

  1. The instance currently in the field runs its teardown spine: drain → dissolve, including its child cascade. Cleanup such as closing @ffi handles happens before the replacement’s birth. Its storage is released once started runs have given up their holds, as in the teardown when its parent dissolves.
  2. A new instance is constructed from the literal into self’s own arena, owned by the field (not scope-bound) — so it outlives the enclosing method and is reclaimed through the field when self later dissolves, exactly like a field-default child from params-init.
  3. The field is repointed at the live new instance.

The same transition runs when the field is replaced from outside its owner (h.loc = L { … } in a free fn, hs[i].loc = L { … }), with the owner — the locus the store’s path reaches — in place of self (GH #1561; types.md § A store into a locus’s field is the locus’s own). Before, the new instance was the replacing frame’s temporary, dissolved when that frame returned, and the old one was never dissolved.

The old instance’s drain and dissolve finish before the new instance is constructed, unless its own failure is still outstanding: then its whole teardown follows its handler, and a restart that handler asks for about it is not performed (§ “on_failure(c, err)”, “The reclaim wins”). There is one storage-retention exception: when a queued main-thread handler performs the replacement, waiting for an old run inside that handler could deadlock a reply queued behind it. Physical release is then deferred until the handler returns. The old run retains its arena, forms and owned descendants until it finishes; their storage is released before the containing owner’s storage. This does not postpone dissolve() or keep resources closed by that method open. Handler bodies keep their completion order. Outside a handler, replacement waits for the old run while servicing the queue.

For “same instance, reconfigure,” use in-place mutation (self.<field>.<x> = v;), which stays the cheap path and triggers no teardown. v1 scope: the new instance inherits the parent’s pool; reassigning a pinned-placed field does not re-apply the pinned placement.

The right-hand side must be a locus LITERAL (error). Assigning a locus value produced somewhere else — self.held = make_row(…);, or let c = Conn { … }; self.conn = c; — is rejected, because ownership would be ambiguous: the field claims the instance (its teardown reclaims it when self dissolves) and so does the frame that produced the value (its scope exit reclaims what it built). Nothing in the language decides between them.

That ambiguity is not hypothetical. Until this rule, a locus returned from a free fn was routed to a program-lifetime arena and never reclaimed, which is what made such a store appear to work: the field’s pointer stayed valid because nothing ever freed it — the leak was the safety mechanism. Every attempt to give those loci a real lifetime produced either a use-after-free or silently wrong values.

Three remedies, all existing shapes:

Contract-typed fields hold a borrow when assigned a handle (GH #967). An interface-typed field cannot be assigned a locus literal (the literal’s type is not the field’s), and the only values that reach self.<field> = v are interface VALUES — a parameter, another field: a handle somebody else owns. That store is a borrow, the same decision F.39 makes for a name in a field initialiser (Owner::Borrowed), applied to assignment:

  1. The instance the field owned until then — its default, or a literal it was built with — is reclaimed, break-before-make as above.
  2. The field is marked borrowed: the holder’s cascade never reclaims what it now points at. The handle’s own owner does, at its own time.
  3. The handle is stored.

A field that already held a borrow releases nothing when assigned again. What the rule does not decide is lifetime: the borrowed instance has to outlive the holder, exactly as one passed by name at construction has to — that is the contract of every handle, and the checker’s question in GH #730. Before this rule the store was a plain value store: the field kept describing the default it was built with, so the holder’s teardown reclaimed the handed-in instance (its owner then read freed memory, or reclaimed it a second time) and the default leaked.

A borrow outlives its holder (GH #730, 2026-09-22). A handle stored by name into a locus-carrying param field — LocusRef, interface — is borrowed, never the holder’s to reclaim, so what owns it must outlive the holder. Ownership is structural and reclamation a tree cascade, so the checker decides this from position, with no annotation — on the path hale check, build, run and test share, so a program check refuses never builds:

the handle comes from holder owned by the frame by self (a field, an accepted child) by the caller (returned)
a field of self sound sound refused
a let of this frame sound while the binding is in scope refused refused
a bus handler’s payload sound refused (GH #712) refused
a parameter sound every caller is asked left alone

For a parameter, every call site of the method is classified by the same table; the first caller that hands a let of its own frame or a handler payload is the witness the refusal names, and a parameter at the caller recurses to a bounded depth. Nothing else is refused: a chain the walk cannot follow is left alone, never guessed at. A borrow the holder reads only in birth() is birth-scoped and sound — the instantiation runs inside the frame that owns the handle — which is the shape a resident uses to copy what it was handed before the dispatch ends. The other axis of a borrow, the thread domain, is a rule of its own (GH #984): a borrow is read from its holder’s thread, so a handle whose instance runs on another pool is refused where it is handed over, naming both domains and the hand-over (spec/types.md § “One instance is never shared across pools”, GH #1566); a type that synchronizes access from another domain is admitted, and a value that crosses by the bus is a copy, not a borrow. A program wrong on one axis is told that axis alone. A container a handler built and handed to a resident’s form-typed field is the let row of this table (GH #712); the data it holds is copied at the store and is not a borrow.

A handle a method keeps is the same borrow (GH #1048). A method keeps a parameter of a locus-carrying type when its body stores it into self: assigns it to a field, hands it (alone, or inside a record, a tuple or an array) to a mutator of a @form container of self’s (push, set, insert, put, append, …), or passes it to a method of a place under self that keeps it in turn. The checker reads that from the body — the stdlib’s and an imported seed’s included: std::http::Router.add keeps its handler and use its middleware. The argument at a call to such a method is a borrow the receiver holds, decided by the table above with the receiver as the holder, by the receiver’s root binding:

A receiver’s locus is known when its root binding holds a locus literal, a call to a free fn declared to return a locus, or an alias of either, and through the declared field types below it (a.router). A locus literal written as the argument is a temporary of the frame that builds it, so it counts as that frame’s let — also where a parameter carries it into a keeping method, when the caller is asked:

fn build(dir: String) -> std::http::Router {
let r = std::http::Router { };
r.add("GET", "/x", Echo { s: dir }); // refused: r is returned
return r;
}

The router would dispatch into a handler its building frame reclaimed. Within one frame the holder and the argument end together, except in a loop: a locus built in a loop body is reclaimed when the next iteration reuses its slot, so a literal or let inside a loop kept by a router declared outside it is refused; one inside an if block lives to the frame’s end and is sound. A handler that is a field of the locus owning the router (self.router.add("GET", "/x", self.echo)) lives as long as the router and is sound. The birth-scoped exemption above does not apply to a kept handle: birth() can hand the router on to something that outlives it. A keeping method called on self itself (self.observe(j)) is a store into self spelled as a call, left where an assignment self.observed = j is left (GH #967). A call through a value this walk cannot type (an interface, a call’s result used in place) is left alone.

This is the same principle as the no-locus-return rule on methods (fn get() -> SomeLocus is rejected): a locus is structure, not a value to hand around. Ordinary let-bound loci — including factory results — are unaffected; they are owned by the binding that names them. A factory result written as a locus- or interface-typed field of a locus literal — Router { quick: make("q") }, in a body, a default, or another factory — is owned by that literal: the literal is the construction site, so this is not the ambiguous store above, and the frame that made the call does not reclaim the result at its exit (dna/FRICTION.md F.17).

Topic declarations

Section titled “Topic declarations”

A topic Foo { payload: T; } declaration names a typed pub/sub channel at top level. Subscribers, publishers, and send sites reference the topic by name; the payload type travels with the declaration instead of being repeated at every subscribe ... of type T site.

type Tick { n: Int; }
topic Ticks { payload: Tick; }
locus Counter {
params { count: Int = 0; }
bus { subscribe Ticks as on_tick; } // no `of type T`
fn on_tick(t: Tick) { self.count = self.count + 1; }
}
locus Pub {
bus { publish Ticks; } // no `of type T`
run() {
Ticks <- Tick { n: 1 }; // identifier subject, not "Ticks"
}
}

Type-check rules:

  1. Every subscriber’s handler signature must match Topic.payload exactly — a static error cites both sites if they diverge. (Enforced 2026-08-11 — downstream handoff; this rule was written but never implemented, and the reinterpreted payload surfaced a String field’s heap pointer through an Int parameter from safe code. The check covers both subject forms — declared topics and string subjects with of type — plus arity, accepts Drain<T> batch handlers by their element type, and names the topic-as-parameter-type mistake (fn on_h(msg: Hello) where Hello is the topic) specifically. Payloads that resolve Unknown — cross-seed topics — stay permissive by the milestone-2 rule; stdlib paths resolve to their real nominal types since GH #470 and are checked like any user type.)
  2. The send-expression’s type at a topic-ref <- site must match Topic.payload.
  3. The of type T clause is forbidden on topic-ref subscribe / publish; the topic carries the payload type.
  4. A topic identifier outside subscribe / publish / send-subject position (e.g. let x = Foo;) is a type error — topics are not values, they only address bus channels.

topic is a contextual keyword: lexes as IDENTIFIER except in top-level declaration position, so existing names (struct fields called topic, local variables named topic) continue to work.

Lowering: codegen and runtime work against the legacy string-subject form. A desugaring pass between typecheck and codegen rewrites BusSubject::Topic(Foo) → BusSubject::Literal { subject: "Foo" } and fills in the elided payload type, so the downstream pipeline (cooperative queue, mailbox post, transport fanout) is unchanged from the string-subject path. The wire-format subject for a topic named Foo is the bare string "Foo".

Coexistence: the literal-string form (subscribe "S" as h of type T;) is still accepted because the log namespace lotus relies on wildcard publish (publish "log.**" of type LogEvent;)

Canonical form for new code: prefer the topic-decl form (topic Foo { payload: T; subject: "wire.subject"; } + subscribe Foo as h;). Reach for the literal-string form only when you need a wildcard subscription or a runtime-computed publish subject — those are the cases the topic system doesn’t cover at v1.

Computed publish subjects are confined to their declaration

Section titled “Computed publish subjects are confined to their declaration”

A send whose subject is not a literal (subj <- v) requires the enclosing locus to declare a wildcard publish whose payload accepts v. That declaration is an authorization, and it is enforced — not merely required at the declaration site:

  1. Pattern. At the send, the computed subject must lie under one of the locus’s declared publish patterns. A locus declaring publish "io.tcp.**" cannot publish "app.order". Violating this raises BusPublishUnauthorized.
  2. Payload. The computed subject must not reach a subscription declared for a different payload type. Violating this raises BusPayloadMismatch.

Both are runtime checks on the computed path only; a literal subject is bound to its declaration at compile time and pays nothing for either. The payload check reads the subjects every subscription recorded when it registered, which may be on any thread (a pinned or pool anchor initializes its subtree on its own). A send reads them with no lock while another thread may be recording more; a subscription recorded while the read is under way is not checked by that send. (The runtime’s subject-to-payload table has the registration table’s publication scheme: rows that never move, behind an array published as a pointer and a count, appended under a lock, a replaced array kept until teardown.)

They are not stylistic. Without them the computed string reached dispatch verbatim, so a subject outside the declared pattern was delivered to whatever subscribed to it and the payload was reinterpreted as that subscriber’s type — a two-field LogEv { a, b } published on "app.order" arrived at an Order handler as id=a qty=b, with hale check reporting ok.

Statically, a subscription that sits under another locus’s declared wildcard pattern while expecting a different payload is a warning: whether the hazard is live depends on whether that locus ever publishes a subject reaching it (a std::log::Logger declares all of log.** but publishes only under its own path), so it names the risk without refusing the program.

The pattern also bounds analysis. Because a computed publish cannot escape its declaration, an unresolved publish inside a locus declaring "io.tcp.**" provably cannot produce a publisher of an application topic. Subject-specific questions — how many publishers a topic has, whether @effects(depends:) names the complete inbound surface — are answered against the patterns rather than against one program-global “some publish is unknown” bit. Residue that carries no pattern (an unfollowable call, a truncated frontier, a publish whose subject expression resolves to nothing) stays unbounded and still withdraws every subject.

Phase 2: hierarchy, subjects, bindings, closed-world optimization

Section titled “Phase 2: hierarchy, subjects, bindings, closed-world optimization”

Phase 2 extends topic declarations with three orthogonal pieces:

1. Hierarchical topics + wire subject. A topic may declare a parent and an own-subject segment. The materialized “wire subject” is the dot-joined chain of segments root-to-leaf:

topic Events { payload: Event; subject: "events"; }
topic Login : Events { payload: Login; subject: "login"; }
// Login's wire subject is "events.login".

Defaults: own-subject defaults to the topic’s name (verbatim), so top-level topic Ticks { payload: Tick; } keeps Phase-1’s behavior of wire subject "Ticks". Parent must reference a declared topic; cycles + missing parents are typecheck errors. Two distinct topics that produce the same wire subject are also errors — path-shaped routing would be ambiguous.

The desugar pass rewrites BusSubject::Topic(Login) to BusSubject::Literal { subject: "events.login" } so codegen and the bus runtime see only the wire form.

2. main locus + bindings { } block. A locus prefixed with main is the binary’s entry-point holder and is the only place a bindings { } member is legal. Bindings choose a transport per topic; the same library compiles to in-process or external in different binaries by varying the main locus. An entry may name an imported topic — dna::ReviewVerdict: unix(...) binds the declaration the library owns, never a re-declaration of it — and resolves exactly as a qualified bus subject does (GH #527 B6).

main locus App {
bindings {
// Beat: not bound — same-binary cooperative queue (default).
Login: unix("/tmp/login.sock"); // role inferred
Events: unix("/tmp/events.sock", role: listen); // explicit override
Remote: MyNatsAdapter { url: "nats://..." }; // adapter locus
}
}

The publish contract (GH #227, 2026-07-22). T <- value succeeding means the broker accepted the message; what “accepted” obligates the broker to is defined per binding, and the broker may never accept a message it already knows it cannot handle under that binding’s guarantee. Per binding:

Binding “Accepted” means
none (in-process) dispatched to every born subscriber in this binary
unix(...) handed to the peer connection, message boundaries preserved
udp://... handed to the local IP stack; lossy from there by declaration
shm_ring(...) slot claimed + committed, under the declared on_overflow policy
adapter locus whatever the adapter’s own contract says (it owns delivery)
hub (Topic: self.hub) a stream: handed to every admitted subscriber’s queue under the row’s bound and on_full (spec/api.md § Streams)

This contract is what lets <- be an infallible statement: the error channel isn’t missing, it’s relocated to where it can be acted on. Consequences, all normative:

The api binding (retired)

Section titled “The api binding (retired)”

A program’s API is no longer an entry in the main locus’s bindings { }. bindings { api: … }, @gated, serve: and an expose member read as an API are refused with one diagnostic that names the replacement, and the compiler carries no code to accept them. spec/api.md is the contract:

What stays here, because it is not the API’s: the publish contract (§ “The publish contract”, above) and the bus codec clause codec(…) of a binding (F.36) apply to every bindings { } entry, a topic bound to a hub among them. A message that did not come through a transport is not a call: std::api::Context (spec/stdlib.md § std::api) is built by the exposure for a handler that declares it, and a handler called any other way gets the caller it names.

Transport surface:

Foreign rings via ring_layout (Proposal B). The shm_ring transport above reads/writes the native Lotus ring (the LRSRNG1 header + equal-sized slots). To read a ring defined by another program — an externally-defined binary broadcast ring — a ring_layout declaration describes that ring’s binary shape, and a binding references it with the layout: kwarg:

ring_layout ForeignRing {
magic 0x52494E47464D5431; // expected header magic at offset 0
version 1 at 8 : u32; // header field `version`: expect 1
buffer_size at 12 : u32; // ring data capacity, read from header
data_at 128; // first-record byte offset
cursor published { // the published byte cursor
at 64; repr atomic_u64; load acquire; unit bytes;
}
framing byte_records { // records are [u32 len][payload]
len_prefix u32; align 8; pad_sentinel 0xFFFFFFFF;
}
overflow lap_detect;
}
main locus App {
bindings {
Ticks: shm_ring("/foreign.ticks", on_overflow: drop,
layout: ForeignRing) where zero_copy;
}
}

The layout: reference must resolve to a declared ring_layout (else a typecheck diagnostic). A binding with no layout: is the native ring, unchanged.

Record headers (record_header_bytes). The default byte_records shape is [len_prefix][payload] — the prefix is the whole per-record overhead. A real foreign producer often prepends a fixed header (sequence number, kernel timestamps, opcode) before the payload. Set record_header_bytes N on the byte_records framing to describe it: the payload then starts N bytes into the record and the stride is N + align(len) (the len field is still read at record offset 0 with len_prefix). N must be a multiple of align. A producer that marks a tail pad with a header field rather than a len sentinel (e.g. a kind byte where 1 means padding) declares pad_field_offset / pad_field_width / pad_field_value; a record whose field equals that value is skipped to the wrap. The in-band header scalars are surfaced to the handler by declaring their offsets (seq_offset / seq_width, kernel_ns_offset / kernel_ns_width, user_ns_offset / user_ns_width): the reader decodes them per record into thread-locals the subscribe handler reads via std::shm::last_record_{seq, kernel_ns, user_ns}() — the errno-style idiom of recv_stamped’s last_recv_*_ns. The payload itself is still delivered as the BytesView / typed value. recheck post_copy adds a torn-read guard: each record is copied out, an acquire fence taken, and the cursor re-read; if a free-running producer lapped the record during the copy it is discarded rather than handed to the handler.

Slot rings (framing slots). The example above is a variable-length byte_records ring. A slots framing describes a fixed-stride slot ring instead — the shape of the native Lotus ring itself. The geometry (slot_size, slot_count) is read from the foreign header rather than fixed in the layout, the cursor is the published seqno (1-based; unit slots), and slot S lives at data_at + (S mod slot_count) × slot_size. A consumer skips a seqno the producer has already lapped (published − S ≥ slot_count) rather than read a torn slot — matching the native reader. This makes the native LRSRNG1 ring expressible as a ring_layout, read through the same abstraction as a foreign one:

ring_layout LotusRing {
magic 0x4C5253524E4731; // "LRSRNG1"
slot_size at 8 : u64; // geometry read from the header
slot_count at 16 : u64;
data_at 128; // first slot (after the 2-cache-line header)
cursor published { at 24; repr atomic_u64; load acquire; unit slots; }
framing slots { }
overflow lap_detect;
}

The producer side for a foreign slots ring (a Hale writer) is not yet offered; slots is a consumer framing at this version.

The layout contract. A ring_layout is validated at typecheck (hale-types::check), so a malformed layout fails the build, not the read. The rules:

Cross-field conformance. Because the foreign format is fixed and unchangeable, a layout that mis-transcribes it is the program’s own bug — and several of these fields silently corrupt the reader if wrong, so they are caught at compile time:

Payload conformance at the binding. A layout:-bound topic’s payload picks the consumer mode:

Any other payload (with String, Bytes, or variable-size fields and not itself BytesView) is rejected.

Out-of-bounds safety. The guarantee is that a wrong layout — or a non-conforming / hostile foreign producer — yields wrong values, never an out-of-bounds access. It holds given the checks above plus the runtime’s boundary defenses: the consumer rejects, at attach, a foreign buffer_size that isn’t a multiple of align; each record’s len-prefix read is clamped within the data region; and the framed len must equal the bound payload’s fixed size before the handler is invoked (a short record is resynced, never dispatched), so the handler cannot read past a record near the wrap. The bound checks are overflow-safe against a hostile len or offset.

The member token positions (acquire, atomic_u64, bytes, and words that collide with keywords like release) are layout words, not Hale type expressions — bare identifiers (or keyword-spelled words) checked against the sets above, never resolved as types.

Consumer (read). A subscriber on a layout-bound topic registers via lotus_bus_register_subscriber_shm_ring_layout(subject, name, desc, self, handler), where desc is a flat 16-entry descriptor codegen builds from the resolved layout. The runtime attaches the foreign segment read-only (it never creates it — the foreign producer owns the ring), validates the magic and version, reads buffer_size for the data-region capacity, then runs a byte_records reader thread: acquire-load the published byte cursor, and for each record walk data_at + local % capacity, read the len_prefix, skip a pad_sentinel tail-pad to the wrap, hand the payload view to the handler, and advance by align_up(len_prefix + len, align). Field roles are read by convention from the layout — a scalar named version (with an expected value) is the version check; one named buffer_size is the capacity source.

Producer (write). If the bundle publishes a layout-bound topic, it is the ring’s single producer (SPMC): the prelude CREATES the segment via lotus_bus_register_shm_ring_layout(subject, name, desc, capacity) — sizing it data_at + capacity, writing the header (magic, version, buffer_size = capacity) and zeroing the cursor — and each Topic <- value routes through lotus_bus_publish_shm_ring_layout, the exact inverse of the reader: reserve align_up(len_prefix + payload, align), write a pad_sentinel and wrap if the record would straddle the end, write the length prefix + a memcpy of the (flat) payload, then release-store the cursor. Capacity comes from the binding’s buffer_size: kwarg (bytes; a per-transport default applies when omitted). A layout binding that is only subscribed in this bundle creates nothing — it attaches the foreign producer’s ring.

Limitations (v1). A subscriber reads records published after it attaches (no historical replay): it starts at the producer’s cursor as it stands when the subscription is registered, so every record published after that is delivered, however late the reader thread first runs; a record published before it is not. Lap handling is lossy + safe: if the producer runs more than capacity bytes ahead, the missed bytes are gone, so the reader resyncs to the producer’s cursor (a commit boundary) and resumes rather than reading a torn record. Handlers run on the reader thread (same constraint as the native subscriber), so the readers stop at the teardown spine’s reader stop (spec/runtime.md § Lifecycle obligations, line 7): after the wait-abort and the cooperative pools’ join (a pool’s job still publishing finishes against a live reader), and before the pinned joins and the dissolve cascade. A handler in flight finishes, what was published when a reader stops is delivered, and a record published after that is not (a main locus built as a statement with no run() is torn down at once, and its subscribers with it). The slots (fixed-stride) framing kind ships for consumers, and the zero-copy writable producer view ships as Topic.write(max) { w => … } (A1 — fields written directly into the reserved slot, no intermediate copy). What remains post-v1: a slots producer with parameterized slot geometry, and multi-cursor back-pressure.

In-memory delivery is absence-of-entry. A topic with no binding entry is delivered same-process via the cooperative queue. There is no in_memory variant — the runtime default covers the case and explicit syntax would be ceremony.

Operational constraints (Form K). A binding entry may carry an optional where clause listing constraint keywords the dev team asserts the route must satisfy:

bindings {
L2Updates: unix("/sock") where intra_machine, zero_copy;
}

Constraints split into two orthogonal axes:

The typechecker validates three classes of constraint issue (Form K4a):

  1. Intra-constraint consistency. At most one scope keyword per binding (intra_machine + intra_process is rejected as ambiguous). zero_copy + cross_machine is rejected as a contradiction — network transports require serialization.

  2. Transport-constraint compatibility. Each declared constraint is checked against the binding’s transport variant:

    • unix(...) satisfies intra_machine. Rejects intra_process (sockets cross processes), cross_machine (AF_UNIX is host-local), and zero_copy (kernel memcpy at the socket boundary).
    • Adapter loci: trusted for scope constraints (the adapter body knows where its protocol routes). Rejected for zero_copy — the Adapter contract (fn send(subject, bytes)) requires serialization.
  3. Payload-shape compatibility. zero_copy requires the topic’s payload to satisfy is_flat_shapeable: its bytes are the whole value, so a raw memcpy of it is the value on the other side. Flat are the fixed-layout primitives (Int, Float, Decimal, Bool, Time, Duration), a struct whose fields are all flat, an identity or a range (its integer), and a fixed-size array of Int, Float, Bool, Decimal or Duration (and a bounded[T; N] of those): codegen lays a scalar-element [T; N] field out inline in its struct ([N x T], since 2026-07-01), so its elements travel in the slot. Not flat: String, Bytes, BytesView and StringView (heap-shaped or fat pointers); a fixed-size array of anything else ([P; 2] of a struct, [Time; 2]), which keeps the out-of-line layout, a pointer that would dangle across the zero-copy / shm boundary; an unbounded array [T]; a tuple (a pointer to its block); a bounded list of strings, bytes, records or enums; and an enum. The bus wire carries all of these (§ Payload type); a raw copy does not. The binding is refused at typecheck, at its zero_copy, rather than compiled into a cross-process use-after-free: “binding for topic TA requires zero_copy but payload type PayA is not flat-shapeable — it contains a String, Bytes, fixed-size array, tuple, enum or list-of-pointers field, …”. A native shm_ring binding is held to the same rule without zero_copy (GH #2030). Send variable data on a unix(...) binding, or as a layout:-bound BytesView raw frame.

The shm_ring(...) transport variant above satisfies zero_copy (and intra_machine) intrinsically; its slot size is derived from the payload’s flat layout. Existing bindings without a where clause continue to work unchanged.

The entry locus. A program’s entry is its seed’s own main locus; the checker reads it from one row (hale_types::entry, the registry’s entrypoint family) for rule 1’s count and rule 9’s closed world, and --env and --matrix read the same row for what an entrypoint is. An imported main locus — a library’s, renamed with its seed — is not the entry (F.40 phase 3, E0): it is a declaration the importing seed does not run. A seed whose only main locus is imported has no entry and checks as a seed with no main does: the library’s placement seeds nothing, and the world is not closed.

With more than one candidate (rule 1’s error) the checker reads the last.

The build deploys the entry and nothing else (F.40 phase 3, L4): its placement, its bindings, its pinned threads. The placement-safety rules (the pool map behind the cross-pool method call error, spec/types.md § “Single-threaded-method invariant (F.31)”, the pinned-in-a-loop rule, placement rule 17, the instance-aliasing warning, one locus shared by two of the root’s fields placed apart, #334, which reads where each field runs from the placement table, and the async_io advisory, spec/verification.md § “Placement-implied contracts”) judge the entry. The api binding is generated into the entry, and the editor’s hale/placement view and the model’s entrypoint name it (main when there is none, as for a seed whose only main locus is imported).

The entry is started by the seed’s top-level fn main, which instantiates it; a main locus does not start itself. A seed that declares its own top-level main locus and no fn main has nothing that starts the locus, so hale check, the editor, hale build, hale run and hale test refuse it with one located error at the locus’s name (until GH #2108 hale check accepted it and only the build refused it; until 2026-10-14 the build’s error was the spanless program has no fn main()). It is one of the rules a build refuses beside the check (hale_types::build_rule_diags, which hale check runs too), not an error of the typing, so the seed still denotes its model and its laws are judged while its fn main is missing:

main.hl:1:12: type error: a `main locus` is started by `fn main`, and this seed has none: add `fn main() { App { }; }`

An application another seed imports and starts is checked through that importer, where its main locus is imported and not the entry. Checked alone it is a program like any other, and starts its main locus with a fn main of its own; an importer runs its own fn main, never the imported seed’s, which is renamed with its seed.

Two programs start somewhere other than a fn main of their own, and the rule does not apply to them: a module that @exports, the wasm entry inversion’s (an export-only module needs no fn main: spec/ffi.md § “@export — exports”; a native target refuses the inversion itself), and a *_bench.hl file, which declares no fn main because hale bench appends its driver’s (spec/testing.md). A *_test.hl file is a program hale test builds as it stands, so the rule holds there. A seed whose fn main does not instantiate its main locus checks and builds: the locus is a declaration nothing runs.

A program with neither says program has no fn main(): a native program starts at its top-level fn main when it is built; it checks clean, as a library seed does.

Whether a thread runs beside the bus’s main drain, so that the bus queue takes its lock, is decided from what the build deploys (F.40 phase 3, E2): a domain of the placement table that is not main (a pinned field, a non-main cooperative pool, an adapter binding, the api binding’s pool), or an entry of the entry’s bindings { }. An imported main locus’s placement { } block and bindings { } start nothing, so a program that imports one keeps the single-threaded queue.

Bundle-wide rules:

  1. At most one main locus per bundle, counting the entry program’s own. A main locus that arrives through import belongs to the imported seed, not to the entry: it does not count (rule 3), so a program may import a seed that has one and declare its own (GH #1059). Zero is fine — the classic bare fn main() shape is still legal.
  2. Each bindings entry’s topic must name a declared topic.
  3. A topic may appear at most once across the entrypoint’s bindings. An imported seed’s main locus is renamed with its seed and its bindings are inert: they bind nothing, count toward nothing here, and do not make a second main (GH #1104 piece 5).
  4. Bindings only legal in a main-modified locus. The parser rejects them in any other locus position.
  5. Every binding’s role must be either explicit (role: kwarg) or unambiguously inferable from the bus block.

Codegen emits one runtime registration call per binding entry into fn main’s prelude, right after the bus queue is published:

Subjects use the desugared wire form (so a binding for hierarchical Login registers as "events.login"). Topics with no binding entry get no register call and stay same-process via the cooperative queue.

3. Closed-world topology optimization. When a topic has no binding and the publisher / subscriber relationship is statically unambiguous, the desugar pass rewrites the publisher’s Stmt::Send into a direct method call. Two shapes qualify:

Common preconditions for both shapes:

When eligible, the publish→queue→drain→dispatch path collapses to a synchronous method call. The subscribe / publish entries stay declared (still type-check) but the bus runtime never sees traffic on the optimized subject. This is a pure-perf rewrite — observable behavior is identical modulo timing (synchronous instead of cooperative-deferred) — provided publisher and subscriber share an execution context (see the placement carve-out below; that condition is what keeps the rewrite observably transparent), and provided nothing the publishing thread sent earlier still waits on its own queue: one publisher’s order holds across topics (runtime.md § “Bus message router”, “One publisher’s order”), so while such a cell waits the send is queued to its subscriber behind it, and only otherwise is it the direct call (2026-10-12: before, TA <- a; TB <- b; ran TB’s rewritten handler ahead of TA’s queued ones).

Out of scope for v1 (fall through to bus dispatch unchanged):

A bound topic is never optimized: the binding may publish to remote subscribers that aren’t visible at compile time.

Phase 3 extends topic declarations with a per-message routing key so the bus can shard dispatch by key value at the (subject, key) granularity, rather than fanning every published message to every subscriber on the subject. Motivated by a downstream market-data workload: one reader thread publishes book frames for N symbols; N per-symbol loci each want only their own symbol’s frames. Without routing keys, every BookSignal would receive every L2Data frame and have to filter in user code — O(N × messages) dispatches; per-symbol state corruption pressure if filtering is forgotten.

Routing keys are also reusable for any “many similar loci sharing one publisher” pattern (per-tenant request streams, per-account ledger updates, etc.).

Surface — three pieces.

type L2Data {
sym_id: Int; // i64 routing key field
bids: [BookLevel; 100];
asks: [BookLevel; 100];
}
topic MarketL2 { // (1) topic-decl additions
payload: L2Data;
subject: "market.l2";
keyed_by sym_id; // ← new
on_unmatched: swallow; // ← new (default if absent)
}
locus BookSignal {
params { sym_id: Int = 0; ... }
bus { // (2) subscribe-clause filter
subscribe MarketL2 as on_l2
where key == self.sym_id; // ← new
}
fn on_l2(d: L2Data) { /* d.sym_id == self.sym_id, statically */ }
}
main locus Ingest { // (3) per-instance bindings
params {
btc: BookSignal = BookSignal { sym_id: 1 };
eth: BookSignal = BookSignal { sym_id: 2 };
sol: BookSignal = BookSignal { sym_id: 3 };
}
}

Width is inherited from the keyed_by field’s type. No separate width annotation. Acceptable field types and their bus storage at v0.1:

Field type Bus storage Compare cost
Bool u64 (zero-extended) one i64 cmp
Int u64 one i64 cmp
Time, Duration u64 (ns since epoch) one i64 cmp
no-payload enum u64 (i32 tag zero-extended) one i64 cmp
Decimal u128 (i64 pair) two i64 cmps
String u64 hash + owned copy one i64 cmp; full compare on hash match

The bus runtime stores both halves of a u128 uniformly (key_lo: u64, key_hi: u64) — narrower types zero-extend. Apps that need compound keys ((sym_id, venue, side)) pack them into a Decimal field themselves; the language does not bake compound- key derivation at v0.1.

String keys (2026-07-17) hash-gate the per-entry compare: the registry stores the subscriber key’s 64-bit hash plus its own copy of the string (capture-by-value — see “Key stability” below), the publish site hashes the payload’s keyed_by field, and only a hash match pays the full string compare, so a mismatched key still costs one i64 compare per entry. StringView and Bytes are not key-eligible. Remote fanout is unkeyed for String keys just as for scalars — no key material crosses a process boundary. The RECEIVE side of a binding derives the key instead (2026-09-09, DNA F.12): codegen synthesizes one extractor per keyed wire subject, the publish site’s exact computation over the deserialized payload, and every inbound path (unix serve loop, boot-window flush, UDP reader, adapter inbound) dispatches keyed. A where key == … subscription therefore means the same thing on both sides of a socket; before this it received nothing over a binding. An adapter’s inbound delivery (std::bus::__local_dispatch(subject, bytes)) carries wire bytes and no key, so for a keyed subject the runtime decodes the bytes once — through the binding’s codec(...) when it has one — into an arena of the delivery’s own, derives the key, and delivers keyed: matching where key == subscribers and unfiltered ones hear it, non-matching ones do not, and each subscriber still gets its own decoded copy (GH #1041). That arena is freed when the delivery returns and draws its memory from the thread’s chunk pool, so deriving the key costs no heap allocation in steady state. An unkeyed subject takes the unkeyed wire path unchanged.

where key == EXPR — what EXPR can be.

The RHS is evaluated at the subscribing locus’s instantiation (the point where its params defaults are resolved), and the resulting key value is captured into the bus registry alongside the handler’s self pointer. v0.1 restricts EXPR to:

  1. An integer / decimal / string literal: where key == 42, where key == "lobby"
  2. A const identifier resolving to a scalar of the topic’s key type
  3. A self.<field> path read, where <field> is a params-block field of the subscribing locus (for a String-keyed topic, a String field — e.g. where key == self.name)
  4. The bare word replica (2026-08-12, contextual — only this exact RHS position): the subscribing INSTANCE’s 0-based replica index. Each instance of a pinned(..., replicas = K) fan-out registers its own index, so K replicas shard an Int-keyed topic with one subscribe line and K spelled once, in the placement entry; a non-replicated instance is replica 0. Requires an Int-family key (String keys rejected — the index is a number). This is the bridge between the placement scale axis and the delivery axis, built so that placement itself stays semantics-free: the filter is still written on the subscription; the placement only decides how many indices exist.

A where key == … filter of any shape requires a KEYED topic (2026-08-12): an unkeyed publish never runs the key match, so a filtered subscriber would silently receive nothing — previously accepted without a word, now a type error.

Higher-shape expressions (self.a + self.b, method calls in the filter, cross-locus reads) are reserved for later. The restriction keeps the static check simple (“EXPR is a let- bindable expression with no side effects, types to the topic’s key type”) and avoids surprising semantics at registration time.

Key stability — captured by value at register.

A routing-key subscription captures its key value at the locus’s instantiation (or restart). The key expression is evaluated once, when the subscription is registered: at the instance’s construction, before birth() runs (GH #737). A key a locus computes in birth() is therefore not the registered one — the field’s default is — so a key comes in as a param at the literal (Feed { symbol_id: 7 }); registering the default on purpose stays valid. hale check warns at an assignment to a keyed field that runs during birth(): one anywhere in its body (inside an if, a match arm, a loop or a block) or in a method of the locus’s own that birth() calls as self.<m>(…), at any depth (GH #2027). The same holds for a subscription a locus imported from another module declares. Subsequent mutations to fields the filter expression references do not change which messages the handler receives. If dynamic re-keying is needed, dissolve and re-instantiate the locus. The alternative — re-evaluating the filter on every dispatch — would break the bus’s “register once, dispatch many” cost model and introduce ordering complexity against concurrent self mutation; the capture-by-value rule is the right default, and a re-subscribe API is a follow-up if a workload demands it.

on_unmatched: V — policy when no subscriber’s key matches.

A keyed publish may find zero subscribers whose where key == X filter matches the message’s key. Topic-level config picks the behavior; default is swallow (matches today’s no-subscriber semantics on unkeyed topics).

on_unmatched: Behavior
swallow (default) Drop the message silently. Diag visible only with LOTUS_BUS_LOG_UNMATCHED=1 env var (per-publish stderr line citing subject + key + subscriber counts).
fail Publish becomes a fallible expression. Caller must attach an or disposition: K <- value or raise panics via lotus_root_panic with a BusUnmatchedKey marker; K <- value or discard silently swallows on no-match. The err-payload-carrying dispositions (or handler(err) / or fail <p>) are reserved for v0.2 — they require synthesizing BusUnmatchedKey { subject: String, key_lo: Int, key_hi: Int } as a stdlib type, which is a small follow-up. or <substitute> is permanently rejected: Send produces no value, nothing to substitute.
fallback A catch-unmatched subscriber on the subject — subscribe T as h where key == _ — receives the message. At least one such subscriber is required; cross-module resolve-time check rejects the topic otherwise. The _ sentinel is legal only on fallback topics.

Static checks at typecheck:

  1. keyed_by FIELD — FIELD must be a declared field of the topic’s payload type; FIELD’s type must be one of the table above; the topic must not also declare a keyed_by via a parent topic with a different field.
  2. where key == EXPR — EXPR’s type must match the topic’s keyed-by field type after width inference.
  3. where key == EXPR is forbidden on topics without keyed_by; rejecting prevents silent-no-match bugs from typo’d filters.
  4. where key == _ is forbidden except on topics with on_unmatched: fallback.
  5. fail topics: every Topic <- value send site must carry an or disposition clause (or raise / or discard at v0.1 of the impl; or handler(err) / or fail <p> reserved for v0.2). The or clause attaches to the Send statement, not the value expression — the parser strips it off the value’s Expr::Or wrapping into Stmt::Send.or_disposition. Conversely, an or clause on a Send to a non-fail topic is rejected.
  6. fallback topics: at least one program-wide where key == _ subscriber must exist; checked at resolve after import merging.

Routing keys are orthogonal to topic hierarchy (Phase 2): a parent’s keyed_by and on_unmatched are inherited by children that don’t override; children may override either independently. A child topic re-declaring keyed_by must agree with the parent’s key type (subjects derived from a parent’s wire prefix share the parent’s key shape — anything else makes dispatch ambiguous on the wire).

Runtime — lotus_bus_entry_t extension.

The bus router’s subscriber-entry struct (crates/hale-codegen/runtime/lotus_arena.c, around line 4034) gains a tri-state filter and a u128 key value:

typedef struct {
/* ...existing fields: subject, self_ptr, handler, etc... */
uint8_t key_filter_kind; /* 0 = no filter (receive-all)
* 1 = specific key
* 2 = catch-unmatched (`_`) */
uint64_t key_lo; /* i64 key, or low half of i128 */
uint64_t key_hi; /* 0 for i64 / narrower types */
} lotus_bus_entry_t;

Dispatch (lotus_bus_local_dispatch_keyed):

int matched_specific = 0;
for (entry in the registration table with matching subject):
if (entry.key_filter_kind == 1
&& entry.key_lo == msg.key_lo
&& entry.key_hi == msg.key_hi) {
fire(entry);
matched_specific = 1;
} else if (entry.key_filter_kind == 0) {
fire(entry); /* unkeyed receive-all */
}
if (!matched_specific) {
for (entry in the registration table with matching subject):
if (entry.key_filter_kind == 2) fire(entry);
}

Walk cost is O(N_subscribers_on_subject) for the specific pass, with a second pass only when there’s no specific match (fallback case). For workloads with thousands of keyed subscribers per subject, a per-(subject, key_lo, key_hi) open-addressing index can be added later — YAGNI until a workload demands.

A registration may come from any thread (the instantiating thread, a pinned anchor’s thread initializing its subtree, a pool’s worker initializing a pool root’s), while any thread dispatches. The table is append-only: a registration appends under a lock, and a dispatch walks the entries published when the walk began, without one; an entry registered meanwhile is not in that walk (spec/runtime.md § “Bus message router” and lotus_arena.c, inventory row R50).

Two new runtime symbols:

void lotus_bus_register_keyed(
const char *subject, void *self,
lotus_handler_fn handler,
/* ...existing... */,
uint8_t key_filter_kind,
uint64_t key_lo,
uint64_t key_hi);
int lotus_bus_dispatch_keyed( /* returns match count;
* `fail` topics check this */
lotus_bus_queue_t *queue,
const char *subject,
const void *payload, size_t payload_size,
uint64_t key_lo, uint64_t key_hi,
lotus_serialize_fn serialize_fn);

Existing lotus_bus_register / lotus_bus_dispatch stay as the unkeyed entry points (compat for unkeyed topics).

Backward compatibility. Topics without keyed_by and subscribers without where key == behave exactly as today — the new fields default to key_filter_kind = 0 (receive-all) and the dispatch dispatches uniformly. Existing programs need no source change to keep working; new programs opt in per-topic.

v0.2 — err-payload Send dispositions.

On on_unmatched: fail topics, all four or disposition shapes are now supported:

What counts as a match is what the dispatch delivers to: a specific-key subscriber whose key equals the publish’s, a String key compared by its text (until GH #2025 the signal compared a String key’s hash and the publisher’s pointer, so a delivered publish read as unmatched and or raise panicked); and an open reservation (runtime.md § “Lifecycle obligations”, line 6), a subscriber of the same static tree still being built, which takes its key when it claims and is owed what it parked. A cell a reservation holds for a key no claimant takes is reported on stderr when the reservation closes.

BusUnmatchedKey is a synthesized stdlib type, injected into scope when any topic declares on_unmatched: fail. Layout:

type BusUnmatchedKey {
subject: String; // wire subject of the failing publish
key_lo: Int; // low 64 bits of the unmatched key
key_hi: Int; // high 64 bits (0 for i64 keys)
}

Codegen allocates a fresh BusUnmatchedKey in the current arena on the no-match branch and binds it as err for the disposition expression’s lowering. Mirror of the existing KeyError / IndexError / IoError synthesis pattern.

Out of scope at v0.1 (explicit non-goals):

A send is refusal-fallible when its topic can refuse it: the topic declares on_full: fail (with bounded(N): a subscriber at the topic’s capacity refuses the send, GH #255 phase 2) or on_unmatched: fail (a keyed send no subscriber’s filter matches is refused, § “Phase 3: routing keys”). A refusal-fallible send must carry an or disposition, and only such a send may carry one (or wait aside, below). Which ones each policy admits (GH #2146):

topic declares or raise or discard or wait or <expr> or fail <p>
on_full: fail yes yes yes no no
on_unmatched: fail yes yes no yes yes
both yes yes no no no

The rule holds whether or not the topic is keyed: an unkeyed bounded(N); on_full: fail; topic takes or raise and or discard (until GH #2146 the check read only on_unmatched, so it asked such a send for a disposition and refused every one but or wait, while hale build took them). A send with no disposition to a topic declaring both policies is asked for one once.

The placement { } block on main locus controls per-locus thread placement, parallel to bindings { } for bus topology. Placement is a deployment seam — same library, different placement entries, different binary behavior. See spec/decisions.md § F.31 for the intrinsic-vs- deployment axis the block sits on, and spec/runtime.md § “Placement classes” for the runtime semantics.

main locus App {
params {
gateway_a: Gateway = Gateway { venue: "venue-a" };
gateway_b: Gateway = Gateway { venue: "venue-b" };
metrics: MetricsServer = MetricsServer { port: 9100 };
ui: Renderer = Renderer { };
}
placement {
gateway_a: pinned(core = 1);
gateway_b: pinned(core = 2);
metrics: cooperative(pool = io);
ui: cooperative(pool = render);
// unspecified main-locus params → cooperative(pool = main)
}
}

These placement/bus rules are part of the broader compile-time verification surface; spec/verification.md is the canonical catalog of every static check (with severities and enforcing passes).

  1. placement { } is main locus only. Any other locus declaring placement { } is a parse error (same shape as bindings { }).

  2. Keys reference main-locus params field names. The key on the left of each placement_entry must match a declared params field on the enclosing main locus. Unknown field name → typecheck error pointing at the params block.

  3. Field values are locus types. A placement entry on a non-locus field (port: Int, host: String) is a typecheck error — placement applies only to locus instances. An exposure param (web: api::Exposure = api::serve(…), GH #1565) is one, and its row places the exposure’s listener and the connections it starts while the exposure stays with main, beside the sources it calls: the row is cooperative(pool = X) where async_io, and any other is refused (spec/api.md § Serving). A server locus’s listener runs where the row of the param that holds it places it, when that row hosts async_io.

  4. At most one placement entry per field. Duplicate keys are a parse error.

  5. Pool names use snake_case Idents. The set of pool names is inferred from cooperative(pool = X) references across all placement entries in the bundle. Pool main is always available; it refers to the program’s main OS thread.

  6. Locus-pinning compatibility. A locus placed pinned is subject to the pinned-class restrictions: no accept(c: Child) accept-method, and no closure whose epoch is birth or dissolve (dissolve is the default when no epoch clause is written). Those two epochs fire inside the lifecycle cascade, which the owner’s thread runs and cannot route across the pinned thread; a tick, duration, explicit or inline closure fires on the pinned thread itself and is permitted (a pinned heartbeat with epoch duration, a pinned connection with an inline closure). These restrictions belong to the placement site, not the declaration: the typechecker applies them to every instance that runs pinned — a pinned entry’s field (each of its replicas) and an adapter inline in bindings { }, which has a thread of its own with no entry — and judges the locus the instance realizes (a construction site’s override literal, a std:: locus), at the entry’s span. The refusal carries its witness as related locations, in order: the entry that runs the instance pinned (the placement entry, or the binding entry), the declaration the instance realizes, and the member that conflicts (the accept, or the closure’s assertion). A locus that uses neither feature can be placed either cooperative or pinned at the deployment’s discretion. (F.40 phase 0: until then the rule was stated as “no closure declarations” while lowering refused only birth and dissolve closures; the rule now says what ships, and the typechecker judges it. Phase 3, C7: it is judged over the placement table’s rows, so the adapter, an accept() with no parameter and a field whose written type the entry walk could not resolve are judged too, and lowering keeps no refusal of its own. Phase 4, W2: the refusal’s message is unchanged, and the witness is new.)

  7. Dead bus receiver (error). A locus that declares bus { subscribe ... }, is placed cooperative(pool = X) with X != main (and not where async_io), and whose run() makes a known-blocking stdlib call is rejected. A cooperative locus receives cells only while its pool thread is free to run the dispatch (the cross-process transport reader dispatches into the handler set; the in-process cooperative queue is drained at yield points). A blocking call monopolizes the pool thread, so the dispatch never runs and the subscriber’s handlers never fire. Placement alone is not the condition — an event-driven subscriber that yields (handlers plus a time::sleep loop, or where async_io, which parks) receives fine and is not flagged; only the blocking-and-subscribing combination is rejected. A subscription to a topic the locus also publishes is also spared (an intra-locus self-publish→subscribe is devirtualized to a direct call). Fix: pinned (own thread + a mailbox drained at sleep/yield) or keep run() non-blocking. (Corrected 2026-06-03: an earlier form rejected on placement alone and over-fired on event-driven non-main cooperative subscribers, which receive reliably.) The rule is judged over the bus graph (rule 9): a topic the locus publishes by its declared name and subscribes by its literal subject is one subject under the graph’s canonical key, so that subscription is spared as a self-publish, and the error lists the handlers of the subjects the locus subscribes and does not publish. A subscription whose subject the graph cannot resolve is compared as written. (F.40 phase 3, C4.)

  8. Blocking syscall on a cooperative pool (warning). A locus placed cooperative(pool = X) without where async_io whose run() calls a known-blocking stdlib op (tcp/tls recv, accept, process::run/wait) but is not a dead receiver (rule 7) gets a warning (not an error — hale’s only non-fatal diagnostic). A blocking call holds the pool’s OS thread for its whole duration, stalling every other locus scheduled on that pool and the pool’s bus drain. The fix is pinned (its own thread — the prescribed shape for blocking I/O) or cooperative(pool = X) where async_io (parks on I/O readiness). It is a warning rather than an error because a single-purpose blocking server with nothing co-scheduled is legitimate. Detection is interprocedural: it follows the call graph, so a run() that blocks indirectly — through a helper fn or a self.method it calls (transitively) — is flagged too, with the diagnostic naming the offending call. It remains best-effort at the edges (blocking via a handle method like stream.recv, or across a cross-locus self.field.method() hop, isn’t traced). Note rule 7 (the dead-receiver error) stays direct-call-only — it is not widened onto indirect paths, so the higher-stakes diagnostic keeps its precision. Rules 7 and 8, the pool-starvation warning and the birth-order trap read where each field runs from the placement table: they judge the main locus lowering deploys, the entry (one lowering does not deploy, an imported one, spawns nothing and is not judged), and each field by the locus it realizes, an alias or an imported seed’s qualified path included (a stdlib locus’s run() is judged by the known-long-running list, as before).

  9. Orphan bus topic (warning). In a closed-world program (one with an entry: the seed’s own main locus; an imported one is not the entry: “The entry locus”, § “Phase 2: hierarchy, subjects, bindings, closed-world optimization”), a bus subject — a declared topic or a literal string — wired to only one end is flagged: published with no subscriber (the cells go nowhere) or subscribed with no publisher (the handler can’t fire), and a declared topic touched by neither is dead wiring. Suppressed when the other end is plausibly external: a transport binding (bindings { T: ... } implies a cross-process peer), a wildcard subscriber/publisher covering the subject (log.** covers log.app), a cross-seed reference (alias::Foo — the other seed owns the other half), an external ingress — a std::bus::__local_dispatch(subject, bytes) call, the inbound side of an adapter, which publishes the subject its literal names or, computing it (a NATS connection dispatches whatever subject arrives), any subject (friction sweep 2026-10-12) — or the same locus being both publisher and subscriber. (A topic is no longer reachable by a caller because a locus subscribes it: the retired api binding’s lift of this rule went with it, and a served surface reaches handlers, not topics.) The closed- world gate is why this is skipped for library seeds (no main): their consumers are downstream, out of the bundle. (GH #18 #4.) Rules 9 and 10 and the dead-receiver rule (7) are judged over the bus graph. The graph carries as columns what the walk computed: whether a topic is bound to a transport, whether a subject crosses a seed, whether a subscription is a wildcard, whether an external ingress may deliver on it; rule 9’s closed world is the entry row’s. A subject is compared under the graph’s canonical key, its wire subject (spec/model.md rule 8): a topic published by its declared name and subscribed by its literal subject is one subject, wired at both ends. Where the graph cannot resolve a subject (a topic name no declaration answers, a qualified path through an import the bundle never resolved, an open world), the rule does not fire: an unresolved subject is not a proven orphan, and the row records the hole. The silence is about the orphan judgment, not about admitting the reference: in a whole program a qualified subject that names no declaration is a located “unknown topic” error at the check (spec/projects.md, “An unresolvable qualified name is a located error”), as a local one is. (F.40 phase 3, C4.)

  10. Bus cycles. An edge S →(L) D exists when locus L subscribes subject S with a handler that sends to subject D. A cycle in this graph is a publish→subscribe→publish loop, and the dispatch model splits it two ways:

    • A cross-locus cycle (edges from ≥2 loci) hops between loci through the cooperative queue (drained at yield) — it spins the queue / livelocks → warning.
    • An intra-locus cycle (every edge in one locus) whose every send the intra-locus rewrite turns into a direct synchronous call (rule 7) recurses on one thread without bound → stack overflow → error. To keep the error precise, only unconditional sends form intra-locus edges: a self-republish guarded by an if/match/loop is a terminating state machine, not unbounded recursion, and is not flagged. (GH #18 #4.)
    • An intra-locus cycle with a send the rewrite leaves on the bus is carried by the queue like a cross-locus one: each cell is handled at a later drain, so the stack does not grow, and it is the queue’s warning. The rewrite makes a direct call only where its preconditions hold (§ “Phase 2: hierarchy, subjects, bindings, closed-world optimization”, Closed-world topology optimization), and it counts only a subscription by the topic’s declared name, so a topic sent by name and subscribed by its literal subject cycles through the queue. The check reads which sends lowering rewrites from the rewrite’s own relation, keyed by each send’s identity, never from the subjects’ spelling. (F.40 phase 3, C4.)

    The graph’s edges are keyed by declaration identity: a handler body belongs to the declaration that wrote it, so two loci of one name have their own edges, and the cycles follow the edges, not the name — a cycle whose edges two declarations of one name wrote is cross-locus, and neither declaration’s intra-locus check sees the other’s edges. An edge joins canonical subjects (rule 9): a send by a topic’s declared name meets a subscription by its literal subject, and a send whose subject the graph cannot resolve (an unresolved path, a computed subject) forms no edge. (F.40 phase 3, C4.)

  11. Bus backpressure (warning). A locus that publishes to the bus inside an unbounded while true loop carrying no flow-control or exit point — no cooperative yield, no time::sleep/tick throttle, no input-pacing blocking recv, no break/return — has no backpressure: it posts cells faster than any subscriber can drain, so the queue and the payload arena grow without bound. A full producer-vs-consumer rate analysis is undecidable, so this is a deliberately narrow structural heuristic (warning): only literal while true loops are considered (bounded for/while cond loops never are), and any flow-control point anywhere in the loop body clears it. (GH #18 #4.)

  12. Bus subject type-mismatch (error). Every publish/subscribe site addressing the same literal subject string must declare the same of type payload — otherwise a subscriber decodes the publisher’s bytes as the wrong type at runtime. A declared topic is already unified by its declaration (and of type is forbidden on topic refs), so this closes the literal-subject gap. Grouping is by exact subject string, which excludes wildcards (log.** and log.app are different strings, never cross-compared). The fix is to declare a topic (one payload type, fixed in one place) or align the of type annotations. (GH #18 #4.)

  13. Empty / degenerate pinned(cores = …) (error). A cpuset affinity spec that selects no cores is rejected statically: an exclusive range whose upper bound is ≤ its lower (4..4, 8..4), an inclusive range that runs backwards (8..=4), or a set with a duplicated element ({2, 4, 2}). Bounds/elements are integer literals — placement is closed-world — so the selected core list is known at compile time and a spec that reduces to “no cores” (or a redundant one) is an authoring error, not a deploy-box question. Whether the selected cores exist on the target stays best-effort at runtime (out-of-range indices are skipped, exactly as pinned(core = N) degrades on a smaller machine). Linux-only affinity; a no-op on other hosts. (Topology Phase 1a, 2026-07-04.)

  14. topology { } consistency + pinned(node/l3) resolution (error). The declare-only topology { } block is validated statically: NUMA node ids must be unique; L3-domain names must be globally unique (they’re referenced by pinned(l3 = name) without node qualification); each cores spec must be well-formed (rule 13); a core may belong to at most one L3 domain (overlap is ambiguous affinity); and a domain core may not overlap a reserved range (reserved cores are held back for the OS / main). A pinned(node = N) / pinned(l3 = name) placement entry must reference a domain the block declares — using either with no topology { } block, or naming an undeclared node/domain, is an error. Resolution is closed-world (ids and domain cores are literals), so the selected core set is known at compile time. Whether those cores exist on the deploy box stays best-effort at runtime. A pinned(node/l3) locus gets thread + memory co-location: its thread is affinity-masked to the domain’s cores (Phase 1a cpuset path) and its arena — including method-scratch sub-regions — is mbind-bound to the node, so its working set lives on the node its thread runs on. Node binding is a raw mbind syscall (no libnuma dependency), Linux-only and best-effort (falls back to first-touch when the node can’t be honored); non-node arenas are unchanged. (Topology Phase 1b, 2026-07-05.)

  15. replicas = K (error on K < 1; pinned-only). A pinned(..., replicas = K) entry fans the field into K single-threaded instances — replica i pinned to one core of the affinity set (round-robin), each on its own OS thread. K must be >= 1 (0 / negative is rejected). replicas is valid only on pinned: K cooperative loci on one pool would share a single thread (not parallel), so cooperative(..., replicas = K) is rejected at parse with guidance toward the pinned form. The point is that parallelism comes from more single-threaded units, never a multi-worker pool — each replica is its own single consumer, so the lock-free rings, bus devirtualization, and single-threaded-method guarantee all hold. Replicas compose with node/l3 (each replica’s arena binds to the target node) and are non-addressable (no field[i] surface; they are bus-subscribing or run-loop workers). All K are joined and dissolved at parent teardown. (Topology Phase 1c, 2026-07-05.) Replicas compose with KEYED DELIVERY via where key == replica (2026-08-12) — see the routing-key filter rules.

  16. Pool affinity (2026-08-12). cooperative(pool = X, core/cores/node/l3 = …) binds pool X’s worker THREAD to the core set — the same affinity forms pinned takes, resolved against topology { }, same best-effort contract. The pool has one worker, so entries naming one pool must agree: a second entry may name the pool bare (it inherits) but a different affinity is a type error citing both entries. Affinity without a named pool (or on pool main) is rejected — the main pool is the program’s main thread, whose affinity belongs to the operator. Thread affinity only; pool workers own no arena to node-bind (handler scratch lives in each locus’s own arena).

  17. A pinned placement forbids a loop (error). A locus whose placement { } block pins any field may not be instantiated inside a loop body — a while / for at any nesting depth, in a free fn, a locus method or a lifecycle hook. pinned gives its field its own OS thread, spawned during the placing locus’s params-init and joined at the instantiating scope’s exit, and the join record (the deferred-dissolve slot plus the thread handle beside it) is one slot per instantiation site: a second pass over the site overwrites the record of the first, so only the LAST instance is joined and arena-destroyed and every earlier pinned thread is orphaned with its arena still live. Placement names static resources — a core, a NUMA node, replicas = K — one thread per entry for the program’s life, so a per-iteration thread is a category error rather than a reclaim policy to pick. placement { } is main-only (rule 1), so the shape this rejects is the deployment root booted once per iteration, and the placement it reads is the deployment root’s (an imported main locus is not deployed and pins nothing: “The entry locus”, § “Phase 2: hierarchy, subjects, bindings, closed-world optimization”). The fix is to instantiate it once outside the loop; a loop that calls a fn holding the literal is unaffected and correct (each call joins its own thread at that fn’s exit), and the rule is positional on that literal, so it is not a rule about the whole call graph. The typechecker judges it over the placement table’s constructions of the root (every literal of the root declaration, as resolved, in a fn or locus body), and over the root literals written in another locus’s params default: such a literal is built wherever a literal of that locus takes the default, so it inherits that literal’s loop, through any depth of defaults, and is rejected at the outermost literal written in a loop (for i in 0..3 { Holder { }; }, where Holder’s default is App { }, at Holder { }). A root literal written in a position lowering emits again at every use — a const’s value (at each read of the const), a type’s field default (at each literal of the type that takes it), a closure’s assertion (at each evaluation of the closure) — or reached through params defaults from a literal written in one, has no construction the table records, so the position does not let the compiler show the root is built once: when the root pins a field it is rejected outright at that position’s literal, loop or no loop, and the fix is to build it in a locus’s params or a fn body. A root literal in an adapter’s inits is built once, by the bindings prelude, and is not judged. A const or type written in a locus body is refused on its own rule. The test harness’s build, which skips the rest of the check, judges it too, so lowering keeps no refusal of its own. (GH #826, 2026-09-20; F.40 phase 3, C7.)

  18. Every entry is consumed by exactly one instantiation (error). A placement entry is carried by the locus LITERAL lowered for its field, and by nothing else: the thread class, the cooperative pool and the NUMA node all ride an override that the next T { } takes. So a placed field whose value arrives any other way — a factory call, a fallible call, a conditional, a reference to an instance somebody else built — leaves the entry untaken, and the next field’s turn through the params-init loop resets it. Nothing is placed and nothing is said. That shape is rejected at the initialiser, with the literal form spelled out. The entry’s value is the init written at the instantiation site when the literal supplies one, and the params default otherwise, so both spellings are checked — and a default every site overrides is dead text, not a dropped placement. The entry is not applied after the fact because there is nothing left to place: the pinned path does not mark an instance, it spawns a thread that runs the locus’s whole lifecycle — birth, run(), the mailbox loop, drain, dissolve — and a factory’s literal has already run birth and run() (and registered its subscriptions against the global queue) before the value returns. Scope matches rule 17’s: an imported seed’s main locus is renamed __lib_*, is not the deployment root, and its entries never reach the plan; the instantiation sites judged are every literal of the root declaration as resolved, wherever it is written: the placement table’s constructions of the root (a literal in a fn or locus body), and the literals the table records where no body reaches — another locus’s params default, at any depth of defaults, a const, a type’s field default — which lowering expands wherever their holder is built (locus Holder { params { app: App = App { w: make_worker() }; } } is rejected at make_worker()). The root’s own default is live when one of those literals leaves the field to it, or when no literal lowering emits builds the root (no construction, and no such literal whose holder something builds): lowering then builds no root at all, but a library seed checked on its own takes the default, and so does the rule. So App { w: Worker { } } in Holder’s default, with Holder { } built, leaves a make_worker() default dead. The test harness’s build, which skips the rest of the check, judges it too, so lowering keeps no refusal of its own. (GH #890, 2026-09-20; F.40 phase 3, C7.)

  19. Uncarriable bus payload (error). An of type T clause on a publish / subscribe must name a type the bus can carry — a user type, an enum with a payload variant, or BytesView (§ Bus subscription dispatch → Payload type, below, has the full statement of what the wire carries). A primitive, a tuple, an array, bounded[T; N] or a no-payload enum is rejected at the clause’s own span. Before this rule of type Int checked clean and could not be lowered: codegen refused the publish (bus send payload must be a user-type or has-payload enum value) and the subscribe (m60 requires a TypeRef, has-payload Enum, or BytesView), unlocated and from another layer. A payload type the bundle cannot resolve — a qualified path into a seed it does not hold, a generic instantiation, a name nothing declares — is left alone: the rule is about what the bus carries, not about which names are in scope. A topic’s payload: is under the same contract, but the checker does not desugar topics (lowering does), so that half is still diagnosed during lowering. (GH #876, 2026-09-20.)

  20. Unowned subscriber (error). A locus with bus handlers that is born in another locus’s bus handler — a literal in the body of a fn that one of its bus { subscribe … as h } entries names — must be owned: a handler returns after each message, so a local it binds dissolves at its return, and the subscription could never fire for a later message. A locus with bus handlers is owned: it is the entry’s root, a replica or field of an owned locus, a binding’s instance, or accepted by an ancestor through an accept edge of the ownership graph. The judgment reads the graph’s edges, which are keyed by declaration identity: an accept that names the subscriber’s declaration through an alias, an import path or a generic specialization owns it; a name that merely matches the declaration’s last segment, or its template, does not. When two declarations share a name, the graph orders them by declaration order and the diagnostic names the declaration it judged. Where the graph cannot decide which locus is born, or whether the tower is complete (an unresolved type, an open world), the rule does not fire: unknown ownership is not proven absence, and the row records the hole. An unknown construction path cuts the other way: it proves no owner. A literal in a handler’s body is not the entry’s root, a replica or a binding’s instance, so the rule reads its accept edges: the nearest accepting ancestor owns it as it owns any other birth, and a literal assigned to a field of self is judged by those edges too, since the graph records no assignment target. An ancestor owns it only if one accepts it on every construction path of the handler’s locus: the paths the placement table records (each instance row under its owner’s declaration; at a template’s top, a literal directly in fn main, the root’s construction, the entry’s implicit one or a bindings { } adapter, none of which has an ancestor; each dynamic site in a locus’s bodies, or in a free fn, whose callers are not followed), together with the graph’s own edges (a literal in a locus’s bodies or params defaults). A path that reaches no acceptor, a free fn or a hole of the table (a held instance it does not link, a field whose initializer is no literal, a dynamic site of unknown domain) refuses the birth, and the diagnostic names that path: an accepting parent somewhere is no proof that every instance has one. The graph cannot decide in an open world (no entry, so a consumer may complete the tower), for a generic template no declared type specializes, or for a qualified path that names no declaration. A subscriber born in run(), birth() or a plain method is not judged: it lives for that scope and can receive what is published during it. --allow-unowned-subscriber allows the shape for a program that manages the subscriber’s lifetime another way. (2026-05-29; judged over the ownership graph since F.40 phase 3, C4.)

A locus’s methods may be invoked only on the OS thread that owns the locus’s placement’s pool. This is enforced at typecheck via a static call-graph walk starting from each top-level placement entry:

  1. Seed each placement entry with its pool: gateway_a → pinned (own thread), metrics → cooperative pool io, etc.
  2. For each method call expression recv.foo(args), determine the receiver’s pool from the receiver’s static type and the surrounding pool context.
  3. Cross-pool direct method calls are rejected with a focused diagnostic naming both pools and pointing at the placement { } entries that picked them.
  4. Bus publishes (Topic <- payload; / "subj" <- payload;) are unrestricted — they route through the substrate’s cross-thread dispatch machinery (the existing m28b condvar+memcpy mailbox path generalized to cooperative pools).

This invariant is the substrate enforcement that makes M:N safe. Without it, multi-pool deployments would silently race on locus arenas (which are unsynchronized bump allocators by design).

Step 3 has one exemption, and it belongs to the receiver’s form. Every @form declaration has one resolved row (F.40 phase 3, C1) that keeps two facts apart:

Two questions are asked of the row:

  1. Is it explicitly configured? Any sync = argument, none included. Inference runs only over a form that is not, so an author who writes sync = none keeps the map unsynchronized.
  2. Is it safe for cross-domain access? Its effective discipline synchronizes: serialized, striped or lockfree, written or inferred. A cross-pool method call into a receiver whose form is safe is accepted; any other is rejected by step 3. sync = none is configured and not safe, so a cross-pool call into a sync = none map is rejected, as one into a map inference left unsynchronized is.

The build lays each map out by the same row: the discipline a program runs with is its form’s effective one, and no sync = argument is ever written into the program on the author’s behalf. Three readers ask whether a form synchronizes as one question — the depends law (a held form is an input channel outside the bus graph), the effects contracts (a call into the form or a locus holding it may take its lock, which @no_block and @deterministic refuse) and the instance-aliasing rule (a field behind a discipline is not unsynchronized state) — and they ask the second question alone. An explicit sync = none is configured, unsynchronized, and holds no lock: a @no_block method may read the map, a depends: locus may hold it, and one instance holding it, reached from two pools, gets the unsynchronized-state warning.

Loci instantiated nested in another locus’s body (birth / run / lifecycle methods, let-bound children, or params fields of non-main loci) inherit their containing tower’s pool by construction:

main locus App {
params {
gw: Gateway = Gateway { };
}
placement {
gw: pinned(core = 1);
}
}
locus Gateway {
params {
// Cache instantiated nested in Gateway's params —
// inherits Gateway's pool (the pinned thread). No
// placement entry is permitted on `cache` at any
// main locus.
cache: Cache = Cache { };
}
}

Placement entries on nested fields are a typecheck error — placement is a top-level main-locus surface only. To run a nested locus on a different pool, hoist it to a main-locus sibling.

Main-locus params fields with no explicit placement { } entry default to cooperative(pool = main). The pre-F.31 shape (: schedule cooperative on every cooperative locus declaration, with a single shared main thread) is exactly the behavior a program without any placement { } block receives. Existing programs that don’t declare placement see no observable change.

The set of cooperative pools is the union of X values appearing in cooperative(pool = X) references across all placement entries, plus the implicit main pool. The runtime spawns one OS worker thread per inferred pool name beyond main. No threads { } declaration block at v1 — pools are named purely by use site, and the runtime materializes them on demand at startup.

A param of the main locus of type std::observe::Probes (GH #1477, 2026-10-19) asks the runtime to serve the process’s health over HTTP on its port, every interface:

params {
probe_port: Int = 9090;
probes: std::observe::Probes = std::observe::Probes { port: self.probe_port };
}

Since #1565 what the runtime serves is an ordinary param of main, recognized by its type as a hub and an exposure are; there is no keyword. The check allows one, on the main locus, built by its default: a param of the type on another locus, a second one, and a construction of the main locus that supplies it are refused. Its port is a param literal’s field, checked as one, and a default reading self.<param> is a default like any other. Nothing is served, and nothing is sampled, in a program that declares none.

The param’s birth() starts the probes on a thread of the runtime’s own, not on a pool or a thread the program places: the probes judge the program’s pools and its main thread, so they must answer while any of those is wedged or busy. The param is declared and named like any other; a placement does not apply to the thread. A port that cannot be bound fails the start. wasm32 has no threads or sockets and serves none.

path answers
GET /healthz liveness: 200 ok, unless a queue holds work its consumer has not touched for the stall window (main’s queue, each cooperative pool’s; 10 s, LOTUS_PROBES_STALL_MS), then 503 and stalled: <queue> … (main, pool:<name>)
GET /readyz readiness: 503 starting until the main locus’s births are done (its params’ children born, a placed child’s readiness awaited, its bindings open, its boot subscriptions in place, its run() not yet entered), 200 ready from then, 503 draining once the process drains (a signal’s drain or the main locus’s tree drain, self.draining)
GET /capacity application/json: {"ready", "draining", "queues": [{"name", "pending", "capacity", "stalled_ms"}]}, a queue’s cells waiting, the cells it holds before it grows or spills, and how long it has stalled (0 while it moves)

Any other path is 404, and any method but GET and HEAD is 405; each connection gets one response and closes. The readings cost the program nothing on its own paths: once a second the probe thread reads each queue’s depth and its consumer’s heartbeat (the count every drain and every cell taken bumps), and a queue is stalled while it holds work and that count stands still. A pool worker running one long cell with nothing waiting is not stalled.

A program is observed through a backend it holds as a param of its main locus, beside the others, and places with placement { } as any other (§ Placement block). Nothing is observed unless the program holds one.

main locus App {
params {
reg: std::metrics::Registry = std::metrics::Registry { namespace: "app" };
metrics: std::observe::Scrape = std::observe::Scrape { port: 9100 };
}
placement { metrics: pinned; }
}
fn main() { App { }; }

Recognized by its type. The compiler recognizes a backend param by its type, std::observe::Scrape (metrics) or std::observe::Otlp (lifecycle events, S4), as it recognizes a hub (observe_expand, beside hub_expand):

Its literal is checked as any param’s default: it may read an earlier param (port: self.metrics_port) or the environment.

How it runs. Scrape is an ordinary locus whose run() serves a std::http::Server on its host and port, answering its path. It runs wherever placement puts it: pinned gives it a thread of its own; left unplaced it serves on main’s pool, as an unplaced server does. It is born, drained and torn down as any param of the main locus: a signal’s drain stops its listener, and main’s run() returning does not (§ “Drain cascade (whole-process)”).

Otlp is a locus whose run() drains the runtime’s event ring and sends it to an OpenTelemetry collector until the tree’s drain or a signal’s (spec/runtime.md § “Observe backends”); holding one turns the event ring on, and nothing in a program that holds none.

What holding one turns on. Three things, and only in a program that holds one (a program without it lowers none of them and pays nothing): every std::metrics::Registry registers in the process-wide series table the scrape renders, and every handle mirrors its updates there; restarts and delivered failures are counted; and the runtime counts in counters-only mode (spec/runtime.md § “Observe backends”).

One port. Scrape’s port is required, and it is a listener of its own. std::observe::Probes (§ Probes) is a second listener on its own port and does not serve /metrics, so a deployment that holds both annotates two ports.

In the topology artifact. Schema 1.21’s observe section lists each backend param with its endpoint (param, kind, backend, and a scrape’s host, port and path or an OTLP backend’s endpoint; a field the literal does not write is its declared default, a value the source computes is null), so a deployment elaborator renders the scrape annotations without parsing the source.

A seam (GH #1530, 2026-10-17) stitches a producer whose output is a set to a consumer whose methods cover it, inside one locus tower. It is a member of a locus, beside bus, in one of two shapes:

locus Gateway {
params {
feed: Feed = Feed { };
wire: Wire = Wire { };
desk: Desk = Desk { };
log: Log = Log { };
}
seam {
self.feed.next()
-> self.wire.decode
-> self.desk
-> self.wire.encode
-> self.log.write;
or end;
}
}
locus Counter {
params { wire: Wire = Wire { }; desk: Desk = Desk { }; }
seam answer(frame: String) -> String {
frame
-> self.wire.decode
-> self.desk
-> self.wire.encode;
}
}

The closed flow (no name) has a source, a call of a method of the locus or of a child that makes the entry value, and ends at a sink, a method that takes the last value and returns nothing. It is the locus’s run: while the locus is not draining, it pulls a value from the source and runs the chain on it; a failing source ends the flow (the source has ended). A locus with a closed seam declares no run of its own. The callable form, seam name(x: T) [-> R] { x -> … ; }, is the method name, which runs the chain on its parameter and returns the last hop’s value: of R when written (each path’s value flows into it), else of the one type every path ends in, which is refused when the paths end in more than one (“declare what it returns, a set holding them all”).

A hop is self.m or self.child.m, one method, or self or self.child, a locus, where the compiler writes the dispatch: each member of the incoming set goes to the locus’s method whose one parameter takes it. A child is a params field holding a locus; a hop on an interface is refused (its method is not known statically), and so is a hop on a child that placement puts on another pool than the seam’s (a seam is one tower; the bus crosses pools).

Coverage is one check applied at every boundary, both ways. At a locus hop, every member of the incoming set (a type that is no set is a set of one) has exactly one eater: a method whose parameter is the member or a set holding it. A member with none is refused, naming the member, what produced it and the locus; one with two names both methods. Methods no member reaches are ordinary methods. At a method hop and at the sink, every incoming member is in the parameter’s set (or is its type), and one that is not is refused by name. A locus hop’s output is the union of the dispatched methods’ results; a method returning nothing ends the chain.

Failures. A hop declared fallible(E) has its failure placed: entering the chain at the first later hop whose parameter set holds E (so an Outbound that includes WireError lets encode answer it as a protocol-level reject); else by the seam’s or end; (the closed flow ends, as run ends; the callable seam fails with E, declared fallible(E), and it fails with one type) or or violate NAME; (the closed flow violates the locus’s closure NAME); a failure placed nowhere is refused, naming the hop and E. A refused callable seam still declares its method, from what the seam spells: its parameter, its result when written (else unknown) and, under or end;, a failure of unknown type. So its callers check, and the refusal is the seam’s one error.

Lowering. A seam is expanded before the check into the methods it means, which are then checked as any methods are. The chain is direct calls, written a path per member: where a set meets a locus hop the expansion writes a match whose arm for each member runs the rest of the chain on that member, so a member keeps its static type from the producer’s return to the sink and no union is built that the program did not declare. Each hop call is inlined into the seam. Where the seam splits the set a hop returns, and the split is the result’s one use, the seam calls the hop’s fused clone: the method lowered a second time with one more parameter, storage for the set in the seam’s frame. Each return of the clone deep-copies a member into the caller’s arena as the member it is, writes it there beside its tag as a constant, and returns that storage (a value of the whole set is copied out as the set, then into the storage). Inlined, each return site goes straight to its arm: the dispatch reads no tag back and switches on none. A program with no seam has no clone, and a hop whose set the seam hands on whole is called as written. A closed flow’s frame is a method of its own, __seam_turn() -> Int (the source pulled, the chain run), which answers whether the flow goes on, has ended (the source ended, or or end;) or met a failure routed to or violate NAME;. The locus’s run calls it while the locus is not draining, returns when the flow has ended, and violates NAME itself when the turn says so (a method that returns a value may not violate), so the violation is the lifecycle’s, as before. What a frame’s hops make is reclaimed when the turn returns (spec/memory.md), as a callable seam’s is at its return.

xs.filter(<expr>).count() and xs.filter(<expr>).into(target) are recognized forms, not values. A chain is rewritten to a single loop by a post-parse pass, so typecheck and codegen both see an ordinary while and neither knows chains exist.

self.users.filter(it.active).into(self.actives)

it is bound to the current element by the rewrite. Stages fuse: two filters are one pass, because nothing is produced between them.

Why a form and not a value. A chain that produced something at each step would need either a lazy object or an intermediate collection. Both are sequence values, which need an owner, which reopens arenas and placement — the knot that made composition look like a language-sized change. A recognized form produces nothing at any step, so the question does not arise.

Three properties follow, and they are the contract:

  1. A chain allocates nothing. It is therefore legal inside @budget(alloc_per_call = 0) and @hot. A design that returned a new collection would have been illegal in exactly the code Hale exists for.
  2. A chain is eager. A predicate’s effects are attributed to the predicate’s own source position. A lazy chain would execute it at the terminal and the witness path would name the wrong line.
  3. A chain needs no lambdas. The predicate is an argument position the compiler knows about, not a value, so there is no closure to represent — no capture modes, no escape analysis, no cross-thread question.

Boundary. Elementwise operations fuse. Whole-set operations (sort_into, reverse_into, group_count_into) cannot — they need every element before producing any — so they are terminals that materialize into caller storage: the loop fills (or bumps) a target the caller owns, and any reordering runs on that target after the loop. The chain itself still allocates nothing. Over a stream source (a bus subscription, where the driver is delivery rather than a loop) they are rejected outright: “needs an end” is a property the compiler can decide.

A bare method call with no stage (v.count()) is an ordinary form method, not a chain, and is left alone. A chain over a non-form receiver fails with the ordinary “no method get” diagnostic.

Elementwise stages (fuse into the one loop):

stage meaning
filter(pred) drop elements where the it-predicate is false
map(expr) rebind the element to the it-expression’s value
take(n) stop the whole chain once n elements have passed this point (2026-08-11)
skip(n) drop the first n elements that reach this point (2026-08-11)
enumerate() bind idx — the 0-based count of elements reaching this stage — in every later stage and the terminal (2026-08-11)

take and skip count elements arriving at their own position, so filter(p).skip(2) skips the first two matches, not the first two source elements; their limits are evaluated once, before the loop. enumerate is an explicit opt-in stage rather than an always-bound name so a chain never captures a user’s own idx local; written after a filter, idx counts the filtered stream. A min/max key mentioning idx is left unrecognized (the best element’s key is re-derived from the element at compare time, and its enumerate count is not recoverable from it — rejecting beats a silently wrong comparison).

Terminals:

terminal result
count() Int
sum() / sum(seed) sum() is Int; sum(seed) seeds the accumulator and the seed is its typed zero — sum(0.0) sums Float elements, sum(100) starts an Int sum at 100 (2026-08-11)
into(target) pushes each surviving (mapped) element
any(pred?) Bool; empty selection ⇒ false (vacuous)
all(pred) Bool; empty selection ⇒ true (vacuous)
first() the first surviving element — fallible on empty
find(pred?) find(p) ≡ filter(p).first()
min(key?) / max(key?) the element with the least/greatest key (min_by_key shape; bare form compares elements) — fallible on empty
each { … } run the block per surviving element
sort_into(target, cmp?) push survivors into the caller’s vec, then reorder it in place — sort() (primitive ordering) or sort_by(cmp) with a named comparator (2026-08-11)
reverse_into(target) push survivors, then swap ends inward on the caller’s vec (2026-08-11)
group_count_into(target, key?) one hashmap bump(key) per survivor — increment-or-init tallying into the caller’s @form(hashmap); the bare form keys on the element itself (2026-08-11)

Chain sources. A chain rewrites to a loop that fetches each element through the source’s get(Int) -> T fallible(IndexError), so answering that name is exactly what makes a form chainable:

source accessor
@form(vec) its synthesized get
@form(hashmap) via .entries entry_at, same shape
[T; N] get, over all N slots
bounded[T; N] get, over the live slots (not capacity)
std::str::split(s, sep), lines(s), words(s) a cursor: the source’s own scan (below)

A cursor source (GH #1995 S2). A text source has no index to get a part by: finding the ith part again on every turn would make the chain quadratic. It is the one source that is a cursor instead. The rewrite recognizes it by its call (std::str:: and the source’s name, of the source’s arity), and the chain’s loop is the scan § Text sources describes, moved part by part (hale_syntax::str_sources::scan, which the for loop’s rewrite uses too), with the part bound as the element before the stages run. An element-valued terminal (first, find, min, max) cannot re-fetch its pick through get, so it keeps the picked part’s offsets in the scan’s view, two Ints, and its value is that part read through a one-element array’s own get: index 0 when a part was picked, -1 when none was, the ordinary IndexError. The best part is never copied out again to be compared: min() and max() compare each later part with it where it lies in the view, byte by byte as < compares Strings, and min(key) and max(key) keep the best part’s key. A key’s type is known only from the first part picked, so the scan that finds it goes on inside its body, from the same cursor, with the key bound, and leaves when that inner scan ends. No other source is a cursor; a form keeps answering get. Unlike every other source, a text source’s chain allocates, one String per part (the part itself), so property 1 above holds for it only in the sense that no intermediate list of the parts exists.

The two type-level collections are a deliberate exception to the types-have-no-methods axiom, and the only one: their operations are otherwise grammar intrinsics (at(f, i), count(f)), and at remains the idiomatic spelling for a direct index. get exists so the chain source protocol is uniform, and is identical to at in signature and semantics — on bounded it is at.

The rewrite happens post-parse, before typecheck, so it cannot dispatch on the source’s type; a form that does not answer get fails with an ordinary no-method diagnostic at the chain’s site.

A chain over a bounded[T; N] or an array walks it by its type, however it is reached and whatever it is named: a local, a param, a record’s or a locus’s field, a path of fields (`o.inner.tags.filter(it

1).count()). Its element cursor is the collection's own at, so the effect and allocation analyses read it as that intrinsic (no effect, no allocation) and the chain holds under @no_syscalland@budget( alloc_per_call = 0)(GH #1984)..itemsand.entriesanchor a chain on a form's iteration surface, and the rewrite strips the anchor before any type is known; the receiver's type then decides what it was: a@formlocus, or one that declares the cursor itself, keeps the pseudo-field, and a receiver with a real field of the anchor's name (a record'sitems: bounded[T; N]`) walks that field.

Fallible terminals ride the source’s own get. first / find / min / max lower to an index search whose value is src.get(idx) — an empty result is the ordinary IndexError, so or raise / or fallback / or handler(err) all apply with no new error machinery:

let bob = users.find(it.id == want) or User { id: 0, age: 0, name: "?" };
let oldest = users.max(it.age) or raise;

For the same reason they do not compose with map (the or fallback would need the mapped type while get yields the source element): project after the find, on the returned element.

each takes a block, not a lambda. The block is spliced as the fused loop’s body with it bound — it executes in the enclosing scope, so there are no capture semantics to define, and break / continue act on the fused loop (continue advances to the next element):

users.filter(it.age >= 18).each {
total = total + it.age;
}

Recognition is conservative so user facade methods sharing these names never get hijacked: with at least one stage, every terminal is recognized (no ordinary method chain looks like that); stage-less, a terminal is recognized only when its argument mentions it — which is unbound outside a chain, so no valid ordinary call can look like that — or when it is each with a block. Bare xs.sum() / xs.first() therefore stay ordinary method calls (stage-less first is just xs.get(0) or …; a stage-less sum can be written xs.map(it).sum()). A text source is the exception: on std::str::split / lines / words, every terminal is recognized with no stage (§ Text sources). On a fixed array or a bounded[T; N], which has no member of a terminal’s name, the check’s “no field sum on [Decimal; 2]” says so: an element chain needs a stage before its terminal, ….map(it).sum(…) (friction sweep 2026-10-12). The whole-set terminals (sort_into / reverse_into / group_count_into) are recognized stage-less too: xs.sort_into(sorted) is their natural spelling, and the compound *_into names belong to this vocabulary — unlike bare into, no plausible user facade carries them (2026-08-11).

Every stage and terminal above is recognized only after a ., so a free fn map(...) / fn first(...) / fn count(...) is admissible and is called as written. The exceptions are the names the compiler claims at a BARE call site — sum, prod, min, max among them — which a free fn may not take; see tokens.md § Built-in identifiers for the full set, the rule and the diagnostic. A locus method may still carry any of them (2026-09-20, GH #863 / GH #880).

@vectorize on a fn (a free fn or a locus method) asserts that every innermost loop written in its body — each for and while that holds no loop, an element chain’s loop included — is vectorized by the build’s optimizer on the build’s target. @vectorize(min_width: N) asks too that each is vectorized at least N lanes wide (N from 2 to 1024). It changes nothing the program computes: it asks no transformation of the optimizer, permits no reordering of Float arithmetic, and overrides no cost model (spec/decisions.md F.63).

@vectorize
fn total(xs: bounded[Int; 1024]) -> Int {
let mut s = 0;
for x in xs {
s = s + x;
}
return s;
}

What the check refuses. hale check cannot run the optimizer, so it refuses what it can see that no target’s vectorizer takes, at the thing that stops the loop:

main.hl:6:17: type error: `@vectorize` on `f`: this loop cannot vectorize on any target: it holds a call to `noisy`, which has effects (syscall, stdio). Move it out of the loop, or drop `@vectorize` (spec/semantics.md § Vectorized loops)

A fallible step, a text value read in the loop and a call through a fn value are not refused: each may still vectorize (bounds-check elimination removes a get … or …’s failure branch, an unchanging text read is hoisted out of the loop, a fn value known where the fn is inlined is called directly), so the build answers for them.

What the build checks. What is left depends on the target, and is a build assertion: the build reads what LLVM’s loop vectorizer reported of each loop (its optimization remarks, traced back to the loop through its debug locations; a build that emits no DWARF gives the loops locations for the check alone and strips them before the object is written). A loop it did not vectorize fails the build at the loop, with the target, the reason in the program’s terms and LLVM’s own words:

main.hl:5:5: codegen error: `@vectorize` on `until`: this loop does not vectorize on x86_64-unknown-linux-gnu (x86-64-v3): its trip count is not known when the loop starts (an exit that depends on what the loop computes) (LLVM: could not determine number of loop iterations)

The same loop can pass on one target and fail on another. A Float sum or product keeps its written order (Hale does not reassociate floating-point arithmetic), so it vectorizes only where the target has an in-order vector reduction (aarch64) and not where it has none (x86-64). The cost model decides as well: a 64-bit integer multiply has no fast vector form on NEON. The assertion holds on the target the build is for — the host’s CPU by default, --target-cpu, or a cross target’s (generic) CPU — and a build for another target is judged on its own.

Where the loop is judged:

Check/build agreement. A program the check accepts that the build refuses only by this assertion is the target’s answer, not a gap between them: the check/build parity gate counts such a refusal apart (Verdict::TargetAssertion in crates/hale-codegen/tests/parity/gate.rs) and never lists it as a divergence.

A bus { subscribe SUBJECT as HANDLER of type T; } declaration wires:

  1. The runtime registers HANDLER as the receiver for SUBJECT on the bound transport.
  2. Inbound messages on SUBJECT are decoded as T, then HANDLER(payload) is invoked.
  3. HANDLER runs in the locus’s scheduler context. It may call publish(SUBJECT, msg) to emit responses (subject to bus { publish ... ; } declarations).
  4. HANDLER yields naturally on completion; scheduler returns to other loci.

If HANDLER panics:

A subject’s payload type — T in of type T, or a topic’s payload: — must be one of exactly three things:

A delivery is a serialized struct, so the payload needs a field layout: of type Int has none, and neither does a tuple, an array, or a no-payload enum. An of type clause naming one is rejected at typecheck, at the clause (rule 18 above). A topic whose payload: names one is rejected at typecheck where it is delivered: at each subscribe of the topic and each <- to it, naming the topic’s payload and the repair (wrap it in a user type). A topic that is declared, or listed publish, and never subscribed or sent carries nothing and is not judged.

main.hl:3:11: type error: subscribe `Chunk`: topic `Chunk` declares
`payload: String`, which the bus cannot carry. A delivery is a
serialized struct, so a topic's payload needs a field layout: a user
`type`, an enum with a payload variant, or `BytesView` (the raw-frame
path). To send one, wrap it in a user `type` and declare the topic's
`payload:` as that.

Within a payload, every value a type may hold is carried, at any depth (GH #1951 item 4). Serialize walks the value in declaration order and deserialize allocates each pointer-shaped value (a string, a record, a list’s or an array’s element, an enum’s cell, a tuple) in the lazy global payload arena. The encodings are the wire format’s carriage table, hale_types::wire_carriage::WIRE_TABLE; the check’s refusal and the serializer both read it, so the list a refusal prints is the list the serializer encodes. The format is internal (F.36): Hale talks to Hale with it, and a foreign peer goes through a codec(...) clause. Little-endian, nothing between values:

Value Wire bytes
Int, U64, Float, Bool, Duration, Time, a unit type over an Int or a U64 8 bytes
I32 / U32, I16 / U16, I8 / U8 (GH #2132), a unit type over one 4, 2, 1 bytes
Decimal 16 bytes
U256, I256 32 bytes
a payload-free enum its tag, a u32 (the variant’s declaration index)
String, Bytes an i64 length, then its bytes
a record its fields, in declaration order
bounded[T; N], T a scalar or a payload-free enum its inline storage: the i64 count and all N slots
bounded[T; N], T a String, Bytes, record or enum with payloads an i64 count, then that many elements, each as a value of T
[T; N] its N elements (an array of scalars as one block, as before)
an enum with payloads its u32 tag, then the variant’s values in order
a tuple as a record of its elements
std::json::Value its text, as a String

What no frame can hold stays refused, naming the part and the carried set: a fn value, a locus handle, a view (BytesView, StringView, BytesMut as a field), a projection, an array of no fixed length, and a type that reaches itself (type Node { kids: bounded[Node; 4]; }), whose frame has no bound. A topic whose payload holds one is rejected at typecheck where it is delivered, as above (“topic `Ev` declares `payload: Msg`, whose field `f` is a fn value (`fn(Int) -> Int`), which the wire format does not carry: a delivery serializes each value, and carries scalars (…), …, and records of these”). Until 2026-11-16 the check refused an enum with payloads, a tuple, a bounded of strings, bytes or records and an array of strings as a field, and the build refused a top-level enum with a String value with no place (and copied any other pointer value of one as the pointer).

A frame is decoded only as far as it reaches (2026-11-07, downstream handoff): one shorter than its type’s minimum encoded size (its fixed fields, length prefixes, list counts and enum tags; the empty datagram included) is refused before any field is read, and every read after that — a fixed field, a length prefix, the bytes a String or Bytes length announces, a list’s count, an enum’s tag, a nested struct’s or an element’s fields — is held to what remains of the frame after it, never to the frame’s whole length. A list count below zero or past the list’s N, and an enum tag past its last variant, are refused too. A refused frame is dropped by the reader that received it and counted (dropped_decode in the counters dump), and nothing of the reader’s previous frame is delivered as part of it. It used to be that an empty datagram was delivered as a zero-filled record, one after a valid frame replayed that frame, and a one-byte one delivered the previous frame with its first byte replaced. The rule is the transport readers’ (the udp:// and unix:// readers, the early-ingress flush, the replay injector): a local cell is not a wire frame. In-process delivery — a publish materialized on the owner’s thread, a cross-pool create cell — holds the program’s own serializer’s bytes and is decoded straight through, unchecked, so a create cell’s dispatch stays one straight-line block (accept, the children’s push, then birth, in the text’s order). For that reason a cross-pool spawn’s params keep to the shapes the walk takes without a loop or a switch: a counted list, an enum’s cell and a tuple are refused there (lowering_laws::cross_pool_child_shape).

The flat paths are unchanged: a zero_copy binding and a layout: ring copy the payload’s bytes raw, so every new shape (a counted list, an enum’s cell, a tuple, an array of strings) is not flat-shapeable and is refused at the binding, as a String field is; a keyed_by key is one of the key table’s types. A literal subject’s of type struct (subscribe "m" as on_m of type M) is held to the same rule, once per payload type, at the first clause that names it; it reached the build until GH #1942. So is a binding’s transport: a native shm_ring holds fixed-size struct slots, so a topic whose payload is an enum is refused at its entry, and a layout: ring hands its subscriber one record at a time, so a Drain<T> batch handler on one is refused at the subscribe.

Size. A delivery is as large as its fields make it, and local delivery is bounded only by the payload arena (spec/memory.md): the synthesized serializer honours the cap it is handed — it writes nothing past it and answers the size the payload needs — and the runtime serializes a payload past its 64 KiB wire buffer again into a buffer of that size (GH #1155). A remote transport’s frame is 64 KiB (LOTUS_PAYLOAD_MAX): a payload past it reaches every local subscriber and is dropped, uncorrected, for every remote one — there is no fallible-publish path or counter a program can observe this through yet; the runtime says so on stderr once per subject, for an operator reading logs, not for the program. A publisher that must reach a remote peer keeps every payload on that subject under 64 KiB on the wire until this gets a program-visible signal. Before this fix the serializer overran the buffer, and a reply carrying a String past 64 KiB died in it.

For each closure NAME { LEFT ~~ RIGHT within TOL; epoch ... }:

  1. At each declared epoch boundary, runtime evaluates LEFT and RIGHT in the locus’s scope.
  2. Computes |LEFT - RIGHT|.
  3. If <= TOL: closure passes silently.
  4. If > TOL: flips the locus’s “exploded” flag; emits a typed ClosureViolation event.

The band is computed in one type: LEFT, RIGHT and TOL are all Int (a Duration, a Decimal) or all Float. An Int beside a Float — most often a literal beside mean(self.x), which is a Float, or a Float beside count(), which is an Int — is refused by hale check at the Int (“closure `band`: the band is a `Float` (the other side is one), and its tolerance is an `Int`; … write it as a `Float`”).

The accumulators sum(…), count() and mean(…) are a closure assertion’s, sampled once per epoch, and each accumulates one field of the locus (sum(self.x), mean(self.x)). Outside a closure assertion they name nothing the build can call, an accumulator over a wider expression (sum(self.a + self.b)) has no slot to sample, and prod(…), which the grammar reserves, has no lowering: hale check refuses each at the accumulator (“`sum(…)` is a closure assertion’s accumulator …, and is compiled only there”; “hale can’t compile the `prod(…)` accumulator yet”), where the build refused it after a passing check (GH #1942). A running product, or a sum of two fields, is kept in a field the locus updates, and asserted on.

Epoch boundaries:

Per-epoch field reset (F.34, v1.x-WINDOWED)

Section titled “Per-epoch field reset (F.34, v1.x-WINDOWED)”

A closure paired with epoch duration(N) may declare resets_per_epoch(field1, field2, ...);. The named locus fields are zeroed by the runtime after the assertion fires at each duration boundary. Ordering matters: the assertion sees the window’s accumulated value; the reset prepares the next window.

closure low_corrupt_rate {
self.corrupt_per_min ~~ 0 within 10;
epoch duration(1min);
resets_per_epoch(corrupt_per_min);
}

Restrictions enforced at typecheck:

User code increments / decrements the field as the window accumulates. The closure assertion is the structural contract (rate bounded by a per-window budget); resets_per_epoch keeps the substrate honest about which window the counter belongs to without forcing the user to maintain a last_reset_at field or a parallel pre-fire hook.

Recovery events (persists_through, resets_on)

Section titled “Recovery events (persists_through, resets_on)”

A closure’s accumulators (sum, count, mean) are zeroed when its locus goes through a recovery event, unless the closure persists through that event:

closure within_band {
sum(self.delta) ~~ 0 within 100;
epoch tick;
persists_through(quarantine);
}

The recovery events are a closed alphabet, the recovery statements a parent applies to a failed child: restart, restart_in_place and quarantine (a spent restart(c) for N bound quarantines, and is the quarantine event). The check holds each name a clause writes to it:

resets_on(...) states the default. An accumulator resets on every recovery event its closure does not persist through, whether or not resets_on names it, so resets_on(E) adds nothing at run time; it is a statement the check holds to the alphabet like any other, and an event a closure names in both clauses is an error at the resets_on name, with the persists_through name as its witness (Contradicting recovery clauses).

Two warnings say when a clause cannot take effect:

(F.27, v1.x-VIOLATE.) Inline closures provide a pull-only structural-failure channel for locus method bodies that catch a value error and want to escalate it. The declaration carries no assertion; the optional captures: clause names locus fields whose values are snapshotted into the ClosureViolation payload at fire time.

closure fatal_io { captures: last_error; epoch inline; }

violate NAME; (optionally violate NAME with EXPR;) fires the closure synchronously at the call site:

  1. Runtime synthesizes a ClosureViolation value carrying:
    • locus, closure — string names of the failing locus and the inline closure (always present).
    • The captured fields named in the closure’s captures: clause are NOT materialized on the ClosureViolation struct, which has a fixed shape. The access pattern for captured state is to read the frozen child through the child handle in on_failure(c, err) — see “Reading the audit state” below.
    • If with EXPR was given, EXPR is evaluated for side effects (and to detect typecheck errors on the payload type) but no payload field is materialized on the ClosureViolation.
    • The assertion-shape fields (left, right, tolerance) are not fields of the struct, and diff is 0 for an inline violation.
  2. The locus’s exploded flag is set (same as the auto-epoch path; downstream observers can’t tell from the flag whether the fire was auto-epoch or inline).
  3. The synthetic __drain_requested field on the locus is set. Readable from user code as self.draining.
  4. The parent’s on_failure(child, ClosureViolation { ... }) handler runs — same routing as for auto-epoch closure violations.
  5. The method exits. In a fallible(ClosureViolation) fn the violation is the call’s failure: the caller’s or disposition runs, with err bound to the ClosureViolation, and no value is produced. In a fn returning nothing the method exits as a return does and the caller continues. The owner’s on_failure (step 4) runs first, posted to the owner’s domain and awaited when the pools differ (decision L0-1); then the caller’s or disposition runs. Either way, loci the method let-bound dissolve and its per-call scratch is freed (GH #1036; violate used to skip both).

A value-returning method that may violate is fallible

Section titled “A value-returning method that may violate is fallible”

(F.42.) A value-returning fn or locus method whose body may violate is declared fallible(ClosureViolation), so that its callers say what happens when the locus fails instead of reading a value nothing computed:

locus Picker {
params { picked: Int = 0; }
closure exhausted { epoch inline; }
fn take() -> Int fallible(ClosureViolation) {
if self.picked >= 3 { violate exhausted; }
self.picked = self.picked + 1;
return self.picked;
}
}
// in the owner, which handles Picker's failures:
let n = self.p.take() or 7; // 7 once `take` has violated

A fn may violate when its own body holds a violate statement, or when it calls a value-returning fn that may violate and is not fallible (a fallible callee is answered at its call by the bare-call law, below, and once this law holds no other kind is left). A violation in a method that returns nothing is not the caller’s failure: calling one does not make the caller one that may violate. Lifecycle bodies, bus handlers (the fns a subscribe … as names) and fn main are exempt: the runtime is their caller.

The call to a fallible(ClosureViolation) method follows the bare-call law unchanged: an or disposition is required, and the err that or handler(err), or { … } and or fail see is the ClosureViolation the owner’s on_failure received. or raise in a fn that is not fallible ends the process (§ “Process exit”), which is what a caller says when the activation should not continue past the locus’s failure. The stdlib’s two such methods are BytesBuilder.snapshot and finish (a failed allocation violates alloc_failed, F.27).

The portable access pattern in on_failure(c, err) is to read the child’s frozen locus state through the child handle:

on_failure(c: Child, err: ClosureViolation) {
log::error(err.closure, " ", c.last_error, " fd=", c.conn_fd);
}

violate is divergent — the method body’s remaining statements do not execute, so the child’s locus state is frozen at the violate moment. c.last_error reads exactly the value the violate site observed.

The ClosureViolation value carries err.locus and err.closure (Strings) and err.diff (an Int: left - right for an Int or Duration assertion, 0 otherwise); it does not materialize the captured fields. Source that reads err.last_error is a type error at the read (“no field last_error on ClosureViolation”): read captured state through the child handle (c.last_error) instead. (Until F.40 phase 4, S8 the checker left ClosureViolation unresolved, so such a read passed hale check and failed at build without a location.)

The violate statement is divergent: the typechecker treats it as Never, the same as fail in fallible fn bodies and bubble in on_failure. No statement after violate in the same block is reachable; the typechecker does not require a trailing return on a violate branch.

(F.27 v2, 2026-05-20.) A declarative form for construction-time invariants:

locus L {
params { x: Int = 0; }
closure invariant_broken { captures: x; epoch inline; }
birth() { /* set up state */ }
birth_check { self.x < 0 } -> violate invariant_broken;
}

After birth() body completes and birth-epoch closures have fired — at the first birth and at every restart’s re-birth (§ “restart(child)”) — each declared birth_check clause’s cond expression is evaluated. A true result fires the named closure with the locus’s fully-constructed state — every field reads its declared post-birth value, so the on_failure handler’s capture-snapshot sees coherent state. Multiple clauses evaluate in declaration order; the first to fire short-circuits the rest.

Why a separate clause vs. calling violate NAME; inside the birth body: a violate mid-birth leaves the locus partially constructed (some fields set, others at defaults) when the on_failure handler reads captures. birth_check runs the body to completion before the check fires, so the post-birth invariant of “every field has its declared value” holds at violation time. The runtime-routing semantics are otherwise identical to a regular violate (drain_requested set, parent on_failure absorbs or process exits non-zero with diagnostic). The codegen emits the check + violate routing INLINE at the instantiation site, branching to a continuation block on absorbed violations rather than returning from the caller’s fn — the absorbed-then- continue contract matches what users expect when wrapping the instantiation in a parent that handles the failure.

The check expression is read-only against self.X fields; the closure name must resolve to a declared epoch-inline closure on the same locus, same constraint as a regular violate.

While the locus is draining — after violate on it, or once the process drains on SIGINT / SIGTERM (§ “Drain cascade (whole-process)”) — the synthetic self.draining field reads true from any locus method body. Reading it is optional: the runtime stops a run() that never reads it on a signal by itself (GH #1858). A run() that reads it takes the drain into its own hands (no back-edge stops; § “Drain cascade (whole-process)”), the canonical shape a loop that ends on it (while !self.draining { … }) and then flushes. Elsewhere it suppresses downstream sends once the locus has escalated:

fn on_tick(t: Tick) {
if self.draining { return; } // this locus violated earlier
Sampled <- self.count;
}

An error-check method that substitutes a value or escalates is fallible(ClosureViolation) (§ “A value-returning method that may violate is fallible”), and its caller says what an escalation means at the call: let r = expr or (self.handle_io(err) or { return; });.

self.draining is one of the three synthetic members exposed by name to user code (with self.children and self.k_max); its backing field __drain_requested is internal-only. All three names are reserved — a locus may not declare a member that shadows one; see types.md § Reserved member names.

violate is rejected at typecheck in:

Allowed everywhere else that has self: named locus method bodies, bus-handler methods (subscribe X as foo → fn foo), run(), lifecycle methods (birth(), dissolve(), drain()). The same body shape gets the same primitive.

Restarts the child on the same instance — its arena, its subscriptions and its param values as they stand (a restart never re-evaluates a default):

  1. The failure’s drain request is lowered: the child is live again.
  2. birth() runs again, then the birth-epoch closures, then the birth_check clauses — every birth is checked, the first and each restart’s alike.
  3. run() runs again.

When it takes effect depends on where the failure came from. A birth-epoch closure’s failure re-runs birth right after the handler returns, before run() has started. So does any other failure of the birth — a violate in birth(), a failed birth_check — whether its handler ran in place or was held: the decision is read against the restart count as the birth began, so a handler that had already returned by the time birth() did is not missed, and a restart whose birth fails again — a violate in its birth(), a birth-epoch closure, a birth_check it no longer passes — is decided the same way before run() starts: restarted again within the bound, quarantined at it. (A restart used to skip the birth_check clauses, so a re-birth that broke its invariant ran on.) The restart runs on the child’s own placement — its pinned thread, its pool’s worker — as its first birth() and run() did. A failure raised while run() executes — a violate in it, or for a pinned child the tick and duration closures its thread checks after it — restarts once run() has returned, on the thread that ran it (a pinned child’s own thread). A failure held while the parent was still setting params takes effect when its handler returns (§ “on_failure(c, err)”).

A restart is not taken while the process is draining: the drain ends the child anyway.

The retry bound. restart(c) for N gives this child at most N restarts. The count is per child instance and cumulative over its lifetime, and it is compared before the restart, so for N admits exactly N restarts and the failure that follows the last one quarantines the child instead — the supervisor tried N times and is done with it. for 0 is meaningful and quarantines on the first failure without restarting.

Exhaustion quarantines rather than falling through: a bounded supervisor has stated when to stop, and stopping means the child does not run — on every placement (a pinned child’s thread used to start its run() once anyway). This is the difference from an unbounded restart(c), which stops re-running at the default cap of 2 but leaves the child live.

N is an expression, evaluated at the recovery site. Without the modifier the bound is the default 2, so an unbounded restart(c) is unchanged.

The bound is recorded in the topology artifact as retry_bound on the supervision row (schema 1.10), so the declared policy and the observed restarts are comparable.

The same as restart(child), except that before birth() runs again every param is put back to the value this instance was built with: the value its literal gave it, or its default as that default evaluated when the instance was built. Params are settled once, from the literal; a restart never re-evaluates a default. So Worker { tag: "a" } restarts with tag "a", whatever its declared default says, and a default that builds a locus or reads the clock is not run again. A param that holds a locus (or an interface handle) keeps its child: a restart re-runs this instance, not its children’s construction. The retry bound and the default cap are shared with restart.

Useful for transient failures that don’t invalidate the locus’s structural commitments (e.g., the locus’s k_max is fine; just had a bad message).

  1. Pause child (no new messages dispatched, no new accepts permitted, no run scheduling).
  2. Preserve arena and state.
  3. If for d clause given, automatically restart after d.
  4. Otherwise wait until parent explicitly resolves.

Not lowered: the for d duration clause. quarantine(c) itself ships; quarantine(c) for d is refused by the check, at the statement. Note that this for is a duration before an automatic restart — a different modifier from restart(c) for N, which is a retry count.

main.hl:6:50: type error: `quarantine(c) for d` (an automatic restart
after a duration) is specified but not implemented: `quarantine(c)`
itself ships, the `for d` clause does not. Note that this `for` is a
duration before an automatic restart, a different modifier from
`restart(c) for N`, which is a retry count.

Also not lowered: the until modifier on any recovery op, refused by the check at the statement (`until` (restart while a condition holds) is specified but not implemented), and a for on bubble, which restarts nothing. Each of these passed the check and stopped the build in codegen with no location before.

Reserved syntax. Semantics TBD; expected: relocate child’s sub-children to a sibling. Not in v0: the check refuses the statement (`reorganize(...)` is reserved syntax with no semantics yet).

Re-raise the error to self’s parent. Equivalent to:

on_failure(c, err) { bubble(err); } // for self's failures

Fully traverses the lotus tower upward until a handler absorbs.

Force-dissolve child immediately. Skips drain; closure tests at non-dissolve epochs do not fire on this path. Used for forced-shutdown scenarios.

The drain is the runtime’s (GH #1858). A SIGINT or SIGTERM stops every program the same way: the runtime ends every run() loop between two iterations and wakes every blocking wait, so run() returns, teardown runs the drain() / dissolve() hooks and the process exits 0. An author writes nothing for it. A locus that wants to decide for itself when to stop — flush a batch, finish a handshake — reads self.draining in its run(), and then its loops are its own:

The locus’s run()… The compiler On SIGTERM
never reads draining a drain stop at each loop’s back-edge its loops end between iterations, hooks run, exit 0
reads it, and the check proves its loops stop on it nothing to report the author’s loop ends, hooks run, exit 0
reads it, and the check cannot prove it a warning at each such loop the author’s code, bounded by the grace

Manual control is the run()‘s. A locus takes the drain into its own hands when its run() reads its locus’s draining, itself or through a fn or method of the program it calls, transitively, through any receiver that is the locus by declared type — self, a let alias of it (in its block), a parameter a method or free fn binds to it (a call on another locus that hands it this locus is followed), or a declared field path whose type is the locus (a call on a locus whose params declare a field of this locus’s type, or of a holder of one, transitively, a collection or projection of it included, a type alias of it resolved to it, is followed, and its self.<field> is this locus: by declared types, not by construction) — or that the declarations cannot resolve (a type name they do not know is never taken as no locus), which is taken as a read. A read in a handler, a drain() / dissolve() hook, or a method run() does not call, or of another locus’s draining (a holder’s own self.draining included), does not make the run() manual (the flow rows’ watches-drain column, registry.md § flows). The check’s “Manual drain not honoured” rule (verification.md § Structural & design rules) says, conservatively, whether each loop of a manual run() stops on the flag; what it cannot prove it reports, never refuses: the author chose manual control, and the grace is the backstop.

Back-edge stops. In the run() of a program’s own locus that is not manual, and in fn main’s own body (the program’s run), the compiler places a drain check at the back-edge of every loop the body holds lexically — while and every for, nested ones included; not a loop in a fn or method it calls, nor one in a closure. The check is one load of the runtime’s flag and one branch, weighted cold, on every iteration, @hot and @budget code included — except on a counted loop (for i in a..b, while i < n { …; i = i + 1; }) whose body calls nothing and holds no loop, which takes it once every 4096 iterations so the loop can be vectorized (spec/runtime.md § “Back-edge stops”, GH #2089): such a loop ends at the end of a chunk, still between two iterations. When a stop has begun the loop exits there, as a break written at the end of the iteration would: between two iterations, never inside one, with the iteration’s state as the iteration left it. A continue goes through the same check. Code after the loop runs (the loop is left, not the run()), so a nested loop’s stop ends the inner loop and the outer one’s iteration finishes, then the outer loop ends at its own back-edge. The standard library’s loci keep their own loops (their bodies read draining where they need to). A stop is a signal’s drain or a failed test’s unwind (std::test); a main locus’s tree drain (below) is not one and ends no loop by itself.

SIGINT or SIGTERM:

  1. The runtime raises the process drain, a stop. From then on every locus’s self.draining reads true, on every thread, and every back-edge check above ends its loop.
  2. Waits return early, so a loop reaches its back-edge or its check:
    • A wait already in progress returns: a std::time::sleep at its next 100 ms slice (at once on an async_io pool) and a deadline-bounded park on an async_io pool with its timeout, wherever they are; and an untimed blocking wait (an accept, a receive on a socket with no set_recv_timeout of its own) made in a run() (what it calls included) or in fn main with its existing closed or empty outcome — no new variant, so the or its caller already writes covers it (stdlib.md § “What a drain does to a wait”): an accept its closed -1, a TCP or TLS recv the empty answer a peer’s close gives (recv_into 0), a UDP recv its timeout’s, on main, a classic pool, an async_io pool and a pinned thread alike. An untimed wait a handler, a hook or a standard-library coroutine makes (a server’s connection, which answers the calls in flight before it closes) is not ended by the stop; the listeners’ stop (step 3) and the grace bound it.
    • A wait that begins during the drain returns at once, in the same way: in a manual run() that has not yet read draining as true (what it calls included; a standard-library locus’s bodies run in their caller’s frame); and in a run() the runtime stops, or fn main, a sleep written in that body itself, and an untimed wait anywhere it calls. So a loop that was mid-iteration when the signal landed reaches its back-edge (or, manual, its while !self.draining check) instead of starting a 30 s sleep into the grace. A sleep in a fn or method a stopped run() calls runs its length: a loop there has no back-edge stop, and cutting its sleeps would only spin it. A handler is not part of the run() (one delivered inside the run()’s wait neither takes its cut nor ends it by reading draining). On an async_io pool such a park is resumed before the pool’s shutdown abandons what is still parked, so the run() returns and is joined. Every other wait begun during the drain runs its full length: a drain() or dissolve() body pacing a flush, a manual run() pacing a final flush after its loop has seen the drain, a handler. A drain raised again later (a second tree’s, then a signal’s) cuts a manual run() that saw the first one until it reads draining again.
    • What no stop can wake is a documented limit, bounded by the grace: a blocking foreign (@ffi) call, a subprocess the program waits for (std::process::run, wait), a connect or an HTTP call until its own deadline. (2026-11-06: a sleep begun during the drain ran its full length wherever it was made, and before GH #1858 an untimed wait was not interrupted at all.)
  3. The process’s listeners stop: every named listener’s socket is shut down (as std::io::tcp::stop(name) does), so each accept loop — a std::http::Server’s, a std::io::tcp::Listener’s, the api runtime’s — ends wherever it waits, on main, a pinned thread or a pool, and its run() returns once the connections it accepted are answered (stdlib.md § “Shutdown is a drain, never a cut”). A server used to keep accepting, and held the drain for the whole grace. (2026-10-19, downstream handoff.)
  4. Each run() returns: one the runtime stops at its next back-edge, a manual one when its own code says so.
  5. Leaves dissolve first, each parent after its children, the root last — the ordinary end-of-program teardown, which runs every drain() and dissolve() hook and the runtime’s own (schedulers, bus router, allocator, the atexit hooks).
  6. Process exits 0.

Exit codes. A program stopped by a signal exits 0 once its hooks have run, whatever it reads. Before GH #1858 a program that read draining nowhere and declared no hook died by the signal at once (128 + signal, 143 for SIGTERM) with its hooks unrun, and one that did (GH #1077, #1838) could hold the whole grace on a loop that never looked and then die by the signal all the same. A supervisor or a test that expected 143 from a stopped program now sees 0; 143 now means the grace ran out (a manual loop that did not stop, a wait no stop can wake) or a second signal.

The drain has a grace period: if the process has not exited 5 s after the signal (LOTUS_DRAIN_GRACE_MS sets it), the runtime writes one record (runtime.md § Runtime diagnostics are records: logger=lotus.drain, with signal, grace_ms and waiting_on) naming the signal — and what the drain was still waiting on: each cooperative pool with its mode, whether a worker is mid-iteration and in which locus, and how many cells queue behind it — restores the signal’s default action and re-raises it: the process dies BY the signal, as it would with no runtime at all (a waiting parent sees it killed by that signal; a shell reports 128 + signal). A second SIGINT / SIGTERM ends the process the same way at once.

The handling is installed in every program a signal can reach (not on wasm). The signal is caught, never blocked, so a subprocess the program spawns inherits the default disposition. (GH #1039: before 2026-09-24 the runtime caught neither signal, so every program ended at the signal and a while !self.draining loop never saw a drain. GH #1077 and #1838 then installed it only in a program that read draining or declared a drain() / dissolve() hook, and drained only while a live instance of such a locus was counted; GH #1858 retired the count, along with the check’s “drain hook behind an endless run” warning: no hook is behind an endless run unless its locus chose manual control.)

When main’s run() ends first. Teardown follows the ownership tree: when a main locus’s run() returns, the first step of its teardown raises the drain for its tree, steps 1–2 above without a signal and without a stop (runtime.md § “Lifecycle obligations”, line 15): self.draining reads true and a timed wait in progress returns, but no back-edge check ends a loop and no untimed wait is woken. A child whose run() still loops on while !self.draining — pinned, on a classic cooperative pool or on an async_io one — sees it, a timed wait it is in returns early, its run() returns and it is joined; the tree then dissolves, leaves first. So a main whose run() returns at once — or that declares none — ends its program once its children’s loops see the drain: a server stays up because main’s run() waits (while !self.draining { std::time::sleep(…); }, or self.web.wait() on an exposure param), and SIGINT / SIGTERM end that wait. A main that declares no run() and holds an exposure’s listener is given the run that waits on its exposures (spec/api.md § Serving). A child’s run() that never reads self.draining keeps the process alive until it returns (a signal’s stop ends its loops; the tree’s drain does not). main’s run() returning does not cut a live listener: the tree’s drain does not take step 3 above, so a server the tree runs on main or on a pinned thread — its own param, or one a pinned child’s run() builds — keeps accepting, and its join keeps the process alive, until a signal’s drain stops it. A main that only builds its tree (no run(), its children doing the work) serves for as long as they do. (2026-10-19: GH #1659 had the tree’s drain stop every listener, which cut such a program’s servers, one bound before the drain and one bound after alike; downstream handoff.) With no run() (an empty one is the same program), the tree’s drain begins once the run() of each pinned child whose run() does not read draining has returned, on the eager and the deferred spine alike: a sleep such a run() is in is not cut short, a sibling that watches the drain keeps serving until then, and what such a run() publishes in its last moments reaches a pinned sibling that still consumes, in any declaration order; a child whose run() reads draining (itself or through a fn or method it calls) is what the drain ends, so it is not waited for. A read in the child’s handler or drain() hook does not count: such a child was not waited for, and a pinned publisher whose hook read the flag lost its deliveries again (GH #1858, the review of the fix below). (2026-11-06, downstream handoff: the teardown joined the pinned children in declaration order right after the tree was built, so the pinned subscriber declared first was shut down while the pinned publisher declared after it was still running, and every delivery of the program was lost, silently.) An async_io child parked on an untimed wait (a plain recv, an accept) is abandoned at its pool’s shutdown (runtime.md § the wakeable park), as before. The tree’s drain ends with its teardown: a main locus built afterwards starts undrained, and a signal’s drain is neither masked nor ended by it. (Before 2026-10-12 a pinned or classic child’s loop kept the process alive after main’s run() returned, until a signal ended it.)

Under hale run. hale run stands aside for the program’s drain: it ignores SIGINT (a terminal’s Ctrl-C reaches the program through the process group) and forwards a SIGTERM sent to its own pid, then reports how the program ended (projects.md § “What hale run starts, hale run ends”).

A closure violation at any epoch:

  1. Runtime emits ClosureViolation event.
  2. Locus’s exploded flag is set.
  3. Subsequent epochs may also fail; flag persists.
  4. At the failing epoch, parent’s on_failure(self, ClosureViolation { ... }) invoked; held while the parent’s params are open (runtime.md § “Lifecycle obligations”, line 9).
  5. Parent’s policy decides: absorb, recover, bubble.
  6. If bubbled, propagates to grandparent; recursively until absorbed or reaching root (process exit).

epoch inline closures (F.27) take the same cascade path with one addition: at step 2 they also set __drain_requested, so the locus enters drain at the next cooperative yield rather than continuing on its current epoch. The drain initiation is the only divergence from the auto-epoch cascade; routing to parent’s on_failure at step 4 is identical.

Per runtime.md: multi-scheduler cooperative.

  1. N schedulers, one per CPU core (configurable).
  2. Each scheduler holds a queue of runnable loci.
  3. Scheduler picks a locus, runs it until cooperative yield.
  4. At yield, scheduler picks next.
  5. Cross-scheduler communication via bus (typed messages).
  6. Loci may be migrated between schedulers transparently for load balancing.

Failures flow upward:

  1. Child failure → child’s parent’s on_failure.
  2. Parent’s handler decides absorb / restart / bubble / quarantine / dissolve.
  3. If bubble, → grandparent’s on_failure.
  4. If reaches runtime root, process exits with structured error report.

Failures never flow laterally (sibling-to-sibling) — the framework’s vertical-only-flow expressed at the runtime layer.

Fallible call semantics (v1.x-FORM-1; PR6 reframe)

Section titled “Fallible call semantics (v1.x-FORM-1; PR6 reframe)”

Hale carries two orthogonal failure channels:

The two channels meet at exactly one place: the implicit main locus’s root boundary (see “Process exit” below). Everywhere else, the channels are independent. See spec/design-rationale.md.

Where each channel lives (declaration sites)

Section titled “Where each channel lives (declaration sites)”

The two channels are realized through different declaration sites. The mapping is canonical, not advisory:

The rule is two-channel separation at substrate-facing surfaces, not “no fallible on any locus method.” The load-bearing constraint is who’s the caller — when the substrate orchestrates a method (lifecycle, closure assertion, bus handler) there’s no caller frame to address the error channel, so fallible(E) would describe a contract that cannot be satisfied. User-declared fn members called from inside a method body or from another locus’s method body have an addressable caller; they carry fallible(E) like free fns do, with the same or disposition surface.

Example shape post-narrowing:

type ParseError { msg: String; }
locus Reader {
// Allowed: user-declared `fn` member with fallible(E).
// The body can `fail ParseError { msg: ... }` or call
// other fallible functions and propagate via `or raise`.
fn parse_message(b: Bytes) -> Message fallible(ParseError) {
// ...
if bad { fail ParseError { msg: "bad header" }; }
return Message { ... };
}
// Allowed: lifecycle method calling a fallible member fn
// and addressing the error inline.
run() {
let m = self.parse_message(b) or default_message();
// ...
}
}

The earlier v0 rule (blanket “no fallible on locus methods”) was narrowed because the friction signal across multiple apps and libraries showed devs extracting free fns just to get a value-error channel back — losing self ergonomics and splitting closely-related code across two top-level decls. See notes/open-questions.md § #24 for the narrowing’s full reasoning and the rejected alternatives.

fail <expr>; inside a fallible fn body:

  1. Evaluates <expr> to a value v (typed as the fn’s declared payload type E, or as a member of E when E is a set type: the member’s value is the set’s, spec/types.md § Set types).
  2. Exits the enclosing fallible fn body via the error path.
  3. The caller’s Expr::Call sees the result as FallibleErr(v) — a tagged value the immediate caller’s or clause is required to address.

fail outside a fallible body is a typecheck error; statement-position recognition is also parser-gated to a fallible-body scope (so let fail = 0; outside such a body stays admissible).

A bare fallible call is an error (GH #738)

Section titled “A bare fallible call is an error (GH #738)”

One rule holds for every fallible call, whether the callee is a fn or method the program declares, an interface method, a container’s or an array’s get, or a stdlib entry point: only an or handles it. The call must be the operand of an or disposition (or raise, or <fallback>, or handler(err), or fail <payload>, or discard). In any other position the call is bare: an argument (g(f())), an operand (f() > 1), a match scrutinee (match f() { .. }), a let initializer (let v = f();), a statement (f();), a returned value (return f();, in a fallible fn too). A match does not handle a fallible call.

A bare call is a type error naming the callee, the payload it can fail with, and the shapes that address it (or raise, or <fallback>, or discard, or handler(err)). That includes the legacy Int-status form of the stdlib write fns, let r: Int = std::io::fs::write_file(..). It is reported by hale check, hale verify, hale build, run, test and the language server alike, one error per call. There is no flag or mode that accepts it. The rule for stdlib calls was staged (a warning, then --strict-fallible, then this) and the flag is removed. For any other callee the bare call was always refused, by the build if not by the check.

A narrowing into a range (Session(n), spec/units.md § Conversions) is fallible the same way, with a RangeError, and is bare in the same positions; its error lists the narrowing’s own discharges (or <fallback>, or clamp, or wrap, or handler(err), or raise).

A handled call and a deliberately discarded one (or discard, which needs a () success type) are not reported. The stdlib entry points concerned are the signature table’s rows with a payload (stdlib_surface.rs): 94 at the time of the ruling, across std::io::fs, std::process, std::http::client, std::io::tcp, std::compress, std::tar, std::bytes, std::str and std::time. Lowering carries no bare form of any of them: it reads the same rows, and the last bare forms (std::bytes::at, which answered -1, and std::io::fs’s read_file, read_bytes, write_file, write_file_append, mkdir, file_size, list_dir_count and list_dir_at, which answered a direct value or an Int status) are gone (F.40 phase 4, S5). A bare call that reaches lowering, in a build that skipped the check, is an internal error naming the row.

Limitations to lift. These are where lowering’s support stops today, not part of the rule:

<expr> or <disp> evaluates <expr>. If the result is a non-error value, that value is the expression’s value (disposition is a no-op). If the result is FallibleErr(p):

<expr> is the fallible call itself (a fn’s, a generic fn’s, a method’s, a stdlib path’s) or a narrowing conversion. Anything else in that place — a field read of a record whose field holds a fallible call (Box { v: f() }.v or 0), an element, a name — has no failure of its own, and the or is a type error at it (GH #1966): the or goes on the call where it is written.

Chains are right-associative: a() or b() or raise reduces the value to the success type level by level.

An or raise (and the implicit or raise of a fallible handler, spec/types.md § “Disposition operators (or)”) whose call fails with P inside a fallible(E) fn, P not E, converts the error into an E in one of two ways, tried in this order (GH #1951, F.50):

  1. A set member (R2). E is a set type holding P (spec/types.md § Set types): the error becomes the set’s member, exactly as fail p; and or fail err make it. One relation decides all four: fail, or fail <expr>, or raise and a fallible handler’s failure.

  2. A conversion (R3). One @raise fn from P to E is declared: the raise is or fail conv(err), so the caller’s handler sees the converted error and every field the conversion copied.

    type StoreError { key: String; }
    type ApiError { status: Int; detail: String; }
    @raise fn api_from_store(e: StoreError) -> ApiError {
    return ApiError { status: 404, detail: "no key " + e.key };
    }
    fn lookup(key: String) -> Int fallible(StoreError) {
    if key == "missing" { fail StoreError { key: key }; }
    return len(key);
    }
    fn get(key: String) -> Int fallible(ApiError) {
    return lookup(key) or raise;
    }

A @raise fn is a free fn of one parameter, not generic and not fallible, whose result type is not its parameter’s; each other shape is refused at the fn. It runs on the error path of the raise, so @raise implies the effect assertion @effects(none: {syscall, publish, spawn, block}), held as every assertion is (spec/verification.md): it may allocate the error it returns and do nothing else with an effect. The conversion’s call is not written, and every analysis of the fn that raises reads it as the call it is, the or fail conv(err) the raise stands for (GH #1982): its allocations count against the raising fn’s @budget(alloc_per_call = N), an effect class it reaches beyond the four (time, a program’s own effect class) is one the raising fn reaches, with the conversion on the witness path (get -> api_from_store), and @no_panic judges the raise as the or raise it is written, a trap.

Conversions are coherent:

A set member is tried first: where E is a set holding P, a conversion from P to E is never called. Where neither applies, the or raise is refused as above, and the error is translated where it is raised, or fail E { … }.

The runtime ends a program against its will via one of two boundary events at the implicit main locus’s root:

  1. Closure-violation escape (F.9). If a closure violation bubbles past every on_failure handler back to the runtime root, the process exits with the violation’s payload as the structured error report.
  2. Value-error escape (PR6). If an or raise reaches the implicit main locus’s body with no enclosing fallible(E) frame to absorb it, the value error escapes the locus’s body. The runtime panics via lotus_root_panic(payload, size, typename) — today dprintf to stderr ("Hale panic: unhandled <T> escaping main locus") + exit(1). Architecturally this is the seat for a future routing-through-main-locus- on_failure extension: when (if) the main locus declares on_failure, the runtime will route the synthesized ClosureViolation through that handler before falling out to the dprintf+exit fallback. Until then the boundary collapses both channels to the same exit shape.

Both paths preserve the framework’s vertical-only-flow: every failure exits through the top of the recursion, never laterally.

A seed’s declarations share one flat top-level scope: every file of the seed directory declares into it, under the names it writes, and two declarations of one name are the ordinary duplicate-name error. There is no in-file namespace form. A module is a directory, reached by import "<path>" as <alias>; (§ “Cross-seed namespace resolution”); the module NAME { … } declaration that once grouped declarations inside a file was removed (spec/decisions.md F.57), and a program that still writes one is refused at the word module with one located error:

main.hl:1:1: parse error: `module` declarations were removed: a module is a directory, reached by `import "path" as name;`. Move the declarations inside `module NAME { }` to the top level, or into their own file or directory and import it (spec/decisions.md F.57)

module is an ordinary identifier everywhere else: a local, a field, a parameter or a fn may be named module.

The bundled stdlib’s declarations share that one scope, under their internal names (std::http::Server is the locus __StdHttpServer). A program declaration of any kind that reuses one of those names is the same duplicate-name error, in the same one namespace: hale check refuses it where it stands and names the stdlib’s declaration. The stdlib’s own source checked as a program declares the same thing again, not a second thing, and is not refused; and a library’s names reach an importer mangled (__lib_…), so only a library checked on its own can meet one. The stdlib itself declares each name once, which its own test holds it to.

A seed’s entry point is its fn main (or the main locus that one instantiates).

Cross-seed namespace resolution (v1.x-IMPORT)

Section titled “Cross-seed namespace resolution (v1.x-IMPORT)”

A file may declare import "<path>" as <alias>; at the top. References to library decls go through the alias as alias::Name. Resolution is two-step:

  1. Parse / merge. The CLI resolves each import’s path (per spec/projects.md “Resolution order”), parses every .hl file in the resolved target, applies the auto-mangler with a stable path-derived <lib_id> + each file’s stem, and merges the mangled items into the importing program’s item list. A per-build path-rename table is built mapping ["<alias>", "<Name>"] to __lib_<lib_id>__<stem>__<Name> — the <alias> is the importer’s local namespace choice; the <lib_id> is the lib’s canonical path identity, so two consumers importing the same lib under different aliases see identical mangled symbols.

  2. Codegen lookup. Codegen’s qualified-name resolution consults three tables in order — static STDLIB_PATH_RENAMES, static MOA_PATH_RENAMES, and the per-build import table — when lowering any path-qualified type expression, struct literal, or method receiver. The first matching table wins.

A qualified literal checks like a local one. alias::Type { ... } resolves to the merged declaration before its initializers are validated, so field names, field types, interface coercions, and missing required fields are all checked exactly as they are for a literal on a locally declared type — an unknown field is the same type T has no field f error, at the offending initializer’s span. A literal whose path resolves to no visible declaration keeps the permissive Unknown typing. Diagnostics name the spelling the author wrote (alias::Type), not the mangled symbol. (GH #707, 2026-09-19 — downstream handoff. Until then only the RESULT type was resolved: a misspelled field in an imported literal was dropped in silence and the field’s default constructed instead, so check reported ok on a program the same literal on a local type would have rejected.)

Cross-seed references in user code (foo::Bar) and intra-seed references inside the imported library (bare Bar from a file that uses a type declared in a sibling file) BOTH resolve to the same mangled symbol. The mangler builds a unified rename map across every file in the imported library before rewriting, so greet.hl’s reference to a Formatted type declared in format.hl rewrites to the same __lib_<lib_id>__format__Formatted symbol that format.hl’s decl ends up at.

Local bindings (let, let mut, fn params, lifecycle params, for-loop vars, pattern bindings, generic params) shadow top-level names per ordinary lexical scope; the mangler’s scope-aware walker leaves shadowed references unrewritten.

Per-importer scoped imports (A4). Imports declared inside imported library files are followed transitively by the resolver, but each library’s imports land under that library’s own alias namespace — they do not become visible to the top-level program. So library A importing library B exposes A’s surface to the importer; B is reachable only through A’s API surface (or by the importer re-declaring its own import "lib/B" as ...;). This replaces the prior strict barrier (which rejected transitive imports outright) and unblocks composition without leaking dependency identity. See spec/projects.md for the rationale and per-alias scoping rules.

hale run interaction. hale run compiles through the same codegen path as hale build, and — as of WS3.3 — the same import path: both the single-file and directory forms (hale run ./dir) resolve cross-seed imports, build the per-build path-rename table, and rewrite qualified alias::Name references identically. A directory run produces the same resolved program as the corresponding build and execs it. (Previously the directory run form bundled files without the rename table, so cross-seed imports only worked under build; that gap is closed.)

Per memory.md:

Forward-looking / deferred items for this area now live in the decision log — see decisions.md § Deferred & future work.