Cotal TypeScript packages
    Preparing search index...

    Class MeshHandler

    The one subject the remaining seam is gated by: turn and wait(replied) both ride the turn machinery an agent handle answers through (spawn, conclave, ask, monitor and wait(down) perform). Named once so the refusals cannot drift apart.

    Index
    • Parameters

      • nc: NatsConnection
      • kv: KV
      • js: JetStreamClient
      • jsm: JetStreamManager
      • binding: MeshHandlerBinding
      • watcher: SettleWatcher
      • clock: () => number = ...
      • Optionalservices: RunMeshServices
      • lag: LoopLagObserver = ...

        How this handler learns whether its own process was scheduled (#1508). Injected so a suite can drive a starved loop deterministically; the default is the process-wide observer, which is the only honest source outside a test.

      • onStarved: (note: string) => void = ...

        Where the operator notice for an absorbed starvation goes (#1508). A daemon routes it to its own log rather than stderr, and a suite counts it: an absorbed starvation is otherwise INVISIBLE, and a cell asserting "the sleep completed" cannot tell a completion that survived starvation from one that was never starved at all.

      Returns MeshHandler

    • WHAT to repair when this process takes a run over. The driver decides WHEN and calls this.

      It is a method rather than an optional hook the host wires: an adopted run whose timers stay armed at the predecessor's coordinates fires where nobody listens, and the object that knows how to re-arm is the one the driver already holds.

      Failures are raised, not swallowed: a driver holding a run whose pauses it could not re-arm cannot advance it.

      Parameters

      Returns Promise<string[]>

    • checkpoint is the same durable pause with somebody expected to answer it.

      The mint is identical to sleep's — one token, one deadline, one settle fact — and everything that differs is on the ANSWER side, which is deliberately not this handler's to arrange: the run driver's resolveCheckpoint writes the answer record and presents the token, because the checkpoint's holder is the driver and a resume is holder-bound. So this waits, and then reads what the arbiter says was accepted.

      It returns the RAW outcome and never the program's result. Whether an expiry throws or returns is onExpiry, which is computed from today's source on the live path and the replay path alike; deciding it here would bake one answer into the journal.

      WHAT IT ASKS IS BOUND ON THE ENTRY, and that is not decoration. A pause the reference calls "a durable pause a human or an agent resolves from anywhere" is answered by address (run plus step key), and the prompt lived only in the source: everything durable held the input HASH, so whoever was asked saw a token and had to go find the program to learn the question. to rides with it for the same reason — an escalation names an addressee, and an addressee nothing records is an addressee nobody can be shown.

      Parameters

      Returns Promise<CheckpointRaw>

    • End the external state of a cancelled scope's LOSERS: the world half of the discharge the scope entry's cancel.issued records (§7.6, and the driver's dischargeCancellations is the caller). The entries handed in are the losers' subtrees; what has external state to end is the three pause kinds — a pause's timer is claimed so its armed schedule cannot fire into a run that moved on, and a wait's durable consumer is deleted because a cancelled wait replays as cancelled and nothing will ever read its position.

      IDEMPOTENT BY THE PLANE: cancelTimer declines a pause that is not waiting, the consumer delete tolerates one already gone, and both tolerate a loser that cleaned up after itself on the live path — this is the durable backstop for the process that died before its own cleanup landed, and the flip to issued: true happens only after it returns.

      Parameters

      Returns Promise<void>

    • End the pauses a step armed: claim every token pauseTokens says it owns and, for a wait, close its consumer. A cancelled loser's discharge calls it, and so does a hold before its first bind (spec/cotal-lang.md §7.8), which claims the held step's open attempt. The relay an ask attempt rode is the discharge's to withdraw, not this.

      Parameters

      Returns Promise<void>

    • monitor registers interest: after it, down(agent) is an event a branch can await (§5.9).

      THE REGISTRATION IS THE JOURNAL ENTRY, and that is the whole mechanism. Death is a STATE on this mesh — the monitored incarnation's presence row gone (see waitDown) — not a message that must find a standing mailbox, so there is no subscription to create, nothing to arm, and nothing for a discharge or a migration to release: wait(down(...)) reads the same fact whenever it is asked, and the migration table's row for monitor ("nothing outlives it") stays true. What the step performs is the validation a registration owes: the value must BE an agent handle, refused loudly when it is not, because a wait parked on a malformed handle would poll for a death nothing can ever report.

      Monitoring an agent that is ALREADY dead succeeds — Erlang's monitor of a dead process delivers its DOWN rather than failing, and the rescue idiom (race work against wait(down(...))) needs exactly that: the death is observed by the wait, immediately.

      Parameters

      Returns Promise<null>

    • notify writes one bounded decision record per addressee, onto the run.

      NOT a channel post, and that is the whole point of the primitive: a post would put the program into the conversation as a participant, where conversation is the data plane and the program is the control plane. A notice is data filed on the run and rendered ahead of the addressee's next turn.

      One call to N agents is N records, and a retry lands on its own. The id is derived from the step's request id and the addressee, so a crash between the second and third write is repaired by re-running the call: the first two creates find their own bytes and return, the third happens. Nothing is written twice and nothing needs a memo of how far it got. That holds only because the instant every notice carries is bound with the step rather than read from the clock again, which is the one field a second pass could otherwise change.

      The fact's bound is the language's and is enforced BEFORE this is reached (L3043 at the effect boundary), so a fact that could not be rendered as one table row cannot arrive here.

      Parameters

      Returns Promise<null>

    • waitUntil's cadence, as a durable pause nobody answers.

      THE SAME PLANE AS sleep, for the reason sleep gives for reusing the checkpoint plane: a durable pause with a deadline, a token that survives a crash and a one-use settle is what this needs, and a second timer mechanism would be a second thing to get wrong. What differs is that a waitUntil parks MANY times under one step, so each observation's pause takes its own DERIVED token (observeToken), exactly as an ask's re-attempts and a wait's second deadline do. Deriving rather than remembering is what makes it recoverable: a resumed run re-derives the same token from the request id and the attempt index, and re-attaches to the pause the crashed attempt armed instead of arming a second one.

      THIS HANDLER NEVER OBSERVES ANYTHING. The probe is the program's and the interpreter calls it; all that happens here is the waiting. So there is nothing to bind and nothing to read back: the observations are the journal's, written by the interpreter, and this returns only whether there was time left.

      Parameters

      Returns Promise<boolean>

    • Despawn the seats of a run that completed (the driver's releaseSeats is the caller). On the mediated path the run's own journal decides which seats those are, never the entries handed in.

      Parameters

      Returns Promise<void>

    • Hand this program the seats a committed migration kept for it under --adopt (spec §11.2). The orphaned spawn's settled entry is the whole hand-over: the next spawn of its persona returns that entry's handle, binds that entry's floor, and submits nothing, so the seat keeps its identity, its worktree and its turn history across the edit. Called by the driver on the migrated run before the program runs; a map with no entry for a persona changes nothing.

      Parameters

      Returns Promise<void>

    • sleep is a checkpoint nobody answers.

      There is no separate timer plane and there should not be one: a durable pause with a deadline, a token that survives a crash, and a one-use settle is exactly what the checkpoint plane is, and a second mechanism would be a second thing to get wrong. The difference is only that no resolveCheckpoint will ever arrive for this token, so the timer's expiry is the whole story and null is the whole answer.

      Parameters

      Returns Promise<null>

    • wait — an event await that survives the process waiting for it.

      A DURABLE consumer named from ctx.requestId holds the run's position on the channel, so an event published while the host was down is still there when the run re-attaches under the same derived name. An ephemeral consumer, or one created on resume, starts from "now" and the event never happened.

      The TIMEOUT rides the checkpoint plane and is minted once with an absolute deadline, so a resumed 20-minute wait with 30 seconds left has 30 seconds left. A timeout resolves null and never throws: ?? is otherwise.

      down(agent) and replied(agent) are agent-addressed events with no channel, so they branch to waitDown and waitReplied before any of the channel machinery. The binding comes first because a hosted run mints only the timers its entry records, whichever branch arms them.

      Parameters

      Returns Promise<unknown>