Documentation
¶
Overview ¶
Package assign executes the coordinator's ModelAssignment pushes on the operator's terms (SPEC §4.1, §4.4; plan 05).
The mesh may fill this node with models — download, load, and later evict what it placed — but only inside the operator's consent:
- the models mesh_managed switch (default on; off = decline all),
- max_disk_mb (a placement that cannot fit even after evicting other mesh-placed models is declined, never forced),
- pin (never evicted) and exclude (never assigned),
- and the operator's own models, which the mesh cannot evict at all (cache entries carry an origin; only "mesh" ones are the mesh's).
Every decision is reported back over the tunnel as a ModelState: "assigned" (accepted, queued), "downloading", "ready", "cached" (on disk, not loaded: the memory budget is full, the model went idle, or the coordinator only *staged* it), "declined" (policy), "failed" (error), "evicted". The coordinator uses declined / failed to back off, counts cached as a warm candidate that costs a load rather than a live replica (it re-sends the assignment when demand returns, and the node then loads without downloading), and the heartbeat carries assigned/downloading so placement knows a replica is on its way. A placement is never declined for memory alone: the artifact is fetched inside max_disk_mb and reported cached.
ModelAssignment.stage is the download-only half of assign: same consent rules, same disk budget, same assigned → downloading progression, but the terminal state is cached and the runtime is never started. An assign for a model that is already on disk still loads it.
Every ModelState the daemon sends carries origin: "operator" for models the operator installed (app/CLI/config, or adopted from the model dir), "mesh" for coordinator placements — including ones not on disk yet or already evicted, which can only be the mesh's.
Index ¶
- Constants
- type Pending
- type Policy
- type Service
- func (s *Service) Apply(ctx context.Context, ma *tunnelv1.ModelAssignment)
- func (s *Service) Cacheable(id string) bool
- func (s *Service) Get(id string) (Pending, bool)
- func (s *Service) ModelStates() []*typesv1.ModelState
- func (s *Service) Origin(id string) string
- func (s *Service) Pending() []Pending
- func (s *Service) Run(ctx context.Context)
- func (s *Service) SetReporter(fn func(*typesv1.ModelState) error)
- func (s *Service) States() []*typesv1.ModelState
- func (s *Service) Unloaded(id string)
Constants ¶
const ( StateAssigned = "assigned" StateDownloading = "downloading" StateReady = "ready" StateCached = "cached" StateDeclined = "declined" StateFailed = "failed" StateEvicted = "evicted" )
States reported to the coordinator and shown in the local API.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pending ¶
type Pending struct {
ID string `json:"id"`
State string `json:"state"`
Since time.Time `json:"since"`
// Error is the failure or refusal reason (failed/declined only).
Error string `json:"error,omitempty"`
// Stage marks a download-only placement (ModelAssignment.stage): it
// ends cached, never loaded. An assign for the same model while the
// download runs upgrades it.
Stage bool `json:"stage,omitempty"`
}
Pending is one assignment the node is working on or has concluded.
type Policy ¶
Policy is the operator's standing consent, read fresh per decision so a dashboard toggle applies to the next assignment without a restart.
type Service ¶
type Service struct {
Ops *modelops.Service
Mgr *models.Manager
Eng *engine.Engine
// OnBattery reports power state; downloads wait while true.
OnBattery func() bool
// Policy returns the current consent. Required.
Policy func() Policy
// Events receives model_assignment events. May be nil.
Events *events.Hub
// Activity receives assignment / declined rows. May be nil.
Activity *activity.Ring
Log *slog.Logger
// contains filtered or unexported fields
}
Service applies assignments. Nil Ops (mock runtime) declines everything with a clear reason so the coordinator backs off instead of retrying.
func (*Service) Apply ¶
func (s *Service) Apply(ctx context.Context, ma *tunnelv1.ModelAssignment)
Apply handles one ModelAssignment: evictions first (they free the disk the assignments need), then admission of each assignment and each staged download under the policy. Idempotent: a repeated push for a model already ready or in flight is acknowledged, not restarted.
func (*Service) Cacheable ¶ added in v0.4.0
Cacheable reports whether id should be advertised to the coordinator as `cached`: complete on disk, and loadable by a mesh assignment under the operator's policy (mesh-managed on, not excluded, a real model store). Advertising a model the node would only decline invites assignments that go nowhere.
func (*Service) ModelStates ¶ added in v0.5.0
func (s *Service) ModelStates() []*typesv1.ModelState
ModelStates is the model list for Hello and heartbeats: loaded models are `ready`; complete artifacts on disk that are not loaded (idle-unloaded, never admitted for memory, or only staged) are `cached` — warm candidates the coordinator can light up with a load instead of a download — provided the policy would let a mesh assignment load them (Cacheable); plus in-flight placements (assigned/downloading), so the coordinator counts a replica that is on its way and does not push the same assignment again next round. Every entry carries origin.
func (*Service) Origin ¶ added in v0.5.0
Origin is who owns a model as far as the coordinator is concerned: the cache's record ("operator" or "mesh") when the artifact is indexed; otherwise "operator" for something loaded outside the store (file:// artifacts, the mock runtime) and "mesh" for a placement that is not on disk — queued, declined, or already evicted — which only the mesh could have asked for.
func (*Service) SetReporter ¶
func (s *Service) SetReporter(fn func(*typesv1.ModelState) error)
SetReporter installs the tunnel send used for ModelStateUpdate messages (swapped on every (re)connect). Reports while disconnected are dropped; the next Hello/heartbeat carries the live states anyway.
func (*Service) States ¶
func (s *Service) States() []*typesv1.ModelState
States returns the in-flight assignments for Hello/heartbeat model lists (assigned + downloading only, staged ones included; failures/refusals are one-shot reports, otherwise the coordinator would read every heartbeat as a fresh one).
func (*Service) Unloaded ¶ added in v0.4.0
Unloaded is the modelops OnUnloaded hook: a model that left memory but is still on disk is reported `cached` so the coordinator knows it can be warmed with a load, not a download. Operator and mesh models alike — both are legitimately serveable — as long as the policy would let the mesh load it (Cacheable).