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, or the model went idle), "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.
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) 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"`
}
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 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) 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; 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).