The core

docs/core.md · wiki index

The core

The core owns every process, every byte of memory, and every job that is not inside a model. This page gives the state of each object and the event that moves it. A state that is not in a table does not exist.

1. Objects

ObjectKeyLives in
Peerserver id from hellosupervisor
Modelserve namecatalog and residency
Devicetarget.id plus indexledger
Loadone per resident modelledger
Jobstream id on one connectionadmission and the core

2. Peer

DISCOVERED ──probe──► PROBED ──spawn──► SPAWNED
SPAWNED ──hello/welcome/catalogue──► HANDSHAKEN
HANDSHAKEN ──grant + ready──► READY
READY ──bye + last terminal──► DRAINING ──exit──► CLOSED
any ──fatal, exit, or timeout──► FAILED
FAILED ──backoff──► SPAWNED
EventGuardResult
probe answersthe catalogue is validPROBED
probe answersthe catalogue is invalidFAILED
spawn returns a pidSPAWNED
welcome arrivesversion overlapHANDSHAKEN
catalogue arrivesnames are uniqueHANDSHAKEN
ready arrivesREADY
bye sentno job is openDRAINING
the process exitsCLOSED
fatal arrivesFAILED

Rules:

  1. A peer that fails twice in one minute is not spawned a third time. The backoff doubles from the measured start time, and sixty seconds is its ceiling.
  2. A peer in FAILED holds no ledger reservation. The core closes its socket, stops the child, fails every live job on it with plugin_crashed, settles the device, and releases the reservation.
  3. A peer in DRAINING accepts no new job.
  4. A permanent failure marks the peer unloadable. A request is refused until an operator switch starts it again. A transient failure waits for its backoff, and a successful start clears the failure memory.

3. Residency

Unload is process death (decision D13). There is no unload frame: the core stops the child and releases the reservation. The state below is the state of the supervisor, not of the plugin.

COLD ──spawn, load──► LOADING ──ready──► RESIDENT ──stop child──► COLD
RESIDENT ──idle for idle_unload──► WARM
WARM ──new job──► RESIDENT
IntentCold startIdle unloadChosen by
pinnedallowedneveroperator
warmallowedidle_unloadoperator
interactiveallowedon pressureengine
alwaysat startneveroperator

A cold bind is discovered with --describe and no load. Its names enter the catalog, and the first request starts the child through the loader with the weight files that the deploy file names. An unload removes the peer but keeps the catalog names, so the next request reloads the same name with the same weights.

Rules:

  1. idle_unload is a duration that the operator states, or it is absent.
  2. A model is unloaded when its idle window passes, or when its ledger reservation is needed by another model. The web sweeps idle plugins while it serves; the ledger decides the pressure eviction.
  3. The order of unload is least recently used. A pinned model is never chosen.

4. Ledger

A load reserves weights + context × kv_bytes_per_token on every device that its bind names. A job reserves nothing. Decision D5.

FREE(bytes) ──reserve──► HELD(load) ──release──► FREE(bytes)

Rules:

  1. A reservation is a number of bytes on one device. It is not a percentage.
  2. reserve fails when the device has fewer free bytes than the request. The refusal is no_room with Retry-After.
  3. The core reports the reservation of a model at load, before grant.
  4. A reservation that no load holds is a bug. The ledger asserts it at drop.
  5. A device is added to the ledger without rebuilding it, so a reservation on an already-declared device survives a later declaration.
  6. The bind names the devices. A card that another bind owns is not part of this load's bill.
  7. A release waits until the driver reports the free bytes that remain after the release, not until the driver reports the size of the released bytes.

5. Job

SUBMITTED ──refuse──► REFUSED
SUBMITTED ──admit──► QUEUED ──slot──► RUNNING
RUNNING ──done──► DONE
RUNNING ──cancel──► CANCELLED
RUNNING ──deadline──► EXPIRED
RUNNING ──reader gone──► CANCELLED
RUNNING ──peer lost──► FAILED
EventGuardResult
submita refusal code appliesREFUSED with that code
submitthe queue is fullREFUSED with queue_full
submita slot is freeRUNNING
slot freesa job is QUEUEDbest priority, then arrival; an aged background job competes as interactive
doneDONE
cancelCANCELLED
the reader drops the jobCANCELLED
deadlineno frame before the budgetEXPIRED

Rules:

  1. A refusal is decided before a queue slot. The order is: name, capability, parts, size, queue, room.
  2. A job in RUNNING holds one slot of its plugin's max_inflight. Every served name of one plugin, aliases included, shares that one set of slots.
  3. The deadline starts at admission. The queue wait spends it, and the plugin receives only the remaining time in open. A read that would wait past the deadline ends the job as timeout instead of blocking forever.
  4. A background waiter that waits longer than one second competes as interactive. Its earlier arrival number then puts it first, so a stream of new interactive jobs cannot starve it.
  5. A job never outlives its peer. When the peer is FAILED, every job on it becomes FAILED with plugin_crashed. The job whose own deadline failed keeps the timeout code, because its budget ended before the peer failed.
  6. A caller that drops a job without reading it has cancelled it. The row ends as cancelled; it does not stay running for the life of the process. The web removes terminal rows after its retention window.

