dsh-session-superagent 0.9.119 → 0.9.121

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 CHANGED
@@ -2,6 +2,68 @@
2
2
 
3
3
  格式参照 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
4
4
 
5
+ ## [0.9.121] - 2026-11-03 —— 重试要花预算:连续失败 6 次后放慢到 2 小时一次
6
+
7
+ ### 学到什么(出处)
8
+ Google SRE《Handling Overload》:
9
+
10
+ > We implement a **per-request retry budget of up to three attempts**. If a request has already failed
11
+ > three times, we let the failure bubble up to the caller. … Secondly, we implement a **per-client retry budget**.
12
+
13
+ <https://sre.google/sre-book/handling-overload/>
14
+
15
+ 核心是:**重试要花预算,花完就该慢下来**,而不是无限次地按固定节奏重来。
16
+
17
+ ### 我们原来的问题
18
+ `nextDelayMs` 是指数退避,但**封顶 30 分钟之后就一直是 30 分钟** —— 一条凭证失效的守会以
19
+ 每 30 分钟一次的频率重试**几天**(真机就在这个状态:失败 4 次)。
20
+
21
+ ### 改法
22
+ 引入 `RETRY_BUDGET_ATTEMPTS = 6`:
23
+ | 连续失败 | 等待 |
24
+ |---|---|
25
+ | 1 | 2 分钟 |
26
+ | 3 | 8 分钟 |
27
+ | 5 | 30 分钟(预算内上限) |
28
+ | **6 起** | **最多 2 小时一次**(预算外上限) |
29
+
30
+ `watch_doctor` 同时补一行解释:`已连续失败 8 次,重试间隔已放慢到最多每 2 小时一次` ——
31
+ 否则客户看到"很久没动"会以为定时器坏了(这正好和 0.9.96 的"重启 vs 定时器丢了"是同一类误会)。
32
+
33
+ ### 测试
34
+ 新增 1 例(doctor 解释);更新 1 例(退避取值,含 30s/60s 两种基准下的上限)。合计 **231 例**。
35
+
36
+ ## [0.9.120] - 2026-11-03 —— 合并唤醒消息:同一份「接下来」只印一次
37
+
38
+ ### 学到什么(出处)
39
+ Google SRE 书《Monitoring Distributed Systems》讲告警的核心原则:
40
+
41
+ > **Every page should be actionable.** … Every time the pager goes off, I should be able to react
42
+ > with a sense of urgency.
43
+
44
+ <https://sre.google/sre-book/monitoring-distributed-systems/>
45
+
46
+ 但 **actionable ≠ 把同一份指令印 N 遍** —— 合并唤醒(多条一起叫)原来每条都带一份
47
+ 「接下来:1/2/3」,三条就是同一段指令重复三次,读者只会更快跳过它。
48
+
49
+ ### 改法
50
+ `mergeWakeTexts()` 把每条消息里 `接下来:` 之后的收尾剥掉,最后**统一附一份**,
51
+ 每条自己的【完成标准】仍各自保留(内容不同,不能合并)。
52
+
53
+ ### 证据(3 条合并,实测)
54
+ | | 长度 |
55
+ |---|---|
56
+ | 改前 | 309 字符(「接下来」出现 **3** 次) |
57
+ | 改后 | 259 字符(出现 **1** 次,净省 50) |
58
+
59
+ 省下的不是大头(分隔行会补回来一点),关键是**读起来的噪音**:一份指令只出现一次。
60
+
61
+ ### 测试
62
+ 新增 1 例:3 条合并后「接下来」恰好 1 次、每条完成标准都在、净省长度 > 30。合计 **229 例**。
63
+
64
+ ### 说明
65
+ `raw.githubusercontent.com` 与 `api.github.com` 本轮仍 502,所以学习源换成了 `sre.google`(可访问)。
66
+
5
67
  ## [0.9.119] - 2026-11-03 —— 凭证失效要单独报,并说清"不会自己恢复"
6
68
 
