返回目录
模型与 MCP 插件

dsh-model-fallback-queue

HelloQingTao/dsh-model-fallback-queue

模型故障转移队列:当前模型限额/限流/不可用时自动切到队列下一个模型继续,全图形界面配置 | Model fallback queue for DeepSeek Harness

Stars
0
Forks
2
Issues
0
更新
11 天前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:HelloQingTao/dsh-model-fallback-queue

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

dsh-model-fallback-queue

npm version npm downloads MIT license GitHub stars Awesome

English | 中文


中文

当前模型限额、限流或不可用时,自动切到队列里的下一个模型,把会话接着跑完。开关、队列、P1 恢复策略都在设置页里点,不需要命令行。

功能

  • 请求级自动切换:命中熔断码立刻熔断当前路由;非即时错误连续失败 2 次也熔断。
  • 队列 P1 → Pn:P1 默认跟随当前会话模型(你在模型选择器里换,P1 跟着换),队列里加的是后备 P2、P3…
  • 三档 P1 恢复策略:粘滞(默认)/ 探测回切 / 手动回切。
  • 输入框状态芯片:显示当前生效路由与健康状态,全熔断时是红色「全部熔断」徽章;展开是队列面板,可「切回 P1」或跳到设置页。
  • 全熔断只试一条:所有路由都在冷却里时,只发冷却最早到期的那一条,不再把整条链重打一遍——否则每条消息都会把全部路由再撞一次 429,把 openedAt 一起刷新,60s 冷却永远滑不到头(现象就是「刚探测还有 2 个可用,发一句话全红了」)。其余路由照常倒计时,到点自动回半个开。
  • 可恢复 + 一键放行:如果某条路由在这次熔断之后探测成功过(探测确实通了、但本地熔断锁还没到期),面板把它画成🟡「可恢复」而不是纯红「熔断」,行内多出一个「恢复」按钮,点一下立刻降到半开、下一条真实请求说了算。没有「熔断后探测成功」证据的路由不给这个按钮——探测不允许伪造可用性,也不允许把熔断变成摆设。
  • 不抢同路由重试的活:非致命错误一律放行,退避重试仍由 dsh-llm-retry 负责。
  • 界面中英双语:所有界面文案跟随 DSH 的语言设置,自动在中文 / English 之间切换。
  • 厂商勾选批量添加:模型选择器按厂商分组,复选框一次勾选多个,批量入队(按「先厂商、后组内序」追加;已入队的自动防重复)。
  • 拖动排序:队列行支持按住拖动调整顺序,物理顺序=尝试顺序,所见即所得(无隐藏排序)。
  • 免费/付费标记:每个队列行有一个小胶囊标签,点它本身就在 未标注 → 免费 → 付费 → 未标注 之间轮转(默认未标注);芯片与设置页同步显示(中性小标签,不占用颜色)。它纯粹是给你自己看的备注——不参与排序、不影响故障转移、也不会自动判断该标什么;设置页底部有同样的用途说明。
  • 切换是否生效,面板直接回答:切换本身只决定「下一个请求用哪条」,不产生任何可用性结论。面板顶部那一行写的是上一轮真实请求走了哪条、成没成(上一轮:P3 · 成功 · 12s前 / 上一轮:P3 · 失败 · QUOTA);还没发过消息就写「还没发过消息」,刚切换就写「已切到 P3,下一条消息会用它」。没有探测伪造的「验证通过」,也没有自相矛盾的「P1 验证失败」。
  • 健康色与前瞻:颜色只表示健康——🟢 可用、🟡 风险(探测失败或偏慢)、🔴 熔断、⚪ 未测。行内只用一个小圆点图标,具体状态词与证据(额度用尽 / 限流 / 延迟 / 失败码 / 多久以前)全部放在悬浮提示里,把宽度让给模型名。没有新一轮检测或状态更新时,就一直显示上次的结果,不会因为「时间久了」凭空降级。周期探测默认关闭,藏在设置页「高级」折叠区里;探测失败只记证据、不会把路由自己熔断,探测请求被厂商拒绝时显示为灰色「未测」而不是「不可用」。
  • 快速探测(ping):队列标题右侧一个「探测全部」按钮,一键探测队列里所有模型可用性;周期健康探测默认关闭,需要时在设置页「高级:周期健康探测」里展开填间隔(毫秒,0=关闭)开启,也可选择是否跳过付费模型省配额。
  • 探测体可配:探测请求的 maxTokens 可调(默认 8,在「高级」折叠区;1 会被一部分网关按 400 拒绝,于是「能正常对话的模型」长期显示探测失败)。插件内部仍保留「发一条和真实对话同形的请求」的验证能力,但设置页队列行已不再放「验证」按钮,界面更简洁。
  • 失败原因说人话:探测失败不再一律写「探测失败」,而是按上游原文归类成「额度用尽 / 免费额度用尽 / 被限流 / 连不上 / 探测超时 / 鉴权失败」,完整原文进悬浮提示;上游给了明确解锁时刻时,面板直接显示倒计时。
  • 面板直接点选切换:点芯片面板里的任意一行,立即把生效路由切到该模型(不用等它故障);切换是按会话隔离的——在哪个会话切,只在那个会话生效,不会影响其它已在跑的会话。P1 行在已生效时点击会打开宿主的模型选择器——P1 的身份就是当前会话模型,只有宿主能改。

