dsh-subagent-default-model 2.1.12 → 2.1.14
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 +82 -0
- package/lib/index.js +123 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,87 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.1.14 (2026-11-05)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
**`agent.model.select()` 被拒时仍记账**(自查发现,2.1.13 的 npm 构建早于该修复)。
|
|
8
|
+
|
|
9
|
+
原实现先 `pending.set(...)` 再调 `agent.model.select()`。一旦 `select()` 抛出,会记录一次**并未发生**的切换:`count` 被计满、该 step 被标记为「已处理」,于是那个池内候选被白白消耗,同一步也不再尝试它。
|
|
10
|
+
|
|
11
|
+
改为 `select()` 成功后才记账,并补回归用例(`select` 先拒后成功,断言同一步仍能选到该候选)。
|
|
12
|
+
|
|
13
|
+
> **2.1.13 与 2.1.14 的关系**:2.1.13 的 npm 包在等待 2FA 授权**之前**就已打包,本修复是在那段等待期间提交的,因此没有进入 2.1.13。npm 上的 2.1.13 内容等于提交 `57891f0`,而修复在 `63956a1`。npm 版本不可覆盖,故发 2.1.14 承载修复。**请使用 2.1.14。** 该缺陷只在宿主拒绝 `select()` 的罕见路径下触发,其余 0.2.2 适配 2.1.13 已具备。
|
|
14
|
+
|
|
15
|
+
### Docs
|
|
16
|
+
|
|
17
|
+
`RELEASING.md` 新增两条纪律:按下 `npm publish` 后不再改动任何要发布的文件;发布后必须下载真实 tarball 与 git tag 逐字节比对(「版本号对」不等于「内容对」)。
|
|
18
|
+
|
|
19
|
+
## 2.1.13 (2026-11-05)
|
|
20
|
+
|
|
21
|
+
适配宿主 **0.2.2-rc.1**。这次不是行号位移,而是**一条契约收紧了语义**。
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
**故障转移在 0.2.2 上会抛宿主内部错误。**
|
|
26
|
+
|
|
27
|
+
0.2.2 把模型路由从「每次请求由 `agent/request` 瀑布决定」改成「**每个 step 在准备阶段固定**」:
|
|
28
|
+
|
|
29
|
+
- `preStep()` 里 `const selection = this.model.current()` 先捕获,随后一路传递,**重试复用同一份**(类型文档:*captured step selection, retained across retries*);
|
|
30
|
+
- `prepareRequest()` 用它拼出 `seedConfig`,并对瀑布返回的配置新增硬校验——改 provider/model 直接抛 `agent "X": agent/request proposed … after step preparation fixed …`;
|
|
31
|
+
- 该瀑布本身被标 **`@deprecated`**:*a replacement may adjust controls but must keep the provider, model, and reasoning effort selection*,并指明唯一替代是 `agent.model.select()`。
|
|
32
|
+
|
|
33
|
+
本插件的故障转移恰好就是「在 `agent/request` 里把 seed 换成池中下一个模型」,因此在 0.2.2 上**必然抛错**——一次额度耗尽会变成一句难懂的宿主内部错误,比不修更糟。
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
**双路径故障转移,按能力探测自动选择**(`typeof agent.model?.select === "function"`;`agent.model` 在 0.2.2 之前不存在,无需版本比较):
|
|
38
|
+
|
|
39
|
+
- **旧宿主(≤0.2.1)**:行为完全不变,失败的那次请求当场换模型重试。
|
|
40
|
+
- **新宿主(≥0.2.2)**:
|
|
41
|
+
1. 先 `await next()` 让下游处理。`dsh-llm-retry` 已在 `dsh-base` 组合里默认启用并负责退避;**瞬时失败不该换路**——`select()` 会持久化到下一步,重试成功后仍会留下一次无辜的切换。
|
|
42
|
+
2. 下游不重试才说明这条路真的死了:用 `agent.model.select()` 为**下一个 step / turn** 预选池中下一条健康路由,然后**放行原始错误**(它才说明真实原因:配额、密钥)。
|
|
43
|
+
3. 每个 step 最多选一次;`agent/request` 在新宿主上直接 `return next()`,绝不改写路由。
|
|
44
|
+
4. `select()` 被宿主拒绝时打 warn 并照常放行原始错误,绝不吞掉真实原因。
|
|
45
|
+
|
|
46
|
+
**必须承认的代价**:0.2.2 上「同一次请求内透明续跑」无法实现——失败的那一步路由已锁定,`select()` 只影响下一步。因此永久性失败(配额耗尽、密钥失效)会结束当前 turn,而不再换供应商续跑;可续跑的 subagent 下次被唤醒时已在健康路由上。这是宿主收回的能力,不是实现取舍,README 中英文两版都已如实写明。
|
|
47
|
+
|
|
48
|
+
### Compatibility
|
|
49
|
+
|
|
50
|
+
`ADMITTED_HOST_VERSIONS` 补入 `0.2.2-rc.1`(自检用例先失败后通过,符合预期)。
|
|
51
|
+
|
|
52
|
+
本轮逐包比对 rc.5 → 0.2.2-rc.1:`desktop-runtime.json` 的共享包从 305 增至 329,几乎所有包都有改动,但**只有 `dsh-agent-loop` 这一处契约收紧**。其余依赖面实测完好:
|
|
53
|
+
|
|
54
|
+
| 依赖面 | 结论 |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `agent/pre-step` 瀑布 | 完好(payload 新增 `modelSelection`,增量) |
|
|
57
|
+
| `agent/request-error` 瀑布 | 完好(payload 新增 `provider` / `retryPolicy`) |
|
|
58
|
+
| `agent.inbox.prepend/claim` | 完好(内部重构 `projections` → `readState`,API 未变) |
|
|
59
|
+
| `subagents.getProvider` / `startActivation` | 完好 |
|
|
60
|
+
| provider 的 `inheritsParentContext` | 完好(fork provider 仍为 `true`,`applyToForkChildren` 门禁依据不变) |
|
|
61
|
+
| `session.requestContext()` | 完好(`:1627` → `:1636`) |
|
|
62
|
+
| 客户端槽位 / locale / `settings.mutate` | 完好(`chat-subagent-model-notice` 实测 active) |
|
|
63
|
+
| `request/header` 的 `reason` 取值 | 完好(`initial` / `resume` / `change` / `series` 未变,对话行仍正常) |
|
|
64
|
+
|
|
65
|
+
实测(宿主机 0.2.2-rc.1):`subagent` 子代理拿到池中 `minmax/MiniMax-M3.1-Flash`;`subagent_fork` 子代理按门禁继承父路由 `dsh-opencode-go`,未注入。
|
|
66
|
+
|
|
67
|
+
### Tests
|
|
68
|
+
|
|
69
|
+
`173/173`(164 → 173),`skip 0`。`integration.mjs` 16/16、`prove.mjs` 1/1。新增 9 个用例覆盖新宿主路径:
|
|
70
|
+
|
|
71
|
+
- 下游重试成功时**不得**换路(否则重试成功后仍会留下一次无辜切换)
|
|
72
|
+
- 无人重试时选中下一条池内路由,并**放行原始错误**(而非宿主 guard 错误)
|
|
73
|
+
- `agent/request` 必须**原样返回**该 step 的路由(这条正是回归本体)
|
|
74
|
+
- 同一 step 最多选一次;下一个 step 可再选
|
|
75
|
+
- 池耗尽不再选新候选、不再伪造 retry
|
|
76
|
+
- `select()` 被拒时打 warn 且不吞原始错误
|
|
77
|
+
- `select()` 被拒时**不得**记账:候选不能被白白消耗,同一步仍须能再选它
|
|
78
|
+
- AUTH 仍切换,且仍打「密钥可能无效」告警
|
|
79
|
+
- 主代理循环仍不受影响
|
|
80
|
+
|
|
81
|
+
变异验证 5/5 命中:①新宿主仍走旧的 `agent/request` 覆盖路径 → 5 个用例失败;②`agent/request` 不提前 return → 原样返回用例失败;③忽略下游 retry → 不换路用例失败;④去掉「每 step 一次」限制 → 该用例失败;⑤把记账移回 `select()` 之前 → 候选被消耗用例失败。
|
|
82
|
+
|
|
83
|
+
> 夹具也被修了:原来它只驱动 `agent/request` 并断言返回值变了,模拟的是**旧宿主契约**,所以在会抛错的新宿主上依然全绿。当宿主给契约加硬校验时,夹具必须把校验也加进去,否则它只是在自证清白。
|
|
84
|
+
|
|
3
85
|
## 2.1.12 (2026-10-30)
|
|
4
86
|
|
|
5
87
|
### Fixed
|
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,98 @@ 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
|
+
try {
|
|
448
|
+
agent.model.select({
|
|
449
|
+
provider: target.provider,
|
|
450
|
+
model: target.model,
|
|
451
|
+
...(target.reasoningEffort === void 0 ? {} : { reasoningEffort: target.reasoningEffort })
|
|
452
|
+
});
|
|
453
|
+
} catch (error) {
|
|
454
|
+
// A host that exposes `model.select` but refuses this call is not a
|
|
455
|
+
// reason to swallow the real failure — report it and let the original
|
|
456
|
+
// error through.
|
|
457
|
+
ctx.logger.warn(
|
|
458
|
+
`[dsh-subagent-default-model] could not pre-select %s/%s after %s; the subagent keeps its route: %s`,
|
|
459
|
+
target.provider,
|
|
460
|
+
target.model,
|
|
461
|
+
failure.code,
|
|
462
|
+
error instanceof Error ? error.message : String(error)
|
|
463
|
+
);
|
|
464
|
+
return downstream;
|
|
465
|
+
}
|
|
466
|
+
// Record ONLY a selection that actually landed: an incremented `count` for a
|
|
467
|
+
// switch the host refused would retire a pool entry that was never used and
|
|
468
|
+
// stop the next step from retrying it.
|
|
469
|
+
pending.set(agent.id, {
|
|
470
|
+
index,
|
|
471
|
+
tried,
|
|
472
|
+
count: (current?.count ?? 0) + 1,
|
|
473
|
+
step
|
|
474
|
+
});
|
|
475
|
+
ctx.logger.warn(
|
|
476
|
+
`[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)`,
|
|
477
|
+
agent.id,
|
|
478
|
+
failure.code,
|
|
479
|
+
payload.turn,
|
|
480
|
+
step,
|
|
481
|
+
target.provider,
|
|
482
|
+
target.model
|
|
483
|
+
);
|
|
484
|
+
if (isAuthFailure(failure.code)) {
|
|
485
|
+
ctx.logger.warn(
|
|
486
|
+
`[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.`,
|
|
487
|
+
payload.provider ?? "(unknown)",
|
|
488
|
+
failure.code,
|
|
489
|
+
target.provider,
|
|
490
|
+
target.model
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
return downstream;
|
|
494
|
+
}
|
|
495
|
+
|
|
383
496
|
/**
|
|
384
497
|
* Install the subagent-only failover waterfalls. Both listeners no-op for the
|
|
385
498
|
* main agent (origin gate) and for subagents whose failure code is not a
|
|
@@ -394,13 +507,17 @@ function installFailover(ctx, state) {
|
|
|
394
507
|
// After a model failure on a subagent loop: advance the pool index and ask
|
|
395
508
|
// the loop to rebuild the request (`{ kind: "retry" }`). When every pool
|
|
396
509
|
// entry has been tried, let the real error surface untouched.
|
|
397
|
-
const disposeRequestError = ctx.on("agent/request-error", (payload, next) => {
|
|
510
|
+
const disposeRequestError = ctx.on("agent/request-error", async (payload, next) => {
|
|
398
511
|
const view = failoverView(state);
|
|
399
512
|
if (view === void 0) return next();
|
|
400
513
|
const { agent, turn, step, failure, signal } = payload;
|
|
401
514
|
if (signal?.aborted) return next();
|
|
402
515
|
if (!isSubagentAgent(agent)) return next();
|
|
403
516
|
if (failure === void 0 || !FAILOVER_ELIGIBLE_CODES.includes(failure.code)) return next();
|
|
517
|
+
// 0.2.2+ fixed the route for the whole step, so the route cannot be
|
|
518
|
+
// swapped on the retry this hook used to request. See
|
|
519
|
+
// `switchForNextStep` for what replaces it.
|
|
520
|
+
if (fixesStepRoute(agent)) return switchForNextStep(ctx, state, pending, payload, next);
|
|
404
521
|
const current = pending.get(agent.id);
|
|
405
522
|
// The primary already failed (that triggered the first switch), so the
|
|
406
523
|
// remaining candidates are the other pool entries: at most
|
|
@@ -464,6 +581,11 @@ function installFailover(ctx, state) {
|
|
|
464
581
|
if (view === void 0) return next();
|
|
465
582
|
const { agent } = payload;
|
|
466
583
|
if (!isSubagentAgent(agent)) return next();
|
|
584
|
+
// 0.2.2+ : the route is fixed for the step and the host throws when a
|
|
585
|
+
// listener changes it. `switchForNextStep` already recorded the new
|
|
586
|
+
// selection, which the NEXT step reads; returning the seed untouched is
|
|
587
|
+
// the only correct answer here.
|
|
588
|
+
if (fixesStepRoute(agent)) return next();
|
|
467
589
|
const current = pending.get(agent.id);
|
|
468
590
|
if (current === void 0) return next();
|
|
469
591
|
const target = view.entries[current.index];
|
package/package.json
CHANGED