update

package
v0.209.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 35 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 update is the `local-offload update` verb: it resolves each harness component's newest complete build from its publisher, verifies the publisher's digest, stages it, promotes it as a write-once generation behind the component's existing live path, keeps the previous generation, rolls back on any failure and records everything in installed.json (schema 2). Run with nothing new upstream it is one conditional request.

The engine builds on internal/nodeswap for the single-file component (llama-swap): hash verify, idle wait, backup by rename, restart, verify, automatic rollback. Directory components (llama, whisper, sdcpp, hyperframes) get the generation layout in generations.go. Docs: docs/systems/update.md.

Index

Constants

View Source
const (
	Llama       = "llama"
	LlamaSwap   = "llama-swap"
	Whisper     = "whisper"
	SDCpp       = "sdcpp"
	Hyperframes = "hyperframes"
)

Component names the verb takes.

View Source
const (
	// MaxSlowdown is the most a decode or prefill rate may fall below the previous generation's.
	MaxSlowdown = 0.20
	// MaxVRAMGrowth is the most the seat's VRAM may grow over the previous generation's.
	MaxVRAMGrowth = 0.10
)

Gate thresholds (Ruling R6).

View Source
const (
	DefaultLeaseWait       = 30 * time.Minute
	DefaultSidePort        = 11499
	DefaultLoadTimeout     = 5 * time.Minute
	DefaultPostFlipTimeout = 5 * time.Minute
)

Gate defaults (config.json update.gate.*).

View Source
const (
	ExitOK       = 0
	ExitRejected = 1
	ExitError    = 2
)

Exit codes: 0 no-op, updated, skipped or inconclusive; 1 rejected or rolled back; 2 error.

View Source
const ComfyPacks = "comfy-packs"

ComfyPacks is the component that moves the installed ComfyUI node packs. It is not part of AllComponents and does not use the generation layout: the work is render/comfy-packs-update.mjs, which this verb starts and whose report and exit code it relays (docs/systems/update.md, "Node packs").

Variables

AllComponents is the order `--component all` walks: the engines first, the daemon that hosts them last.

View Source
var ErrBelowFloor = errors.New("below the floor")

ErrBelowFloor means the newest complete build is under a floor, so none is selected.

View Source
var ErrUnsupported = errors.New("no prebuilt for this node")

ErrUnsupported means the publisher ships no prebuilt for this node (a source build is the way); the component is skipped.

Functions

func Attest

func Attest(ctx context.Context, repo, file string) (string, error)

Attest runs `gh attestation verify` on a downloaded file when gh is on PATH. A publisher with no attestation published is recorded as "none published"; anything else that fails is a failure (fail closed).

func CheckFlags

func CheckFlags(ctx context.Context, stagedServer, yamlPath, live string) (string, error)

CheckFlags compares the long flags of every cmd line that runs the live llama-server with the staged help text.

func ComfyPacksScript

func ComfyPacksScript(runGraphScript string) string

ComfyPacksScript names the updater beside the run-graph runner the node already uses: same render directory, same script resolution (relative to the binary), so a node that can run a graph can run this.

func DetectVariant

func DetectVariant(backend string) string

DetectVariant picks the build family for this node: cuda13, cuda12, vulkan or cpu. backend is the serving backend the installer recorded ("" when unknown).

func Download

func Download(ctx context.Context, hc *http.Client, a Asset, dir string, logf func(string, ...any)) (string, int64, error)

Download streams asset into dir, hashing as it goes, and verifies size and the publisher's sha256 digest. The file is removed on any mismatch. It returns the path and the verified size.

func Extract

func Extract(archive, dir string) error

Extract unpacks a .zip or .tar.gz into dir. Entries that would leave dir are refused.

func GitHubToken

func GitHubToken() func() string

GitHubToken finds a read token without storing it: GH_TOKEN, GITHUB_TOKEN, else `gh auth token` (for the account named by OFFLOAD_UPDATE_GH_USER when set). Empty means unauthenticated.

func PrintReports

func PrintReports(w io.Writer, reports []Report, opts Options)

PrintReports writes the generation table and, under it, what each component did.

func Probe

func Probe(ctx context.Context, def *compDef, dir string) (id string, ok bool, detail string)

