dsh-model-rotator 0.2.5 → 0.2.6

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 CHANGED
@@ -4,11 +4,15 @@
4
4
 
5
5
  User-visible changes, newest first. Commit hashes in brackets.
6
6
 
7
+ ## 0.2.6
8
+ - **Fixed: other channels of the same model were deduplicated out of the walk.** This is the real problem 0.2.5 uncovered once the classification was right: when WorkBuddy met its quota wall, **buddy and trae — the same model on other channels — were healthy**, but "one channel per model family" kept them out of the candidate list entirely, so the turn ended on the quota error with a working route sitting one slot away. A family now keeps up to **two channels**: the ranked winner plus one proven-usable backup. A cooling backup is dropped, since dispatching it would walk into the same wall. The switch notice is already deduplicated by model id, so arriving at a second channel of the same model is not announced as "switched to the same model again".
9
+ - Measured: before the fix the walk held one channel of `deepseek-v4.1-flash` and `buddy` (ok=1538, healthy) was absent; after it holds three and `buddy` is back. [`TBD`]
10
+
7
11
  ## 0.2.5
8
12
  - **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
13
  - **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
14
  - **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`]
15
+ - **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. [`a2d5a0c`]
12
16
 
13
17
  ## 0.2.4
14
18
  - **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`]
package/CHANGELOG.zh.md CHANGED
@@ -4,11 +4,15 @@
4
4
 
5
5
  本文件按版本记录用户可感知的变化。方括号内为对应提交。
6
6
 
7
+ ## 0.2.6
8
+ - **修复:同一模型的其它渠道被去重挡在候选之外**。这是 0.2.5 修好分类之后暴露出来的真问题:WorkBuddy 撞上额度墙时,**buddy 与 trae 这两个同模型的渠道是健康的**,但「每个模型家族只保留一个渠道」的规则让它们根本不在候选里,于是整轮以额度错误结束 —— 而可用线路就在旁边。现每个家族保留最多 **2 个渠道**(排名靠前的一个 + 一个经证实用可用的备份);备份若正在冷却则不保留,因为那等于再撞一次同一堵墙。切换通知本就按模型 id 去重,所以落到同模型的第二个渠道不会被播报成「又切到同一模型」。
9
+ - 实测:修复前候选列表里 `deepseek-v4.1-flash` 只占 1 个渠道,`buddy`(ok=1538,健康)缺失;修复后占 3 个,`buddy` 回到列表中。[`TBD`]
10
+
7
11
  ## 0.2.5
8
12
  - **修复:额度耗尽被误判为限流,导致不切换**。WorkBuddy 的报错是「可用账号均在限流中,最近一个将于 … 解禁」,判成 `rate-limit` 就按 60 秒冷却反复重试同一堵墙(实测一晚累计 702 次失败)。现新增「账号池耗尽」识别归入 `quota`,与「余额不足」同一处置。
9
13
  - **新增:解析报错里的解禁时间**。提供方既然写明了何时恢复,就比任何日历策略都准。`parseReleaseTime()` 支持 `2026/10/18 00:29:52`、`2026-10-18 00:29:52` 与 ISO 形式;解析到就用作精确冷却(本次实测把 60 秒变成 1.7 小时),解析不到才回落到次日策略。
10
14
  - **修复:切换后未落盘**。切换通知入队后直接 `return`,`scheduleStatsSave()` 没有被调用,所以重启后看不到这次切换发生过。现在入队时一并保存。
11
- - **改进:pin 在冷却时让位**。此前被 `model_rotator_select` 置顶的模型即使正在冷却也每轮抢在第一位,于是每轮都先撞一次墙再切换。现只在模型健康时置顶,冷却期间交给排序,冷却结束后自动回到首位。[`TBD`]
15
+ - **改进:pin 在冷却时让位**。此前被 `model_rotator_select` 置顶的模型即使正在冷却也每轮抢在第一位,于是每轮都先撞一次墙再切换。现只在模型健康时置顶,冷却期间交给排序,冷却结束后自动回到首位。[`a2d5a0c`]
12
16
 
