seatwait

package
v0.209.1 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: 5 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 seatwait is the CONTRACT-scoped wait for a seat that answered "busy".

Verified against llama-swap v251's scheduler source (2026-09-02): HTTP 429 means the model's RESERVED requests (queued + in-flight) reached its concurrencyLimit (default 10) — it is sent with `Retry-After: 1` and the body `code:"concurrency_limit"`. A process that is not up yet answers 503 "process is not ready", and a health-check timeout answers 500 with src:"llama-swap". None of these means the seat is broken; they mean PEERS hold it — every parallel session's MCP process fans out against the same limit. Before this package the harness filed them as DeferClassInfrastructure and the CALLER re-routed the work to a weaker seat by hand (2026-09-01: several sessions, the operator's #1 priority).

One Budget per RunAgentTask, carried in ctx and shared by every chat and re-pack call of that contract: a 10-step loop cannot burn ten budgets, and a server that always says Retry-After: 1 still runs out. The budget is the wait's whole authority — no attempt count, no per-call timer.

Index

Constants

View Source
const DeathMarker = "upstream command exited"

DeathMarker is llama-swap's own wording for a start whose engine exited ("upstream command exited prematurely", process_command.go in upstream's source): the one body that says a start died.

View Source
const DefaultBudget = 90 * time.Second

DefaultBudget is the wait a contract may spend on a peer-held seat before the failure stands. Long enough for a fan-out's generations to drain (a slot frees only when a FULL generation finishes), short enough that a wedged seat is still noticed well inside one contract's wall.

Variables

This section is empty.

Functions

func Retryable

func Retryable(status int, body string) bool

Retryable reports whether a non-200 is llama-swap saying "peers hold the seat" — the three answers verified against its source — keyed on the STATUS plus the smallest body discriminator that separates them from a real fault (a 500 from CUDA OOM is not a wait; a 502 is a generation that died mid-body and must not be silently re-sent).

func Sleep

func Sleep(ctx context.Context, d time.Duration) error

Sleep waits d, or until ctx ends, whichever comes first.

func StartFailed

func StartFailed(body string) bool

StartFailed reports whether a refusal's body says the seat's process did not start: the engine exited, or llama-swap was "unable to start process". Re-sending that request is a second failed start, whatever the status code says.

func WithBudget

func WithBudget(ctx context.Context, b *Budget) context.Context

WithBudget attaches the contract's Budget to ctx for every seat call below.

Types

type Budget

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

Budget is one contract's wait allowance. The zero Budget never waits.

func FromContext

func FromContext(ctx context.Context) *Budget

FromContext returns the attached Budget, or a disabled one (never waits) when the caller attached nothing — so every seat client can call it unconditionally.

func NewBudget

func NewBudget(cfgSec int) *Budget

NewBudget builds a Budget from the config value in seconds: 0 = the DefaultBudget, negative = disabled (the pre-2026-09-02 behaviour: the first busy answer stands).

func (*Budget) Attempts

func (b *Budget) Attempts() int

Attempts is how many busy answers were waited out.

func (*Budget) CausedTimeout

func (b *Budget) CausedTimeout(wall time.Duration) bool

CausedTimeout reports whether contention, not the model's own work, is what spent a wall of length `wall`: a sleep was in flight when it expired, or the reserved waits account for at least half of it. A single early 429 that resolved in a second must NOT relabel a genuine budget timeout 15 minutes later as "seat contended" (review finding, 2026-09-02).

func (*Budget) LastStatus

func (b *Budget) LastStatus() int

LastStatus is the most recent busy status waited out (0 = none).

func (*Budget) Next

func (b *Budget) Next(retryAfter string) (time.Duration, bool)

Next reserves the next sleep. A server Retry-After (whole seconds) wins over the ladder; BOTH count against the budget. ok=false means the caller must stop retrying and let the failure stand — the reservation is not made.

func (*Budget) NextFor

func (b *Budget) NextFor(status int, retryAfter string) (time.Duration, bool)

NextFor is Next with the busy STATUS that triggered it, remembered as LastStatus so a defer reason can name what the seat answered.

func (*Budget) Sleep

func (b *Budget) Sleep(ctx context.Context, d time.Duration) error

Sleep is Sleep with the in-flight flag kept on this budget for the duration.

func (*Budget) Sleeping

func (b *Budget) Sleeping() bool

Sleeping reports whether a reserved sleep is in progress right now — the fact a wall-timeout classifier needs: "did the wall expire WHILE waiting on peers?" is a different question from "was there ever a busy answer?".

func (*Budget) Spent

func (b *Budget) Spent() time.Duration

Spent is the wait this contract has reserved so far — the number the wire result reports as contention_wait_sec.

func (*Budget) WithSeatGate

func (b *Budget) WithSeatGate(g SeatGate) *Budget

WithSeatGate installs the gate: while it says the seat is not serving, NextFor refuses the wait. A 5xx from llama-swap on a seat whose engine died or cannot start is the seat's failure, not peers holding its slots — sleeping the contention budget on it (90 s by default) only delays the run's typed outcome. A 429 is contention by definition and is never asked. It is the seam every client of the budget shares, the structured re-pack's included, so none of them needs its own check. Returns b.

type SeatGate

type SeatGate func(status int) (down bool)

SeatGate answers, before the budget waits out a busy answer other than 429, whether the seat is NOT SERVING right now (ADR 0066). It reads the seat, so it may take a moment and must be safe to call from any client of the contract.

Jump to

Keyboard shortcuts

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