Probe runs the component's version probe under dir and returns the upstream id it prints ("" when the program prints none) and whether any probe exited 0. Hyperframes reads its installed package.json instead.

func RunComfyPacks

func RunComfyPacks(ctx context.Context, r ComfyPacksRun) int

RunComfyPacks runs the updater to its end and returns its exit code: 0 done, no-op, inconclusive or refused; 1 a candidate was rejected and undone; 2 an error (also: the script could not be started). The script's own stdout is the report (one JSON line with --json), so it is passed through untouched.

func RunGateChild

func RunGateChild(ctx context.Context, jobPath, resPath string, w io.Writer) error

RunGateChild is the lease-held half: `update --gate-child <job> --gate-result <file>`. It measures, prints the table, and writes the verdict to the result file (the parent reads only that file).

func SelfCheck

func SelfCheck(ctx context.Context, def *compDef, dir, yamlPath, live string) ([]string, error)

SelfCheck is the offline check every staged build passes before anything moves: the program starts (--version exits 0) and, for llama, every long flag the rendered llama-swap yaml passes to this binary exists in the staged `llama-server --help`. It returns notes for the table and an error that rejects the candidate.

Types

type Asset

type Asset struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Digest string `json:"digest"` // "sha256:<hex>" (GitHub) or "sha512-<base64>" (npm integrity)
	Size   int64  `json:"size"`
}

Asset is one downloadable file of a candidate with the publisher's own integrity value.

type Candidate

type Candidate struct {
	Component string   `json:"component"`
	ID        string   `json:"id"`
	Source    string   `json:"source"`
	Variant   string   `json:"variant,omitempty"`
	Assets    []Asset  `json:"assets"`
	Channel   string   `json:"channel,omitempty"`
	Notes     []string `json:"notes,omitempty"`
	// Checksums is the publisher's own checksums file when the release has one (a second source for the digest).
	Checksums *Asset `json:"-"`
}

Candidate is the newest complete build of a component for this node, from its publisher.

type ComfyPacksRun

type ComfyPacksRun struct {
	Node     string // the node executable ("" = node)
	Script   string // the render directory's comfy-packs-update.mjs
	ComfyDir string // the ComfyUI install; "" leaves COMFY_DIR as the environment has it
	DryRun   bool
	Resolve  bool // print the candidates and change nothing
	Rollback bool
	JSON     bool
	Stdout   io.Writer
	Stderr   io.Writer
}

ComfyPacksRun is one invocation of the node-pack updater.

type Consumer

type Consumer struct {
	Endpoint string
}

Consumer is the local llama-swap, reached through the harness's own client: its unload with drain, never a kill.

func (Consumer) Ready

func (c Consumer) Ready(ctx context.Context, timeout time.Duration) error

Ready reports whether llama-swap answers /running, waiting up to timeout.

func (Consumer) RunningOn

func (c Consumer) RunningOn(ctx context.Context, live string) ([]string, error)

RunningOn lists the models llama-swap runs from the live path (matched on the argv llama-swap actually spawned).

func (Consumer) UnloadAll

func (c Consumer) UnloadAll(ctx context.Context, drain time.Duration) ([]string, error)

UnloadAll unloads, with drain, every running model, keep-set members included: the whole daemon is about to restart.

func (Consumer) UnloadOn

func (c Consumer) UnloadOn(ctx context.Context, live string, override bool, drain time.Duration) (unloaded, left []string, err error)

UnloadOn unloads, with drain, every model running from the live path so the next load starts the new build. A keep-set member is left (and named); a model that stays busy past the drain wait is an error and nothing further is touched. override unloads keep-set members too (only when the whole daemon is about to restart).

type Env

type Env struct {
	Home     string
	Config   FileConfig
	Endpoint string // the node's llama-swap, "" when none is configured
	Floors   floors.Set
	HTTP     *http.Client
	GitHub   string
	NPM      string
	// HFNode and HFRunner drive the HyperFrames browser refresh in stageNPM: the node executable and the resolved
	// render/compose-hyperframes.mjs. HFRunner empty = compose_script is unset, the browser is not refreshed.
	HFNode   string
	HFRunner string
	Gate     Gate
	Deps     nodeswap.Deps
	Out      io.Writer
	Logf     func(format string, args ...any)
	Now      func() time.Time
	// contains filtered or unexported fields
}

