Skip to content
dsh.fish
Bundle

@dsh-external/dsh-auto-retry

Bounded fallback recovery for DSH rate limits, empty responses, and truncated model output

Source
Windsland52
License
MIT
Updated
Updated 14 days ago

Readme

# dsh-auto-retry

DSH 的有界后备恢复插件。它不会替换官方 `@deepseek-ai/dsh-llm-retry`,而是在官方提供方策略不再重试后接手。

它解决的是一类容易混淆的问题:中转方把可恢复的瞬时 429 标成 `QUOTA`,或者模型请求“正常结束”但没有可见输出。插件只在有明确证据时接手,并把重试次数、总等待时间和自动续行次数全部限制在配置预算内。

## 安装

从 GitHub 安装到 Web profile:

```powershell
dsh plugin --profile web add "github:Windsland52/dsh-auto-retry#main"
```

安装器会把包含 `dsh.bundle.patch` 的依赖加入 profile bundle。GitHub 安装会通过包的 `prepare` 脚本构建 `lib/`;如果 pnpm 提示阻止构建脚本,按提示把该包加入 profile 的 `pnpm-workspace.yaml` `allowBuilds` 后重新执行安装。

安装后重启 DSH。配置写在 profile 自己的 `cordis.patch.yml`,不要直接修改 `node_modules` 里的 bundle 文件。

## 默认行为

- 额外重试 `RATE_LIMIT`、HTTP 429、`EMPTY_RESPONSE`、`STREAM_CLOSED`。
- 中转方把瞬时 429 误标成 `QUOTA` 时,只在错误详情包含 `rate_limit_exceeded`、`rate limit`、`allocated quota exceeded` 等特征时重试;真正的余额/credits 耗尽不会重试。
- 最多额外重试 8 次,总等待时间不超过 15 分钟。
- 优先使用提供方的 `Retry-After`,否则使用带抖动的指数退避(1.5 秒至 60 秒)。
- 正常结束但没有可见文本/工具调用时,自动续行。
- `max-tokens` 截断时自动续行。
- 每个 turn 最多自动续行 2 次,避免空响应死循环。
- `AUTH`、`QUOTA`、上下文超限、无效请求和用户取消不会被默认重试。

## 配置

```yaml
- id: dsh-auto-retry
  name: '@dsh-external/dsh-auto-retry'
  config:
    # 空数组表示所有 provider;也可以只写 [scnet]
    providers: []
    retryCodes:
      - RATE_LIMIT
      - EMPTY_RESPONSE
      - STREAM_CLOSED
    retryQuota: true
    quotaRetryPatterns:
      - rate_limit_exceeded
      - rate limit
      - too many requests
      - allocated quota exceeded
      - temporarily unavailable
    maxRetries: 8
    maxElapsedMs: 900000
    initialDelayMs: 1500
    maxDelayMs: 60000
    jitterRatio: 0.2
    maxAutoContinuations: 2
    continueOnMaxTokens: true
```

每次后备重试都会复用 DSH 已有的 `llm/retry` 和 `llm/retry-started` 持久事件,因此会话重放和现有重试状态 UI 仍能理解它。内部自动续行使用 `plugin` 来源的 user message,不会伪装成人类输入。

## 和其他插件的边界

| 插件 | 主要职责 | 是否覆盖本插件的核心场景 |
| --- | --- | --- |
| 官方 `@deepseek-ai/dsh-llm-retry` | provider 自己声明的请求错误重试策略 | 它先处理;本插件只在它放弃后接手 |
| [`dsh-llm-bounded-retry`](https://github.com/911218sky/dsh-llm-bounded-retry) | 对结构化 LLM 请求错误统一做有界重试 | 不处理静默成功响应、max-tokens 续行或 relay `QUOTA` 识别;不要和本插件同时接管同一 profile 的请求重试 |
| [`dsh-retry-override`](https://github.com/ggykx123/dsh-retry-override) | 覆盖指定 provider 的 retry policy | 不处理输出续行;适合需要按 provider 改策略的用户 |
| [`dsh-client-auto-retry`](https://github.com/Frog755/dsh-client-auto-retry) | Web 客户端监听 `turn/end` 后发送“继续” | 和本插件的 max-tokens/错误续行有重叠,不建议同时启用 |
| [`dsh-autofix`](https://github.com/cyanseek/dsh-autofix) | 工具调用错误的单次恢复动作 | 不处理模型请求或模型输出 |

本插件的定位是 **Host 侧、provider-aware 的后备恢复**:保留官方重试优先级,专门补齐中转方瞬时限流误报、空可见输出和输出截断这三个缺口,而不是再提供一个无限重试器。

## 兼容性

- 已针对 DSH `0.1.0-rc.7` 的 Web profile 验证。
- 插件不切换模型或 provider,不修改请求内容,也不把自动续行伪装成人类消息。
- 同一个 profile 只应有一个插件负责 `agent/request-error` 的全局重试预算;需要使用其他重试策略时,应按 provider 划分责任范围。

## GitHub 发布

发布仓库后建议添加 `dsh` GitHub topic,方便社区目录发现。当前 package 保留了 `private: true`,表示只支持 GitHub 源码安装;如果以后要发布到 npm,需要删除该字段并改用正式的 npm 发布流程。

## 开发

```powershell
npm install
npm test
npm pack --dry-run
```

Install

dsh plugin --profile web add github:Windsland52/dsh-auto-retry

Profile: web

  • This package builds from source on install. pnpm will ask you to allow its build script — that is permission to run the package’s code on your machine, outside the agent sandbox. Only allow sources you trust.
  • This source has no pinned commit, so a later push upstream changes what installs. Prefer pinning a commit.
Source