yg6888 on X (tweet 2123308968848379920): in a group routed Smart, Cursor Plus's Composer and Grok 4.7 were never used. Not a bug: Smart orders by allowance tier, then soonest renewal, then listed order, and never weighs the context window, so the 1M members listed ahead always answered. The small ones were only ever reached as a fallback. Smart itself is unchanged; changing its order would move every Smart user's traffic. A group gets a new routing instead, `fit` (Small context first; 小上下文优先, 小上下文優先, 小さいコンテキスト優先, Kleiner Kontext zuerst): - routes.SmallFirst takes Smart's order and sorts it stably by band (a provider set to be used first, the rest with room, the all but used up) and then by window, the smaller known first, an unknown one last. - Its strategy sets ByWindow, so weighRouted fills Seat.Window from windowIn (the provider's own Contexts, else the catalog's). - roomy already leaves out every member the request is estimated past, so the first left is the smallest that holds it: a small model is never asked for a request too long for it, and keeps its last-resort place as under every routing. - The trace's rows carry `context`; the Routing page says "its 200K context window is the smallest that holds this request". - A group's only: provider.normalize already drops it from a provider and the CLI refuses it there. GUI menu, hint, why-lines, TUI and CLI (`routing=fit`, small-first) carry it; docs/reference.md, the gateway-routing and plugin-runtime pages and the en/zh/ja start pages say it, with the search index rebuilt (via docs-index.mjs; #7065). Run first at the tree rebased on origin/main6e5882109, then at this head's (on 856423806; search index rebuilt; gateway/routes vet, routes, rotation, ./internal/gui, the gateway's new tests and routing-small-first, routing-group-strategy and i18n-keys 42/42 again), mote over its cores with another session's full suite on it and mica's disk full, so on the Linux box (wsl-run) and the Windows box: - go test -tags nogui ./internal/routes ./internal/cli ./internal/tui ./plugins/rotation ./internal/gateway -count=1 -timeout 45m: all ok but gateway, whose one red was this commit's own new test asserting a single group while an auto group for the shared model exists; fixed (FindGroup "group/g") and the window/strategy tests rerun ok, both new ones pass. ./internal/provider ok (its only FAIL was the stale search index, since rebuilt). ./internal/gui -run Budget ok. - Broken by hand: SmallFirst returning Smart's order makes TestSmallFirstOrdersByWindow and the gateway test red ("a short request went to big first"); dropping fit from SaveGroup's whitelist makes the gateway test red ("the group didn't keep Small context first"). - GUI (Chromium + WebKit, en zh zh-TW ja de): routing-small-first, routing-group-strategy, i18n-keys, routing-cheapest-first, routing-free-expiring 112/112 before and after the rebase; every routing*, group* and builtins* file (253): 4139 of 4198, the 59 reds in 11 files that fail the same at origin/main239da9991run alone (57; routing-many-keys moves between languages each run), all filed: #7016, #7097, #6520, #5049, #6512, #4711, #3954, #3799, #4082. - Windows: CGO_ENABLED=0 go vet -tags nogui ./internal/... ./plugins/... ok. gofmt -l clean. Not tried: the full `go test ./...` and darwin vet (mote busy, mica out of disk); a real Cursor/Grok account in a group (the window comes from the same windowIn roomy already trusts). Seen on the way: a recovered "close of closed channel" in continuation_test.go's doneHold fake, no test failed from it.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
// Package rotation is the routings a provider or group can be set to
|
|
// besides Smart: In order, Until used up, In turn, Least used first,
|
|
// Use before expiry, By weight, Free first, Speed first, and a group's
|
|
// Cheapest first, Free quota by expiry and Small context first. While a
|
|
// provider or group is routed by one, it stays on.
|
|
//
|
|
// It is the first consumer of the gateway's router strategy point (P3 of
|
|
// docs/subsystems/plugin-runtime.md): Apply registers internal/routes'
|
|
// strategies, and off, a pool set to one of them is tried in its listed
|
|
// order and the window offers Smart alone.
|
|
package rotation
|
|
|
|
import (
|
|
"github.com/yetone/magpie/internal/pluginrt"
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/routes"
|
|
)
|
|
|
|
func init() {
|
|
pluginrt.Register(pluginrt.Manifest{
|
|
ID: "rotation", API: "^1", Requires: []string{"providers", "gateway"}, Essential: true,
|
|
Name: "Routing strategies", Sub: "The routings besides Smart: In order, Until used up, In turn, Least used first, Use before expiry, By weight, Free first, Speed first and Cheapest first",
|
|
Opens: "providers",
|
|
One: "1 provider or group routed so", Many: "{n} providers and groups routed so",
|
|
InUse: inUse,
|
|
Parts: []pluginrt.Part{{Slot: "part", Key: "rotation"}},
|
|
Apply: func(c *pluginrt.Ctx) error {
|
|
for name, s := range routes.Builtin {
|
|
c.OnDispose(routes.Register(name, s))
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
}
|
|
|
|
// inUse counts the providers and groups routed by one of its strategies;
|
|
// a providers.json that can't be read is not known, so it stays on.
|
|
func inUse() (int, error) {
|
|
routings, err := provider.Routings()
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
n := 0
|
|
for _, r := range routings {
|
|
if _, ok := routes.Builtin[r]; ok {
|
|
n++
|
|
}
|
|
}
|
|
return n, nil
|
|
}
|