Env is everything the verb needs from the node. NewEnv builds the real one.

func NewEnv

func NewEnv(home string, cfg FileConfig, endpoint string, floorsJSON []byte, out io.Writer, logf func(string, ...any)) (*Env, error)

NewEnv builds the real environment: publisher hosts reached through the public-only dial guard, the default smoke gate (OfflineGate when update.gate.enabled is false), nodeswap's real deps.

func (*Env) LivePath

func (e *Env) LivePath(name string, opts Options) string

LivePath is where a component's live build is (the --live flag, config.json update.paths, the recorded live path, else <home>/<component>).

func (*Env) Run

func (e *Env) Run(ctx context.Context, opts Options) ([]Report, int)

Run walks the components. It returns every report and the process exit code.

func (*Env) WatchFirstLoad

func (e *Env) WatchFirstLoad(ctx context.Context, live string) (note string, err error)

WatchFirstLoad is the post-flip watch: llama-swap has just been told to unload its seats, so the next request loads the seat on the new build. It sends one short completion for the resident seat through llama-swap (which loads it), checks the seat now runs from the live path and answers /health through llama-swap. An error here makes the caller roll back ("post-flip load failed"). Nothing to watch (no endpoint, no chat seat in the yaml, llama-swap not answering) is a note, not a failure.

type FileConfig

type FileConfig struct {
	// Channel is "nightly" (default) or "release" (llama.cpp only).
	Channel string `json:"channel"`
	// Paths overrides a component's live path.
	Paths map[string]string `json:"paths"`
	// Restart overrides how the llama-swap consumer is restarted.
	Restart map[string]RestartSpec `json:"restart"`
	// LlamaSwapYAML is the rendered llama-swap config the llama flag check reads (default <home>/llama-swap.yaml).
	LlamaSwapYAML string `json:"llama_swap_yaml"`
	// Gate configures the side-port smoke gate and the post-flip watch (docs/systems/update.md, "Gate").
	Gate GateConfig `json:"gate"`
	// Home is the install root when neither --home nor $OFFLOAD_HOME names one (a node whose binary does not sit
	// under the root, and whose root is not ~/offload-stack).
	Home string `json:"home"`
	// Variant pins a component's build family (cuda13, cuda12, vulkan, cpu) when the live build and the node's
	// backend would pick another.
	Variant map[string]string `json:"variant"`
}

FileConfig is the `update` object of the node's config.json. Every field is optional.

func ReadFileConfig

func ReadFileConfig(path string) FileConfig

ReadFileConfig reads the `update` object of a config.json; a missing file or key is the zero value.

type Gate

type Gate interface {
	Name() string
	Run(ctx context.Context, in GateInput) GateResult
}

Gate is the seam between "the staged build passed the offline self-check" and "it is promoted". The default (OfflineGate) adds nothing to the offline self-check, which the verb always runs first. The side-port smoke (a completion on a side port under the GPU lease, compared back to back with the previous generation) is a later task and plugs in here through Env.Gate; it must return GateInconclusive, not GateReject, when it cannot get the lease.

type GateConfig

type GateConfig struct {
	// Enabled false turns the smoke gate (and the post-flip watch) off; default on.
	Enabled *bool `json:"enabled"`
	// LeaseWait is how long the gate queues for the GPU lease ("30m"); past it the answer is inconclusive.
	LeaseWait string `json:"lease_wait"`
	// SidePort is the loopback port the gate's llama-server listens on (default 11499).
	SidePort int `json:"side_port"`
	// LoadTimeout is how long a llama-server may take to answer /health ("5m").
	LoadTimeout string `json:"load_timeout"`
	// PostFlipTimeout is how long the first real seat load after the flip is watched ("5m").
	PostFlipTimeout string `json:"post_flip_timeout"`
}

GateConfig is `update.gate` of the node's config.json. Every field is optional.

func (GateConfig) LeaseWaitOr

func (c GateConfig) LeaseWaitOr() time.Duration

LeaseWaitOr is the lease queue budget.

func (GateConfig) LoadTimeoutOr

func (c GateConfig) LoadTimeoutOr() time.Duration

LoadTimeoutOr is the /health budget of one llama-server.

func (GateConfig) On

func (c GateConfig) On() bool

On reports whether the gate is enabled.

func (GateConfig) PortOr