13
17
  ## 0.2.4
14
18
  - **文档**:新增中英双语更新说明(本文件),并纳入发布清单与发布门;README 与仓库首页说明同步更新。npm 包开始随版本携带 CHANGELOG。同时修复发布门自身的一处崩溃:SHA 校验把清单注释行当成文件名读,导致整门以 ENOENT 中止、掩盖其余全部检查。[`fc14e99`]
package/index.js CHANGED
@@ -392,6 +392,16 @@ export function isNonChatModelId(provider, id) {
392
392
  /** Hard ceiling on candidates considered per turn, regardless of config. */
393
393
  const HARD_MAX_CANDIDATES = 8
394
394
 
395
+ /**
396
+ * How many channels of one model family may share the candidate walk.
397
+ *
398
+ * One per family was too few - a channel failing while its healthy siblings were
399
+ * unreachable is exactly the report this constant answers - and all of them is
400
+ * too many, because five channels of one model would spend the entire budget on
401
+ * a single model. Two keeps the representative and one proven-healthy backup.
402
+ */
403
+ const FAMILY_CHANNELS_MAX = 2
404
+
395
405
  /**
396
406
  * Hard ceiling on same-model retries per candidate, regardless of config.
397
407
  *
@@ -1509,19 +1519,35 @@ export function apply(ctx, config = {}, runtime = {}) {
1509
1519
  }
1510
1520
  ranked.sort((a, b) => (b.score !== a.score ? b.score - a.score : a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
1511
1521
 
1512
- // One candidate per model *family*, not one per channel. The same model on
1513
- // five channels shares its fate - one quota wall, one dead endpoint - so
1514
- // keeping all five in the walk spends the whole candidate budget retrying
1515
- // what is effectively one model, and the switch notice then reads as
1516
- // "switched to the same model again". The best-scoring channel of each
1517
- // family survives; its siblings wait for another turn (no cooldown is
1518
- // written for them, so a later walk can still pick them).
1519
- const familySeen = new Set()
1522
+ // A model family contributes more than one channel - but not all of them.
1523
+ //
1524
+ // The same model on five channels used to occupy five candidate slots, which
1525
+ // spent the whole budget retrying what is effectively one model. Collapsing it
1526
+ // to exactly one channel fixed that and introduced a worse failure: a channel is
1527
+ // not the whole family. WorkBuddy met its quota wall while buddy and trae, the
1528
+ // same model on other channels, were healthy and serving - and the walk could
1529
+ // not reach them, because the family had already been represented by the channel
1530
+ // that failed. The turn ended on the wall with a working route sitting one slot
1531
+ // away.
1532
+ //
1533
+ // So a family keeps up to FAMILY_CHANNELS_MAX channels, ranked, and a sibling is
1534
+ // only kept while it is actually usable. Cooling siblings are dropped: they would
1535
+ // be dispatched into the same wall the representative just hit, and the walk
1536
+ // already knows better. The switch-notice dedup keys on the model id, so arriving
1537
+ // at a second channel of the same model does not announce "switched to the same
1538
+ // model again" - the reason that motivated one-per-family in the first place is
1539
+ // handled where it belongs.
1540
+ const familyCount = new Map()
1520
1541
  const byFamily = []
1521
1542
  for (const row of ranked) {
1522
1543
  const family = String(row.pair.model).toLowerCase()
1523
- if (familySeen.has(family)) continue
1524
- familySeen.add(family)
1544
+ const used = familyCount.get(family) ?? 0
1545
+ if (used >= FAMILY_CHANNELS_MAX) continue
1546
+ const stat = statFor(row.key)
1547
+ // The family's first channel is always kept - it is the ranked winner and the
1548
+ // representation of that model. Only the siblings have to prove they are usable.
1549
+ if (used > 0 && stat.cooldownUntil > nowMs) continue
1550
+ familyCount.set(family, used + 1)
1525
1551
  byFamily.push(row)
1526
1552
  }
1527
1553
  const ordered = [current, ...byFamily.map(row => row.pair)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-rotator",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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",