usage: a model list that was answered is no row of Requests (ferock on Discord)
ferock (Discord #general): Usage > Requests is full of rows like "magpie · magpie's own · Remote magpie · API · Model list · 0 0 · 757 ms · 200, GET /v1/models", which no tool of theirs sent. Cause:ffe493773(v0.1.1446) wrote every request magpie sends a provider on its own into the request log (source "probe"): the editor's Test and Detect APIs, and every model-list fetch.0152f6696then gave a Remote magpie a 10-minute list schedule (KeepListsFresh), so each Remote magpie added ~144 such rows a day. The same rows came from every other automatic fetch: start-up's FetchNew, the panel's FetchNewSoon, the Providers page's FetchNewBehind and any provider with a RefreshEvery. They were already counted in no token, cost, chart, budget or quota total, but they were listed and counted in the page's row total. Fix: a model_list probe with a 2xx/3xx status and no error (usage.quietProbe) is not written by usage's probelog.Sink, and is skipped when the log's index parses one (logSnapshot.probes). This rule covers every list fetch, whoever started it, so every sibling is covered by one check. A list that failed is still a row (the Failed filter finds it, and the row says why models are missing), and every Test and Detect APIs row stays as it was. Older rows: the answered model lists already in usage.jsonl stop being listed at the next start of the index, with no rewrite. The lines stay in the file and nothing reads them. Quota and usage polls and health checks were never written there (only Test, Detect and list are marked by probelog), so nothing else needed changing. The TUI and CLI have no request list. The heatmap, Summarize, Load and the exports skipped probes already. Tests: - usage TestAnsweredModelListIsNoRow (new): 200 and 304 lists aren't written; a 503 and a connection-refused list are listed and Failed finds both; a 200 Test is listed; an old answered list line in the log is not listed, and Total is 3. - TestProbeRowsListedNotCounted and the rename tests now use a failed list (a 200 one would no longer be a row). Broken by hand, each red: quietProbe returning false (the 200 list written and listed); the index's skip removed, Sink's kept (the old line listed, total 4). Run, on mote: - go test -tags nogui -timeout 45m ./... at the pre-rebase head (b4f2fa9d3 on0a7633136): every package ok, 76 ok, exit 0 (gateway 547s, agent 298s, provider 167s, usage 48s). - After rebase on origin/main9ba3f049e(which touched neither usage nor probelog): go build ./...; go vet for darwin, GOOS=linux and GOOS=windows on usage and probelog; go test usage, probelog, usageapi, and provider -run Probe|Detect|TestTestWrites: ok. gofmt -l clean. - GUI (no asset changed): usage-ledger*.test.cjs, ledger-*.test.cjs and own-requests.test.cjs, chromium and webkit, each file's languages: 381 tests, 375 pass. The 6 reds are usage-ledger's "newest live route needs no return-to-live button" (en, zh, both engines), which is already filed as #3104. usage-ledger-probe passed in every language. Not tried: a real Remote magpie over a day. The row filter was not checked on a real usage.jsonl.
This commit is contained in:
@@ -537,6 +537,16 @@ for: `provider_test`, `api_detect` or `model_list`
|
||||
request page lists them as a chunk of their own (`probeChunk`) and adds
|
||||
them to no total, cell, group, chart or filter count; `?via=` other than
|
||||
all leaves them out.
|
||||
- **A model list answered is no row:** magpie fetches lists by itself
|
||||
(start-up's `FetchNew`, the panel's and the Providers page's, and
|
||||
`KeepListsFresh`, which asks a Remote magpie every 10 minutes), so a
|
||||
`model_list` row with a 2xx/3xx status and no error is neither written
|
||||
(`usage`'s `probelog.Sink`) nor read back from an older log
|
||||
(`quietProbe`, in the index's parse): ferock on Discord, a Requests page
|
||||
full of 0-token rows no agent sent. A list that failed is still a row,
|
||||
under the Failed filter too, as is every Test and Detect APIs. Older
|
||||
lines stay in `usage.jsonl`, read by nothing.
|
||||
`TestAnsweredModelListIsNoRow` covers it.
|
||||
- **Whose:** a row recorded under its host, sent before its provider had
|
||||
an id, is listed under the provider saved on that host now
|
||||
(`Renames.ProbeOf`), and with none on it, a deleted one's, under the id
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
// Detect APIs and per-model detection, and a model list's refresh (neiko
|
||||
// and gys619 on Discord: a test left no trace in the request log). Each
|
||||
// such request is one row of the request log, marked as magpie's own test
|
||||
// (usage.SourceProbe) and never counted in a usage or cost total.
|
||||
// (usage.SourceProbe) and never counted in a usage or cost total; a model
|
||||
// list that was answered is left out there (usage's quietProbe), as magpie
|
||||
// asks for lists by itself all day.
|
||||
//
|
||||
// The provider package marks a context with the kind of test (With); every
|
||||
// request sent under it is written down once, by the provider's Do or by
|
||||
|
||||
@@ -179,7 +179,9 @@ func readLogSnapshot() *logSnapshot {
|
||||
}
|
||||
next.sawHost(r)
|
||||
if r.IsProbe() {
|
||||
next.probes = append(next.probes, probeRow{r, next.off})
|
||||
if !quietProbe(r) { // a model list answered is no row (ferock)
|
||||
next.probes = append(next.probes, probeRow{r, next.off})
|
||||
}
|
||||
continue
|
||||
}
|
||||
if tail == nil {
|
||||
|
||||
@@ -34,12 +34,29 @@ type probeRow struct {
|
||||
|
||||
func init() {
|
||||
probelog.Sink = func(p probelog.Row) {
|
||||
Append(Record{Time: p.Time, Agent: "magpie", Provider: p.Provider, ProviderAccount: p.Account,
|
||||
r := Record{Time: p.Time, Agent: "magpie", Provider: p.Provider, ProviderAccount: p.Account,
|
||||
Host: p.Host, Model: p.Model, Requested: p.Model, Status: p.Status, Millis: p.Millis,
|
||||
Error: clipProbeError(p.Error), Endpoint: p.Endpoint, Kind: p.Kind, Source: SourceProbe})
|
||||
Error: clipProbeError(p.Error), Endpoint: p.Endpoint, Kind: p.Kind, Source: SourceProbe}
|
||||
if quietProbe(r) {
|
||||
return
|
||||
}
|
||||
Append(r)
|
||||
}
|
||||
}
|
||||
|
||||
// quietProbe is a request of magpie's own the request log leaves out: a
|
||||
// model list that was answered. magpie asks for one by itself, at start-up,
|
||||
// behind the panel and the Providers page, and on a schedule (a Remote
|
||||
// magpie's every 10 minutes, RemoteMagpieEvery), so the Requests page
|
||||
// filled with rows of 0 tokens that no agent sent (ferock on Discord). One
|
||||
// that failed is listed, as is every Test and Detect APIs: a list that
|
||||
// couldn't be fetched is why models are missing, and the row says why.
|
||||
// Rows written before this are left out the same way as the log is read
|
||||
// (logSnapshot.probes); the lines stay in the file, counted nowhere.
|
||||
func quietProbe(r Record) bool {
|
||||
return r.Kind == probelog.KindList && r.Status >= 200 && r.Status < 400 && r.Error == ""
|
||||
}
|
||||
|
||||
// clipProbeError keeps an error's first 500 bytes, as a vendor's answer can
|
||||
// be a whole page.
|
||||
func clipProbeError(s string) string {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package usage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -28,7 +31,7 @@ func TestProbeRowsListedNotCounted(t *testing.T) {
|
||||
Append(Record{Time: now, Agent: "claude", Provider: "anthropic", Model: "claude-opus-5-5", Input: 1000, Output: 100, Status: 200})
|
||||
probelog.Sink(probelog.Row{Time: now.Add(time.Second), Kind: probelog.KindTest, Provider: "relay", Account: "me", Model: "gpt-9",
|
||||
Host: "relay.example", Endpoint: "/v1/chat/completions", Status: 401, Millis: 120, Error: strings.Repeat("页", 400)})
|
||||
probelog.Sink(probelog.Row{Time: now.Add(2 * time.Second), Kind: probelog.KindList, Provider: "relay", Host: "relay.example", Endpoint: "GET /v1/models", Status: 200, Millis: 30})
|
||||
probelog.Sink(probelog.Row{Time: now.Add(2 * time.Second), Kind: probelog.KindList, Provider: "relay", Host: "relay.example", Endpoint: "GET /v1/models", Status: 502, Millis: 30, Error: "bad gateway"})
|
||||
|
||||
page := QueryPage(All, Filter{}, 0, 50)
|
||||
if page.Total != 3 || len(page.Rows) != 3 {
|
||||
@@ -85,3 +88,46 @@ func TestProbeRowsListedNotCounted(t *testing.T) {
|
||||
t.Fatalf("provider filter: total %d sum %+v", p.Total, p.Sum)
|
||||
}
|
||||
}
|
||||
|
||||
// ferock on Discord: Usage > Requests filled with "Model list" rows, 0
|
||||
// tokens and 200, one every 10 minutes for a Remote magpie, that no agent
|
||||
// sent. A model list that was answered is no row, neither written nor
|
||||
// read back from a log that has it from before; one that failed is still
|
||||
// listed (it is why models are missing), and so is every Test.
|
||||
func TestAnsweredModelListIsNoRow(t *testing.T) {
|
||||
reportedHome(t)
|
||||
now := time.Now().Add(-time.Hour)
|
||||
list := func(at time.Duration, status int, err string) probelog.Row {
|
||||
return probelog.Row{Time: now.Add(at), Kind: probelog.KindList, Provider: "remote", Host: "10.0.0.2:3425",
|
||||
Endpoint: "GET /v1/models", Status: status, Millis: 757, Error: err}
|
||||
}
|
||||
probelog.Sink(list(time.Second, 200, ""))
|
||||
probelog.Sink(list(2*time.Second, 304, ""))
|
||||
probelog.Sink(list(3*time.Second, 503, "upstream down"))
|
||||
probelog.Sink(list(4*time.Second, 0, "dial tcp 10.0.0.2:3425: connection refused"))
|
||||
probelog.Sink(probelog.Row{Time: now.Add(5 * time.Second), Kind: probelog.KindTest, Provider: "remote", Host: "10.0.0.2:3425",
|
||||
Endpoint: "/v1/chat/completions", Model: "m", Status: 200, Millis: 900})
|
||||
// a log written before: its answered lists are left out as it is read
|
||||
Append(Record{Time: now.Add(6 * time.Second), Agent: "magpie", Provider: "remote", Host: "10.0.0.2:3425",
|
||||
Endpoint: "GET /v1/models", Kind: probelog.KindList, Status: 200, Millis: 700, Source: SourceProbe})
|
||||
|
||||
b, err := os.ReadFile(Path())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n := strings.Count(string(b), `"kind":"model_list"`); n != 3 {
|
||||
t.Fatalf("%d model list lines written, want the 2 that failed and the old one:\n%s", n, b)
|
||||
}
|
||||
page := QueryPage(All, Filter{}, 0, 50)
|
||||
var got []string
|
||||
for _, r := range page.Rows {
|
||||
got = append(got, r.Kind+" "+strconv.Itoa(r.Status))
|
||||
}
|
||||
want := []string{"provider_test 200", "model_list 0", "model_list 503"}
|
||||
if page.Total != 3 || !slices.Equal(got, want) {
|
||||
t.Fatalf("total %d, rows %v, want %v", page.Total, got, want)
|
||||
}
|
||||
if p := QueryPage(All, Filter{Failed: true}, 0, 50); p.Total != 2 {
|
||||
t.Fatalf("failed filter: total %d", p.Total)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func TestRenamedProviderShownOnce(t *testing.T) {
|
||||
}
|
||||
then := time.Now().Add(-time.Hour)
|
||||
Append(Record{Time: then, Agent: "codex", Session: "s1", Provider: "myrelay", Model: "gpt-9", Input: 100, Output: 10, Status: 200})
|
||||
probelog.Sink(probelog.Row{Time: then.Add(time.Second), Kind: probelog.KindList, Provider: "myrelay", Host: "relay.example", Endpoint: "GET /v1/models", Status: 200, Millis: 30})
|
||||
probelog.Sink(probelog.Row{Time: then.Add(time.Second), Kind: probelog.KindList, Provider: "myrelay", Host: "relay.example", Endpoint: "GET /v1/models", Status: 502, Millis: 30, Error: "bad gateway"})
|
||||
// read once under the old id, so what is kept of it is built again
|
||||
if p := QueryPage(All, Filter{}, 0, 50); !slices.Equal(p.Providers, []string{"myrelay"}) {
|
||||
t.Fatalf("before: %v", p.Providers)
|
||||
@@ -183,7 +183,7 @@ func TestProbesOfAProviderOnAnotherHostOfItsSiteListIt(t *testing.T) {
|
||||
"https://leee.baby/v1/models", "https://Leee.Baby/v1/models", "https://www.leee.baby:443/v1/models",
|
||||
"https://two.example/v1/models", "https://mine.vercel.app/v1/models", "http://127.0.0.1:7/v1/models",
|
||||
} {
|
||||
probelog.Note(adding, u, http.MethodGet, then, 200, nil)
|
||||
probelog.Note(adding, u, http.MethodGet, then, 401, nil) // an answered list is no row (quietProbe)
|
||||
}
|
||||
id, err := provider.Add(provider.Provider{Name: "Leee", Key: "k", Chat: "https://api.leee.baby/v1", Models: []string{"gpt-9"}})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user