ysicing_01858 on Discord (Use before expiry, three accounts): the
account at 90% of its week, renewing today, took few requests, while most
went to one renewing tomorrow. Smart and Use before expiry put every
account at 90% of any window into tier 1 ("kept for last"), behind every
one with room, so what that week had left was lost at its reset.
Now 90% means "kept for last" only for a rate cap: the five hours, or a
window that doesn't say how long it runs (Allowance.CapUsed). An account
at 90% of its week alone (Seat.WeekLow) keeps its place: by its reset
(Smart) or by share left per hour (Use before expiry). 98% of any window
still puts it last. A new conversation kept for its session may go to
such an account (readyForNew). The trace carries weekLow, so the Routing
row doesn't call it "kept for last" and doesn't dim it. Least used first,
In order and the others are unchanged. The Pace description in Settings
says so in every language.
Their later report ("90% 额度账号已经自然重置了 现在的调度机制又默认主要调度到刚重置的
账号了") is not this bug, and this change doesn't alter it. Use before
expiry orders by share left / hours to reset. A fresh week is about
0.6%/h (100/168h), so it goes ahead of any account with less than that
per hour, e.g. 30% left in six days. Conversation affinity and the
fewest-tokens tie-break, for paces within a tenth, keep it there. Smart
is the routing that goes by the soonest reset alone. Their numbers would
tell whether a pace is wrong there.
Run on mote:
- At 49d6ad779, the same tree on 0ee424e3e:
- go test internal/routes and internal/provider: ok.
- internal/gateway -run WeekLow|Reset|Smart|Pace|Spread|Session|
Affinity|Weigh|Trace|Routing: ok.
- GUI: 162 routing-*, i18n-* and gui-* files, chromium and webkit:
2535 tests, 2500 passed, 35 failed. The 35 are in 11 files:
routing-folder, -many-keys, -order-unknown, -row-swap, -rule-drag,
-rule-remove, -rules-line, -sky-under, -steady, -steps-cap and
-story-shrinks. Run again alone at 49d6ad779: 26 red. At origin/main
0ee424e3e: 24 red, the same tests (#5088, #4585, #4627, #4628,
#4629). mote was at load 70-200 after a reboot.
- routing-week-low (new) passed: pace and smart, en/zh/zh-TW/ja/de,
1100 and 420, both engines.
- Rebased on origin/main 129baeca0, which changed internal/gateway's
resting. At d187c0c0c (this tree):
- go vet ok; internal/routes ok; internal/gateway -run with Rest|Fail|5 added: ok (146s).
- TestCoreScriptBudget: still red as on main (#5139). This tree's core
is 1534033, 12 bytes under main's.
- routing-week-low and i18n-keys: 46 of 46 ok.
- gofmt clean. go vet for darwin, linux and windows ran at 0ee424e3e.
Broken by hand:
- seatTier back to tier(s.Used): TestWeekLowKeepsItsPlace and
TestWeekLowIsSpentBeforeItsReset red.
- readyForNew without the weekLow clause: "isn't ready for a new
conversation" red.
- client.js's row label back to !w.routing: routing-week-low red (pace
rows lacked "kept for last" for the 93% five-hour account).
Not tried:
- Real accounts near 90% of a week.
- Smart's own description in Settings still says 90% of any window; it
was left as is to keep the core budget from growing.
90 lines
3.9 KiB
Go
90 lines
3.9 KiB
Go
package gateway
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// ysicing_01858 on Discord, three accounts under Use before expiry: one at
|
|
// 90% of its week, renewing today, took few requests, most going to one
|
|
// renewing tomorrow. 90% of any window put an account behind every one
|
|
// with room, so the week it would lose at its reset went unused. A week at
|
|
// 90% alone now keeps its place by when it renews (Smart) or its pace
|
|
// (Use before expiry), and new conversations kept for the session may go
|
|
// to it; 90% of its five hours, a rate cap, still holds it back, and 98%
|
|
// of its week still puts it last. Least used first is unchanged.
|
|
func TestWeekLowIsSpentBeforeItsReset(t *testing.T) {
|
|
old := allowances
|
|
defer func() { allowances = old }()
|
|
now := time.Now()
|
|
share := map[string]provider.Allowance{}
|
|
allowances = func(string) map[string]provider.Allowance { return share }
|
|
acct := func(user string) candidate {
|
|
return candidate{p: provider.Provider{ID: "codex", Account: &provider.Account{Agent: "codex", User: user}}, model: "gpt-5.6-sol", rest: "codex#" + user}
|
|
}
|
|
plan := func(fiveHours, week float64, renews time.Duration) provider.Allowance {
|
|
return provider.Allowance{
|
|
{Used: fiveHours, Resets: now.Add(3 * time.Hour), Span: 5 * time.Hour},
|
|
{Used: week, Resets: now.Add(renews), Span: 7 * 24 * time.Hour},
|
|
}
|
|
}
|
|
for _, routing := range []string{provider.Pace, ""} {
|
|
name := map[string]string{provider.Pace: "pace", "": "smart"}[routing]
|
|
p := provider.Provider{ID: "codex", Routing: routing, Account: &provider.Account{Agent: "codex", User: "b@x.com"}}
|
|
order := func() (string, []Weighed) {
|
|
got, wg := weigh(p, []candidate{acct("b@x.com"), acct("a@x.com")}, "gpt-5.6-sol", provider.Chat)
|
|
var s []string
|
|
var ws []Weighed
|
|
for _, c := range got {
|
|
s = append(s, c.p.Account.User[:1])
|
|
ws = append(ws, weighed(c, p, wg, false, provider.Chat))
|
|
}
|
|
return strings.Join(s, ""), ws
|
|
}
|
|
// B has room and renews tomorrow; A is at 91% of its week, which
|
|
// renews in three hours: 9% left in 3h is more per hour than 70%
|
|
// in 48h, and sooner, so A goes first by either routing
|
|
share["b@x.com"] = plan(10, 30, 48*time.Hour)
|
|
share["a@x.com"] = plan(20, 91, 3*time.Hour)
|
|
got, ws := order()
|
|
if got != "ab" {
|
|
t.Fatalf("%s: a week at 91%% renewing in 3h went %s, want ab", name, got)
|
|
}
|
|
if !ws[0].WeekLow || ws[1].WeekLow {
|
|
t.Fatalf("%s: weekLow %v %v, want A only", name, ws[0].WeekLow, ws[1].WeekLow)
|
|
}
|
|
// a new conversation kept for the session may go to A: Smart and
|
|
// Use before expiry would put one there
|
|
if !readyForNew([]Weighed{ws[1], ws[0]}, 1) {
|
|
t.Fatalf("%s: A at 91%% of its week alone isn't ready for a new conversation", name)
|
|
}
|
|
// at 92% of its five hours it is near a rate cap: kept for last
|
|
share["a@x.com"] = plan(92, 91, 3*time.Hour)
|
|
if got, ws = order(); got != "ba" || ws[1].WeekLow {
|
|
t.Fatalf("%s: five hours at 92%%: %s weekLow %v, want ba, false", name, got, ws[1].WeekLow)
|
|
}
|
|
if readyForNew(ws, 1) {
|
|
t.Fatalf("%s: A at 92%% of its five hours is ready for a new conversation", name)
|
|
}
|
|
// all but used up: last, whatever its reset
|
|
share["a@x.com"] = plan(20, 98, 3*time.Hour)
|
|
if got, ws = order(); got != "ba" || ws[1].WeekLow {
|
|
t.Fatalf("%s: week at 98%%: %s weekLow %v, want ba, false", name, got, ws[1].WeekLow)
|
|
}
|
|
}
|
|
// Least used first goes by the share used: A at 91% goes after B, and
|
|
// the trace doesn't call it kept with those with room
|
|
p := provider.Provider{ID: "codex", Routing: provider.LeastUsed, Account: &provider.Account{Agent: "codex", User: "b@x.com"}}
|
|
share["a@x.com"] = plan(20, 91, 3*time.Hour)
|
|
got, wg := weigh(p, []candidate{acct("a@x.com"), acct("b@x.com")}, "gpt-5.6-sol", provider.Chat)
|
|
if got[0].p.Account.User != "b@x.com" {
|
|
t.Fatalf("least used: %s first, want b", got[0].p.Account.User)
|
|
}
|
|
if w := weighed(got[1], p, wg, false, provider.Chat); w.WeekLow {
|
|
t.Fatalf("least used: A told weekLow")
|
|
}
|
|
}
|