7
69
  ### 真机现场
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="assets/icon-180.png" width="88" height="88" alt="">
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
- [![Version](https://img.shields.io/badge/version-0.9.119-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.121-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
7
7
  [![npm](https://img.shields.io/npm/v/dsh-session-superagent.svg)](https://www.npmjs.com/package/dsh-session-superagent)
8
8
  [![dsh](https://img.shields.io/badge/DeepSeek%20Harness-plugin-orange.svg)](https://github.com/topics/dsh-plugin)
9
9
 
@@ -123,7 +123,7 @@ dsh plugin install /path/to/dsh-session-superagent
123
123
  ## 开发
124
124
 
125
125
  ```sh
126
- node --test # 228 项单测
126
+ node --test # 231 项单测
127
127
  ```
128
128
 
129
129
  ### 工具输出:文本给人和 agent,JSON 给程序
package/client.js CHANGED
@@ -14,7 +14,7 @@ window.__ModuleLoader__.load({
14
14
  const { useCallback, useEffect, useRef, useState } = React
15
15
 
16
16
  // 客户端版本探针:每次模块加载写一次,用来确认浏览器里跑的是哪一版
17
- const CLIENT_VERSION = '0.9.119'
17
+ const CLIENT_VERSION = '0.9.121'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
 
41
41
  export const name = 'dsh-session-superagent'
42
42
  /** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
43
- export const SERVER_VERSION = '0.9.119'
43
+ export const SERVER_VERSION = '0.9.121'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -2069,6 +2069,10 @@ const UPDATE_CACHE_MS = 10 * 60 * 1000
2069
2069
  } else if (Number.isFinite(age) && age > staleMs) {
2070
2070
  lines.push(`INFO ${entry.repo} 上次轮询是 ${Math.round(age / 60000)} 分钟前,但进程才启动 ${Math.round(uptimeMs / 60000)} 分钟 —— 刚重启,等下一轮即可`)
2071
2071
  }
2072
+ // 连续失败很多次时间隔已被拉长(retry budget):要解释清楚,别让人以为又卡住了
2073
+ if (Number(entry.consecutiveFailures) >= 6) {
2074
+ lines.push(`INFO ${entry.repo} 已连续失败 ${entry.consecutiveFailures} 次,重试间隔已放慢到最多每 2 小时一次`)
2075
+ }
2072
2076
  }
2073
2077
 
2074
2078
  // 6. 最近一次状态
package/lib/watch.js CHANGED
@@ -341,11 +341,23 @@ export function permanentBackoffMs(kind, baseMs = 60000) {
341
341
  if (!PERMANENT.has(kind)) return 0
342
342
  return Math.max(30 * 60 * 1000, Number(baseMs) || 0)
343
343
  }
344
+ /**
345
+ * 失败后的等待时间。
346
+ *
347
+ * 前几次按指数退避(上限 30 分钟);**连续失败到第 6 次就不再密集重试**,改成 2 小时一次 ——
348
+ * 思路来自 Google SRE《Handling Overload》的「per-request retry budget」:
349
+ * 重试应当有预算,用完就不能再无限次立刻重来。
350
+ * 出处:https://sre.google/sre-book/handling-overload/
351
+ */
352
+ export const RETRY_BUDGET_ATTEMPTS = 6
344
353
  export function nextDelayMs(entry, baseMs) {
345
354
  const failures = Number((entry && entry.consecutiveFailures) || 0)
346
355
  if (failures <= 0) return baseMs
347
- const factor = Math.min(2 ** failures, 60)
348
- return Math.min(baseMs * factor, 30 * 60 * 1000)
356
+ const overBudget = failures >= RETRY_BUDGET_ATTEMPTS
357
+ // 预算内:最多 60 倍(默认 60s 间隔 → 1 小时);超出预算:最多 120 倍(→ 2 小时)
358
+ const factor = Math.min(2 ** failures, overBudget ? 120 : 60)
359
+ const cap = overBudget ? 2 * 60 * 60 * 1000 : 30 * 60 * 1000
360
+ return Math.min(Math.max(baseMs * factor, baseMs), cap)
349
361
  }
350
362
 
351
363
  /** 每小时唤醒上限:把过去一小时的唤醒时间戳剪掉再判断。 */
@@ -663,9 +675,22 @@ export function mergeWakeTexts(parts) {
663
675
  .join(String.fromCharCode(10))
664
676
  return out
665
677
  })
678
+ // 「接下来」那一整段是每次唤醒都一样的收尾(三条动作)。合并后重复 N 遍纯噪音:
679
+ // 它就是同一份指令,客户读一遍就够。依据:SRE 的「Every page should be actionable」,
680
+ // 但 actionable 不等于把同一份指令印 N 次。
681
+ const TAIL = '接下来:'
682
+ const withTail = trimmed.filter((text) => text.includes(TAIL))
683
+ const stripped = trimmed.map((text) => {
684
+ const at = text.indexOf(TAIL)
685
+ return at < 0 ? text : text.slice(0, at).replace(/[\s]+$/, '')
686
+ })
687
+ const tailBlock = withTail.length > 1
688
+ ? withTail[0].slice(withTail[0].indexOf(TAIL))
689
+ : ''
690
+
666
691
  const head = '【主理鱼】这一小段时间内有 ' + list.length + ' 处变化,合并成一条:'
667
- const body = trimmed.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
668
- return head + body
692
+ const body = stripped.map((text, i) => String.fromCharCode(10, 10) + '—— 第 ' + (i + 1) + ' 处 ——' + String.fromCharCode(10) + text).join('')
693
+ return head + body + (tailBlock ? String.fromCharCode(10, 10) + tailBlock : '')
669
694
  }
670
695
 
671
696
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.119",
3
+ "version": "0.9.121",
4
4
  "description": "Session-level superagent for DeepSeek Harness: watch a GitHub repository and wake a session when something needs doing. Credentials never reach the model.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",