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
- func Retryable(status int, body string) bool
- func Sleep(ctx context.Context, d time.Duration) error
- func StartFailed(body string) bool
- func WithBudget(ctx context.Context, b *Budget) context.Context
- type Budget
- func (b *Budget) Attempts() int
- func (b *Budget) CausedTimeout(wall time.Duration) bool
- func (b *Budget) LastStatus() int
- func (b *Budget) Next(retryAfter string) (time.Duration, bool)
- func (b *Budget) NextFor(status int, retryAfter string) (time.Duration, bool)
- func (b *Budget) Sleep(ctx context.Context, d time.Duration) error
- func (b *Budget) Sleeping() bool
- func (b *Budget) Spent() time.Duration
- func (b *Budget) WithSeatGate(g SeatGate) *Budget
- type SeatGate
Constants ¶
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.
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 ¶
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 StartFailed ¶
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.
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 ¶
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 ¶
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) CausedTimeout ¶
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 ¶
LastStatus is the most recent busy status waited out (0 = none).
func (*Budget) Next ¶
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 ¶
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) Sleeping ¶
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 ¶
Spent is the wait this contract has reserved so far — the number the wire result reports as contention_wait_sec.
func (*Budget) WithSeatGate ¶
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.