provider: the minute's look for model lists due reads only the user's own providers, not every agent's sign-in (#3185)
KeepListsFresh called provider.All() every minute to find the lists due.
All builds every provider, signed-in subscriptions among them, and so
asks each agent for its accounts: the Claude keychain through an exec of
`security` too. An idle magpie woke ~134 times in a burst for it once a
minute. Only providers of the user's own (with an endpoint) have lists
to fetch, so refreshDueLists now reads those from the file (ownOf, the
split allProviders already made).
Run at this head (19253f67b + this):
- TestKeepListsFreshFetchesWhatIsDue asserts a look with nothing due
builds All 0 times: red on the old autolist.go ("built All 1 times"),
green now.
- go test ./internal/provider -skip TestUnreadLoginsWriteErrorsKeepCredentials:
ok (that test crashes the package on main too: #3632, filememo).
- gofmt; go vet darwin, GOOS=linux and GOOS=windows -tags nogui.
This commit is contained in:
@@ -283,7 +283,13 @@ func KeepListsFresh(ctx context.Context) {
|
||||
// answers the ids it asked.
|
||||
func refreshDueLists(ctx context.Context, now time.Time) []string {
|
||||
var asked []string
|
||||
for _, p := range All() {
|
||||
// the user's own providers alone, as All lists them: only those keep a
|
||||
// list on a schedule (ownList), and All asks every agent for its
|
||||
// sign-in, the Claude keychain's `security` among them, each minute
|
||||
// of an idle magpie (#3185)
|
||||
f := load()
|
||||
own, _ := ownOf(f)
|
||||
for _, p := range ordered(own, f.Order) {
|
||||
every := p.RefreshInterval()
|
||||
// one that lists nothing (Preset.NoList) has no list to keep fresh
|
||||
if every == 0 || p.Off || !p.lists() {
|
||||
|
||||
@@ -241,9 +241,15 @@ func TestKeepListsFreshFetchesWhatIsDue(t *testing.T) {
|
||||
}
|
||||
// fetched just now: not due for 6 hours
|
||||
r.set("gpt-7", "gpt-6", "llama-5")
|
||||
built := AllBuilt.Load()
|
||||
if got := refreshDueLists(context.Background(), now.Add(5*time.Hour)); len(got) != 0 {
|
||||
t.Fatalf("asked %v before its 6 hours", got)
|
||||
}
|
||||
// a look with nothing due asks no agent for its sign-in: All reads
|
||||
// each one's, the Claude keychain's `security` among them (#3185)
|
||||
if n := AllBuilt.Load() - built; n != 0 {
|
||||
t.Fatalf("a look with nothing due built All %d times", n)
|
||||
}
|
||||
got := refreshDueLists(context.Background(), now.Add(6*time.Hour+time.Minute))
|
||||
if !slices.Equal(got, []string{"relay"}) || r.asked.Load() != 2 {
|
||||
t.Fatalf("asked %v (%d times) after its 6 hours", got, r.asked.Load())
|
||||
|
||||
@@ -660,17 +660,7 @@ var AllBuilt atomic.Int64
|
||||
func allProviders() []Provider {
|
||||
AllBuilt.Add(1)
|
||||
f := load()
|
||||
stored := f.Providers
|
||||
picks := map[string]Provider{}
|
||||
var out []Provider
|
||||
for _, p := range stored {
|
||||
p = normalize(p)
|
||||
if !hasEndpoint(p) {
|
||||
picks[p.ID] = p
|
||||
continue
|
||||
}
|
||||
out = append(out, p)
|
||||
}
|
||||
out, picks := ownOf(f)
|
||||
for _, a := range Accounts() {
|
||||
if _, taken := find(out, a.ID); taken || picks[a.ID].Hidden {
|
||||
continue
|
||||
@@ -687,6 +677,21 @@ func allProviders() []Provider {
|
||||
return ordered(out, f.Order)
|
||||
}
|
||||
|
||||
// ownOf is f's providers of the user's own, and the model picks it keeps
|
||||
// for the signed-in accounts by id.
|
||||
func ownOf(f file) (own []Provider, picks map[string]Provider) {
|
||||
picks = map[string]Provider{}
|
||||
for _, p := range f.Providers {
|
||||
p = normalize(p)
|
||||
if !hasEndpoint(p) {
|
||||
picks[p.ID] = p
|
||||
continue
|
||||
}
|
||||
own = append(own, p)
|
||||
}
|
||||
return own, picks
|
||||
}
|
||||
|
||||
// withPicks is the signed-in account a with what the user set on its
|
||||
// provider (pk, as providers.json keeps it): its models, routing, limits
|
||||
// and queue. The account the agent is signed in to gets them in All, and
|
||||
|
||||
Reference in New Issue
Block a user