Commit Graph
1 Commits
Author SHA1 Message Date
yetone 6a050eebe6 provider: the catalog a request built is kept for the next requests while nothing it is built from moved
heldEntries held the providers' catalog for heldFor (1s) after a request,
so an agent's requests a few seconds apart each built it again from
every provider's models and accounts (buildEntries via Resolve and
Served, ~725 MB of allocations in 300s of a gateway in use), and with it
the switched-off providers' models (heldOffEntries, entriesOf again), the
groups and the groups' entries (heldFrom). They are now kept across
requests (kept, hold.go) while provider.StampNow stays the same and for
at most keptFor (a minute), as the gateway's stamped does for model
lists: a provider, account or setting saved, a plugin's change, the
providers', settings' or catalog's file written by another process, or
another environment moves the stamp and the next request builds them
again. What moves no stamp (an account another program signed in to, a
model retired by its date) is seen within the minute. Only a request
that holds the catalog uses what is kept; a look outside one builds its
own, as before.

Measured with a gateway probe (5 providers, ~9.9KB settings.json; at the
parent commit -> this one), 40 requests 1.1s apart:
  messages   675 KB/request, allProviders 1.02/request -> 285 KB, 0.00
  chat       614 KB, 1.00                              -> 245 KB, 0.00
  responses  676 KB, 1.00                              -> 297 KB, 0.00
and 200 back to back: messages 259 -> 234 KB, chat 211 -> 184 KB,
responses 253 -> 251 KB.

TestCatalogKeptAcrossRequests (heldFor 0, so each request is past the
last one's hold) counts builds. Broken by hand, it went red each way:
  - kept never used: "20 requests with nothing changed built the catalog
    20 times, want 0"
  - groups not kept (heldFrom): "20 requests with nothing changed built
    the groups 20 times, want 0"
  - the stamp not checked: "relay2/m3 not in the served catalog after
    the save"
  - no time bound: "past keptFor: built 0 times in 2 requests, want one
    each at least"

Run at this commit's tree (go1.26.8 darwin/arm64, sandbox HOME):
  gofmt -l .: nothing
  GOOS=linux go vet -tags nogui ./...: ok
  GOOS=windows go vet -tags nogui ./...: ok
  go test -tags nogui -race -timeout 45m ./internal/provider
    ./internal/gateway: gateway ok (2072s); provider red once on
    TestSignInDoneOnceTheAccountIsBack, a data race between the test's
    write of catalog.Changed (signin_removed_test.go:112) and a plugin
    refresh goroutine left running by an earlier test reading it in
    catalog.Touched (live.go:202, from plugin.tell). Neither side is
    code this commit touches. It reproduces on origin/main 2201b6628
    (go test -race -run TestSignInDoneOnceTheAccountIsBack -count=30
    ./internal/provider: 1 race in 30). Provider -race run again at
    this tree: ok (171s).
  set -o pipefail; go test -tags nogui -timeout 45m ./...: ok, every
    package (66 ok, 20 with no test files)
2026-10-21 07:32:11 +08:00