Repository navigation
fix(retry): 传输重试交给 dsh-llm-retry 退避,不再 140ms 内空转 5 次 - #136
Merged
Merged
Conversation
TRANSPORT 分支用裸 { kind: 'retry' } 短路了 waterfall,排在后面的
dsh-llm-retry 收不到该事件,也就不会安排退避——预算内的 5 次重试背靠背
发出。实测一次真实代理故障(2026-11-28):6 次尝试共 140ms,而
DEFAULT_TRANSPORT_MAX_RETRIES 的注释承诺的是『~15 s of blip cover』。
改为 return next(),与相邻的 transient 分支一致:预算继续决定『允许几次』,
宿主继续决定『每次等多久』(500ms→1s→2s→4s→8s,累计约 15.5s)。
代理刷新订阅这类秒级断流因此有机会自愈,而不是必然报错。
- src/index.ts:transport retry 分支改走 next();移除仅为旧写法服务的
RequestErrorAction 导入,并修正随之过时的 async 注释
- src/transport-retry.ts:模块注释说明『次数归本模块、时长归宿主』
- tests:respond() 改为 downstream 语义,新增静态回归用例钉住该分支
- lib/:随源码重建
验证:npm test 1248/1248、typecheck 退出码 0、build 通过
上一提交把 transient 分支那句话复制到了 transport 分支,与该处本就完整的 英文说明重复。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
症状
代理出现秒级断流时,本轮直接报错终止,且重试在 140ms 内打完:
插件已自动重试 5 次数字准确,但体感就是「一次就弹出来」——因为 5 次重试之间几乎没有间隔。根因
src/index.ts的agent/request-error监听器里,TRANSPORT 分支用裸 decision 短路了 waterfall:dsh-llm-retry是排在后面的监听者,靠next()才能收到事件。没有next(),它既看不到这次失败,也就不会agent.session.append('llm/retry', ...)、不会走cancellableDelay——它的退避完全没生效。于是预算内的 5 次重试背靠背发出。更关键的是:这跟本仓库自己的注释相反。
src/index.ts:671-672:dsh-llm-retry still owns the wait between allowed attempts.src/index.ts:703(相邻的 transient 分支):只约束次数;仍由官方重试器决定退避和 Retry-After,避免即时重发。→ 该分支返回的是next()。src/transport-retry.ts:24:default 5: ~15 s of blip cover on the route cadence。三处都声称「次数归本模块、时长归宿主、因此约 15 秒」,但 TRANSPORT 分支的实际行为是零退避。所以
~15 s of blip cover一直是空头支票。实测证据
从 DSH 会话日志(
~/.dsh/sessions/,turn/end的原始 error +assistant/attempt时间戳)统计:assistant/attempt次数llm/retry事件数llm/retrydelayMs≈ 452–547ms(正是 500ms 起的本地退避)最后一行是关键对照:宿主退避机制本身工作正常,只是 commandcode 的 TRANSPORT 分支没走进去。
顺带把 9 次故障按错误形态分了类,8 次是
socket disconnected before secure TLS(代理已连上、转发时被掐断),只有 1 次是ECONNREFUSED 7890——即绝大多数是代理刷新订阅/切节点时的秒级断流,正是退避能够覆盖、而 140ms 空转必然失败的场景。改动
与相邻 transient 分支一致:预算继续决定「允许几次」,宿主继续决定「每次等多久」(500ms → 1s → 2s → 4s → 8s,累计约 15.5s)。第 6 次失败仍由
throw浮出,停止链条。src/index.ts:TRANSPORT 分支改走next();移除仅为旧写法服务的RequestErrorAction导入;修正随之过时的async注释(原注释在解释「两个分支返回类型不一致」,现已不存在)src/transport-retry.ts:模块注释补一段「次数归本模块、时长归宿主」,并把 15 秒的说法与真实退避绑定tests/transport-retry.test.ts:respond()从{ kind: 'retry' }改为downstream语义;新增回归用例钉住该分支必须是next()lib/:随源码重建关于测试写法
回归用例断言的是
src/index.ts的源码形态(该分支return next()、且不含裸{ kind: 'retry' }),而非驱动apply()。原因是挂载整个插件需要完整的 Cordis 上下文(llm/credentials/web/…),那测的是宿主而不是这个决策;而「next()之后宿主办退避」由宿主的dsh-llm-retry保证,不在本包职责内。用例里写明了这个取舍。验证
npm testnpm run typechecknpm run buildlib/index.js已含新分支,二次构建逐字节一致未验证:真实代理断流下的端到端表现。要复现需人为制造秒级断流(例如刷新 FlClash 订阅);我这侧只做了日志取证与单元层面验证。若维护者希望,我可以补一份
scripts/下的探针脚本,用故意指向死端口的代理来量退避间隔。行为边界
transportMaxRetries默认仍是 5,配置项语义不变。transportMaxRetries调到 1–2,退避随之缩短(1 次 ≈ 500ms)。关联:#39、#76(「最近总是断开」,根因一直未定;本 PR 不声称修掉 #76 的根因,只是让宿主已有的退避对 TRANSPORT 生效,使秒级断流有机会自愈)。