displaywatch

package
v0.207.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 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 displaywatch is the display layer's guard AFTER admission (ADR 0075).

The layer's guards (presence, display_floor) decide once, at the moment of a placement. A twin that passed them then sits on the desktop's card until llama-swap's idle ttl (300 s) takes it down, however soon the operator is back at the desk or a game takes the card's memory, and a twin that ANOTHER llama-swap client loaded (the twins are ordinary llama-swap models once rendered) was never asked at all. This package closes that gap from the side that can see it: while a seat of the display layer is loaded, it re-asks the layer's own desktop guards (placement.ResidentVerdict) on a short period, and when either refuses it unloads the layer's seats through llama-swap's per-model route.

What it will and will not do, because a periodic unloader is a new posture for this harness (a read never unloads: internal/modelaffinity/seatyield.go):

  • It unloads only models the display layer names (its router's model_map twins, and a seat's own model if one is declared). The pair seat, the memory stack and every other layer's seats are never its to touch, whatever the readings say.
  • It unloads through the vendored llama-swap client's per-model route and never the total one: a route that is absent is an error, not a licence to unload everything.
  • It does not drain. The reason it unloads is that the desktop needs the memory now, so a request in flight on the twin dies with llama-swap's 502. A mechanical cascade call answers that as a structured defer and the caller does the task itself; ADR 0066's wait and re-issue is the agent loop's recovery and the display layer declares no agent seat.
  • It fails loud and recovers nothing: an unload that fails is logged, recorded and retried at the next check, with nothing else unloaded to make room.
  • Every unreadable input is a refusal, as at admission.

It runs in fleet-serve, the one always-on process of a node, in the console session: the presence probe in `auto` mode reads the console session's idle time, which a process in another session cannot see. Its last action and a heartbeat go to a small state file under the machine-wide state root, because offload_status answers from another process (StatusView reads it).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 StatusView

func StatusView(cfg config.Config, now time.Time) map[string]any

StatusView is the display_guard field of offload_status for this box: whether the watcher is alive, and the last thing it did. nil (omitted) when there is nothing to say: no display layer with a desktop guard, or one that is dormant and has never acted.

"Alive" is a heartbeat the watcher's process wrote recently. offload_status runs in another process from fleet-serve, so a box whose fleet-serve is not running (or was started before the layer was seeded) shows watching=false: an awake display layer with nothing re-checking it is the state this field exists to make visible.

Types

type Action

type Action = displaystate.Action

Action and State are the state file's shape (internal/displaystate), which the admission guard reads as well as offload_status.

type Deps

type Deps struct {
	// Running lists what llama-swap has loaded. An error means /running could not be read.
	Running func(ctx context.Context) ([]Model, error)
	// Unload takes one model down through llama-swap's per-model route.
	Unload func(ctx context.Context, model string) error
	// Devices is the latest per-card reading; !ok = none, or too old to trust.
	Devices func() ([]gpuprobe.Device, bool)
	// Presence reads the operator's presence for the config's mode.
	Presence func() placement.Presence
	Now      func() time.Time
	Logf     func(format string, args ...any)
	// StatePath is where the last action and the heartbeat are kept for offload_status and for the
	// admission guard. "" keeps none.
	StatePath string
	// StatePathErr is why StatePath could not be resolved, when it could not. The watcher says so at
	// start and in the status note: with no state file there is no heartbeat, and the display layer's
	// admission (which asks whether a watcher is alive) will refuse for want of one.
	StatePathErr error
}

Deps are the reads and writes a check makes, so a test assembles a box. A nil Now or Logf takes the production one; the rest are required.

func Production

func Production(cfg config.Config, devices func() ([]gpuprobe.Device, time.Time, bool)) Deps

Production wires the watcher to this box: llama-swap's /running and its per-model unload route, the presence probe, and the device sample the caller already holds (fleet-serve's 2 s sampler), so the check execs no nvidia-smi of its own.

type Model

type Model struct {
	ID    string
	State string
}

Model is one row of llama-swap's /running.

type Outcome

type Outcome struct {
	// Loaded are the watched models llama-swap has loaded.
	Loaded []string
	// Reasons is why they are being taken down; empty when every guard holds.
	Reasons  []string
	Unloaded []string
	// Failed lists the unloads that failed, as "model: error".
	Failed []string
	// ReadErr is set when /running could not be read, which unloads nothing.
	ReadErr error
}

Outcome is what one check found and did.

type State

type State = displaystate.State

Action and State are the state file's shape (internal/displaystate), which the admission guard reads as well as offload_status.

type Watcher

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

Watcher is the post-admission guard of the display layer.

func New

func New(cfg config.Config, deps Deps) *Watcher

New builds the watcher for a config, or nil when there is nothing to watch: no display layer with a desktop guard, or display_watch_sec negative (the operator's switch).

func (*Watcher) Check

func (w *Watcher) Check(ctx context.Context) Outcome

Check runs one check. It reads /running first and touches nothing else while no watched model is loaded, so an idle display layer costs one local GET.

func (*Watcher) Interval

func (w *Watcher) Interval() time.Duration

Interval is the period between checks.

func (*Watcher) Models

func (w *Watcher) Models() []string

Models lists every model the watcher may unload, for the startup banner.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context, tick <-chan time.Time)

Run checks once at start (a twin loaded before this process came up is no less on the desktop's card), then on every tick, until ctx ends.

func (*Watcher) RunEvery

func (w *Watcher) RunEvery(ctx context.Context)

RunEvery checks on the configured period until ctx ends.

Jump to

Keyboard shortcuts

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