displaystate

package
v0.209.1 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: 7 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 displaystate is what the display layer's post-admission watcher (internal/displaywatch, ADR 0075) leaves for everyone else: the small state file under the machine-wide state root that carries its heartbeat, its last action and whether it can see llama-swap, and the reader that turns that file into "is a watcher alive".

It is a leaf package (config and gpulease only) because two packages that cannot import each other both need it: internal/displaywatch writes it and imports internal/placement for the guards it re-asks, and internal/placement reads it so the display layer's admission can refuse while nothing is watching a loaded twin. Putting the file's shape and Alive here is what keeps that out of an import cycle.

Index

Constants

View Source
const (
	// StateFileName is the file under the machine-wide state root that carries the watcher's last
	// action and heartbeat to offload_status and to the admission guard.
	StateFileName = "display-watch.json"

	// HeartbeatEvery bounds how often a check that found nothing to do rewrites the state file: a
	// reader tells a live watcher from a dead one by it, and a rewrite per 10 s tick would be churn.
	HeartbeatEvery = 30 * time.Second

	// CheckBudget bounds one check: the /running read and every unload it issues.
	CheckBudget = 20 * time.Second
)

Variables

This section is empty.

Functions

func Alive

func Alive(cfg config.Config, now time.Time) (bool, string)

Alive says whether a watcher is checking a loaded display twin on this box right now, from the heartbeat it leaves, and the reason in words. It is the question the display layer's admission asks before it lets a twin onto the operator's card: a twin that is admitted with nothing watching it stays there until llama-swap's 300 s idle ttl, however soon the operator is back.

Not alive, each with its own reason: display_watch_sec negative (the operator switched the check off, and a layer that leaves only when something watches it does not open without it); no state path; no heartbeat; a heartbeat older than StaleAfter; a watcher whose /running cannot be read (it is up and blind). Whether the layer guards the desktop at all is the caller's question, not this one's.

The watcher's period is read from cfg as this process knows it. A change to operator_presence or display_watch_sec reaches the watcher only when fleet-serve restarts, which re-reads the config: the watcher does not re-read it between checks.

func StaleAfter

func StaleAfter(interval time.Duration) time.Duration

StaleAfter is how old a heartbeat may be before the watcher is called dead: three beats, where a beat is the longer of the check period and the heartbeat throttle, plus the check's own budget.

func StatePath

func StatePath(cfg config.Config) (string, error)

StatePath is where the watcher leaves its state: under the machine-wide state root, beside the GPU lease, never inside a cloud-synced folder.

func Write

func Write(path string, st State) error

Write replaces the state file atomically: a reader sees the old file or the new one, never half of either. On Windows a rename onto a file a reader holds open can fail for an instant, so it is retried briefly.

Types

type Action

type Action struct {
	At    time.Time `json:"at"`
	Layer string    `json:"layer"`
	// Models are the layer's models that were loaded and failed a guard; Unloaded are the ones that
	// came down. Error carries every unload that failed, which leaves its twin where it was.
	Models   []string `json:"models"`
	Unloaded []string `json:"unloaded,omitempty"`
	Reasons  []string `json:"reasons"`
	Error    string   `json:"error,omitempty"`
}

Action is one thing the watcher did: the twins it set out to unload and why.

type State

type State struct {
	CheckedAt   time.Time `json:"checked_at"`
	IntervalSec int       `json:"interval_sec"`
	LastAction  *Action   `json:"last_action,omitempty"`
	// ReadErr and BlindSince are set while llama-swap's /running cannot be read: a watcher that cannot
	// see what is loaded cannot see a twin to unload, so it is not watching however fresh its
	// heartbeat. BlindSince is when the unreadable streak began; both clear on the first good read.
	ReadErr    string     `json:"read_err,omitempty"`
	BlindSince *time.Time `json:"blind_since,omitempty"`
}

State is what the watcher leaves for offload_status and the admission guard.

func Read

func Read(path string) (State, bool)

Read loads the state file; !ok when there is none, or it does not parse, or it carries no heartbeat.

Jump to

Keyboard shortcuts

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