dsh-model-rotator 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/CHANGELOG.zh.md +6 -0
- package/index.js +71 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
User-visible changes, newest first. Commit hashes in brackets.
|
|
6
6
|
|
|
7
|
+
## 0.2.5
|
|
8
|
+
- **Fixed: an exhausted quota read as a rate limit, so the switch never happened.** WorkBuddy answers "可用账号均在限流中,最近一个将于 … 解禁" — every account exhausted. Classified as `rate-limit` it cooled for 60 seconds and retried the same wall; one evening accumulated 702 failures. An account pool that is entirely unavailable is now recognised as `quota` and rests like any other balance wall.
|
|
9
|
+
- **New: the release time is parsed out of the message.** When the provider states when it comes back, that beats any calendar policy. `parseReleaseTime()` accepts `2026/10/18 00:29:52`, `2026-10-18 00:29:52` and ISO forms; a parsed time becomes the exact cooldown (measured here: 60 seconds became 1.7 hours), and only an unparseable message falls back to the next-day rule.
|
|
10
|
+
- **Fixed: a switch was not persisted.** The switch notice was queued and then returned, so `scheduleStatsSave()` never ran — a restart showed the old model still in use. The save happens with the enqueue now.
|
|
11
|
+
- **Improved: a pin defers while it cools.** A model pinned with `model_rotator_select` took the head on every turn even while cooling, so every turn opened by walking into the same wall. The pin now applies only while the model is healthy; the ranking decides during cooldown and the pin returns by itself afterwards. [`TBD`]
|
|
12
|
+
|
|
7
13
|
## 0.2.4
|
|
8
14
|
- **Docs**: adds this bilingual changelog, listed in the manifest and gated by release-check; the README and repository description were refreshed too. The npm package now carries the changelog with each release. Also fixes a crash in this gate: the SHA check fed a comment line to readFileSync, so the gate died with ENOENT and hid every other check behind it. [`fc14e99`]
|
|
9
15
|
|
package/CHANGELOG.zh.md
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
本文件按版本记录用户可感知的变化。方括号内为对应提交。
|
|
6
6
|
|
|
7
|
+
## 0.2.5
|
|
8
|
+
- **修复:额度耗尽被误判为限流,导致不切换**。WorkBuddy 的报错是「可用账号均在限流中,最近一个将于 … 解禁」,判成 `rate-limit` 就按 60 秒冷却反复重试同一堵墙(实测一晚累计 702 次失败)。现新增「账号池耗尽」识别归入 `quota`,与「余额不足」同一处置。
|
|
9
|
+
- **新增:解析报错里的解禁时间**。提供方既然写明了何时恢复,就比任何日历策略都准。`parseReleaseTime()` 支持 `2026/10/18 00:29:52`、`2026-10-18 00:29:52` 与 ISO 形式;解析到就用作精确冷却(本次实测把 60 秒变成 1.7 小时),解析不到才回落到次日策略。
|
|
10
|
+
- **修复:切换后未落盘**。切换通知入队后直接 `return`,`scheduleStatsSave()` 没有被调用,所以重启后看不到这次切换发生过。现在入队时一并保存。
|
|
11
|
+
- **改进:pin 在冷却时让位**。此前被 `model_rotator_select` 置顶的模型即使正在冷却也每轮抢在第一位,于是每轮都先撞一次墙再切换。现只在模型健康时置顶,冷却期间交给排序,冷却结束后自动回到首位。[`TBD`]
|
|
12
|
+
|
|
7
13
|
## 0.2.4
|
|
8
14
|
- **文档**:新增中英双语更新说明(本文件),并纳入发布清单与发布门;README 与仓库首页说明同步更新。npm 包开始随版本携带 CHANGELOG。同时修复发布门自身的一处崩溃:SHA 校验把清单注释行当成文件名读,导致整门以 ENOENT 中止、掩盖其余全部检查。[`fc14e99`]
|
|
9
15
|
|
package/index.js
CHANGED
|
@@ -703,6 +703,12 @@ const FAILURE_KIND_TESTS = [
|
|
|
703
703
|
// that classification would cost the daily rest a dead balance needs.
|
|
704
704
|
['unsupported', /(does not support|doesn't support|unsupported|not supported|no such model|unknown model|model not found|invalid model|model is not available)/i],
|
|
705
705
|
['auth', /(invalid[ _-]*api[ _-]*key|api[ _-]*key[ _-]*(invalid|missing|expired)|unauthori[sz]ed|unauthenticated|authentication|credential|permission denied|forbidden|401|403|鉴权|密钥|授权失败|认证失败)/i],
|
|
706
|
+
// An account pool that is entirely unavailable is a quota wall wearing the
|
|
707
|
+
// word "rate limit". WorkBuddy answers "可用账号均在限流中,最近一个将于 … 解禁" —
|
|
708
|
+
// every account exhausted, with the release timestamp in the sentence. Classified
|
|
709
|
+
// as rate-limit it cooled for 60s and retried the same wall 702 times in one
|
|
710
|
+
// evening; as quota it rests until the pool actually comes back.
|
|
711
|
+
['quota', /(?:可用)?账号[^。,,;;]{0,6}(?:均|全部|都)[^。,,;;]{0,8}(?:限流|不可用|耗尽|用尽)|均在限流|均不可用|all accounts?(?:[ _-]+\w+){0,3}[ _-]+(?:exhausted|unavailable|rate[ _-]*limited)|every account[ _-]+(?:is[ _-]+)?(?:exhausted|unavailable)/i],
|
|
706
712
|
['rate-limit', /(rate[ _-]*limit|too many requests|request[ _-]*limit|throttl|429|限流|请求过于频繁|过于频繁|qps)/i],
|
|
707
713
|
['server', /(internal[ _-]*server[ _-]*error|bad[ _-]*gateway|service[ _-]*unavailable|server[ _-]*(error|overload)|overloaded|gateway[ _-]*timeout|50[0-9])/i],
|
|
708
714
|
['network', /(econnreset|econnrefused|etimedout|enotfound|eai_again|socket|network|fetch failed|timed?[ _-]?out|timeout|disconnected|connection (closed|reset|refused)|aborted)/i],
|
|
@@ -768,9 +774,54 @@ export function quotaRestUntil(nowMs, cfg) {
|
|
|
768
774
|
return Math.max(boundary.getTime(), nowMs + floor)
|
|
769
775
|
}
|
|
770
776
|
|
|
777
|
+
/**
|
|
778
|
+
* A release time the provider stated in its own words, in epoch ms, or 0.
|
|
779
|
+
*
|
|
780
|
+
* A quota message often says exactly when the pool comes back — WorkBuddy writes
|
|
781
|
+
* "最近一个将于 2026/10/18 00:29:52 解禁". That timestamp is strictly better than any
|
|
782
|
+
* policy we could invent: it is the provider telling us when to try again. Fixed
|
|
783
|
+
* midnight arithmetic ignored it and could either sleep far too long or wake into
|
|
784
|
+
* the same wall.
|
|
785
|
+
*
|
|
786
|
+
* Accepts the shapes that actually appear: `2026/10/18 00:29:52`, `2026-10-18
|
|
787
|
+
* 00:29:52`, and an ISO 8601 stamp. A date with no time is treated as that day's
|
|
788
|
+
* midnight. The value is read in the host's local zone, which is the zone these
|
|
789
|
+
* messages are written in.
|
|
790
|
+
*
|
|
791
|
+
* Returns 0 when nothing parseable is present, so the caller falls back to policy.
|
|
792
|
+
* Exported as a test seam: this is date arithmetic on prose, exactly the kind of
|
|
793
|
+
* thing that should be pinned by an offline assertion.
|
|
794
|
+
*/
|
|
795
|
+
export function parseReleaseTime(message) {
|
|
796
|
+
const text = String(message ?? '')
|
|
797
|
+
if (text === '') return 0
|
|
798
|
+
const patterns = [
|
|
799
|
+
/(\d{4})[/-](\d{1,2})[/-](\d{1,2})[ T](\d{1,2}):(\d{2})(?::(\d{2}))?/,
|
|
800
|
+
/(\d{4})[/-](\d{1,2})[/-](\d{1,2})/,
|
|
801
|
+
]
|
|
802
|
+
for (const re of patterns) {
|
|
803
|
+
const m = text.match(re)
|
|
804
|
+
if (m === null) continue
|
|
805
|
+
const [, y, mo, d, h = '0', mi = '0', sec = '0'] = m
|
|
806
|
+
const at = new Date(
|
|
807
|
+
Number(y), Number(mo) - 1, Number(d),
|
|
808
|
+
Number(h), Number(mi), Number(sec), 0,
|
|
809
|
+
)
|
|
810
|
+
const ms = at.getTime()
|
|
811
|
+
// A provider sentence about the past is a stale copy, not a release time.
|
|
812
|
+
if (Number.isFinite(ms) && ms > 0) return ms
|
|
813
|
+
}
|
|
814
|
+
return 0
|
|
815
|
+
}
|
|
816
|
+
|
|
771
817
|
/** Instant until which this failure keeps the candidate out of the ranking. */
|
|
772
|
-
function cooldownUntilFor(stat, cfg, nowMs, errorKind) {
|
|
773
|
-
if (errorKind === 'quota')
|
|
818
|
+
function cooldownUntilFor(stat, cfg, nowMs, errorKind, message) {
|
|
819
|
+
if (errorKind === 'quota') {
|
|
820
|
+
// The provider's own release timestamp outranks our calendar policy.
|
|
821
|
+
const stated = parseReleaseTime(message)
|
|
822
|
+
if (stated > nowMs) return stated
|
|
823
|
+
return quotaRestUntil(nowMs, cfg)
|
|
824
|
+
}
|
|
774
825
|
return nowMs + cooldownFor(stat, cfg)
|
|
775
826
|
}
|
|
776
827
|
|
|
@@ -1476,9 +1527,18 @@ export function apply(ctx, config = {}, runtime = {}) {
|
|
|
1476
1527
|
const ordered = [current, ...byFamily.map(row => row.pair)]
|
|
1477
1528
|
|
|
1478
1529
|
// A pin short-circuits the ranking: the user asked for this head explicitly.
|
|
1530
|
+
//
|
|
1531
|
+
// Unless it is cooling down. A pin is a preference about which healthy model to
|
|
1532
|
+
// try first, not a promise to walk into the same wall every turn: a pinned model
|
|
1533
|
+
// that just failed would be dispatched first on every subsequent turn, fail
|
|
1534
|
+
// again, and make the reader watch the same switch over and over. While it cools
|
|
1535
|
+
// the ranking decides, and the model returns to the head by itself once the
|
|
1536
|
+
// cooldown clears - the pin is not forgotten, only deferred.
|
|
1479
1537
|
if (pinned !== '' && pinned !== current.provider + '/' + current.model) {
|
|
1480
1538
|
const at = ordered.findIndex(pair => pair.provider + '/' + pair.model === pinned)
|
|
1481
|
-
|
|
1539
|
+
const pinnedStat = at > 0 ? statFor(pinned) : null
|
|
1540
|
+
const pinnedCooling = pinnedStat !== null && pinnedStat.cooldownUntil > nowMs
|
|
1541
|
+
if (at > 0 && !pinnedCooling) ordered.unshift(ordered.splice(at, 1)[0])
|
|
1482
1542
|
}
|
|
1483
1543
|
|
|
1484
1544
|
return ordered.slice(0, Math.min(cfg.maxCandidates, HARD_MAX_CANDIDATES))
|
|
@@ -1836,6 +1896,11 @@ export function apply(ctx, config = {}, runtime = {}) {
|
|
|
1836
1896
|
to: { provider: pair.provider, model: pair.model, displayName: pair.displayName ?? '' },
|
|
1837
1897
|
reason: classifyFailureKind(String(lastFailure ?? '')),
|
|
1838
1898
|
})
|
|
1899
|
+
// The switch itself is the event worth persisting. Without this the
|
|
1900
|
+
// counters above were written but the *decision* was not, so a restart
|
|
1901
|
+
// showed the old model still in use and the switch looked like it had
|
|
1902
|
+
// never happened.
|
|
1903
|
+
scheduleStatsSave()
|
|
1839
1904
|
}
|
|
1840
1905
|
}
|
|
1841
1906
|
return
|
|
@@ -1880,7 +1945,7 @@ export function apply(ctx, config = {}, runtime = {}) {
|
|
|
1880
1945
|
// buries the provider's words under ours.
|
|
1881
1946
|
if (!hostRefusal || trustedFailure) {
|
|
1882
1947
|
stat.consecutiveFailures += 1
|
|
1883
|
-
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind)
|
|
1948
|
+
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind, failedBecause)
|
|
1884
1949
|
}
|
|
1885
1950
|
// The error chunk is already in the consumer's hands, so the walk ends
|
|
1886
1951
|
// here either way - and it must, because a fault of ours would repeat
|
|
@@ -1924,7 +1989,7 @@ export function apply(ctx, config = {}, runtime = {}) {
|
|
|
1924
1989
|
// route stays fully available to the next turn.
|
|
1925
1990
|
if (!hostRefusal || trustedFailure) {
|
|
1926
1991
|
stat.consecutiveFailures += 1
|
|
1927
|
-
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind)
|
|
1992
|
+
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind, failedBecause)
|
|
1928
1993
|
}
|
|
1929
1994
|
|
|
1930
1995
|
// A fault of ours ends the walk. Every further candidate would hit the
|
|
@@ -2625,7 +2690,7 @@ export function apply(ctx, config = {}, runtime = {}) {
|
|
|
2625
2690
|
const failedKind = classifyFailureKind(failure)
|
|
2626
2691
|
stat.failures += 1
|
|
2627
2692
|
stat.consecutiveFailures += 1
|
|
2628
|
-
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind)
|
|
2693
|
+
stat.cooldownUntil = cooldownUntilFor(stat, cfg, Date.now(), failedKind, failedBecause)
|
|
2629
2694
|
stat.lastError = failure
|
|
2630
2695
|
stat.lastErrorKind = failedKind
|
|
2631
2696
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-model-rotator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Model auto-ranking and transparent failover for DeepSeek Harness: ranks discovered models by measured connectivity and speed, switches to the next candidate inside the same turn when the current one is unusable, and ships a grouped model list with per-channel switches. Never modifies model or provider configuration.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|