routing: Routing 页 story 会把「按积分到期排序」说成「同一小时保持原顺序」
现象
Routing 页一条请求的 story 是这么写的(账号昵称相同,这里用占位符代替):
「(同一昵称)」和「(同一昵称)」在同一小时内重置,保持原顺序,厂商的提示词缓存也保持命中。
但实际排序理由不是这个。排第一的账号是 WorkBuddy,它的积分包在 2026-11-11T16:00:32Z(11-12 00:00 +08) 就到期了,远早于第二个账号的 11-30 重置。它排第一是因为 Soon 更早,不是同小时平手。
根因
网关和页面用的不是同一个键:
- 排序:
Seat.Soon←Allowance.Renewal()。窗口重置时间,当积分在重置前过期(Limit.RunsOut)时替换成过期时间。 - trace 给页面:
Weighed.Renews←weighed()里的w.Renews = l.renews,而left.renews是Allowance.For()的原始窗口重置,不做到期替换。 - 前端:
routing/client.js的renewsBy()用renews+restarts+unreached重建比较,cmpRenews()只看这套数据 → 两个都是 11-30 →c === 0→ 命中 "renew within the same hour" 分支。
即使两者 Soon 相同,Smart 还会用 Seat.Lapse(积分到期时间)做平手规则,story 也没有对应分支。
实测(v0.1.3271):
magpie quota workbuddy --json
Total credits: runsOutAt = 2026-11-11T16:00:32Z
trace order[0] (workbuddy): renews = ["2026-11-30T15:59:59Z"]
trace order[1] (另一个按月重置的账号): renews = ["2026-11-30T15:59:59Z"]
页面只能看到 11-30,所以它认为两者平手;网关实际比较的是 11-11 vs 11-30。
建议改法
internal/gateway/trace.go:Weighed增加Lapse *time.Time(left.lapse已经算好,weighed()里填一行),或直接暴露Soon []time.Time(left.soon就是排序键)。internal/gui/assets/plugins/routing/client.js:renewsBy()优先用soon,没有再用renews;firstWhy()在 "same hour" 分支前加一条:若f.lapse早于next的重置(或早于自己的renews[0]),输出「它的积分在 {d} 到期,先用掉,否则作废」;c === 0且 Lapse 不同 → 「同一小时重置,但它的积分更早到期,先烧它的」;- 只有 Soon 和 Lapse 都相等时才输出「保持原顺序」。
- 这样 story 才是在复述真正的排序键,而不是另一套数据。
附带的图标问题
同一行 story 里,只有第一个名字前面有 provider 图标,第二个同名账号没有图标——看起来像病句。
原因是 logoed() 只取句中最早命中的那个成员插一个图标,命中一次就返回;两个账号昵称相同时,第二个永远不会被处理。这不是某个 provider 缺图标(trace 里两边的 icon 都有值),任何两个同名账号/Key 都会这样。
建议:同名时在名字里带上 provider(如 WorkBuddy · 昵称 / 其他供应商 · 昵称),或让 logoed() 对每个被点名的成员都插图标。
环境
- magpie v0.1.3271,Linux
- 路由组 routing=smart,成员里有一个 WorkBuddy 账号(积分制,积分包有独立到期时间)和一个按月重置的订阅账号
- 相关字段:
order[].renews、order[].unreached、order[].pace;Weighed目前没有lapse/soon
I'm taking this one: the story will restate the gateway's own sort keys (soon and lapse), and two same-named members will each get their icon.
Fixed in 2b08ccc83, released as v0.1.3288. The Routing story now uses the same keys Smart sorts by. When an account's credit pack ends before the other account renews, it says that account goes first because its credits expire first. When both renew within the same hour, it says the one whose credits expire sooner goes first. It says "keeps the order given" only when everything ties. Two same-named accounts (louis and louis) now each show their own provider icon. Leaving this open until @louisgreen0726 confirms it on their setup.
Confirmed on v0.1.3288. The trace now carries soon and lapse per seat, and the story follows them: on the same request, WorkBuddy's seat has soon = lapse = 2026-11-11T16:00:32Z, while the next account's soon is 2026-11-30T15:59:59Z. The line now says the credits expire first instead of "same hour, keep order". The two same-named accounts also each show their own provider icon now.
Looks good on my side — thanks for the quick turnaround.