backendchain

package
v0.206.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 16 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 backendchain answers, for every lane and every seat of a node, one question: which serving engine is answering for it right now, and how do we know.

The idea is the ordered backend chain with a real probe of Agent-Reach's `doctor` (a channel has an ordered list of backends, each with a real probe, and the report says which one is active and why), rebuilt here without any of its dependencies and kept engine-neutral: the report names an engine KIND ("llama.cpp", "vllm", "rkllm", "whisper.cpp"), never a product path, so a new engine registers by adding one row to the classification table (classify.go) and changes no schema.

Four fields describe a verdict, on every lane and every seat:

active_backend  the engine kind that is answering, or "none". On a lane it is the engine of the seat
                the lane is bound to: the lane routes there, whatever else of its chain is up
backend_chain   the ordered engine kinds the lane or seat may use
backend_probe   how deep the evidence goes: "process", "endpoint" or "completion"
backend_reason  why that backend was chosen, or why none was (it names the failures that came first)

The default probe is cheap and LOADS NOTHING: it reads llama-swap's roster and its running list, and asks a seat that is already loaded for its own health endpoint. It never sends a completion, and never goes through llama-swap's /upstream path (that path loads a model on demand and resets the idle timer). A 1-token completion exists only behind an explicit option, because it loads an idle seat and the load can evict a seat that is running (internal/seatguard exists for the same reason). It goes only to a seat that is already running, or, on a box where nothing is running, to one seat; any other seat is reported as not probed, over the running seat the load would have been, and a seat with no chat route is never sent one.

The existing `backends` field of /fleet/health (hardware tags such as "vulkan" and "cpu", ADR 0054) is a different thing and is untouched.

Index

Constants

View Source
const (
	EngineLlamaCpp = "llama.cpp"
	EngineVLLM     = "vllm"
	EngineRKLLM    = "rkllm"
	// EngineWhisperCpp is the speech-to-text server.
	EngineWhisperCpp = "whisper.cpp"
	// EngineForecast is the time-series forecast server (`forecast-serve`, a Python server).
	EngineForecast = "forecast"
	// EngineNone is active_backend when no backend of the chain can serve.
	EngineNone = "none"
	// EngineUnknown is the kind of a seat that can serve but whose engine the config does not say (an
	// entry whose command names no engine this table knows, or no serving config to read it from), and
	// the active_backend of a row whose probe saw nothing because it timed out, or whose seat is served by
	// another node.
	EngineUnknown = "unknown"
)

Engine kinds. The set is open: a consumer treats an unfamiliar kind as an opaque string.

View Source
const (
	// ProbeProcess: the verdict rests on llama-swap's own state (the roster and the running list).
	ProbeProcess = "process"
	// ProbeEndpoint: the seat was loaded and its own health endpoint was asked (the seat's own address,
	// never through llama-swap).
	ProbeEndpoint = "endpoint"
	// ProbeCompletion: a 1-token completion ran against the seat. Only with the explicit option.
	ProbeCompletion = "completion"
)

Probe levels, shallowest first.

Variables

This section is empty.

Functions

func ClassifyEngine

func ClassifyEngine(f SeatFacts) string

ClassifyEngine names the engine kind that serves a seat: the table's first row that matches what the seat's own declaration and command say, else the kind a shipped table declares for it, else EngineUnknown.

func SetTierLookup

func SetTierLookup(fn TierLookup) (restore func())

SetTierLookup installs the tier-table reader and returns a function that puts the previous one back.

Types

type Candidate

type Candidate struct {
	// Seat is the model name the lane would call (a canonical id or an alias).
	Seat string
	// Engine is the kind; empty asks the collector to classify it from the serving config.
	Engine string
	// Bound is true for the seat the lane's config actually points at, and that seat's engine is what
	// answers for the lane. A chain may list preferred seats the lane is not bound to (a tier's preferred
	// vLLM seat while the lane serves its llama.cpp fallback): they are probed and named in the reason,
	// and they do not answer for the lane.
	Bound bool
}

Candidate is one backend of a chain: a seat and the engine kind that serves it.

type Entry

type Entry struct {
	// Lane is the lane the verdict is about (the config's status key: "agent", "workhorse", ...);
	// empty on a seat row.
	Lane string `json:"lane,omitempty"`
	// Seat is the seat the verdict names: the one that is answering (a lane's bound seat), or, when none
	// is, the lane's bound seat (the first seat of the chain on a lane with no binding).
	Seat          string   `json:"seat,omitempty"`
	ActiveBackend string   `json:"active_backend"`
	BackendChain  []string `json:"backend_chain"`
	BackendProbe  string   `json:"backend_probe"`
	BackendReason string   `json:"backend_reason"`
}

Entry is one verdict. It is the wire shape of /fleet/health's lane_backends and seat_backends and the source of doctor's rows. Every field is additive: a reader that predates it ignores the keys.

func Resolve

func Resolve(ctx context.Context, lane Lane, p Prober) Entry

Resolve reports which backend answers for a lane, and why.

A lane routes to the seat its config binds (the Bound candidate), so the engine that answers is that seat's engine and nothing else's: a preferred seat of the chain that is up while the lane is bound to another does not answer for it, and the reason says so ("the preferred vllm seat X is available (...) but does not answer for this lane, which is bound to Y"). A bound seat that fails is "none", with every failure named, even when another seat of the chain is up: the lane would call the bound seat and fail. A preferred seat that fails while the lane is bound to a later one is named in front of the answer ("vllm seat X unavailable: ...; fell to llama.cpp seat Y: ...").

