This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Fleet
import std/fleetKoru Standard Library: fleet — nodes that share one `world`.
fleet.kz · 9 tors
Koru Standard Library: fleet — nodes that share one `world`. · 37 more lines
claim
koru_std/fleet.kz:149// CLAIM — the conditional write. createNew is the CAS: exactly one caller
// wins the record for a free id; the loser reads who holds it. A won claim
// bumps the persistent counter so its epoch can never repeat. Shared with
// `std/node` through the acquire part below.
~pub tor claim { world: string, id: string, node: string, ttl-ms: u64 }
| claimed u32
| held-by string
| failed stringowner
koru_std/fleet.kz:169// OWNER — the routing probe: who holds this id, if anyone. celld answers
// this from its bucket records; we answer it from the same shared floor.
~pub tor owner { world: string, id: string }
| owned-by string
| free
| failed stringrelease
koru_std/fleet.kz:192// SEIZE and RENEW live in the `lease` part below — seize is operator-decided
// takeover (the health check is upstream), renew refreshes a live lease.
//
// RELEASE — graceful handoff: only the record's owner may clear it. The
// epoch counter stays, so a stale claim token is fenced forever after.
~pub tor release { world: string, id: string, node: string }
| released
| not-owner
| free
| failed stringguard
koru_std/fleet.kz:214// GUARD — the fence at the write. celld's invariant as a runtime check:
// a holder presents its node-id + granted epoch; both must still be on the
// record or the holder is stale and the write must not proceed.
~pub tor guard { world: string, id: string, node: string, epoch: u32 }
| owner
| fenced u32
| free
| failed stringreset
koru_std/fleet.kz:233// RESET — operator/test hook: drop the whole `.fleet` directory. Not part
// of the protocol; exists so tests and tools can re-slate a world.
~pub tor reset { world: string }
| cleared
| failed string~part acquire koru_std/fleet.acquire.kz
Koru Standard Library: the `acquire` part of fleet — the claim path `std/node` and `std/cell` call from host code. Joined via `~part acquire`. Caller ends up holding the id, learns the foreign owner (`nb`), or fails.
~part fence koru_std/fleet.fence.kz
Koru Standard Library: the `fence` part of fleet — read-back helpers: foreign-owner probe, the write-time guard, owner-scoped release. Joined via `~part fence` in fleet.kz. The record's owner if foreign — the slice lives in `nb`.
~part lease koru_std/fleet.lease.kz
Koru Standard Library: the `lease` part of fleet — takeover and lease renewal. seize is operator-decided takeover; an expired-lease claim runs the same serialized bump+commit. Joined via `~part lease` in fleet.kz.
// SEIZE — takeover: a peer claims an owned id after its owner is judged
// dead (leases make "dead" a clock fact; the operator path stays). The lock
// dir serializes concurrent takeovers; `contended` is single-attempt — the
// caller re-decides.
~pub tor seize { world: string, id: string, node: string, ttl-ms: u64 }
| seized u32
| free
| contended
| failed string~part mail koru_std/fleet.mail.kz
Koru Standard Library: the `mail` part of fleet — routing over the floor. Joined via `~part mail` in fleet.kz; merged into the fleet module at load. `.fleet/inbox/<id>/` is a mailbox that belongs to the CELL, not the node: a caller refused `held-by` leaves a turn for the owner of record, and the message survives takeover and ownership gaps — whoever holds the id next drains what was posted to it. `send` is multi-producer: every message is a uniquely-named file committed tmp+rename, so a reader never sees half a message and no two senders collide. `drain` is owner-side delivery: under the lock (serialized against seize and a second drainer), guarded (a stale owner answers `held-by`), ordered by send-time filename, and at-least-once — each file deletes only after the `! mail` arm returns, so a crash inside the arm redelivers on the next drain.
// SEND — post a message to an id's mailbox. `posted` even when the id is
// currently unowned: the mailbox is durable floor, the next owner drains it.
// Filename: <nanoTimestamp>-<from>-<rand> — chronological under lexical
// sort, collision-free across processes.
~pub tor send { world: string, id: string, from: string, body: string }
| posted
| failed string// DRAIN — the owner of record takes delivery. Lock-serialized (`contended`
// if a takeover or another drain holds it), ownership-gated like `guard`:
// a lapsed or foreign node answers `held-by`/`free` and consumes nothing.
// Each message file parses `from=<sender>\n<body>`; the file deletes after
// the arm returns — at-least-once delivery.
~pub tor drain { world: string, id: string, node: string }
! mail *
| done i64
| held-by string
| free
| contended
| failed string~part renew koru_std/fleet.renew.kz
Koru Standard Library: the `renew` part of fleet — lease renewal. Joined via `~part renew` in fleet.kz; merged into the fleet module at load. Renewal is piggyback, celld's ttl/3 cadence without a heartbeat thread: every activity path (acquire-hit, durable write, the explicit verb) renews when the deadline is inside its last third, so a live owner stays held and a dead one's leases lapse. Renews when the deadline is inside its last TTL third; returns the deadline now in force so callers can cache it. The lock is required: an unlocked renew could overwrite a committed takeover with the stale epoch it read before the lock.
// RENEW — the owner refreshes its own deadline (celld renews at ttl/3; the
// cadence is the caller's — there is no heartbeat yet). Under the lock so a
// renew can never overwrite a committed takeover with its stale epoch. A
// lapsed own lease answers `free`: the way back is `claim`.
~pub tor renew { world: string, id: string, node: string, ttl-ms: u64 }
| renewed
| held-by string
| free
| failed string