func (c GateConfig) PortOr() (int, error)

PortOr is the side port, refusing a forbidden or invalid one.

func (GateConfig) PostFlipTimeoutOr

func (c GateConfig) PostFlipTimeoutOr() time.Duration

PostFlipTimeoutOr is the post-flip watch budget.

type GateInput

type GateInput struct {
	Component   string
	Candidate   *Candidate
	StagedDir   string
	PreviousDir string // "" when nothing is installed
	Live        string
}

GateInput is what a gate may look at: the candidate, the staged generation directory (already verified, extracted and offline self-checked) and the directory of the generation now serving, so a measuring gate can run both back to back.

type GateResult

type GateResult struct {
	Verdict Verdict
	Reason  string
	Numbers map[string]float64
}

GateResult is a gate's verdict with the reason and any numbers it measured (recorded in the generation's meta file).

type Generation

type Generation struct {
	ID          string `json:"id"`
	Path        string `json:"path"`
	Digest      string `json:"digest,omitempty"` // the publisher's digest of the archive that produced it
	Size        int64  `json:"size,omitempty"`
	Source      string `json:"source,omitempty"`
	InstalledAt string `json:"installed_at,omitempty"`
	Asset       string `json:"asset,omitempty"`
	// FileSHA256 is the hash of the installed file itself (single-file components), which is what a
	// rollback can verify without the archive.
	FileSHA256 string `json:"file_sha256,omitempty"`
}

Generation is one installed build of a component.

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is <home>/update.lock: one update at a time per node.

func AcquireLock

func AcquireLock(home string) (l *Lock, busy bool, holder string, err error)

AcquireLock takes the lock; busy is true (with who holds it) when another live run has it. A lock left by a process that is gone is taken over.

func (*Lock) Release

func (l *Lock) Release()

Release removes the lock file.

type Manifest

type Manifest struct {
	Path string
	// contains filtered or unexported fields
}

Manifest is the installer's installed.json. Every top-level key this package does not own (profile, backend, accelerators, ...) is kept verbatim: the fleet node reads them.

func LoadManifest

func LoadManifest(path string) (*Manifest, error)

LoadManifest reads installed.json. A missing file is an empty manifest; schema 1 (flat components) is read tolerantly: an entry that is not a schema 2 object is legacy and survives a write unchanged.

func (*Manifest) Backend

func (m *Manifest) Backend() string

Backend is the serving backend the installer recorded ("cuda", "vulkan", "cpu", ...), "" when unknown.

func (*Manifest) Has

func (m *Manifest) Has(name string) bool

Has reports whether a schema 2 state exists for the component.

func (*Manifest) Save

func (m *Manifest) Save() error

Save writes the manifest atomically (tmp + rename), schema 2.

func (*Manifest) State

func (m *Manifest) State(name string) *State

State returns the component's state, creating an empty one on first use.

type OfflineGate

type OfflineGate struct{}

OfflineGate is the default gate: only the offline self-check, already done, stands between staging and promotion.

func (OfflineGate) Name

func (OfflineGate) Name() string

Name implements Gate.

func (OfflineGate) Run

Run implements Gate.

type Options

type Options struct {
	Components  []string // already expanded ("all" -> AllComponents)
	Channel     string   // "", "nightly" or "release"
	DryRun      bool
	ResolveOnly bool
	Rollback    bool // roll the (single) component back to its previous generation
	Live        string
	// Explicit is true when the operator named the component (--component X): only then may the verb install a
	// component the node does not have. "all" updates what the node runs and installs nothing.
	Explicit bool
}

Options is one invocation of the verb.

type Rejected

type Rejected struct {
	ID     string `json:"id"`
	Reason string `json:"reason"`
	TS     string `json:"ts"`
}

Rejected is a candidate that failed and is never retried.

type RepointResult

type RepointResult struct {
	Backup   string
	Replaced int
	LDLines  int
	Diff     []string
}

RepointResult is what a repoint changed.

func Repoint

func Repoint(yamlPath, live string, from []string, now time.Time) (*RepointResult, error)

