swapclient

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: 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 swapclient is the harness's SINGLE adapter onto the vendored llama-swap client (`tools/llamaswap`, package `llamaswap-pp-cli/pkg/llamaswap`).

It exists because the harness had grown three independent readers of GET /v1/models with two different response schemas and three different URL normalizations, and they disagreed about the one thing that matters: llama-swap publishes CANONICAL model ids in `data[].id` and the names the harness actually binds — `offload-e4b`, `gemma4-26b-a4b`, `gemma4-e2b` — only inside `meta.llamaswap.aliases`. Two of the three readers matched ids alone, so `doctor`, `acceptance`, and `report` declared every correctly-served alias MISSING on a healthy box.

Everything in this package is a thin pass-through. The alias rules, the keep-set-from-config rule, and the /upstream auto-start guard live in pkg/llamaswap and are documented there; nothing here re-implements them.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout is the per-request deadline used when a caller passes none. Deliberately short: every caller here is a probe on a health/status path, and a probe that outlives the command it informs is a hang, not a check.

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(endpoint string) string

BaseURL turns a harness `endpoint` (config.Config.Endpoint) into the llama-swap ROOT that pkg/llamaswap dials.

The harness's own convention has always been that `endpoint` may or may not carry the trailing `/v1` — the chat client appends CompletionPath, while /running, /upstream, and /api/models all hang off the root. The three old readers each normalized this differently (one appended "/v1/models" blindly and would have produced "/v1/v1/models" for a /v1-suffixed endpoint, one appended "/v1" when absent, one cut at the first "/v1" occurrence). This is the one rule.

func HTTPStatus

func HTTPStatus(err error) (int, bool)

HTTPStatus reports the HTTP status llama-swap answered with when err is a failed read that got an answer (a non-2xx), and false for a failure that got none (a refused connection, a timeout).

func New

func New(endpoint string, timeout time.Duration) (*llamaswap.Client, error)

New builds a llama-swap client bound to the root behind endpoint.

An EMPTY endpoint is a caller error, not a default: pkg/llamaswap would happily fall back to its own 127.0.0.1:11436 literal, which would make a probe report on a machine the caller never named. Callers guard for it and report "unchecked".

func NewGuarded

func NewGuarded(endpoint string, timeout time.Duration) (*llamaswap.Client, error)

NewGuarded is New with the tailnet DIAL gate installed — for probes whose endpoint is REMOTE and operator-configured (the cascade remote lanes), as opposed to this box's own llama-swap.

It exists because the vendored client builds a plain &http.Client{} on the DEFAULT transport when no HTTPClient is supplied: ProxyFromEnvironment live, no dial-time address check. That is fine for a loopback probe and wrong for a configured remote, because netguard.TailnetURL admits a dotless MagicDNS short name on SHAPE alone (it deliberately touches no DNS at config time), so the only thing that can prove where that name actually resolves is the per-dial check in netguard.SafeTransport — which also strips the proxy, so nothing can dial on our behalf outside the gate. Without this, ADR 0023's "re-checked at every dial" was false for the lane roster probe.

Timeout is carried on BOTH the Options and the supplied client: the vendored New honors a supplied client's own Timeout as-is, so leaving it zero would silently hand a remote probe an unbounded deadline.

Types

type Roster

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

Roster is one alias-aware snapshot of GET /v1/models.

The zero value is an empty roster that serves nothing, which is why every caller must branch on the fetch error rather than on Len(): "the roster is empty" and "the roster could not be read" are different facts, and conflating them is how a health check goes green against a dead endpoint.

func FetchRoster

func FetchRoster(ctx context.Context, endpoint string, timeout time.Duration) (Roster, error)

FetchRoster reads the live roster from the llama-swap behind endpoint.

func FetchRosterGuarded

func FetchRosterGuarded(ctx context.Context, endpoint string, timeout time.Duration) (Roster, error)

FetchRosterGuarded is FetchRoster for a REMOTE endpoint: same roster read, over NewGuarded's tailnet-gated client. Use it for any base the operator configured as remote; FetchRoster stays the right call for this node's own local llama-swap, which is loopback by construction and needs no gate.

func FetchRosterWith

func FetchRosterWith(ctx context.Context, client *http.Client, endpoint string, timeout time.Duration) (Roster, error)

FetchRosterWith is FetchRoster over the caller's own HTTP client, for a reader that already holds one for the other reads of the same observation (seatload reads /running and the seat's gauge over it): one transport for every read, so a caller's dialer or guarded transport also covers the roster. The client's own Timeout is honored as-is (pkg/llamaswap); timeout and ctx still bound the read. A nil client is FetchRoster.

func NewRoster

func NewRoster(models []llamaswap.Model) Roster

NewRoster wraps an already-fetched model list. For callers that hold a client.

func (Roster) Canonical

func (r Roster) Canonical(nameOrAlias string) (string, bool)

Canonical resolves nameOrAlias to the canonical id llama-swap lists it under — ids first, then `meta.llamaswap.aliases`, case-insensitively like Serves. It exists because llama-swap's /running names models by canonical id ONLY, while the harness binds seats by alias: a reader that matches /running by the bound name reads an alias-bound seat as "not loaded" (the 0.113.16–19 drain defect). An empty or unserved name resolves to ("", false).

func (Roster) IDs

func (r Roster) IDs() []string

IDs returns the canonical model ids in roster order.

func (Roster) Len

func (r Roster) Len() int

Len is the number of roster entries.

func (Roster) Names

func (r Roster) Names() []string

Names returns every name this roster answers Serves(true) for — each canonical id FOLLOWED BY its aliases, in roster order, deduped case-insensitively — for a caller that must publish (not merely check) the full servable-name set.

It exists for the same reason the package doc comment (swapclient.go:9) gives for Serves matching aliases at all: llama-swap publishes canonical ids in data[].id, but the names the harness actually binds — agent seats very much included (agent-pool -> qwen3.8-27b-vllm, offload-e4b -> gemma-4-e4b) — live only under meta.llamaswap.aliases. IDs() alone reproduces exactly that defect one level up: a consumer that advertises IDs() as "what this node serves" and a peer that checks the advertisement against an alias seat name will never agree, so a healthy alias-bound seat reads as unserved and the node silently drops out of consideration — the plannerUnserved lesson, again, one hop further down the pipe. Names() is the fix: publish everything Serves() would say yes to, not just the id half of it.

func (Roster) Serves

func (r Roster) Serves(nameOrAlias string) bool

Serves reports whether nameOrAlias is served, matching canonical ids FIRST and then `meta.llamaswap.aliases` — case-insensitively, as pkg/llamaswap resolves. An empty name is never served.

Jump to

Keyboard shortcuts

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