5.1 The scheduler

QuestionAnswer
What owns the slots?One peer, named by the bundle id. Every served name of that peer shares them.
What is the slot count?max_inflight from the catalogue, or the deploy file's value for the bind.
What bounds the waiters?A queue capacity per peer. Above it the job is refused with queue_full.
Who runs next?The highest class, then the lowest arrival number.
When does a class change?A background waiter becomes interactive after one second.
What happens at a deadline?The waiter is removed. A job whose deadline passed before it arrived is refused with timeout, before it takes a queue place.

inf3r-sched takes the current instant from its caller. It has no thread and no sleep, so a test ages a waiter by passing a later instant. A slot is a lease: dropping it releases the slot. Registering the same peer again keeps the slots in use, because a restart must not free a slot that a live job still holds.

6. The session pump

One thread per peer reads frames. This table is what it does with each frame.

FrameAction
welcomecheck the version. Record max_inflight.
cataloguecheck the names. Store it.
readyrecord the measured load time. Set the model RESIDENT.
acceptrecord est_ms.
eventcredit the sender. Append to the job.
doneclose the job. Release the slot. Return the artifacts.
rejectclose the job. Refuse the request with the code.
fatalmark the peer FAILED. Fail its jobs.
pongnote the round trip.

Rules:

  1. The pump never blocks on a worker. It reads and it routes.
  2. A frame for a stream that is not open is fatal{stream}.
  3. A done for a job that the core marked CANCELLED keeps the outcome cancelled.

7. Failure classes

ClassExamplePeerJobs
Refusalbusy, unknown_modelstays READYthe one job is REFUSED
Timeoutno frame for the budgetFAILEDEXPIRED
Protocola frame out of orderFAILEDFAILED
Crashthe process exitsFAILEDFAILED
Loadready never arrivesFAILEDREFUSED with load_failed

Rule: a class that kills the peer records the failure, fails its jobs, and frees its ledger reservation. The failure is recorded before the settle wait, so a request that arrives during the wait sees the backoff; the reservation is released after the device settles. The settle target is the free line the child left, captured before its start, not the card's nominal capacity: a desktop compositor or another process may own part of the card permanently.

8. Invariants

Each one is a test against the mock plugin.

  1. The sum of every reservation on a device is at most the device size.
  2. A peer in READY has exactly one load in the ledger, or none if it serves no model.
  3. A job that the core reports as finished has no open stream.
  4. A frame for an unknown stream ends the session.
  5. No job outlives the peer that runs it.
  6. A refused request has a code from section 12 of the spec.

6. KV cache

The core owns KV cache as a host resource (D22). It does not parse a prompt, a token, a chat template, or an engine slot format.

ObjectKeyLives in
Cache tiername and st_devstate/cache
Cache entrydomain-separated SHA-256one tier
Cache leasesession and lease idthe core, until release or crash
Cache sessionone peer connectionthe core

The rules:

  1. One manager owns each filesystem. Core refuses two tiers on one st_dev and holds a per-st_dev abstract socket, a host-mounted device flock, and a tier flock (D26).
  2. A bundle declares only a codec, a slot count, a state kind, and a maximum entry size. It declares no quota, TTL, tier, or path.
  3. A lookup returns an opaque read descriptor. A reserve returns an opaque writable descriptor. A path never crosses the socket (D23).
  4. A prefix key is a boundary, not a promise that a longer prefix can be truncated. checkpoint_exact engines never roll back (D24).
  5. A miss, a corrupt restore, or a tainted turn erases the VRAM slot. A cache error costs prefill and never changes the answer.
  6. A flush is bounded. The core kills the child when the budget ends, even if the flush did not finish (D25).
  7. A lease belongs to its peer session. EOF, fatal, a timeout, or a child crash aborts every write lease and releases every read lease. A lease that is not released within ten seconds is abandoned, not counted as a hit.
  8. A cache entry has no HTTP route. /cache returns metadata only.
  9. Tiers are ordered hot to cold. A full hot tier demotes a cold victim before eviction; maintenance promotes an entry back after its second hit, and only demotes when the measured restore estimate is below the entry's prefill cost.
  10. Disk pressure on a tier's st_dev evicts that tier before blobs refuses an upload or a model load. Host memory pressure demotes or evicts RAM-backed entries before a load is refused. Both paths skip pinned entries.
  11. A zero pin_bound is a zero budget: pins are refused. A pinned entry does not expire and counts against both the tier bound and the pin bound.