budget

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package budget enforces independent hard, reservation, and cleanup ledgers.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExhausted          = errors.New("budget exhausted")
	ErrReservationClosed  = errors.New("reservation is already closed")
	ErrInvalidConsumption = errors.New("budget consumption cannot be negative")
)

Functions

This section is empty.

Types

type Ledger

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

func New

func New(policy schema.BudgetPolicy, now func() time.Time) (*Ledger, error)

func (*Ledger) ConsumeCleanup

func (ledger *Ledger) ConsumeCleanup(actual Usage) error

ConsumeCleanup spends only the cleanup ledger. Test steps can never call this through a normal reservation, so cleanup remains available after the ordinary hard budget is exhausted.

func (*Ledger) Reserve

func (ledger *Ledger) Reserve(planned Usage) (*Reservation, error)

func (*Ledger) Snapshot

func (ledger *Ledger) Snapshot() Snapshot

type Reservation

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

func (*Reservation) Cancel

func (reservation *Reservation) Cancel() error

func (*Reservation) Commit

func (reservation *Reservation) Commit(actual Usage) error

type Snapshot

type Snapshot struct {
	Consumed        Usage `json:"consumed"`
	Reserved        Usage `json:"reserved"`
	CleanupConsumed Usage `json:"cleanup_consumed"`
	Overshoot       Usage `json:"overshoot"`
	// Unknown identifies token fields the runner did not observe. Consumed may
	// include a conservative estimate where one exists; it is not provider usage.
	Unknown   []string  `json:"unknown,omitempty"`
	StartedAt time.Time `json:"started_at"`
	Deadline  time.Time `json:"deadline"`
	Exhausted bool      `json:"exhausted"`
}

type Usage

type Usage struct {
	Requests      int64 `json:"requests"`
	RequestBytes  int64 `json:"request_bytes"`
	ResponseBytes int64 `json:"response_bytes"`
	ArtifactBytes int64 `json:"artifact_bytes"`
	Processes     int64 `json:"processes"`
	InputTokens   int64 `json:"input_tokens"`
	OutputTokens  int64 `json:"output_tokens"`
}

func (Usage) Validate

func (usage Usage) Validate() error

Jump to

Keyboard shortcuts

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