Package-level declarations

Types

Link copied to clipboard
sealed interface AcquireOutcome
Link copied to clipboard
sealed interface AdmitOutcome

What LocalHeddle.admit did: AcquireOutcome.Acquired or AcquireOutcome.NoLiveLineage. It shares those two arms with AcquireOutcome and has no other, since an admission makes no pick and is never refused for supply or for the lifetime limit: work already started is charged.

Link copied to clipboard
sealed interface AllocationOutcome

What one FairShareAllocator.schedule call did at a parent: delegated something, found nothing to delegate, or stopped because the parent cannot be ordered at all or its pick met the lifetime limit.

Link copied to clipboard
@Serializable
class AllocatorMemory

What a FairShareAllocator remembers between calls, as a value: the wake clamps it has computed, the demanding state each edge was last observed in (design §7.2, issues #1695, #1714), and each parent's net-service clock with the departures read against it (#3376).

Link copied to clipboard
sealed interface ApplyOutcome

What a checked LocalHeddle.apply did: Applied the edit, or refused it whole because the tree it started from is no longer the one running, as TreeChanged.

Link copied to clipboard
data class ApplyResult(val applied: List<TopologyStep>, val refusals: List<StepRefusal>)

What LocalHeddle.apply did: the applied steps, in the order they ran, and one refusal per child whose change did not land, sorted by child.

Link copied to clipboard
@Serializable
value class AttachmentId(val value: String) : Comparable<AttachmentId>

Identity of one attachment generation — the immutable parent→child edge that carries fairness state (see AttachmentRecord). There is exactly one AttachmentId per generation: changing anything fairness-significant (weight, parent, a reset) mints a new id rather than mutating an existing one, so old generations keep their history forever.

Link copied to clipboard
@Serializable
data class AttachmentRecord(val id: AttachmentId, val parent: GroupId, val child: GroupId, val weight: Weight)

The immutable fact of one attachment generation — a parent→child edge in the fairness tree, together with the child's weight among its siblings.

Link copied to clipboard
data class ChildPick(val ledger: EntitlementLedger, val grant: Grant)

One FairShareAllocator.pickChild result: the grant to delegate, and the ledger it must be delegated on, in which every active child of the parent is seated.

Link copied to clipboard

The nine per-edge GCounter families of EntitlementLedger — four base, five relocation. Names one family for EntitlementLedger.storedSlot, whose contract is that every family is grow-only: no piece on any state may lower a stored slot. HeddleInternalApi — test + derivation support.

Link copied to clipboard
@Serializable
data class Demand(val targetOutstanding: Long, val maximumUsefulGrant: Long)

How much more service a child could usefully take right now — the child's advertised appetite, and nothing about its authority.

Link copied to clipboard
@Serializable
data class EdgeSummary(val attachment: AttachmentId, val issued: Long, val returned: Long, val spent: Long)

The parent-facing view of one edge — everything a parent needs to schedule a child, and deliberately nothing more. It exposes how much entitlement was issued down the edge, how much was returned, and how much service was spent through it; the child's queues, identities, placement, and leaf receipts are simply not in this projection. Information hiding here is a hard interface boundary, not a convention (design §4.5).

Link copied to clipboard

The replicated, conflict-free tally of who was granted what fairness entitlement, who passed it down, and who spent it.

Link copied to clipboard

One peer's fair-share scheduler: it hands this peer's holdings at a parent down to the children that want them, one quantum at a time, in the order HeddlePolicy picks (design §7.3).

Link copied to clipboard
@Serializable(with = GaugeSerializer::class)
data class Gauge(val folded: Long, val ticksHigh: Long = 0, val ticksLow: Long = 0)

One edge's replicated virtual-time gauge: an asserted lower bound on its gross position, paired with the base issuance the writer had actually observed when it asserted it.

Link copied to clipboard
data class Grant(val attachment: AttachmentId, val amount: Long)

The outcome of one HeddlePolicy.pick: delegate amount service units down the edge named by attachment. The caller applies the patch to its ledger before the next pick (design §7.3 step 5).

Link copied to clipboard
@Serializable
value class GroupId(val value: String) : Comparable<GroupId>

Identity of one group in the fairness tree — a tenant, a lane, a leaf where work actually runs. Opaque, value-equal, and stably serialized: a GroupId is just a stable string name, compared as a string so every peer orders a set of groups identically.

Link copied to clipboard
sealed interface GroupPath

Where a group sits in a Topology, read from root down: a child the config declares, a child the consumer attached while running beneath a group with a template, or a child it attached beneath one of those, whose template carries a template of its own.

Link copied to clipboard
@RequiresOptIn(message = "Heddle's ledger/control-plane protocol. No stability promise; it may change in any release.", level = RequiresOptIn.Level.ERROR)
annotation class HeddleInternalApi

Marks the protocol the entitlement ledger shares with heddle's own control plane, and nothing else. It carries no stability promise for consumers.

Link copied to clipboard

The reference EEVDF allocation policy — a pure function from edge summaries, demand, and immutable attachment policy to a single delegation choice (design §7). It inspects nothing else: no global queues, no descendants, no wall clock, no randomness, no floating point. Purity is what makes it testable at virtual time and safe to run divergently on partitioned peers — a bad local decision only misplaces entitlement, it can never create any.

Link copied to clipboard
data class Lease(val id: LeaseId, val leaf: GroupId, val reserved: Long, val startedAt: Long)

One open lease: one slot of work running for leaf.

Link copied to clipboard
data class LeaseId(val epoch: Long, val seq: Long) : Comparable<LeaseId>

A lease's name: the epoch the engine that issued it was started with, and its place in that engine's issue order. Ordered by epoch, then by seq.

Link copied to clipboard
data class LeaseReconciliation(val orphaned: List<LeaseReconciliation.Orphan>, val unknown: List<LeaseId>)

What LocalHeddle.reconcileLeases found: the two ways the caller's running work and the engine's open leases can disagree. Both lists are in LeaseId order.

Link copied to clipboard
interface LedgerCell

Where a FairShareAllocator reads the ledger and lands its writes.

Link copied to clipboard

An integrity fault EntitlementLedger.validate derives from merged state.

Link copied to clipboard
@Serializable
enum class Lifecycle : Enum<Lifecycle>

The lifecycle of one attachment generation — a four-point chain climbed in one direction only:

Link copied to clipboard

A fair-share scheduler for one process: it decides which group's work runs in each free slot, so that over time each group gets the share its weight promises, and it keeps the books on what each one actually used.

Link copied to clipboard
data class LocalHeddleRevision(val epoch: Long, val count: Long) : Comparable<LocalHeddleRevision>

How far a LocalHeddle has come: the epoch it was started with, and how many calls that can change it have returned since, count. Ordered by epoch, then by count, like a LeaseId.

Link copied to clipboard
@Serializable(with = LocalHeddleSnapshotSerializer::class)
class LocalHeddleSnapshot

Everything a LocalHeddle needs to carry on after a restart, as one value you can encode, as JSON or CBOR, and store: the books, the open leases, how many slots the engine was sized for, what the fair-share allocator remembers, and the topology it last applied. Take one with LocalHeddle.persist, and start an engine from it with LocalHeddle.restore.

Link copied to clipboard
data class LocalHeddleState(val ledger: EntitlementLedger, val leases: List<Lease>, val epoch: Long, val allocatorMemory: AllocatorMemory)

A LocalHeddle's state, as one immutable value: once taken, safe to read or hand to another thread without the caller's scheduling lock. What a restart needs is LocalHeddleSnapshot, taken by LocalHeddle.persist; this is the status view.

Link copied to clipboard

The questions you can ask a LocalHeddle without changing it, asked of a saved state instead of a running engine: who goes next (previewPicks), why a leaf is waiting (explain), what share a leaf is owed (entitlement), and what share every group is owed (shareLine). An admin screen that holds only the last stored snapshot gets the same answers the engine that took it would give, with no engine to start and nothing to move.

Link copied to clipboard
data class LocalPolicy(val defaultReservation: Long, val sleeperCredit: Long = 0, val supply: SupplyPolicy = SupplyPolicy())

How a LocalHeddle sizes a lease, how much idle credit a waking group keeps, and how far ahead it mints supply.

Link copied to clipboard
@Serializable
value class MintId(val value: String) : Comparable<MintId>

Identity of one mint — a single act of introducing root supply into the ledger. Mints are keyed by MintId rather than by the holder's replica id so that two independently-recorded mints union instead of max-colliding: under control-plane failover the same holder may be credited by more than one committed mint, and each must survive the merge.

Link copied to clipboard
@Serializable
data class MintRecord(val root: GroupId, val holder: ReplicaId, val amount: Long) : Comparable<MintRecord>

One act of introducing root supply: holder is credited amount units at root's path. Keyed in the ledger by a unique MintId so independently-recorded mints union rather than collide (design fix 4).

Link copied to clipboard
@Serializable
value class PathKey : Comparable<PathKey>

Names an entitlement path by its final edge. Each group has exactly one active inbound edge, so the edge names the whole path from the root — no List<AttachmentId> is ever needed as a key. The root path has no final edge and is named by the ROOT sentinel.

Link copied to clipboard
data class PolicyConfig(val quantum: Long, val perChildOutstandingCap: Long = Long.MAX_VALUE, val sleeperCredit: Long = 0)

Tuning for one allocation round (design §7.3). Every field is a hard cap in service units; the round grants the smallest of all the applicable caps.

Link copied to clipboard
data class PolicyEdge(val record: AttachmentRecord, val summary: EdgeSummary, val demand: Demand, val gauge: Gauge?, val baseIssued: Long, val offsetTicks: Int128 = Int128.ZERO, val origin: Int128 = Int128.ZERO)

One immediate child, as the policy sees it: the immutable attachment metadata (record — parent, child and weight), the parent-facing accounting (summary — issued/returned/spent), the child's advertised demand, the replicated virtual-time seat (gauge paired with baseIssued), and the scheduler-local wake clamp (offsetTicks).

Link copied to clipboard
sealed interface PreviewOutcome

What a checked LocalHeddle.previewApply found: Previewed, or ApplyOutcome.TreeChanged when the checked apply at the same moment would refuse, since the tree the edit started from is no longer running. It shares that arm with ApplyOutcome, so a preview never shows a result the save would refuse.

Link copied to clipboard

An exact rational number — a numerator/denominator pair over Long, kept reduced to lowest terms with a strictly positive denominator.

Link copied to clipboard
sealed interface Relocation

The outcome of deriving the §4 generation-move from log-recorded acked finals (EntitlementLedger.relocationPatch). Three outcomes, all deterministic functions of the same inputs, so every peer derives the identical one.

Link copied to clipboard
sealed interface RestoreResult

What LocalHeddle.decode found in a stored snapshot.

Link copied to clipboard
@Serializable
value class ServiceUnits(val value: Long) : Comparable<ServiceUnits>

A non-negative quantity of service — the abstract unit the ledger accounts in (CPU-milliseconds, tasks, tokens; whatever the consumer meters). Always >= 0; a negative amount of service is meaningless and is rejected at construction rather than allowed to poison the tally.

Link copied to clipboard
class ShareLine

What every group is owed of the whole pool while one waiting set holds still, and how far each stands from it: one read of the tree, answered group by group with share and lag. A table that shows a share on every row reads one line and looks each row up, rather than asking the engine once per row.

Link copied to clipboard
@Serializable
data class SlotFinals(val issued: Long, val returned: Long, val leafSpent: Long, val rollupSpent: Long, val transfers: Map<ReplicaId, Long> = emptyMap())

One replica's final authored values on a fenced edge — its four base counter slots and its own transfer row at the edge's PathKey — the promise a ControlCommand.QuiesceAck carries (docs/heddle-ledger-relocation-design.md §6.2 step 2).

Link copied to clipboard
sealed interface StepRefusal

Why one child's change did not land in a LocalHeddle.apply.

Link copied to clipboard
data class SupplyPolicy(val lowWatermarkSlots: Long = 1, val targetSlots: Long = 2)

How much supply a LocalHeddle keeps ahead of its leases, in rounds of capacity: one round is every slot (LocalHeddle.reconcileCapacity) leased once at LocalPolicy.defaultReservation.

Link copied to clipboard
@Serializable
data class Topology(val root: String, val children: List<Topology.Node>)

The tree you write in a config file: who shares the pool, and in what proportions.

Link copied to clipboard
sealed interface TopologyChange

One difference between two trees, named the way the admin who edited them thinks of it: a lane added, a weight changed, a template removed. Topology.changesTo lists them, so an admin page can show what an edit does before it is applied.

Link copied to clipboard
@Serializable
data class TopologyDocument(val root: String, val children: List<TopologyDocument.Node>)

The fair-share tree exactly as an admin wrote it, before anything is checked.

Link copied to clipboard
sealed class TopologyDraft

The children of one group while a draft is being written, in the order they are declared.

Link copied to clipboard
annotation class TopologyDraftDsl

Marks the draft scopes, so a block written inside a group cannot quietly reach a member of an enclosing group.

Link copied to clipboard
sealed interface TopologyEdit

The outcome of one edit of a TopologyDocument: the edited document, or why the edit was refused. An edit never throws, and a refused edit changes nothing.

Link copied to clipboard

Thrown when a Topology would hold problems; its message lists every one, one per line.

Link copied to clipboard
sealed interface TopologyParse

The outcome of Topology.from: a checked tree, or everything wrong with the document.

Link copied to clipboard

What applying a candidate topology would do, worked out on a copy: nothing it came from changes. Take one with LocalHeddle.previewApply from a running engine, or with LocalHeddleSnapshot.previewApply from a stored snapshot.

Link copied to clipboard
data class TopologyProblem(val path: List<Int>, val names: List<String>, val kind: TopologyProblem.Kind, val detail: String)

One thing wrong with a topology, addressed so a config page can show it beside the right line.

Link copied to clipboard
sealed interface TopologyStep

One step of moving a ledger to a new Topology. Topology.diff lists them in the order they must run, and an interpreter applies them one at a time.

Link copied to clipboard
object TopologyWeightSerializer : KSerializer<Weight>

Writes a Weight as the text an admin writes: "3" for a whole number, "3/2" for a ratio.

Link copied to clipboard

A virtual time kept unreduced, as a sum of positions over a weight: V = ticks / (G · w), where w = weightNumerator / weightDenominator.

Link copied to clipboard
sealed interface WaitExplanation

Why a leaf is waiting, as LocalHeddle.explain answers it: the first reason, in Kind order, that stops the next LocalHeddle.acquire from picking it.

Link copied to clipboard
@Serializable(with = WeightSerializer::class)
class Weight : Comparable<Weight>

A sibling's fairness share, expressed as a positive integer ratio.

Link copied to clipboard
object WeightSerializer : KSerializer<Weight>

Decodes a Weight through Weight.of, so a value that arrived over the wire is indistinguishable from one the factory built (#1647).

Functions

Link copied to clipboard

Whether activating edge on this ledger keeps its parent's active children inside the weight budget: true when LocalHeddle.apply would let the activation through on budget grounds, false when it would refuse it as over budget.

Link copied to clipboard

Adds child, a TopologyDocument.Group with anything beneath it or a TopologyDocument.Lane, as the last child of the group at parent; [] adds it to the root. Every existing address is unchanged, and TopologyEdit.Edited.path is the new child's.

Link copied to clipboard
fun Topology.attach(path: GroupPath, ledger: EntitlementLedger, generation: Long): List<TopologyStep>

The steps that attach the child at path, read from root down, at the weight the template it is attached under gives, and every attached group above it that is not attached yet, in the same list: [Prepare, Activate] for a new child of an attached group, the prepares top-down and then the activations top-down when its ancestors are new too, [Activate] when only the prepare landed, and [] when the whole path is attached. Each name is opaque and lives in its own namespace, so it never collides with a declared child, however it is spelt.

fun Topology.attach(group: List<String>, name: String, ledger: EntitlementLedger, generation: Long): List<TopologyStep>

The steps that attach the child name to the declared group at group: attach of the one-level path GroupPath.Attached(group, name).

Link copied to clipboard

The ledger id of the attached child name of the group at group, read from root down. A child attached beneath an attached one has no form here: read its id with findGroupId and a GroupPath.Nested.

Link copied to clipboard

Every TopologyChange that turns this tree into after, in document order: walking the tree from the root down, a node's own changes come before its children's, and within a group the children of after come in the order written, followed by the children it no longer has, in the order they were written before. Empty exactly when the two trees differ in nothing but the order of siblings.

Link copied to clipboard

The steps that detach the child at path, and every child attached beneath it: [Close, Retire] for an attached leaf, [Retire] when it is already closing, and [] when there is nothing left to do. Beneath an attached group the whole subtree goes, closes top-down and retires bottom-up, so nothing is retired while a child beneath it still has a live edge. A retire is refused while work beneath it is outstanding or an open lease crosses it, even one reserving nothing, and so is every retire above it; detach again, or diff, once it has drained. Attaching the group again brings none of its children back.

The steps that detach the child name from the declared group at group: detach of the one-level path GroupPath.Attached(group, name).

Link copied to clipboard

The steps that move ledger to new: prepare every edge it lacks, close and retire every edge it no longer wants, and activate the replacements.

Link copied to clipboard
fun draft(root: String, block: TopologyDraft.() -> Unit): Topology

Writes a Topology in code, the way it reads on a whiteboard: groups nested in groups, lanes where work is charged, and a weight beside each.

Link copied to clipboard

The ledger id of the group at path, or null when this topology has no such group: a GroupPath.Declared it does not declare, a GroupPath.Attached whose group has no template, or a GroupPath.Nested whose parent's template carries no template. Never throws.

Link copied to clipboard

Where group sits in this topology, or null unless group is exactly an id findGroupId returns for it. Never throws.

Link copied to clipboard
fun Topology.groupId(vararg path: String): GroupId

The ledger id of the group at path, read from root down: groupId() is the root, and groupId("acme", "batch") is the batch lane inside acme.

Link copied to clipboard
fun Topology.lower(generation: Long = 0): List<AttachmentRecord>

Every declared edge of this tree, as the records a ledger is prepared with, sorted by id.

Link copied to clipboard
inline fun <K, V> Map<K, V>.mergeValues(other: Map<K, V>, combine: (mine: V, theirs: V) -> V): Map<K, V>

Elementwise merge: for each key present in either map, combine the two values (or keep the lone one).

Link copied to clipboard

Moves the child at path, with everything beneath it, to be the last child of the group at parent; [] is the root. parent is an address in this document, before the move, and TopologyEdit.Edited.path is where the child lands after it.

Link copied to clipboard

Removes the child at path, with everything beneath it. Later siblings move up one index, and TopologyEdit.Edited.path is the parent's. A group left with no children and no template is a problem Topology.from reports.

Link copied to clipboard

Renames the node at path to name, keeping everything else about it and everything beneath it. [] renames the root. The name is not checked here; Topology.from reports an empty one.

Link copied to clipboard

Sets the maxConcurrent ceiling of the child at path: a count, 0 to pause it, or null to clear the ceiling. Not checked here; Topology.from reports a negative one. A group's template ceiling is not this one: it is on TopologyDocument.ChildTemplate.

Link copied to clipboard

Sets the template of the group at path to template, replacing the whole of the old one, nested templates included; null removes it. A template is what lets the app attach children to the group while it runs, and says what each one gets (see TopologyDocument.ChildTemplate). To change one field, pass a copy of the group's own. Nothing in template is checked here; Topology.from reports a bad weight or a negative ceiling at the group's path.

Link copied to clipboard

Sets the weight of the child at path to weight, written as text the way a file writes it: "3" or "3/2". The text is not checked here; Topology.from reports a bad one.

Link copied to clipboard

Whether weight could be activated at all: true when it fits the weight budget as the only active child of its parent, false when no parent could ever take it.