Say when a budget cannot be spent against

A team was given a budget of a million, the quota page showed it, and after
sixty requests it read zero percent used. Not because the counting was wrong:
cost comes from a price table, no model had a price, and every request
therefore cost nothing. The number was a limit in appearance and bound on
nothing.

An empty price table is the ordinary case — self-hosted models have no
per-token price, which the schema already says. Showing somebody a budget
without mentioning it is not.

The page says so, and says it precisely: rate and token limits are unaffected,
because they count requests and tokens rather than money. A warning that read
as "no quota works here" would be worse than the silence it replaces — those
two were enforcing perfectly well, as twenty served and ten refused had just
shown.

AnythingPriced is on the accountant rather than the price table, because what a
caller is asking is whether the budgets it is about to display mean anything,
and the accountant is what would enforce them. A model priced at zero is not
priced; a fallback price prices everything.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-27 21:56:56 +02:00
1 parent dfbb7557dd
commit 832d0a652c
8 files changed
+121 -3

No files matched your search

+2
View File
@@ -57,6 +57,8 @@ type AccountPages struct {
hasMirror bool
// hasQuotas is set when /admin/quotas is registered.
hasQuotas bool
// priced says whether a budget can ever be spent against.
priced Priced
// registry browses a model registry, or is nil where there is no way out.
registry Registry
// catalog puts a mirrored model into service; fleet says whether anything
+11 -1
View File
@@ -12,6 +12,10 @@ import (
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
)
// Priced says whether anything a request could name costs money. The
// accountant implements it.
type Priced interface{ AnythingPriced() bool }
// QuotaAdmin is the store half of the quota page.
type QuotaAdmin interface {
AllOrgs(ctx context.Context) ([]store.Org, error)
@@ -65,6 +69,10 @@ type quotaRow struct {
type adminQuotasData struct {
Rows []quotaRow
// BudgetsBind is false when no model has a price, which makes every budget
// on this page a number that cannot move. Shown, because a limit that binds
// on nothing and reads as "0% used" is worse than no limit at all.
BudgetsBind bool
// Editing is the "scope:id" whose form is open, so the template can keep
// the link on every other row.
Editing string
@@ -89,8 +97,9 @@ type adminQuotasData struct {
// could see or change without a shell on the control plane — which in practice
// means quotas nobody sets. Every change is logged with who made it and what it
// was before.
func (p *AccountPages) RegisterAdminQuotas(mux *http.ServeMux, s QuotaAdmin) {
func (p *AccountPages) RegisterAdminQuotas(mux *http.ServeMux, s QuotaAdmin, priced Priced) {
p.hasQuotas = true
p.priced = priced
mux.HandleFunc("GET /admin/quotas", p.adminOnly(
func(w http.ResponseWriter, r *http.Request, _ store.User) {
@@ -193,6 +202,7 @@ func (p *AccountPages) renderQuotas(w http.ResponseWriter, r *http.Request,
Now: time.Now().UTC().Format(time.RFC3339),
}
d.BudgetsBind = p.priced != nil && p.priced.AnythingPriced()
d.Editing = r.URL.Query().Get("edit")
limits, err := s.AllLimits(r.Context())
+41 -1
View File
@@ -59,12 +59,22 @@ func quotasPage(t *testing.T, s *fakeQuotas, admin bool) *http.ServeMux {
a := fakeAccounts{user: store.User{ID: "u1", Email: "a@example.com", IsAdmin: admin}}
p := NewAccountPages(a, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
mux := http.NewServeMux()
p.RegisterAdminQuotas(mux, s)
p.RegisterAdminQuotas(mux, s, pricedYes{})
return mux
}
func i64(v int64) *int64 { return &v }
// pricedYes stands for a cluster where models cost something, so the warning
// about budgets binding on nothing stays out of the way of the other tests.
type pricedYes struct{}
func (pricedYes) AnythingPriced() bool { return true }
type pricedNo struct{}
func (pricedNo) AnythingPriced() bool { return false }
// oneTeam is an org with a team and a project under it.
func oneTeam() *fakeQuotas {
return &fakeQuotas{
@@ -300,3 +310,33 @@ func TestSavingClosesTheFormSoTheResultIsVisible(t *testing.T) {
t.Errorf("the page should confirm what was written; got %s", body)
}
}
func TestABudgetThatCannotBindSaysSo(t *testing.T) {
a := fakeAccounts{user: store.User{ID: "u1", Email: "a@example.com", IsAdmin: true}}
p := NewAccountPages(a, nil, nil, "v0", slog.New(slog.NewTextHandler(io.Discard, nil)))
mux := http.NewServeMux()
p.RegisterAdminQuotas(mux, oneTeam(), pricedNo{})
// Whitespace normalised: the sentence wraps in the template and a test
// that pinned the wrap would break on a reflow rather than on a change of
// meaning.
body := strings.Join(strings.Fields(mirrorGet(t, mux, "/admin/quotas").Body.String()), " ")
// A budget is spend per period and spend comes from a price table. With no
// prices the number reads as a limit, reports zero percent used, and binds
// on nothing.
if !strings.Contains(body, "budget below stays at zero") {
t.Errorf("the page should say budgets cannot move; got %s", body)
}
// Said precisely: the other two limits are unaffected and still work.
if !strings.Contains(body, "Rate and token limits are unaffected") {
t.Error("the warning should not read as though no quota works")
}
}
func TestAPricedClusterIsNotWarned(t *testing.T) {
body := mirrorGet(t, quotasPage(t, oneTeam(), true), "/admin/quotas").Body.String()
if strings.Contains(body, "stays at zero") {
t.Error("a cluster with prices should see no warning")
}
}
+11
View File
@@ -10,6 +10,17 @@
<a href="/profile">your keys</a></nav>
</header>
{{if not .BudgetsBind}}
{{/* A budget is spend per period and spend comes from a price table. With no
prices every request costs nothing, so these numbers read as limits and
bind on nothing. Self-hosted models having no per-token price is ordinary;
showing somebody a budget without saying so is not. */}}
<p class="note error-row">No model has a price, so nothing is charged and every
budget below stays at zero however much is used. Rate and token limits are
unaffected — they count requests and tokens, not money. Set prices in the
<code>pricing</code> block of the server configuration to make budgets bind.</p>
{{end}}
{{if .Error}}<p class="error">{{.Error}}</p>{{end}}
{{if .Message}}<p class="ok">{{.Message}}</p>{{end}}