跨路由(provider/model)切换的适配

P1 失败、队列切到另一个 provider/model 时,宿主的请求里有两类内容不能原样带过去:

  1. 适配器物化的控制字段。 宿主的 prepareCall 会把 P1 适配器的默认输出上限物化进请求 (DeepSeek 适配器默认 maxTokens: 256000)。旧实现只剥 reasoningEffort,把 maxTokens 原样带给目标;z.ai/GLM 的上限是 131072,于是直接 400 code 1210 "The max_tokens parameter is illegal.:限制数值范围[1,131072]"。 现在换路由时一并剥掉 maxTokens——目标模型经宿主的 prepareCall 解析自己的默认值。

  2. 跨适配器不可重放的 thinking。 历史 assistant 消息的 thinking 只在同一适配器 + 同一模型 下可重放;跨 provider/model 切换时宿主会丢掉 reasoning,而 DeepSeek 的 Anthropic 兼容 端点要求「text + tool_use」的 assistant 消息必须带 thinking 块,否则 400 "Thecontent[].thinkingin the thinking mode must be passed back to the API."。 现在对 strictThinkingProviders(默认 deepseek-official)下发的请求,把这类消息的 text 块 摘掉(tool_use、参数、工具结果不动)——这是该 API 接受的形状,也是跨适配器降级时最小的损失。 原生可重放与否由 nativeReplayKinds(provider=replayKind,默认 deepseek-official=deepseek-messages)判断。

新增配置:strictThinkingProviders(string[])、nativeReplayKinds(string[],provider=kind)。 测试:node scripts/test-route-adaptation.mjs,以及 scripts/verify-execution.mjs 场景 H/H-2。

效果图

设置页(开关 / 队列 / P1 恢复策略):

故障转移设置页:启用开关、P1 → Pn 队列(优先级、路由名、健康徽章、上移/下移/移除)、+ 添加模型、P1 恢复策略三档单选

输入框右侧的芯片与展开面板:

输入框右侧的故障转移芯片与展开面板:P1 当前会话模型、P2/P3/P4 后备路由与健康状态、最近切换记录

安装

dsh plugin --profile web add dsh-model-fallback-queue

装完重启 dsh(或刷新 Web GUI),bundle 会随包里的 cordis.patch.yml 自动注册。

用法

  1. 设置 → 故障转移 → 打开「启用故障转移」。
  2. + 添加模型:挑后备模型(P2、P3…),↑ / ↓ 调顺序,「移除」删掉。
  3. P1 恢复策略:选粘滞 / 探测回切 / 手动回切。
  4. 回到会话:输入框右侧出现芯片,显示当前生效的 P1 路由。

发生切换时,会话里会出现核心自带的「模型已切换」通知,芯片同步切到新路由。

芯片状态

显示 含义
P1 + 绿点 正常走 P1
P2(黄点) 已切到 P2;黄点表示半开探测中
P! + 红点 队列全部熔断,已降级放行原配置
P(灰点) 插件未启用

恢复策略三档

档位 行为
粘滞(默认) 切到 P2 后只要 P2 可用就一直用,P1 恢复也不切回;P2 也挂时按邻近可用往后找,绕回 P1 是最后手段。
探测回切 P1 冷却到期后,由下一个真实请求探测回 P1;成功留下,失败回 P2(防抖 5 分钟,不发额外探测流量)。
手动回切 切走后不自动回 P1,用芯片面板里的「切回 P1」恢复。

