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:
1 parent
dfbb7557dd
commit
832d0a652c
8 files changed
+121
-3
No files matched your search
@@ -362,3 +362,10 @@ func keyCounter(keyID string) string {
|
||||
}
|
||||
return store.LimitOwner{Scope: store.ScopeKey, ID: keyID}.CounterKey()
|
||||
}
|
||||
|
||||
// AnythingPriced reports whether a budget can ever be spent against.
|
||||
//
|
||||
// On the accountant rather than making callers reach for the price table: what
|
||||
// they are asking is whether the budgets they are about to display mean
|
||||
// anything, and the accountant is what would enforce them.
|
||||
func (a *Accountant) AnythingPriced() bool { return a.pricing.AnythingPriced() }
|
||||
@@ -609,3 +609,24 @@ func TestStatusReportsTheFullestPoolNotTheSmallestNumber(t *testing.T) {
|
||||
t.Error("a member should see the fullest pool that bounds them")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnEmptyPriceTableMeansNoBudgetCanEverBind(t *testing.T) {
|
||||
// The ordinary case for self-hosted models, and the reason a budget on a
|
||||
// team can read as a limit while binding on nothing.
|
||||
if NewPricing(nil, Price{}).AnythingPriced() {
|
||||
t.Error("nothing priced should say so")
|
||||
}
|
||||
if NewPricing(map[string]Price{"m": {}}, Price{}).AnythingPriced() {
|
||||
t.Error("a model priced at zero is not priced")
|
||||
}
|
||||
if !NewPricing(map[string]Price{"m": {PromptPer1k: 1}}, Price{}).AnythingPriced() {
|
||||
t.Error("one priced model is enough for a budget to move")
|
||||
}
|
||||
if !NewPricing(nil, Price{CompletionPer1k: 1}).AnythingPriced() {
|
||||
t.Error("a fallback price prices everything")
|
||||
}
|
||||
var nilPricing *Pricing
|
||||
if nilPricing.AnythingPriced() {
|
||||
t.Error("no price table at all is not priced")
|
||||
}
|
||||
}
|
||||
@@ -68,3 +68,30 @@ func (p *Pricing) For(model string) Price {
|
||||
}
|
||||
return p.fallback
|
||||
}
|
||||
|
||||
// AnythingPriced reports whether any model costs anything.
|
||||
//
|
||||
// A budget is spend per period, and spend is computed from a price table. With
|
||||
// no prices every request costs nothing, so a budget written on a team is a
|
||||
// number that can never move — displayed as a limit, reported as zero percent
|
||||
// used, and binding on nothing.
|
||||
//
|
||||
// Self-hosted models have no per-token price, so an empty table is the ordinary
|
||||
// case rather than a misconfiguration. What is not ordinary is showing somebody
|
||||
// a budget without saying so.
|
||||
func (p *Pricing) AnythingPriced() bool {
|
||||
if p == nil {
|
||||
return false
|
||||
}
|
||||
p.mu.RLock()
|
||||
defer p.mu.RUnlock()
|
||||
if !p.fallback.Zero() {
|
||||
return true
|
||||
}
|
||||
for _, price := range p.byModel {
|
||||
if !price.Zero() {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -160,7 +160,7 @@ func (r *Router) Handler() http.Handler {
|
||||
pages.RegisterAdminUsers(mux, r.store)
|
||||
// Quotas are written on the same tree the accounts page builds, so
|
||||
// they are mounted together.
|
||||
pages.RegisterAdminQuotas(mux, r.store)
|
||||
pages.RegisterAdminQuotas(mux, r.store, r.acct)
|
||||
}
|
||||
|
||||
// Independent of the cluster view: the mirror is a separate machine
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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}}
|
||||
|
||||
|
||||
Reference in new issue
Block a user