magpie icon indicating copy to clipboard operation
magpie copied to clipboard

routing: Smart 只看重置时间,可能让带周上限的套餐永远用不完月度额度(建议加可耗尽性判断)

Open louisgreen0726 opened this issue 4 weeks ago • 4 comments

背景

Smart 目前按「最大窗口的重置时间」排序。这个规则本身有道理(#1778 里解释过:当一个月的额度小于各周之和时,月才是真正的上限),但它只回答「谁先重置」,不回答「在重置之前还来不来得及把剩下的额度用掉」。

现象

一个套餐同时有 5 小时 / 每周 / 每月三层窗口,周和月各自独立重置(月 20,000,周 7,000)。它所在的组用 smart,组里还有按周重置的账号。

由于排序键是月重置(最晚的那一个),它永远排在周重置账号之后,只有在前面全部耗尽或休息时才会被用到。也就是说:它能吃到多少流量,完全取决于别人什么时候用完,而不是它自己还剩多少。

真实数字

本机 v0.1.3260,用量卡片当时的读数:

窗口 已用 上限 重置
5 小时 0 2,000 —
每周 1,628 7,000 次日 00:00
每月 1,628 20,000 下月 6 日 23:59

月度剩 18,372,距重置还有 4 个周窗口。每周最多 7,000,所以理论上还能烧 4 × 7,000 = 28,000,现在开始追还来得及。

但它一直排不上。如果拖到只剩 2 个周窗口才开始被使用,上限就变成 14,000 < 18,372 —— 月度额度在数学上已经不可能用完。若拖到最后一周,最多只能烧 7,000,浪费 11,000 以上。

为什么不是「哪个窗口该决定排序」的问题

即使认可「月是真正的上限」,也还有一个独立的问题:排在最后的账号可能根本等不到流量。重置时间排序假设了「只要还有额度,迟早会用上」,但对被排在后面的账号来说,能不能用上取决于别人什么时候耗尽,而这个时间点可能已经晚于它自己的月度重置。

为什么 pace 也不行

pace 会取各预算窗口里最小的 pace:这个账号月 pace ≈ 0.13(剩余 91.9% ÷ 696 小时),周 pace ≈ 3.25(剩余 76.7% ÷ 23.6 小时),取小之后仍由月窗口支配,排序不变。

建议

在比较重置时间之前,先加一步「可耗尽性」判断:

  • 剩余额度 > 距重置的周窗口数 × 周上限 → 说明月度额度注定用不完,把这个账号提到仍有额度的账号之前;
  • 或者按「重置时预计会损失的额度 / 距重置时间」排序,让「快到期且剩余量大」的账号优先。

如果不想改排序,至少在 Routing 的说明行里标一句「按当前顺序,本月预计有 X 无法用完」,让用户自己决定要不要手动切过去。

参考

  • #1778:最大窗口排序(显示部分已修,排序被确认为有意为之)
  • #4923:pace 对即将过期积分的排序

louisgreen0726 avatar Nov 07 '26 17:11 louisgreen0726

补充一下具体来源:这个结构是火山方舟 Agent Plan,magpie 内置的 volcengine provider 能读出 5 小时 / 每周 / 每月三层窗口(v0.1.3260,magpie quota volcengine --json 可见)。上面表格里的数字就是该账户当时的读数,没有做任何加工。

louisgreen0726 avatar Nov 07 '26 17:11 louisgreen0726

Thanks for the real numbers. Fixed in 3b541a7f3, released as v0.1.3269.

Smart now asks whether an account's biggest window can still be used up. When the month has more left than its weeks can let through before it renews, Smart ranks the account by its week instead. This is your first suggestion, made exact: it counts the current week up to its own reset and any partial week at the end.

  • At your reading: 18,372 left, with the month 696 h away. The four weeks still to come carry about 28,000, so nothing changes yet.
  • About two weeks before the month renews: 14,000 is less than what is left, so the plan goes first, before the point where a week's leftover would be lost.
  • A month that holds less than its weeks add up to: it still ranks by the month while the weeks can carry it, as in #1778.

When this happens, the Routing page's story line says that the shorter window decided.

Not changed yet: Use before expiry (pace) still ranks this plan by its month. That is #5641. Ark replies that only send a percentage carry no counts, so the rule can't apply to them.

Could you confirm on v0.1.3269 once your month gets within about two weeks of renewing? I'll keep this open until then.

yetone avatar Nov 07 '26 18:11 yetone

Follow-up in ee8f4de36 (v0.1.3284): the longer Smart explanation wrapped at narrow widths and tripped a ResizeObserver loop error in WebKit; the story now redraws on the next frame. The ranking change itself is in v0.1.3269. @louisgreen0726, please confirm once you've updated.

yetone avatar Nov 07 '26 19:11 yetone

Updated to v0.1.3288. The rule is in the binary (unreached now shows up in the trace), but at my numbers it hasn't fired yet:

  • month: 1,628 / 20,000 used, 18,372 left, renews 2026-12-06 23:59 +08
  • week: 1,628 / 7,000, next reset 2026-11-09 00:00

From 11-09 the next weekly reset is 11-16, leaving 21 days to the month reset — 21,000, still more than 18,372. From 11-16 it becomes 11-23, 14 days — 14,000 < 18,372, so I expect it to flip then, with the story saying the shorter window decided. I'll confirm here once it does.

Keeping this open until then.

louisgreen0726 avatar Nov 07 '26 20:11 louisgreen0726