三档都按会话隔离:每个会话各自记「锚点」(上一轮真正作答成功的那条路由),新消息的换路链从锚点起跑,不再每条消息都从 P1 重撞一遍。探测回切/手动回切只决定「锚点是否自动回到 P1」,不影响锚点本身的按会话隔离。

配置项

字段 默认值 说明 设置页可改
enabled false 总开关 ✅
queue [] 后备队列,数组顺序即优先级(存在 ~/.dsh/fallback-queue-state.json,不在 settings 里,见下方说明) ✅
failbackMode sticky sticky / probe / manual ✅
p1Follow true P1 跟随当前会话模型 —
immediateCodes QUOTA、ACCOUNT_QUOTA、RATE_LIMIT、AUTH、INVALID_CREDENTIAL、NO_ADAPTER 命中即熔断的错误码 —
failureThreshold 2 非即时码的连续失败阈值 —
cooldownMs 60000 熔断冷却毫秒 —
failbackDelayMs 300000 探测回切防抖毫秒 —

日常用的开关、队列、恢复策略都在设置页;标「—」的高级旋钮默认值适用于绝大多数场景,需要时写进 ~/.dsh/profiles/<profile>/cordis.patch.yml 里本插件那一行的 config。

为什么队列不放在 settings 里:DSH 的 ui-theme 只要你写一次 settings 文档,就会重推一次主题快照,前端随之把整页 design token 逐个移除再写回,深色模式下会闪一帧白。队列排序是高频操作(反复点上下箭头调优先级),放在 settings 里每点一次闪一次;改存独立的 JSON 文件就完全不碰 settings revision,白闪消失。

队列文件是插件私有数据,不在设置页的配置导出/备份范围内,换机器需要重新排序。首次升级时如果文件不存在,会自动把 settings 里的旧队列迁移过来,所以已有配置不会丢。

兼容与注意

  • 实测 dsh 0.2.0-rc.2、0.2.1-rc.2(宿主 + Web GUI)。
  • 兼容范围以 package.json 的 engines.dsh 为准(当前 >=0.2.0-rc.2 <0.3.0)。
  • 与 dsh-client-auto-continue 天然兼容:自动续发走同一条请求瀑布,一样享受队列切换。
  • 与 dsh-llm-retry 分层:它管同路由退避重试,本插件管跨路由切换。
  • 号池类 provider(如 workbuddy-xdpool)单号限流由号池内部换号,整池到顶才轮到本插件跨模型切换。
  • 熔断态是内存态,进程重启归零;不写文件、不动 session。
  • 队列为空或只有一项时不会发生切换。
  • 不要和其他故障转移插件同时启用,两个插件争抢同一错误事件没有意义。

四大新功能

① 厂商勾选批量添加(F1):点「+ 添加模型」打开选择器,顶部按厂商分组(来自 DSH 内置模型目录 group.id),每组是复选框列表,可跨厂商一次勾选多个;点底部「添加 N 个到队列」批量入队,顺序=先厂商、后组内展示序。已入队的行整行置灰防重复,勾了也不会再添。

② 拖动排序(F5):队列行支持按住拖动调整顺序(行首有 ⠿ 手柄提示,整行可拖)。队列采用纯物理顺序:你在界面上看到的从上到下,就是故障转移的尝试顺序,所见即所得,没有「大保底」这类隐藏排序规则。P1 槽(当前会话模型)始终最先。

③ 免费/付费标记(F3):每个行有一个小胶囊标签(像输入框里的 chip),旁边的「标记」按钮在「未标注 → 免费 → 付费 → 未标注」间轮转。标签为中性色(颜色通道专供健康状态,价格不抢色,避免把"付费"误读成"有问题")。芯片面板同步显示。该标注只做展示辅助,不参与排序、不做自动判定(没有可靠的免费/付费数据源,不猜)。

④ 快速探测 ping(F4):队列标题右侧的「探测全部」一键限并发探测队列里所有模型可用性(默认并发 4,可配 probeConcurrency;墙钟时间≈最慢一条而非全部之和),结束后提示「可用 N / 不可用 M」;芯片面板也有同款按钮。周期健康探测收在设置页「高级:周期健康探测(默认关闭)」折叠区里,展开后可配:周期探测间隔(毫秒,0=关闭,默认 0=不开启;填 60000 即每 60 秒一轮)+ 周期探测跳过付费模型(默认开,省配额)+ 探测请求 maxTokens(默认 8,可改 1–512)。⚠ 周期探测会向模型发真实请求,可能消耗配额/费用,所以默认不自动开启——升级后你的存量设置保持原样。

