dsh-subagent-default-model 2.1.11 → 2.1.13
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 +95 -0
- package/lib/client.js +117 -17
- package/lib/index.js +120 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.13 (2026-11-05)
|
|
4
|
+
|
|
5
|
+
适配宿主 **0.2.2-rc.1**。这次不是行号位移,而是**一条契约收紧了语义**。
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
**故障转移在 0.2.2 上会抛宿主内部错误。**
|
|
10
|
+
|
|
11
|
+
0.2.2 把模型路由从「每次请求由 `agent/request` 瀑布决定」改成「**每个 step 在准备阶段固定**」:
|
|
12
|
+
|
|
13
|
+
- `preStep()` 里 `const selection = this.model.current()` 先捕获,随后一路传递,**重试复用同一份**(类型文档:*captured step selection, retained across retries*);
|
|
14
|
+
- `prepareRequest()` 用它拼出 `seedConfig`,并对瀑布返回的配置新增硬校验——改 provider/model 直接抛 `agent "X": agent/request proposed … after step preparation fixed …`;
|
|
15
|
+
- 该瀑布本身被标 **`@deprecated`**:*a replacement may adjust controls but must keep the provider, model, and reasoning effort selection*,并指明唯一替代是 `agent.model.select()`。
|
|
16
|
+
|
|
17
|
+
本插件的故障转移恰好就是「在 `agent/request` 里把 seed 换成池中下一个模型」,因此在 0.2.2 上**必然抛错**——一次额度耗尽会变成一句难懂的宿主内部错误,比不修更糟。
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
**双路径故障转移,按能力探测自动选择**(`typeof agent.model?.select === "function"`;`agent.model` 在 0.2.2 之前不存在,无需版本比较):
|
|
22
|
+
|
|
23
|
+
- **旧宿主(≤0.2.1)**:行为完全不变,失败的那次请求当场换模型重试。
|
|
24
|
+
- **新宿主(≥0.2.2)**:
|
|
25
|
+
1. 先 `await next()` 让下游处理。`dsh-llm-retry` 已在 `dsh-base` 组合里默认启用并负责退避;**瞬时失败不该换路**——`select()` 会持久化到下一步,重试成功后仍会留下一次无辜的切换。
|
|
26
|
+
2. 下游不重试才说明这条路真的死了:用 `agent.model.select()` 为**下一个 step / turn** 预选池中下一条健康路由,然后**放行原始错误**(它才说明真实原因:配额、密钥)。
|
|
27
|
+
3. 每个 step 最多选一次;`agent/request` 在新宿主上直接 `return next()`,绝不改写路由。
|
|
28
|
+
4. `select()` 被宿主拒绝时打 warn 并照常放行原始错误,绝不吞掉真实原因。
|
|
29
|
+
|
|
30
|
+
**必须承认的代价**:0.2.2 上「同一次请求内透明续跑」无法实现——失败的那一步路由已锁定,`select()` 只影响下一步。因此永久性失败(配额耗尽、密钥失效)会结束当前 turn,而不再换供应商续跑;可续跑的 subagent 下次被唤醒时已在健康路由上。这是宿主收回的能力,不是实现取舍,README 中英文两版都已如实写明。
|
|
31
|
+
|
|
32
|
+
### Compatibility
|
|
33
|
+
|
|
34
|
+
`ADMITTED_HOST_VERSIONS` 补入 `0.2.2-rc.1`(自检用例先失败后通过,符合预期)。
|
|
35
|
+
|
|
36
|
+
本轮逐包比对 rc.5 → 0.2.2-rc.1:`desktop-runtime.json` 的共享包从 305 增至 329,几乎所有包都有改动,但**只有 `dsh-agent-loop` 这一处契约收紧**。其余依赖面实测完好:
|
|
37
|
+
|
|
38
|
+
| 依赖面 | 结论 |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `agent/pre-step` 瀑布 | 完好(payload 新增 `modelSelection`,增量) |
|
|
41
|
+
| `agent/request-error` 瀑布 | 完好(payload 新增 `provider` / `retryPolicy`) |
|
|
42
|
+
| `agent.inbox.prepend/claim` | 完好(内部重构 `projections` → `readState`,API 未变) |
|
|
43
|
+
| `subagents.getProvider` / `startActivation` | 完好 |
|
|
44
|
+
| provider 的 `inheritsParentContext` | 完好(fork provider 仍为 `true`,`applyToForkChildren` 门禁依据不变) |
|
|
45
|
+
| `session.requestContext()` | 完好(`:1627` → `:1636`) |
|
|
46
|
+
| 客户端槽位 / locale / `settings.mutate` | 完好(`chat-subagent-model-notice` 实测 active) |
|
|
47
|
+
| `request/header` 的 `reason` 取值 | 完好(`initial` / `resume` / `change` / `series` 未变,对话行仍正常) |
|
|
48
|
+
|
|
49
|
+
实测(宿主机 0.2.2-rc.1):`subagent` 子代理拿到池中 `minmax/MiniMax-M3.1-Flash`;`subagent_fork` 子代理按门禁继承父路由 `dsh-opencode-go`,未注入。
|
|
50
|
+
|
|
51
|
+
### Tests
|
|
52
|
+
|
|
53
|
+
`172/172`(164 → 172),`skip 0`。新增 8 个用例覆盖新宿主路径:
|
|
54
|
+
|
|
55
|
+
- 下游重试成功时**不得**换路(否则重试成功后仍会留下一次无辜切换)
|
|
56
|
+
- 无人重试时选中下一条池内路由,并**放行原始错误**(而非宿主 guard 错误)
|
|
57
|
+
- `agent/request` 必须**原样返回**该 step 的路由(这条正是回归本体)
|
|
58
|
+
- 同一 step 最多选一次;下一个 step 可再选
|
|
59
|
+
- 池耗尽不再选新候选、不再伪造 retry
|
|
60
|
+
- `select()` 被拒时打 warn 且不吞原始错误
|
|
61
|
+
- AUTH 仍切换,且仍打「密钥可能无效」告警
|
|
62
|
+
- 主代理循环仍不受影响
|
|
63
|
+
|
|
64
|
+
变异验证 4/4 命中:①新宿主仍走旧的 `agent/request` 覆盖路径 → 5 个用例失败;②`agent/request` 不提前 return → 原样返回用例失败;③忽略下游 retry → 不换路用例失败;④去掉「每 step 一次」限制 → 该用例失败。
|
|
65
|
+
|
|
66
|
+
> 夹具也被修了:原来它只驱动 `agent/request` 并断言返回值变了,模拟的是**旧宿主契约**,所以在会抛错的新宿主上依然全绿。当宿主给契约加硬校验时,夹具必须把校验也加进去,否则它只是在自证清白。
|
|
67
|
+
|
|
68
|
+
## 2.1.12 (2026-10-30)
|
|
69
|
+
|
|
70
|
+
### Fixed
|
|
71
|
+
|
|
72
|
+
**issue #2:「保存」按钮永久灰着**。三条独立缺陷互相叠加,任一条都能单独锁死保存。
|
|
73
|
+
|
|
74
|
+
1. **保存门禁包含非单调谓词**。`saveDisabled = busy || !dirty || hasIncompleteRoute`:点「添加模型」会在同一次点击里既让 `dirty=true`(启用保存)又让 `hasIncompleteRoute=true`(禁用保存),两个条件互相抵消,按钮永远不亮。并且这个谓词**无法通过 UI 满足**——模型目录为空时新行的 provider 只能是 `""`,Model 下拉又 `disabled: !route.provider`,于是 `!route.provider` 永远成立。
|
|
75
|
+
|
|
76
|
+
改为 `busy || !(dirty || draftDiffers)`,与同作者三个插件(`trae` / `workbuddy` / `qoder`)的既有范式一致:**先把校验放在点击之后**,失败时用 `saveErrorState` 说清哪里不对。一个点不动的按钮无法告诉用户哪里错了,这正是缺陷本身。
|
|
77
|
+
|
|
78
|
+
2. **空行被持久化成裸空串,死锁会跨重启存活**。`serializeDefaultModels` 对「provider 与首行相同且无 effort」的行只写 `route.model`,空行于是落盘为 `""`;`normalizeDefaultModels` 再把 `""` 还原成 `{ provider: <section provider>, model: "" }` —— 一个看上去可填、实际填不完的行。**只要带着空行保存过一次,下次启动就永久灰着**,用户完全不知道是自己那次保存写进去的。
|
|
79
|
+
|
|
80
|
+
三处同时修:`save()` 丢弃全空行;`serializeDefaultModels` 自身兜底过滤;裸串优化加 `route.model` 前置条件(`{provider, model:""}` 这种「刚选好 provider 还没选模型」的行保持显式对象,不再退化成空串);`normalizeDefaultModels` 丢弃空条目,使旧版本写坏的历史文档也不会复活死锁。
|
|
81
|
+
|
|
82
|
+
3. **空模型目录下 `addRoute()` 造出无法填完的行**。`groupsState` 为空时它写 `provider: ""`,而该值在 UI 上无法改变(provider 列表只有 `""`,model 下拉恒禁用)。改为**拒绝新增**并复用已有的 `row.catalogEmpty` 文案;目录可用时直接选中该 provider 的首个模型,让新行一出现就是合法的。
|
|
83
|
+
|
|
84
|
+
4. **`dirty` 是纯组件内 state,卡片重挂载即丢**。卡片在离开 Plugins 页时卸载,重挂载时草稿从 scope 重新 seed,于是表单显示着用户刚才的值、`dirty` 却回到 false,保存按钮灰着且无任何解释。改为**派生**:比较草稿与已保存值(路由列表 + 三个开关),让「有没有改动」成为关于数据的事实,而不是一次被记住的交互。
|
|
85
|
+
|
|
86
|
+
### Tests
|
|
87
|
+
|
|
88
|
+
164/164(159 → 164),`skip 0`。新增 5 个回归用例,每条缺陷一个方向:
|
|
89
|
+
|
|
90
|
+
- 目录可用时点「添加模型」→ Save **变为可点**(旧门禁下恒为 disabled)
|
|
91
|
+
- 目录为空时点「添加模型」→ **不产生**路由行,并给出目录为空提示
|
|
92
|
+
- 全空行经保存链路 → **永不落盘为裸 `""`**
|
|
93
|
+
- **半填行**(选了 provider 未选 model)存在时 Save **仍可点** —— 缺陷核心的最小子集
|
|
94
|
+
- 未改动的重挂载 **不得**误报为有未保存改动
|
|
95
|
+
|
|
96
|
+
变异验证(每条都确认相关用例失败后恢复):①门禁加回 `hasIncompleteRoute` → 半填用例失败;②`serializeDefaultModels` 裸串优化去掉 `route.model` 判空 → 空行落盘用例失败;③`addRoute` 恢复写 `provider: ""` → 目录为空用例失败。
|
|
97
|
+
|
|
3
98
|
## 2.1.11 (2026-10-30)
|
|
4
99
|
|
|
5
100
|
> **发布说明**:本节的改动与下一节 2.1.10 的宿主兼容性核查**同批发布**,npm 上直接从 2.1.9 升到 2.1.11,2.1.10 没有单独发布过。保留两个条目是因为「换了宿主版本」和「改了行为」是两件独立的事,事后查证时分开更好读;`npm install` 请直接用 `2.1.11`。
|
package/lib/client.js
CHANGED
|
@@ -154,13 +154,28 @@ window.__ModuleLoader__.load({
|
|
|
154
154
|
// (see `servedNamespaceNow` in the `configForms` block).
|
|
155
155
|
var SUBAGENT_MODEL_SETTINGS_NS = "dsh-subagent-default-model";
|
|
156
156
|
|
|
157
|
+
// Decode a stored section into the card's route list.
|
|
158
|
+
//
|
|
159
|
+
// An EMPTY entry is dropped rather than decoded (issue #2). A bare `""` in
|
|
160
|
+
// `models`, or an object with neither provider nor model, carries no route;
|
|
161
|
+
// decoding it (the old behaviour) produced `{ provider: <section provider>,
|
|
162
|
+
// model: "" }` — identical in the UI to a genuine half-filled row, so the
|
|
163
|
+
// user saw a mysterious unfillable row after a restart, with no way to tell
|
|
164
|
+
// it apart from their own draft. `serializeDefaultModels` no longer writes
|
|
165
|
+
// such entries, and this keeps a document written by an older version from
|
|
166
|
+
// resurrecting one.
|
|
157
167
|
function normalizeDefaultModels(value) {
|
|
158
168
|
var result = [];
|
|
159
169
|
if (Array.isArray(value.models) && value.models.length > 0) {
|
|
160
170
|
for (var i = 0; i < value.models.length; i++) {
|
|
161
171
|
var entry = value.models[i];
|
|
162
|
-
if (typeof entry === "string")
|
|
163
|
-
|
|
172
|
+
if (typeof entry === "string") {
|
|
173
|
+
if (entry === "") continue;
|
|
174
|
+
result.push({ provider: value.provider || "", model: entry, reasoningEffort: "" });
|
|
175
|
+
} else if (entry && typeof entry === "object") {
|
|
176
|
+
if (!entry.provider && !entry.model) continue;
|
|
177
|
+
result.push({ provider: entry.provider || value.provider || "", model: entry.model || "", reasoningEffort: entry.reasoningEffort || "" });
|
|
178
|
+
}
|
|
164
179
|
}
|
|
165
180
|
} else if (value.provider || value.model) {
|
|
166
181
|
result.push({ provider: value.provider || "", model: value.model || "", reasoningEffort: value.reasoningEffort || "" });
|
|
@@ -169,6 +184,17 @@ window.__ModuleLoader__.load({
|
|
|
169
184
|
}
|
|
170
185
|
|
|
171
186
|
function serializeDefaultModels(previousValue, routes, strategy, failoverEnabled, injectRouteContext, applyToForkChildren) {
|
|
187
|
+
// Drop rows with neither a provider nor a model BEFORE anything else
|
|
188
|
+
// (issue #2). `save()` already filters, and this is the second line of
|
|
189
|
+
// defence: an all-empty row used to serialize as a bare `""` (its
|
|
190
|
+
// provider matched the section, so only `route.model` — the empty string
|
|
191
|
+
// — was written), which `normalizeDefaultModels` decoded back into
|
|
192
|
+
// `{ provider: <section provider>, model: "" }` — a row the UI can never
|
|
193
|
+
// complete, re-locking Save on the NEXT start. Filtering here makes that
|
|
194
|
+
// loss impossible regardless of which caller reaches this function.
|
|
195
|
+
routes = (routes || []).filter(function (route) {
|
|
196
|
+
return route && (Boolean(route.provider) || Boolean(route.model));
|
|
197
|
+
});
|
|
172
198
|
var next = Object.assign({}, previousValue || {});
|
|
173
199
|
next.failoverEnabled = failoverEnabled === false ? false : true;
|
|
174
200
|
next.injectRouteContext = injectRouteContext === false ? false : true;
|
|
@@ -187,7 +213,13 @@ window.__ModuleLoader__.load({
|
|
|
187
213
|
next.provider = provider;
|
|
188
214
|
next.model = "";
|
|
189
215
|
next.models = routes.map(function (route) {
|
|
190
|
-
|
|
216
|
+
// The bare-string (same-provider) form is an OPTIMIZATION, and it is
|
|
217
|
+
// only lossless when the row actually names a model. A row with a
|
|
218
|
+
// provider but no model yet — the normal state right after picking a
|
|
219
|
+
// provider — must stay an explicit object, because the bare form would
|
|
220
|
+
// be `""` and `normalizeDefaultModels` would read that back as a
|
|
221
|
+
// fillable-looking row (issue #2's persistence loop).
|
|
222
|
+
if (route.provider === provider && !route.reasoningEffort && route.model) {
|
|
191
223
|
return route.model;
|
|
192
224
|
}
|
|
193
225
|
var base = { provider: route.provider, model: route.model };
|
|
@@ -391,6 +423,8 @@ window.__ModuleLoader__.load({
|
|
|
391
423
|
var saveErrorState = React.useState(null);
|
|
392
424
|
var toastState = React.useState(null);
|
|
393
425
|
var toastSeq = React.useRef(0);
|
|
426
|
+
// `dirtyState` records "the user has interacted", but it is NOT what
|
|
427
|
+
// decides whether Save can be pressed — see `draftDiffers` below.
|
|
394
428
|
var dirtyState = React.useState(false);
|
|
395
429
|
var busyState = React.useState(false);
|
|
396
430
|
React.useEffect(function () {
|
|
@@ -444,9 +478,27 @@ window.__ModuleLoader__.load({
|
|
|
444
478
|
dirtyState[1](true);
|
|
445
479
|
}
|
|
446
480
|
function addRoute() {
|
|
481
|
+
// A new row needs a REAL provider to be fillable: the model dropdown is
|
|
482
|
+
// disabled until a provider is chosen, and the provider list is empty
|
|
483
|
+
// when the catalog never loaded. Writing `provider: ""` in that state
|
|
484
|
+
// produced a row the UI could not complete — and, before the gate fix in
|
|
485
|
+
// this release, that row locked Save shut permanently (issue #2).
|
|
486
|
+
//
|
|
487
|
+
// So: refuse the add and say why, using the catalog-empty copy the card
|
|
488
|
+
// already owns. Refusing is recoverable (the user retries once the
|
|
489
|
+
// catalog arrives); a dead row is not.
|
|
447
490
|
var firstGroup = groupsState[0][0];
|
|
491
|
+
if (!firstGroup) {
|
|
492
|
+
saveErrorState[1](t("row.catalogEmpty"));
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
// Pick the first model the group actually advertises, so the row is
|
|
496
|
+
// valid the moment it appears rather than one interaction short of
|
|
497
|
+
// complete. An empty model list still yields `model: ""`, which the
|
|
498
|
+
// save-time filter drops instead of persisting.
|
|
499
|
+
var firstModel = firstGroup.models && firstGroup.models[0] ? firstGroup.models[0].id : "";
|
|
448
500
|
routesState[1](function (routes) {
|
|
449
|
-
return routes.concat({ provider: firstGroup
|
|
501
|
+
return routes.concat({ provider: firstGroup.id, model: firstModel, reasoningEffort: "" });
|
|
450
502
|
});
|
|
451
503
|
savedState[1](false);
|
|
452
504
|
saveErrorState[1](null);
|
|
@@ -475,7 +527,23 @@ window.__ModuleLoader__.load({
|
|
|
475
527
|
// cards do — `trae`/`workbuddy` disable on `!dirty || saving` and let the
|
|
476
528
|
// write answer for itself.
|
|
477
529
|
if (busyState[0]) return;
|
|
478
|
-
|
|
530
|
+
// Validate HERE, not on the button (issue #2).
|
|
531
|
+
//
|
|
532
|
+
// An EMPTY row — both fields blank — is not an error: it is a row the
|
|
533
|
+
// user added and has not reached yet. Drop it rather than refusing the
|
|
534
|
+
// whole save, which also stops the empty string from being persisted
|
|
535
|
+
// (the round-trip loss that turned one stray row into a permanent
|
|
536
|
+
// `model: ""` row and re-locked Save on the next start).
|
|
537
|
+
//
|
|
538
|
+
// A HALF-filled row is still saved, not refused: only the sides the user
|
|
539
|
+
// actually set are meaningful, and `serializeDefaultModels` already
|
|
540
|
+
// handles a model-less entry. Refusing here would reproduce the very
|
|
541
|
+
// defect being fixed — a click that does nothing — just with a message.
|
|
542
|
+
var filledRoutes = routesState[0].filter(function (route) {
|
|
543
|
+
return Boolean(route.provider) || Boolean(route.model);
|
|
544
|
+
});
|
|
545
|
+
var nextValue = serializeDefaultModels(value, filledRoutes, strategyState[0], failoverEnabledState[0], injectRouteContextState[0], applyToForkChildrenState[0]);
|
|
546
|
+
|
|
479
547
|
savedState[1](false);
|
|
480
548
|
saveErrorState[1](null);
|
|
481
549
|
busyState[1](true);
|
|
@@ -651,18 +719,50 @@ window.__ModuleLoader__.load({
|
|
|
651
719
|
var warning = checkEffortSupport(route, groupsState[0]);
|
|
652
720
|
if (warning !== null) effortWarnings.push({ index: index, key: warning.key, warning: warning });
|
|
653
721
|
});
|
|
654
|
-
// Save gate
|
|
655
|
-
//
|
|
656
|
-
// here
|
|
657
|
-
//
|
|
658
|
-
//
|
|
659
|
-
//
|
|
660
|
-
//
|
|
661
|
-
//
|
|
662
|
-
//
|
|
663
|
-
//
|
|
664
|
-
//
|
|
665
|
-
|
|
722
|
+
// Save gate: `busy || !dirty` — NOTHING else.
|
|
723
|
+
//
|
|
724
|
+
// Two scope gates used to sit here (`snap.status !== "ready"` and
|
|
725
|
+
// `snap.writable === false`) and made Save permanently unclickable while
|
|
726
|
+
// the describe mirror was still answering. `hasIncompleteRoute` was the
|
|
727
|
+
// third, and it produced the same class of deadlock (issue #2): the
|
|
728
|
+
// predicate is NON-MONOTONIC — "add a model row" sets `dirty` (enabling
|
|
729
|
+
// Save) and simultaneously makes `hasIncompleteRoute` true (disabling it),
|
|
730
|
+
// so the two conditions cancel out and the button never lights up. With an
|
|
731
|
+
// empty model catalog the new row's provider cannot even be filled in, so
|
|
732
|
+
// the deadlock is unrecoverable through the UI.
|
|
733
|
+
//
|
|
734
|
+
// The family cards (`trae` / `workbuddy` / `qoder`) never pre-gate on row
|
|
735
|
+
// completeness; they let the click happen and report the refusal. This does
|
|
736
|
+
// the same: `save()` filters empty rows and `saveErrorState` explains any
|
|
737
|
+
// row that is half-filled. A button that refuses to be pressed carries no
|
|
738
|
+
// information about WHAT is wrong — that is the whole defect.
|
|
739
|
+
// Whether the draft differs from what is SAVED (issue #2, defect 4).
|
|
740
|
+
//
|
|
741
|
+
// `dirty` used to be a component-local boolean that only the six input
|
|
742
|
+
// handlers set. The card unmounts when the user leaves the Plugins page,
|
|
743
|
+
// and on remount the draft is re-seeded from `savedForm` — so the form
|
|
744
|
+
// showed the user's values while Save stayed grey, with nothing on screen
|
|
745
|
+
// explaining it. Deriving "has anything changed?" from the DATA makes a
|
|
746
|
+
// remount unable to disagree with what is displayed.
|
|
747
|
+
//
|
|
748
|
+
// The comparison is over the normalized route list plus the three scalar
|
|
749
|
+
// toggles, i.e. exactly what a save would write.
|
|
750
|
+
var draftSignature = JSON.stringify({
|
|
751
|
+
routes: routesState[0].filter(function (route) { return Boolean(route.provider) || Boolean(route.model); }),
|
|
752
|
+
strategy: strategyState[0],
|
|
753
|
+
failoverEnabled: failoverEnabledState[0] !== false,
|
|
754
|
+
injectRouteContext: injectRouteContextState[0] !== false,
|
|
755
|
+
applyToForkChildren: applyToForkChildrenState[0] === true
|
|
756
|
+
});
|
|
757
|
+
var savedSignature = JSON.stringify({
|
|
758
|
+
routes: normalizeDefaultModels(value),
|
|
759
|
+
strategy: value.strategy === "random" ? "random" : "round-robin",
|
|
760
|
+
failoverEnabled: value.failoverEnabled !== false,
|
|
761
|
+
injectRouteContext: value.injectRouteContext !== false,
|
|
762
|
+
applyToForkChildren: value.applyToForkChildren === true
|
|
763
|
+
});
|
|
764
|
+
var draftDiffers = draftSignature !== savedSignature;
|
|
765
|
+
var saveDisabled = busyState[0] || !(dirtyState[0] || draftDiffers);
|
|
666
766
|
var discardDisabled = !dirtyState[0] || busyState[0];
|
|
667
767
|
var routes = routesState[0].map(function (route, index) {
|
|
668
768
|
var group = null;
|
package/lib/index.js
CHANGED
|
@@ -200,6 +200,27 @@ const AUTH_FAILURE_CODES = ["AUTH", "INVALID_CREDENTIAL"];
|
|
|
200
200
|
/** Every failure code that may trigger a switch. */
|
|
201
201
|
const FAILOVER_ELIGIBLE_CODES = [...FAILOVER_TRIGGER_CODES, ...AUTH_FAILURE_CODES];
|
|
202
202
|
|
|
203
|
+
/**
|
|
204
|
+
* Whether this host fixes the step's route and only sanctions changing it
|
|
205
|
+
* through `agent.model.select()`.
|
|
206
|
+
*
|
|
207
|
+
* DSH 0.2.2 replaced the per-request route with a STEP-FIXED selection:
|
|
208
|
+
* `preStep()` reads `agent.model.current()` once and hands the result to the
|
|
209
|
+
* `agent/request` waterfall as `modelSelection`, which the type documents as
|
|
210
|
+
* "captured step selection, retained across retries". A listener that returns
|
|
211
|
+
* a different provider/model now throws
|
|
212
|
+
* `agent "X": agent/request proposed "p/m" after step preparation fixed "a/b"`
|
|
213
|
+
* — the waterfall itself is marked `@deprecated` for this use ("a replacement
|
|
214
|
+
* may adjust controls but must keep the provider, model, and reasoning effort
|
|
215
|
+
* selection").
|
|
216
|
+
*
|
|
217
|
+
* `agent.model` does not exist before 0.2.2, so this is a capability probe
|
|
218
|
+
* rather than a version compare: one plugin build serves both hosts.
|
|
219
|
+
*/
|
|
220
|
+
function fixesStepRoute(agent) {
|
|
221
|
+
return typeof agent?.model?.select === "function";
|
|
222
|
+
}
|
|
223
|
+
|
|
203
224
|
/** True when a failure code is an auth-class failure (picks the log wording). */
|
|
204
225
|
function isAuthFailure(code) {
|
|
205
226
|
return AUTH_FAILURE_CODES.includes(code);
|
|
@@ -380,6 +401,95 @@ function nextFailoverIndex(view, agent, current) {
|
|
|
380
401
|
return (found + 1) % entries.length;
|
|
381
402
|
}
|
|
382
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Record a healthy route for the steps that FOLLOW a failure (DSH 0.2.2+).
|
|
406
|
+
*
|
|
407
|
+
* On these hosts the failed request cannot be re-routed: `preStep()` captured
|
|
408
|
+
* the step's selection and `agent/request` must hand it back unchanged, so a
|
|
409
|
+
* retry re-issues to the same dead route. The one sanctioned lever is
|
|
410
|
+
* `agent.model.select()`, whose result is read at the NEXT step preparation.
|
|
411
|
+
*
|
|
412
|
+
* Therefore:
|
|
413
|
+
*
|
|
414
|
+
* 1. ask the rest of the waterfall first. `dsh-llm-retry` owns backoff and is
|
|
415
|
+
* mounted in the base composition; a transient failure it recovers must NOT
|
|
416
|
+
* move the route, and pre-empting it here (as the pre-0.2.2 path does, where
|
|
417
|
+
* the retry carried a new route) would strip the backoff for no gain.
|
|
418
|
+
* 2. if nothing retries, this route is the reason the turn dies. Select the
|
|
419
|
+
* next untried pool entry so any later step or turn starts on a healthy
|
|
420
|
+
* route, and let the ORIGINAL error surface — it names the real cause
|
|
421
|
+
* (quota, auth), unlike the host's "after step preparation fixed" guard.
|
|
422
|
+
*
|
|
423
|
+
* The visible consequence, stated plainly: on 0.2.2 a permanently failing
|
|
424
|
+
* route ends the current turn instead of being transparently continued on
|
|
425
|
+
* another provider. The pool still governs every SUBSEQUENT request, so a
|
|
426
|
+
* continuable subagent resumes on a healthy route and the parent's next
|
|
427
|
+
* follow-up is not stuck on the dead one.
|
|
428
|
+
*/
|
|
429
|
+
async function switchForNextStep(ctx, state, pending, payload, next) {
|
|
430
|
+
const { agent, step, failure, signal } = payload;
|
|
431
|
+
const downstream = await next();
|
|
432
|
+
if (signal?.aborted) return downstream;
|
|
433
|
+
// Someone downstream (llm-retry) is recovering this request: leave the
|
|
434
|
+
// route alone, since the failure may be transient.
|
|
435
|
+
if (downstream?.kind === "retry") return downstream;
|
|
436
|
+
// Re-read the view: the settings may have changed while we awaited.
|
|
437
|
+
const view = failoverView(state);
|
|
438
|
+
if (view === void 0) return downstream;
|
|
439
|
+
const current = pending.get(agent.id);
|
|
440
|
+
if (current !== void 0 && current.step === step) return downstream; // already switched for this step
|
|
441
|
+
if (current !== void 0 && current.count >= view.entries.length - 1) return downstream; // pool exhausted
|
|
442
|
+
const index = nextFailoverIndex(view, agent, current);
|
|
443
|
+
const target = view.entries[index];
|
|
444
|
+
if (target === void 0) return downstream;
|
|
445
|
+
const tried = new Set(current?.tried ?? []);
|
|
446
|
+
tried.add(index);
|
|
447
|
+
pending.set(agent.id, {
|
|
448
|
+
index,
|
|
449
|
+
tried,
|
|
450
|
+
count: (current?.count ?? 0) + 1,
|
|
451
|
+
step
|
|
452
|
+
});
|
|
453
|
+
try {
|
|
454
|
+
agent.model.select({
|
|
455
|
+
provider: target.provider,
|
|
456
|
+
model: target.model,
|
|
457
|
+
...(target.reasoningEffort === void 0 ? {} : { reasoningEffort: target.reasoningEffort })
|
|
458
|
+
});
|
|
459
|
+
} catch (error) {
|
|
460
|
+
// A host that exposes `model.select` but refuses this call is not a
|
|
461
|
+
// reason to swallow the real failure — report it and let the original
|
|
462
|
+
// error through.
|
|
463
|
+
ctx.logger.warn(
|
|
464
|
+
`[dsh-subagent-default-model] could not pre-select %s/%s after %s; the subagent keeps its route: %s`,
|
|
465
|
+
target.provider,
|
|
466
|
+
target.model,
|
|
467
|
+
failure.code,
|
|
468
|
+
error instanceof Error ? error.message : String(error)
|
|
469
|
+
);
|
|
470
|
+
return downstream;
|
|
471
|
+
}
|
|
472
|
+
ctx.logger.warn(
|
|
473
|
+
`[dsh-subagent-default-model] subagent %s failed with %s on turn %d step %d; %s/%s is selected for its NEXT step (this host fixes the route of the failed step, so the current turn cannot continue on it)`,
|
|
474
|
+
agent.id,
|
|
475
|
+
failure.code,
|
|
476
|
+
payload.turn,
|
|
477
|
+
step,
|
|
478
|
+
target.provider,
|
|
479
|
+
target.model
|
|
480
|
+
);
|
|
481
|
+
if (isAuthFailure(failure.code)) {
|
|
482
|
+
ctx.logger.warn(
|
|
483
|
+
`[dsh-subagent-default-model] the credentials for the failing provider %s were refused (%s). This is NOT a connection problem: that provider's API key is likely invalid, expired, or unauthorised. The next step will use %s/%s — verify the failing provider's key, because every request routed to it will fail until it is fixed.`,
|
|
484
|
+
payload.provider ?? "(unknown)",
|
|
485
|
+
failure.code,
|
|
486
|
+
target.provider,
|
|
487
|
+
target.model
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
return downstream;
|
|
491
|
+
}
|
|
492
|
+
|
|
383
493
|
/**
|
|
384
494
|
* Install the subagent-only failover waterfalls. Both listeners no-op for the
|
|
385
495
|
* main agent (origin gate) and for subagents whose failure code is not a
|
|
@@ -394,13 +504,17 @@ function installFailover(ctx, state) {
|
|
|
394
504
|
// After a model failure on a subagent loop: advance the pool index and ask
|
|
395
505
|
// the loop to rebuild the request (`{ kind: "retry" }`). When every pool
|
|
396
506
|
// entry has been tried, let the real error surface untouched.
|
|
397
|
-
const disposeRequestError = ctx.on("agent/request-error", (payload, next) => {
|
|
507
|
+
const disposeRequestError = ctx.on("agent/request-error", async (payload, next) => {
|
|
398
508
|
const view = failoverView(state);
|
|
399
509
|
if (view === void 0) return next();
|
|
400
510
|
const { agent, turn, step, failure, signal } = payload;
|
|
401
511
|
if (signal?.aborted) return next();
|
|
402
512
|
if (!isSubagentAgent(agent)) return next();
|
|
403
513
|
if (failure === void 0 || !FAILOVER_ELIGIBLE_CODES.includes(failure.code)) return next();
|
|
514
|
+
// 0.2.2+ fixed the route for the whole step, so the route cannot be
|
|
515
|
+
// swapped on the retry this hook used to request. See
|
|
516
|
+
// `switchForNextStep` for what replaces it.
|
|
517
|
+
if (fixesStepRoute(agent)) return switchForNextStep(ctx, state, pending, payload, next);
|
|
404
518
|
const current = pending.get(agent.id);
|
|
405
519
|
// The primary already failed (that triggered the first switch), so the
|
|
406
520
|
// remaining candidates are the other pool entries: at most
|
|
@@ -464,6 +578,11 @@ function installFailover(ctx, state) {
|
|
|
464
578
|
if (view === void 0) return next();
|
|
465
579
|
const { agent } = payload;
|
|
466
580
|
if (!isSubagentAgent(agent)) return next();
|
|
581
|
+
// 0.2.2+ : the route is fixed for the step and the host throws when a
|
|
582
|
+
// listener changes it. `switchForNextStep` already recorded the new
|
|
583
|
+
// selection, which the NEXT step reads; returning the seed untouched is
|
|
584
|
+
// the only correct answer here.
|
|
585
|
+
if (fixesStepRoute(agent)) return next();
|
|
467
586
|
const current = pending.get(agent.id);
|
|
468
587
|
if (current === void 0) return next();
|
|
469
588
|
const target = view.entries[current.index];
|
package/package.json
CHANGED