Repoint rewrites a hand-kept llama-swap yaml so it names the live path instead of a build directory: it backs the file up (<yaml>.bak-<yyyyMMdd-HHmmss>), replaces every occurrence of a build-named directory, and of each directory in from (a build kept under a name with no build number, such as /opt/llama-vulkan), with live, and on Linux sets any LD_LIBRARY_PATH= in a block that was repointed to the live path's bin directory. A "bin" segment right after a replaced directory is dropped when the live build has no bin folder: the publisher's archives are flat, a source tree keeps its programs in build/bin. It never re-renders the file. Nothing is written (and no backup made) when nothing matches.

type Report

type Report struct {
	Component string     `json:"component"`
	Installed string     `json:"installed"`
	Resolved  string     `json:"resolved,omitempty"`
	Action    string     `json:"action"`
	Detail    string     `json:"detail,omitempty"`
	Previous  string     `json:"previous,omitempty"`
	Candidate *Candidate `json:"candidate,omitempty"`
	Notes     []string   `json:"notes,omitempty"`
	Live      string     `json:"live,omitempty"`
	// contains filtered or unexported fields
}

Report is one component's result.

type Resolver

type Resolver struct {
	HTTP    *http.Client
	GitHub  string // API base
	NPM     string
	Token   func() string
	Floors  floors.Set
	Variant string
	Channel string
	Log     func(format string, args ...any)
}

Resolver talks to the publishers.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, def *compDef, etag string) (c *Candidate, newETag string, notModified bool, err error)

Resolve returns the newest complete candidate for def. etag is the stored ETag of the first listing page ("" to force a fresh read); notModified is true when the publisher answered 304.

type RestartSpec

type RestartSpec struct {
	Task    string `json:"task"`
	Command string `json:"command"`
	None    bool   `json:"none"`
}

RestartSpec names how a consumer restarts: a scheduled task, a shell command, or None (no restart: the swap is verified by hash alone).

type Seat

type Seat struct {
	ID    string
	Argv  []string // the expanded cmd line, argv[Exe] is the llama-server program
	Exe   int
	Env   []string
	Model string
	Size  int64
}

Seat is one llama-server seat of the rendered llama-swap yaml.

func PickSeat

func PickSeat(yamlPath, live string) (*Seat, error)

PickSeat chooses the seat the gate and the post-flip watch copy: among the yaml's llama-server chat seats that run from the live path (embedding and reranking seats cannot answer a chat completion), a resident one (ttl 0 or below) first, else the one with the smallest model file, so the load is the cheapest representative one.

type SmokeGate

type SmokeGate struct {
	Self       string // this binary (re-run under the lease)
	ConfigPath string // config file the lease wrapper reads, "" = its default
	YAML       string // the rendered llama-swap yaml
	Cfg        GateConfig
	Logf       func(format string, args ...any)
}

SmokeGate is the Gate for llama. Other components pass.

func (*SmokeGate) Name

func (*SmokeGate) Name() string

Name implements Gate.

func (*SmokeGate) Run

func (g *SmokeGate) Run(ctx context.Context, in GateInput) GateResult

Run implements Gate.

type State

type State struct {
	Current   *Generation `json:"current,omitempty"`
	Previous  *Generation `json:"previous,omitempty"`
	Rejected  []Rejected  `json:"rejected,omitempty"`
	ETag      string      `json:"etag,omitempty"`
	CheckedAt string      `json:"checked_at,omitempty"`
	Floor     string      `json:"floor,omitempty"`
	// Dest is the installer's local name for the component, carried through untouched.
	Dest string `json:"dest,omitempty"`
	// Live is the live path the verb last worked on (a junction, symlink or file): a later run with no --live and no
	// update.paths finds the component there.
	Live string `json:"live,omitempty"`
	// Staged is the generation the installer left on disk, behind a running engine, for the verb to promote
	// (<live>-versions/<Staged>); the verb clears it once it has promoted, or superseded it with a newer build.
	Staged string `json:"staged,omitempty"`
	// contains filtered or unexported fields
}

State is installed.json schema 2 for one component.

type Verdict

type Verdict int

Verdict is a gate's answer about a staged build.

const (
	// GatePass lets the build be promoted.
	GatePass Verdict = iota
	// GateReject refuses the build: it is recorded in rejected[] and never retried.
	GateReject
	// GateInconclusive means the gate could not run (a lease timeout, a busy card): nothing changes and the next
	// run tries again. It is not a rejection.
	GateInconclusive
)

Jump to

Keyboard shortcuts

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