A candidate whose probe saw nothing (a timeout: Verdict.Unknown) is neither up nor down. Bound to it, the lane reads "unknown"; a preferred one is named as not confirmed and does not answer for a lane bound elsewhere.

A lane with no binding (a chain whose seats the config does not name) takes the first candidate whose probe passes or could not be confirmed. When none does the answer is "none", at the deepest probe level any candidate reached.

type Lane

type Lane struct {
	Name  string
	Chain []Candidate
}

Lane is a named chain: candidates in preference order.

func PlanLanes

func PlanLanes(cfg config.Config) []Lane

PlanLanes derives the lanes to report from a config: one per model route that is bound and that doctor checks against the roster (the config's own table, config.ModelRoutes, so doctor, offload_status and this report read one list; a route doctor does not diff, embed_model, has no seat whose absence means a route cannot run, so it is not a lane here either). Every lane is its one bound seat, except the agent lane of a box whose tier declares a vLLM agent seat: the tier prefers that seat and serves a llama.cpp seat when the vLLM prerequisites are missing, so the lane's chain is [the vLLM seat, the llama.cpp fallback], with the bound one marked.

type Options

type Options struct {
	// HTTP is the client every read goes over; the caller supplies the one its package already builds for
	// the configured llama-swap endpoint (a bare client here would be a new site for the ADR 0042 lint).
	// Required: without it nothing can be read and every entry is "none".
	HTTP *http.Client
	// ProbeCompletion adds a 1-token completion probe. It LOADS an idle seat, so it is off unless a
	// person asked for it (doctor --probe-completion); /fleet/health never sets it. A completion goes only
	// to a seat that is already running (it loads nothing), or, on a box where nothing is running, to the
	// one seat the run is allowed to load; a seat with no chat route is never sent one.
	ProbeCompletion bool
	// ProbeTimeout bounds each cheap read; zero means 3 s.
	ProbeTimeout time.Duration
	// CompletionTimeout bounds each completion probe; zero means 6 min (a cold vLLM load takes minutes).
	CompletionTimeout time.Duration
}

Options tune one collection.

type Prober

type Prober interface {
	Probe(ctx context.Context, c Candidate) Verdict
}

Prober judges one candidate. Implementations must not load a model unless they were asked to run a completion probe.

type ProberFunc

type ProberFunc func(ctx context.Context, c Candidate) Verdict

ProberFunc adapts a function to Prober.

func (ProberFunc) Probe

func (f ProberFunc) Probe(ctx context.Context, c Candidate) Verdict

Probe calls f.

type Report

type Report struct {
	Lanes []Entry `json:"lane_backends,omitempty"`
	Seats []Entry `json:"seat_backends,omitempty"`
}

Report is every lane and every seat of one node.

func Collect

func Collect(ctx context.Context, cfg config.Config, opt Options) Report

Collect reads the node once and reports every lane and every seat.

One observation backs the whole report: llama-swap's roster (GET /v1/models) and running list (GET /running) are read once, the serving config is read once, and a loaded seat is asked for its own health endpoint at most once however many lanes point at it. None of that loads a model: the seat's health endpoint is asked at the seat's own address (seatload.SeatURL), never through /upstream, which loads on demand and resets the idle timer. The default is therefore safe to run against a node that is serving, and to run on every /fleet/health refresh.

Every row's starting state (loaded, not loaded, loading) comes from that one opening reading of the running list, the snapshot. Only the explicit completion probe reads the list again, immediately before each completion (see completionVerdict), and that later reading decides whether a completion may be sent; it never rewrites what a row says about the state the report began with.

A seat has one engine kind wherever it is read. The kinds a lane's plan declares (the tier table's preferred and fallback seats) are registered first, and every candidate of every lane and every seat row is then classified by the same rule, engineOf.

type SeatFacts

type SeatFacts struct {
	// DeclaredVLLM: the box (vllm_seats) or the tier table says a vLLM engine serves the seat. A vLLM
	// entry runs through a wrapper script, so its command cannot name the engine.
	DeclaredVLLM bool
	// Cmd is the seat's command line from the serving config, macros expanded, or the command llama-swap
	// reports it spawned when the seat is loaded; empty when neither is known.
	Cmd string
	// Declared is the kind a table the box ships (the tier table) declares for the seat. It answers only
	// when nothing the seat's own command or declaration says does, so one seat has one kind wherever it
	// is read.
	Declared string
}

SeatFacts is what is known about one seat when its engine is classified.

type TierLookup

type TierLookup func(cfg config.Config, agentSeat string) (TierSeat, bool)

TierLookup answers whether the box's tier declares a vLLM agent seat that agentSeat is (or is the fallback of). The tier table is embedded in the command package, so the command installs the reader (SetTierLookup) and every consumer of PlanLanes sees the same chain.

type TierSeat

type TierSeat struct {
	ID       string
	Aliases  []string
	Fallback string
}

TierSeat is the vLLM agent seat an installed tier declares, with the llama.cpp seat the tier serves when the vLLM prerequisites are missing (vllmseat.Spec.Fallback).

type Verdict

type Verdict struct {
	OK bool
	// Unknown: the probe saw nothing (it timed out), so the candidate is neither up nor down, and a lane
	// bound to it reads "unknown", not "none". OK is false.
	Unknown bool
	// Probe is the deepest level the evidence reached; empty reads as ProbeProcess.
	Probe string
	// Detail is one short clause: what was seen. It never carries an address, a path or a command line,
	// because it is published to every node that reads /fleet/health.
	Detail string
}

Verdict is one candidate's probe result.

Jump to

Keyboard shortcuts

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