caps

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package caps is the concurrency-caps model of design §8.1: which layers a job is counted against, what those layers hold now, and whether a job still fits. The model is pure — it reads no store; the engine builds a Usage from the live jobs and asks Room about each dispatch it considers.

Index

Constants

View Source
const (
	LayerRunner  = "runner"
	LayerAccount = "account"
	LayerModel   = "model"
	LayerPlan    = "plan"
	LayerGlobal  = "global"
)

The layers, in the order Room reports them full (§8.1's order).

Variables

This section is empty.

Functions

func HeadroomCap

func HeadroomCap(limit int) int

HeadroomCap is the account cap a task job sees on the foreman's account (§8.2): one lower than the configured cap, never below 0, so one slot stays reserved for the foreman. An uncapped account (nil limit) stays uncapped: there is no cap to lower.

func Room

func Room(limits Limits, usage Usage, job Job) (bool, string)

Room reports whether every capped layer has room for job (§8.1), and names the first one that does not: runner, account, model, plan, global. A foreman turn counts toward the runner, account and global caps only — the plan and model layers ignore it — so the foreman is never starved by its own tasks.

Types

type Job

type Job struct {
	Runner    int64
	RunnerCap int    // the runner's advertised max_parallel; 0 = unset
	Account   string // the agent's account label; "" = no agent recorded
	Model     string
	Plan      int64
	Foreman   bool
	// Headroom marks a task job whose account is the foreman's (§8.2):
	// the account layer sees HeadroomCap of the configured cap.
	Headroom bool
}

Job is the dispatch Room is asked about: which runner would take the job, through which account and model, for which plan, and whether it is a foreman turn. Plan is 0 for a foreman turn.

type Limits

type Limits struct {
	Global  *int              // the engine's overall ceiling
	Plan    *int              // max parallel tasks per plan
	Runner  *int              // the config's runner cap; a runner may advertise its own
	Account map[string]int    // by account label
	Model   map[string]int    // by model; a per-model cap such as 1 for a heavy model
	Cost    map[string]int    // by "harness/model"
	Tier    map[string]string // by "harness/model"

	// NoHeadroom turns the foreman headroom rule (§8.2) off. The rule
	// is on by default, so the zero value keeps it.
	NoHeadroom bool
}

Limits are the configured caps (§8.1): a job may start only if every layer on its path has room. A nil pointer, or a missing map entry, means the layer is not capped; a set limit of 0 caps the layer at nothing, which is different from not capping it.

Cost is not a limit but is configured beside them: the relative cost weight of one (harness, model) pair, which the foreman reads through `capacity` (§12.2). A missing entry there is the default weight of 1. Tier overrides the model-name table for every agent of a (harness, model) pair. Outcome record keys stay (repo, class, agent), so records earned under one label stay with the agent when an override changes its tier.

func (Limits) CostOf

func (l Limits) CostOf(harness, model string) int

CostOf is the cost weight of one (harness, model) pair (§8.1): what the config named, else the default of 1.

func (Limits) RunnerCap

func (l Limits) RunnerCap(advertised int) *int

RunnerCap folds the config's runner cap with the cap the runner advertised when it registered (§8.1): the smaller of the two, ignoring whichever is unset. advertised follows the runners table: 0 means the runner advertised none.

func (Limits) TierOf

func (l Limits) TierOf(harness, model string) string

TierOf is the configured tier of a (harness, model) pair, else its table tier.

type Usage

type Usage struct {
	Runner  map[int64]int
	Account map[string]int
	Model   map[string]int
	Plan    map[int64]int
	Global  int
}

Usage is the live-job count per layer (§8.1). Live means leased or running: a queued job holds no runner, no agent and no slot. An empty account or model — no agent recorded on the job — and a plan of 0 — a foreman turn — count at the layers that have them.

func (*Usage) Add

func (u *Usage) Add(runner int64, account, model string, plan int64)

Add counts one live job into the usage.

Jump to

Keyboard shortcuts

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