许可证

MIT


English

When your current model hits its quota, gets rate-limited or becomes unavailable, requests automatically fail over to the next model in your queue and the session keeps going. The switch, the queue and the P1 recovery mode are all configured from the Settings UI — no CLI needed.

Features

  • Per-request failover. Known failure codes trip the current route immediately; two consecutive failures of any other kind also trip it.
  • Queue P1 → Pn. P1 follows the current session model by default (switch models in the picker and P1 follows); entries you add are the backups P2, P3…
  • Three P1 recovery modes. Sticky (default), probe-back, manual.
  • Input-box status chip. Shows the active route and its health, a red “all tripped” badge when nothing is left; expand it for the queue panel with a “Back to P1” action and a settings shortcut.
  • Degrades safely. When every route is tripped the original config is passed through untouched — the plugin never blocks a request.
  • Does not fight same-route retries. Non-fatal errors are always passed through; backoff retries stay with dsh-llm-retry.
  • Bilingual UI. Every label follows the DSH language setting and switches between 中文 and English automatically.
  • Batch vendor-based adding. The model picker groups by vendor; check a box per vendor, tick several, and add them all at once (appended vendor-by-vendor then in-group display order; entries already in the queue are greyed out and never re-added).
  • Pin as last resort (📌). Mark any row as a “safety net” and it always stays at the tail of the failover order, no matter how you reorder the rest; the P1 slot is unaffected. Multiple pins keep their relative order; pinning everything just falls back to the natural order.
  • Free/paid marks. Toggle each entry 未标注 → free → paid. Shown in both the settings rows and the chip panel as neutral text tags (colour is reserved for health); purely a visual aid — never used for sorting or guessed automatically.
  • Health colour + foresight. Colour means health only: green = just confirmed working, amber = risk/pending, red = tripped, grey = unverified. Rows carry evidence such as “probe 820ms · 12s ago”. Periodic probing is off by default — enable it in settings (once a minute is a typical choice; paid models are skipped by default).
  • Fast ping probe. One click probes every queue model for availability (serial, ~1 token each); periodic health probing is off by default (set a non-zero interval in settings to enable it; paid models are skipped unless you turn that off).
  • Configurable probe body + verify with a real request. The probe request’s maxTokens is adjustable (default 8; a value of 1 gets rejected with 400 by some gateways, which made perfectly chatty models look permanently broken). Every queue row also has a Verify button that sends one request shaped exactly like a real conversation and reports success/failure, error code, latency and token usage — a probe is always a trimmed-down request, only a real-shaped request counts as evidence.
  • Failures in plain words. A failed probe no longer just says “probe failed”: it is classified from the upstream text into “quota used up / free quota used up / rate limited / unreachable / probe timeout / auth failed”, with the raw text in the tooltip; when the upstream states an unlock time, the row shows a countdown.
  • Click-to-switch in the panel. Click any row in the chip panel to route the active traffic to that model immediately — no failure required. Clicking the P1 row while it is active opens the host's model picker, because P1 is the current session model and only the host can change it.

Screenshots

Settings page (switch / queue / P1 recovery mode):

Failover settings page: enable switch, P1 → Pn queue (priority, route, health badge, move up/down, remove), + Add model, and the three P1 recovery modes

The chip next to the input box and its expanded panel:

The chip next to the input box and its expanded panel: P1 is the current session model, P2/P3/P4 are backups with health badges, plus the last-switch line

Install

dsh plugin --profile web add dsh-model-fallback-queue

Restart dsh (or reload the Web GUI); the bundle registers itself through the cordis.patch.yml shipped in the package.

Usage

  1. Settings → Failover → turn on “Enable failover”.
  2. + Add model to add backups (P2, P3…); reorder with ↑ / ↓, remove with the remove action.
  3. Pick a P1 recovery mode.
  4. Back in the conversation, the chip next to the input box shows the active P1 route.

On every switch the core “model switched” notice appears in the session and the chip follows.

Chip states

Chip Meaning
P1 green dot Running on P1
P2 amber dot Switched to P2; amber means a half-open probe is in flight
P! red dot Every route tripped — original config passed through
P grey dot Plugin disabled

