eval

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 18 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 eval is the hub's evaluation of the harness (moved from the old gateway so that it can be switched off): on a schedule it queues the golden tasks of a suite for a machine, hands them one at a time to the machine's runner, reads the verdicts back, closes the batches and warns the owner when the smoke suites get worse. The runs are paid from the machine owner's own subscription, so nothing starts for a person whose rollout switch is off, nor when the subscription's windows are filling up, nor when the week's runs already took their share. The tables are those of migration 0062 (docs/hub/eval.md).

Index

Constants

View Source
const SwitchScheduler = "hub-eval"

SwitchScheduler is the rollout switch (docs/hub/rollout-switches.md) that lets the scheduler queue and start runs on the machines of a person. Off for everyone until a row says otherwise.

Variables

View Source
var ErrNotDelivered = errors.New("eval: the machine did not get the request")

ErrNotDelivered is what a Link returns when nothing reached the machine (no connection, the hub restarting): the run goes back to the queue. Any other error may come after the runner started, so the run stays claimed and the poll decides.

Functions

func LatestSlot

func LatestSlot(days []int, atMsk string, every int, now time.Time) (time.Time, bool)

LatestSlot is the newest slot of the schedule that is not after now; ok is false for a schedule with no slot in the last eight days or one whose newest slot falls in a week it skips (the week after is not looked back at, as before).

func NextSlot

func NextSlot(days []int, atMsk string, every int, now time.Time) (time.Time, bool)

NextSlot is the first slot after now.

Types

type Check

type Check struct {
	Name     string `json:"name"`
	Passed   bool   `json:"passed"`
	ExitCode *int   `json:"exitCode"`
	Ms       int    `json:"ms"`
}

Check is the verdict of one check of a run.

type Deps

type Deps struct {
	DB   *store.DB
	Gate Gate
	// Link is the way to the machines' runners; nil means the scheduler does nothing.
	Link Link
	Log  *slog.Logger
	// Now is the clock; nil means time.Now.
	Now func() time.Time
}

Deps are what the scheduler is built from.

type Gate

type Gate interface {
	On(ctx context.Context, feature, person, machine string) bool
}

Gate says whether a feature is on for a person.

type HubLink struct {
	Links Linker
	// Offers says whether the machine's agent said the feature in its hello.
	Offers func(machineID, feature string) bool
}

HubLink is the Link that goes over the hub's links to the machines' agents (hubproto eval.run.*).

func (*HubLink) Connected

func (l *HubLink) Connected(machineID string) bool

Connected: the machine is linked now and its agent serves evaluation runs (the operator opted in there).

func (*HubLink) Poll

func (l *HubLink) Poll(ctx context.Context, machineID string, runIDs []string) (map[string]RunState, error)

Poll asks for the state of the runs; a run the agent does not know is missing from its answer.

func (*HubLink) Start

func (l *HubLink) Start(ctx context.Context, machineID string, req RunRequest) error

Start hands one run to the machine's agent.

func (*HubLink) Stop

func (l *HubLink) Stop(ctx context.Context, machineID, runID string) error

Stop asks the agent to end a run.

type Link interface {
	// Connected says whether the machine can be reached now.
	Connected(machineID string) bool
	// Start hands one run to the machine's runner.
	Start(ctx context.Context, machineID string, req RunRequest) error
	// Poll asks for the state of the runs the machine has; a run it does not know is missing from the answer.
	Poll(ctx context.Context, machineID string, runIDs []string) (map[string]RunState, error)
	// Stop asks the runner to end a run.
	Stop(ctx context.Context, machineID, runID string) error
}

Link is the way to a machine's runner. The hub's link to the machine (hub-link) implements it; the scheduler itself does not know how a request travels.

type Linker

type Linker interface {
	Get(machineID string) *link.Link
	Do(ctx context.Context, machineID, op string, params any, timeout time.Duration) (json.RawMessage, error)
}

Linker reaches a machine over the agent link.

type RunRequest

type RunRequest struct {
	RunID string          `json:"runId"`
	Task  json.RawMessage `json:"task"`
	Arm   json.RawMessage `json:"arm"`
}

RunRequest is what a machine's runner is given to start one run: the task with its hidden checks and limits, and the arm (the way the harness is set up for this run). Both are JSON documents the runner reads.

type RunState

type RunState struct {
	RunID       string  `json:"runId"`
	State       string  `json:"state"` // preparing, running, grading, done, failed, timeout, stopped, skipped
	StartedAt   string  `json:"startedAt"`
	FinishedAt  string  `json:"finishedAt"`
	Error       string  `json:"error"`
	Fingerprint string  `json:"fingerprint"`
	Passed      *bool   `json:"passed"`
	WallS       *int    `json:"wallS"`
	Usage       *Usage  `json:"usage"`
	Checks      []Check `json:"checks"`
	Diff        any     `json:"diff"`
}

RunState is the runner's report on one run.

type Scheduler

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

Scheduler runs the evaluation. Of the replicas of a hub one does a pass at a time (store.TakeLease).

func New

func New(d Deps) *Scheduler

New builds the scheduler.

func (*Scheduler) Pass

func (s *Scheduler) Pass(ctx context.Context) error

Pass does one step: queues the due slots, then for each machine with open work reads the runner's state and hands the next run over, then closes what is finished. A pass that finds another replica holding the job does nothing.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context)

Run does a pass every tickEvery until ctx ends.

type Usage

type Usage struct {
	USD        *float64 `json:"usd"`
	ModelCalls int      `json:"modelCalls"`
	FirstCtx   *int     `json:"firstCtx"`
	PeakCtx    *int     `json:"peakCtx"`
	TokensIn   int64    `json:"tokensIn"`
	TokensOut  int64    `json:"tokensOut"`
	Subagents  int      `json:"subagents"`
}

Usage is what the run cost.

Jump to

Keyboard shortcuts

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