assign

package
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Every placement also says why (proto design note 2026-11-01): the coordinator names the pass that produced it (ModelAssignment.placements: floor, demand, warm, stage) and the daemon keeps that on the pending record, the activity row and, once the artifact is on disk, the cache entry, so the operator can tell "placed by the mesh floor" from "requested by a customer". A declined or failed report carries the daemon's reason back (ModelState.reason) so the coordinator's node page shows the cause instead of just the verdict.

Index

Constants

View Source
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.

View Source
const (
	ReasonFloor  = "floor"
	ReasonDemand = "demand"
	ReasonWarm   = "warm"
	ReasonStage  = "stage"
)

Placement reasons, as the local API and the activity feed spell them: the short names of tunnel PlacementReason.

Variables

This section is empty.

Functions

func DescribeReason added in v0.9.0

func DescribeReason(reason string) string

DescribeReason is the operator's sentence for a placement reason ("" for none): what the activity feed appends to a placement row.

func ReasonName added in v0.9.0

func ReasonName(r tunnelv1.PlacementReason) string

ReasonName maps a wire PlacementReason to its short name ("" for unspecified or a value this build does not know).

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"`
	// Reason is why the mesh asked for the model (floor, demand, warm,
	// stage); empty from a coordinator that predates placement reasons.
	Reason string `json:"reason,omitempty"`
}

Pending is one assignment the node is working on or has concluded.

func (Pending) Describe

func (p Pending) Describe() string

Describe renders a pending record for logs/UI.

type Policy

type Policy struct {
	MeshManaged bool
	Exclude     []string
	Pinned      []string
}

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

func (s *Service) Cacheable(id string) bool

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) Get

func (s *Service) Get(id string) (Pending, bool)

Get returns one tracked assignment.

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

func (s *Service) Origin(id string) string

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) Pending

func (s *Service) Pending() []Pending

Pending returns every tracked assignment (local API), sorted by id.

func (*Service) PlacementReason added in v0.9.0

func (s *Service) PlacementReason(id string) string

PlacementReason is why the mesh asked for id, as last told: the pending record's reason, else what the cache entry remembers from an earlier session ("" when unknown or never placed).

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run starts the worker; returns when ctx ends.

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

func (s *Service) Unloaded(id string)

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL