live

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 6 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 live tracks what the node is doing right now and what it did a moment ago: the requests in flight on each model and a bounded ring of the ones that finished. It answers "the GPU spiked two minutes ago — was that flockd, which model, and for whom?".

It records facts about a request, never its content: model, kind, origin, times, token counts and an outcome word. No prompt, no output, no error text (runtime errors can quote input) and no identifier from outside the node — the id is a counter local to this process.

The hot path is one mutex-guarded map insert at start, one atomic add per token chunk, and one ring write at the end.

Index

Constants

View Source
const (
	KindChat       = "chat"
	KindCompletion = "completion"
	KindEmbedding  = "embedding"
	KindDecision   = "decision"
)

Kinds of request (api/openapi.yaml RequestKind).

View Source
const (
	// OriginLocal is the local API on 127.0.0.1 (/v1/*): the operator's
	// own tools.
	OriginLocal = "local"
	// OriginMesh is a coordinator dispatch: a customer request, or a
	// canary — a node cannot tell the two apart, by design.
	OriginMesh = "mesh"
	// OriginChallenge is a fingerprint challenge from the coordinator.
	OriginChallenge = "challenge"
)

Origins: who asked (api/openapi.yaml RequestOrigin).

View Source
const (
	OutcomeOK           = "ok"
	OutcomeError        = "error"
	OutcomeCancelled    = "cancelled"
	OutcomeInvalidInput = "invalid_input"
)

Outcomes of a finished request (api/openapi.yaml RequestOutcome).

View Source
const (
	EventStarted  = "request_started"
	EventFinished = "request_finished"
)

SSE event names.

View Source
const DefaultCapacity = 200

DefaultCapacity is how many finished requests a Tracker keeps.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counts

type Counts struct {
	Total  int
	ByKind map[string]int
}

Counts is the in-flight tally of one model.

type Finished

type Finished struct {
	ID               string    `json:"id"`
	Model            string    `json:"model"`
	Kind             string    `json:"kind"`
	Origin           string    `json:"origin"`
	StartedAt        time.Time `json:"started_at"`
	DurationMS       int64     `json:"duration_ms"`
	PromptTokens     int       `json:"prompt_tokens"`
	CompletionTokens int       `json:"completion_tokens"`
	Outcome          string    `json:"outcome"`
}

Finished is a request that ended.

type Handle

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

Handle is one in-flight request. A nil *Handle is inert.

func (*Handle) AddTokens

func (h *Handle) AddTokens(n int)

AddTokens counts generated tokens as they stream.

func (*Handle) Finish

func (h *Handle) Finish(outcome string, promptTokens, completionTokens int)

Finish moves the request to the recent ring. Only the first call counts. completionTokens < 0 means "unknown": the streamed count is used (a cancelled generation has no usage chunk).

type InFlight

type InFlight struct {
	ID        string    `json:"id"`
	Model     string    `json:"model"`
	Kind      string    `json:"kind"`
	Origin    string    `json:"origin"`
	StartedAt time.Time `json:"started_at"`
	ElapsedMS int64     `json:"elapsed_ms"`
	Tokens    int       `json:"tokens"`
}

InFlight is a request being served. Tokens is what has been generated so far (0 for embeddings and decisions, which generate nothing).

type Tracker

type Tracker struct {
	// Events, when set before use, receives request_started and
	// request_finished.
	Events *events.Hub
	// contains filtered or unexported fields
}

Tracker holds the in-flight set and the recent ring. Safe for concurrent use; a nil *Tracker tracks nothing, so callers need no nil checks.

func New

func New(n int) *Tracker

New builds a tracker keeping the last n finished requests (DefaultCapacity when n <= 0).

func (*Tracker) CountsByModel

func (t *Tracker) CountsByModel() map[string]Counts

CountsByModel tallies the in-flight requests per model.

func (*Tracker) InFlight

func (t *Tracker) InFlight() []InFlight

InFlight lists the requests being served, oldest first.

func (*Tracker) Recent

func (t *Tracker) Recent(limit int) []Finished

Recent lists finished requests, newest first, at most limit (<= 0: all that are kept).

func (*Tracker) Start

func (t *Tracker) Start(model, kind, origin string) *Handle

Start records a request entering the runtime.

Jump to

Keyboard shortcuts

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