acquire
Open one lease for the next slot: pick a leaf among eligible and reserve reservation for it. waiting is every leaf with work queued, and must contain eligible.
A pick never reads startedAt; it is stored on the lease for the caller's own reconciling.
Returns AcquireOutcome.NothingEligible when eligible is empty, or every leaf in it is beneath a group at its ceiling (see "Ceilings"; a name no pick can end at is still AcquireOutcome.NoLiveLineage), AcquireOutcome.SupplyExhausted when the root holds less than reservation and no capacity is reconciled, AcquireOutcome.NoLiveLineage when no eligible leaf can be reached, and AcquireOutcome.LifetimeExhausted when the reservation would carry a lifetime counter past the watermark (see "The lifetime limit"). In each of those cases the ledger is unchanged, with no top-up either; only the allocator's wake memory may have moved (see the class KDoc).
Throws
when reservation is not in 1..MAX_RESERVATION, or eligible is not a subset of waiting.
Samples
val tree = twoLanes()
val heavy = tree.groupId("heavy")
val light = tree.groupId("light")
val (heddle, booted) = LocalHeddle.fromTopology(tree, LocalPolicy(defaultReservation = 3L), epoch = 0L)
check(booted.refusals.isEmpty())
// Four slots: the engine mints its own supply ahead of them.
heddle.reconcileCapacity(totalSlots = 4L)
// Both groups have work queued, and this slot can run either.
val queued = setOf(heavy, light)
val first = heddle.acquire(waiting = queued, eligible = queued, startedAt = 100L)
check(first is AcquireOutcome.Acquired)
// The job overran its 3-unit estimate: all 5 units are charged, 2 of them as overrun.
check(heddle.complete(first.lease.id, actualCost = 5L, waiting = queued) == LeaseOutcome.Done(charged = 5L, overrun = 2L, unrecorded = 0L))
// Over many slots the shares follow the weights, 2 : 1.
val picks = (0 until 30).map {
val lease = (heddle.acquire(queued, queued, startedAt = it.toLong()) as AcquireOutcome.Acquired).lease
heddle.complete(lease.id, actualCost = 3L, waiting = queued)
lease.leaf
}
check(picks.count { it == heavy } in 19..21)