usage: a model's region deployment answered under its own name is not a swap (plugins#628)
WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg, its paid id for the Singapore deployment. The plugin's product config names it paidId to the free deepseek-v4.1-flash, with one window for both. WorkBuddy answers under the model's own name, so the Routing page tagged each request "请求 deepseek-v4.1-flash-sg · 实际 deepseek-v4.1-flash". Old routes and kept usage rows kept the mark, so removing the model and setting the provider up again didn't clear it (chansee97, plugins#628). - RegionTail (internal/usage/served.go) covers a name that is the other with -sg, -us, -eu, -cn, -intl or -global after it. Such a pair is the same model, and Swapped excludes it. - A region in both names, or a name that differs besides the region, is still a swap. - Kept rows (request_page.go) and kept routes (gateway history.go's routedAgain) are judged again with it, so old marks go too. Run on mote, at5f0a84a00plus this change: - gofmt -l internal plugins: clean. - go test -count=1 -timeout 45m on ./internal/usage, ./internal/usageapi, ./internal/budget, ./internal/davsync, ./internal/middleware, ./internal/otlp, ./internal/gui/..., ./internal/cli, ./internal/tui, ./internal/gateway/..., ./plugins/middleware/..., ./plugins/otel/... and ./internal/agent (every importer of internal/usage): all ok except four reds that are filed and don't touch swap marking: - internal/gui TestMainWindowCorners (#3949) - internal/cli TestEveryRouteHasACommandOrIsNamed (#4826) - internal/gateway TestCodexPoolSaysTheClientsVersion (#4807) - internal/gateway TestUnroutedRequestShownThenAnswered (#4200) - GOOS=linux and GOOS=windows go vet ./internal/usage ./internal/gateway/...: ok. After the rebase ontoa32588528, which changed internal/usage's request_page.go and match_chunks.go: - ./internal/usage and ./internal/usageapi: ok. - go test -run "RouteKept|Swap|Served|History" ./internal/gateway: ok. - vet: ok. Broken by hand, each red: - RegionTail taken out of Swapped: TestSwappedRegionTail. - The kept-row re-judge taken out: TestKeptRowRegionTailNotSwapped. - The routedAgain re-judge taken out: TestRouteKeptRegionTailNotSwapped. Not tried: - A live WorkBuddy AI request to -sg, which would spend credits. That WorkBuddy answers -sg under the plain name rests on the report. - The reporter's screen. This assumes the "实际" tag they saw is the Routing page's swap tag (or Usage's Served column, which is fixed by the same rule).
This commit is contained in:
@@ -436,7 +436,7 @@ func (r *Route) routedAgain() {
|
||||
for i := range r.Tries {
|
||||
if tr := &r.Tries[i]; tr.Swapped && usage.GroupRouted(tr.Model, tr.Served) {
|
||||
tr.Swapped, tr.Routed = false, true
|
||||
} else if tr.Swapped && (usage.SameSpelled(tr.Model, tr.Served) || usage.ServingName(tr.Model, tr.Served) || usage.VendorAlias(tr.Model, tr.Served) || usage.ListedAs(tr.ID, tr.Model, tr.Served)) {
|
||||
} else if tr.Swapped && (usage.SameSpelled(tr.Model, tr.Served) || usage.ServingName(tr.Model, tr.Served) || usage.VendorAlias(tr.Model, tr.Served) || usage.RegionTail(tr.Model, tr.Served) || usage.ListedAs(tr.ID, tr.Model, tr.Served)) {
|
||||
tr.Swapped = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package gateway
|
||||
|
||||
import "testing"
|
||||
|
||||
// A route kept with a try marked swapped for WorkBuddy AI's
|
||||
// deepseek-v4.1-flash-sg answered as deepseek-v4.1-flash (the Singapore
|
||||
// deployment's id and the model's own name, plugins#628) is read as not
|
||||
// swapped, so the Routing page's "served" tag goes from old routes too;
|
||||
// deepseek-v4.1-flash-sg answered by deepseek-v4.1-pro stays swapped.
|
||||
func TestRouteKeptRegionTailNotSwapped(t *testing.T) {
|
||||
r := &Route{Swapped: true, Served: "deepseek-v4.1-flash", Tries: []Try{{ID: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-flash", Swapped: true}}}
|
||||
r.routedAgain()
|
||||
if r.Swapped || r.Tries[0].Swapped {
|
||||
t.Fatalf("still swapped: %+v", r)
|
||||
}
|
||||
r = &Route{Swapped: true, Served: "deepseek-v4.1-pro", Tries: []Try{{ID: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-pro", Swapped: true}}}
|
||||
r.routedAgain()
|
||||
if !r.Swapped || !r.Tries[0].Swapped {
|
||||
t.Fatalf("a real swap was cleared: %+v", r)
|
||||
}
|
||||
}
|
||||
@@ -429,8 +429,8 @@ func (c *rowChunk) row(i int) Row {
|
||||
}
|
||||
if r.Swapped && p.Flags&swapKnown == 0 && (SameSpelled(r.Model, r.Served) || ServingName(r.Model, r.Served) || RelayRenamed(r.Model, r.Served) || VendorAlias(r.Model, r.Served)) {
|
||||
r.Swapped = false // kept before a name spelled otherwise, a vendor's serving name, a relay's rename or the vendor's own alias was the same
|
||||
} else if r.Swapped && ListedAs(r.Provider, r.Model, r.Served) {
|
||||
r.Swapped = false // the name the provider's list gives the model asked for
|
||||
} else if r.Swapped && (RegionTail(r.Model, r.Served) || ListedAs(r.Provider, r.Model, r.Served)) {
|
||||
r.Swapped = false // a region's deployment of the model (kept before plugins#628), or the name the provider's list gives the model asked for
|
||||
}
|
||||
if r.cacheNotCounted() {
|
||||
r.CacheUnknown = true // kept before its plugin said its vendor counts no cache
|
||||
|
||||
@@ -64,10 +64,30 @@ func bareModel(m string) string {
|
||||
// is the member another magpie's routing group sent it to (GroupRouted),
|
||||
// nor a vendor's own name for the deployment serving the model
|
||||
// (ServingName), nor the model a relay sold under a name of its own
|
||||
// (RelayRenamed).
|
||||
// (RelayRenamed), nor the model at a region's deployment (RegionTail).
|
||||
func Swapped(sent, served string) bool {
|
||||
a, b := bareModel(sent), bareModel(served)
|
||||
return a != "" && b != "" && squash(a) != squash(b) && a != "auto" && squash(bareModel(provider.EffortFamily(a))) != squash(b) && !GroupRouted(sent, served) && !ServingName(sent, served) && !RelayRenamed(sent, served) && !VendorAlias(sent, served)
|
||||
return a != "" && b != "" && squash(a) != squash(b) && a != "auto" && squash(bareModel(provider.EffortFamily(a))) != squash(b) && !GroupRouted(sent, served) && !ServingName(sent, served) && !RelayRenamed(sent, served) && !VendorAlias(sent, served) && !RegionTail(sent, served)
|
||||
}
|
||||
|
||||
// regionTail is a region a vendor's id names its deployment of a model
|
||||
// by: WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg,
|
||||
// its paid id for the Singapore deployment (the plugin's product config
|
||||
// names it paidId to the free deepseek-v4.1-flash, one window for both),
|
||||
// and answers under the model's own name.
|
||||
var regionTail = regexp.MustCompile(`[-_](?:sg|us|eu|cn|intl|global)$`)
|
||||
|
||||
// RegionTail reports whether one of sent and served is the other with a
|
||||
// region after it: the same model at that region's deployment, not
|
||||
// another model swapped in (plugins#628, chansee97). A region in both,
|
||||
// or a name that differs besides it, is not this.
|
||||
func RegionTail(sent, served string) bool {
|
||||
a, b := bareModel(sent), bareModel(served)
|
||||
if a == "" || b == "" {
|
||||
return false
|
||||
}
|
||||
ra, rb := regionTail.ReplaceAllString(a, ""), regionTail.ReplaceAllString(b, "")
|
||||
return (ra != a) != (rb != b) && ra != "" && squash(ra) == squash(rb)
|
||||
}
|
||||
|
||||
// vendorAlias is a vendor's own alias for one of its models, as the
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package usage
|
||||
|
||||
import "testing"
|
||||
|
||||
// WorkBuddy AI lists DeepSeek V4.1 Flash as deepseek-v4.1-flash-sg, its
|
||||
// paid id for the Singapore deployment, and answers under the model's own
|
||||
// name: the Routing page marked it "requested deepseek-v4.1-flash-sg ·
|
||||
// served deepseek-v4.1-flash" (plugins#628, chansee97). A region after
|
||||
// the name asked for, or after the name that answered, is the same model.
|
||||
// Another model with a region after it is still a swap, as is one region
|
||||
// answered as another.
|
||||
func TestSwappedRegionTail(t *testing.T) {
|
||||
for _, c := range [][2]string{
|
||||
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-flash"},
|
||||
{"deepseek-v4.1-flash", "deepseek-v4.1-flash-sg"},
|
||||
{"workbuddy-ai/deepseek-v4.1-flash-sg", "DeepSeek-V4.1-Flash"},
|
||||
{"glm-5.1-intl", "glm-5.1"},
|
||||
{"qwen3.8-plus_cn", "qwen3.8-plus"},
|
||||
} {
|
||||
if Swapped(c[0], c[1]) {
|
||||
t.Errorf("%s answered as %s is the model asked for", c[0], c[1])
|
||||
}
|
||||
}
|
||||
for _, c := range [][2]string{
|
||||
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-pro"},
|
||||
{"deepseek-v4.1-pro-sg", "deepseek-v4.1-flash"},
|
||||
{"deepseek-v4.1-flash-sg", "deepseek-chat"},
|
||||
{"deepseek-v4.1-flash-sg", "deepseek-v4.1-flash-thinking"},
|
||||
{"gpt-5-sg", "gpt-5-mini"},
|
||||
{"sg", "us"},
|
||||
} {
|
||||
if !Swapped(c[0], c[1]) {
|
||||
t.Errorf("%s answered as %s is another model", c[0], c[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A row kept marked swapped before plugins#628 is read back as not
|
||||
// swapped; a real swap stays one.
|
||||
func TestKeptRowRegionTailNotSwapped(t *testing.T) {
|
||||
c := &rowChunk{}
|
||||
c.add(Row{Record: Record{Provider: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-flash"}, Swapped: true}, "", 0, false)
|
||||
c.add(Row{Record: Record{Provider: "workbuddy-ai", Model: "deepseek-v4.1-flash-sg", Served: "deepseek-v4.1-pro"}, Swapped: true}, "", 1, false)
|
||||
for _, chunk := range []*rowChunk{c, c.pack().unpack()} {
|
||||
if chunk.row(0).Swapped || !chunk.row(1).Swapped {
|
||||
t.Fatalf("region %v, other model %v", chunk.row(0).Swapped, chunk.row(1).Swapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user