Recovery modes

Mode Behaviour
Sticky (default) Once on P2 it stays there while P2 works, even after P1 recovers; if P2 also fails it walks forward and only wraps back to P1 as a last resort.
Probe back After P1's cooldown expires the next real request probes P1; success keeps it, failure returns to P2 (5-minute debounce, no extra probe traffic).
Manual Never returns to P1 automatically — use “Back to P1” in the chip panel.

Configuration

Field Default Description In Settings UI
enabled false Master switch ✅
queue [] Backups; array order = priority (stored in ~/.dsh/fallback-queue-state.json, not in settings — see below) ✅
failbackMode sticky sticky / probe / manual ✅
p1Follow true P1 follows the current session model —
immediateCodes QUOTA, ACCOUNT_QUOTA, RATE_LIMIT, AUTH, INVALID_CREDENTIAL, NO_ADAPTER Codes that trip a route immediately —
failureThreshold 2 Consecutive failures for a soft trip —
cooldownMs 60000 Circuit cooldown in ms —
failbackDelayMs 300000 Probe-back debounce in ms —

The everyday switch, queue and recovery mode live in the Settings UI; the advanced knobs marked “—” keep sensible defaults and can be set in the plugin row's config inside ~/.dsh/profiles/<profile>/cordis.patch.yml.

Why the queue is not in settings: any write to a DSH settings document makes ui-theme republish the theme snapshot, and the client then removes and rewrites every design token for the whole page — in dark mode that shows up as a one-frame white flash. Reordering the queue is frequent (you keep clicking the up/down arrows), so keeping it in settings meant a flash per click. Storing it in a standalone JSON file never touches the settings revision, and the flash is gone.

That file is plugin-private data and is outside the Settings UI's config export/backup, so ordering must be redone on another machine. On the first upgrade, if the file is missing, the old queue in settings is migrated automatically — existing configuration is not lost.

Compatibility & notes

  • Tested with dsh 0.2.0-rc.2 and 0.2.1-rc.2 (host + Web GUI).
  • The supported range is declared by engines.dsh in package.json (currently >=0.2.0-rc.2 <0.3.0).
  • Works alongside dsh-client-auto-continue: auto-continue rides the same request waterfall, so it benefits from failover too.
  • Layered with dsh-llm-retry: it handles same-route backoff, this plugin handles cross-route failover.
  • For pool-style providers (e.g. workbuddy-xdpool) a single account's rate limit is handled inside the pool; this plugin only switches models once the whole pool is exhausted.
  • Breaker state is in memory and resets on restart; the plugin writes no files and never touches the session.
  • No switching happens with an empty or single-entry queue.
  • Do not run another failover plugin at the same time — two plugins competing for the same error event is not useful.

Four new features

① Batch add by vendor (F1). Click “+ Add model”; the picker lists vendors (from the built-in DSH model catalog group.id) with a checkbox list per vendor. Tick across vendors, then “Add N to queue” appends them all in vendor → in-group order. Rows already in the queue are disabled and deduped.

② Drag to reorder (F5). Queue rows are drag-and-drop reorderable (a ⠿ handle hints it; the whole row is draggable). The queue uses a pure physical order: what you see top-to-bottom is exactly the failover try order — WYSIWYG, with no hidden "safety-net" rule. The P1 slot (current session model) always goes first.

③ Free/paid marks (F3). Each row shows a small pill badge (like an input chip) plus a "Mark" button that cycles unmarked → free → paid → unmarked. Badges stay neutral (colour is reserved for health, so "paid" isn't misread as "trouble"). The chip panel mirrors it. Purely a display aid — never used for ordering or auto-detected.

④ Fast ping probe (F4). The “Probe all” button (in the settings page next to the queue, and in the chip panel) pings every queue model serially and reports “N ok / M unavailable”. Below the queue, periodic health probing is configured via probe interval (ms, 0 = off, default 0 = disabled; enter 60000 for once a minute), skip paid models in periodic probes (default on, saves quota; turn it off to probe paid models too) and probe request maxTokens (default 8, editable 1–512; too small a value gets rejected with 400 by some gateways). ⚠ Periodic probing sends real requests to models and can consume quota/cost, so it stays off until you enable it — existing settings are left untouched on upgrade.

License

MIT

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类模型与 MCP
规则置信度高

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: llm、deepseek-harness。