dsh-session-superagent 0.9.171 → 0.9.173

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,69 @@
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.173] - 2026-11-04 —— 重启后的「会话已不在」误报:给 10 分钟宽限期
6
+
7
+ ### 现场(重启后你看到的那条红字)
8
+ ```
9
+ lastError: 会话已不在:请删除或重建这条主理鱼
10
+ ```
11
+ 而那个会话**当时正开着**(就是当前对话)。宿主刚启动时 `agents.get()` 会短暂返回 `undefined`,
12
+ 三分钟后再轮询,错误自己消失了。
13
+
14
+ ### 为什么这条特别糟
15
+ 1. 建议是**不可逆**的 —— 客户照做会删掉一条好好工作的守(水位 / 历史 / 隔离区全没);
16
+ 2. 退避是冤枉的:这不是失败,是启动时序;
17
+ 3. 它**本来会自己好**,但客户已经删了。
18
+
19
+ ### 改法
20
+ `sessionMissingVerdict()`(`lib/watch.js`):
21
+ - 第一次查不到 → 记下起点,进入 10 分钟宽限期;
22
+ - 期内只写 `lastDeferred`(「会话尚未就绪,约 N 分钟后仍找不到才报错」),**不记失败、不退避**;
23
+ - 超过宽限期才判死,文案带上等待时长:`会话已不在(连续 N 分钟找不到):确认该会话是否已被删除,再决定是否重建`;
24
+ - 一旦找得到,立刻清掉计时。
25
+
26
+ ### 证据
27
+ ```
28
+ node --test → 271/271(新增 2 条:宽限期内不判死 / 超期判死 / 时间戳坏掉不卡死)
29
+ 真机:重启后那次 poll 已清除错误(fails 0),文案从「会话已不在」变回「会话正忙,下一轮重试」
30
+ ```
31
+
32
+ ## [0.9.172] - 2026-11-04 —— 真机第一轮唤醒就炸:`iso is not defined`
33
+
34
+ ### 现场(你截图的那条红色「异常」)
35
+ 给本仓库新建一条守之后,第一次真正要走「发唤醒消息」时,
36
+ 面板直接红 `iso is not defined`。
37
+
38
+ ### 根因
39
+ `lib/index.js` 的 `criteria: [...]` 里写着:
40
+
41
+ ```js
42
+ iso && iso.dir ? '回写到哪:推分支并开 PR…' : '回写到哪:在 issue 里留言…'
43
+ ```
44
+
45
+ 而那个作用域里的变量叫 **`isolation`**(上一行 `const isolation = await prepareIsolation(entry)`),
46
+ 从来没有 `iso`。所以只要真的走到"构造唤醒文本"这一步就抛 ReferenceError。
47
+
48
+ **为什么一直没被发现**:老那条守(dsh-go)长期停在 304 / 会话忙的提前 return 上,
49
+ 永远到不了这一行;而 269 个用例里没有一个覆盖"pollOnce 走到发消息"的完整路径。
50
+ 新建守 + 仓库真有新条目 = 第一次踩中。
51
+
52
+ ### 改法
53
+ 把三条完成标准抽成纯函数 `wakeCriteria({ isolation })`(`lib/watch.js`),`index.js` 调用它。
54
+ 这样这段逻辑第一次有了**能直接覆盖的入口**,而不是埋在 400 行 pollOnce 中间。
55
+
56
+ ### 测试
57
+ - 新:`wakeCriteria` 有/无隔离区两条分支都对(无隔离区时**不许**说"推分支");
58
+ - 新:静态守卫 —— `lib/index.js` 里出现裸 `iso` 标识符即失败(注释里出现不算)。
59
+
60
+ 合计 **269 例**。
61
+
62
+ ### 修复后的真机验证
63
+ ```
64
+ POST /watch {action:'poll', id:'MYCF711/dsh-session-superagent#…'}
65
+ → 202;下一轮 lastError 从「iso is not defined」变成「会话正忙,下一轮重试」(正常推迟)
66
+ ```
67
+
5
68
  ## [0.9.171] - 2026-11-04 —— 本地解析错误不该被说成「可能是代理干扰」
6
69
 
7
70
  ### 为什么(这是 PR #2 那句判断的落地)
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.171-green.svg)](https://github.com/MYCF711/dsh-session-superagent/releases)
6
+ [![Version](https://img.shields.io/badge/version-0.9.173-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 # 267 项单测
126
+ node --test # 271 项单测
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.171'
17
+ const CLIENT_VERSION = '0.9.173'
18
18
  let BASE = '/session-superagent'
19
19
  /**
20
20
  * 挑「最新的那个服务端实例」。
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ import { redact } from './redact.js'
25
25
  import { decodeBody } from './body.js'
26
26
  import {
27
27
  advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
28
- TRIAGE_SIGNALS, accessNote, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, diagnoseEmptyBody, diagnoseBadBody, isAuthBroken, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, recordOtherError, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
28
+ TRIAGE_SIGNALS, accessNote, wakeCriteria, sessionMissingVerdict, buildCommentBatchQuery, classifyGhError, commentSummaryLine, parseCommentBatch, pickSuggestion, repoStructureNote, countReasons, filterReason, formatGhCall, diagnoseEmptyBody, diagnoseBadBody, isAuthBroken, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, enterActiveHoursDefer, recordOtherError, permanentBackoffMs, RETRY_BUDGET_ATTEMPTS, RETRY_SLOW_CAP_MINUTES, pushAbsorbed, pushFiltered, normalizeFilters, partitionItems, passesFilters,
29
29
  shouldRunCleanup,
30
30
  bumpDailyWakes,
31
31
  busierThanUsual,
@@ -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.171'
43
+ export const SERVER_VERSION = '0.9.173'
44
44
  export const inject = ['tools', 'agents', 'webServer']
45
45
  /** 一条会话每小时最多被唤醒几次(跨所有守累计)。单守上限挡不住多守叠加。 */
46
46
  // 本进程启动时刻:用来区分「刚重启还没轮到」与「定时器真的丢了」
@@ -1133,12 +1133,23 @@ async function pollOnce(ctx, entry, baseMs) {
1133
1133
  const liveAgents = agentsService(ctx)
1134
1134
  const liveAgent = liveAgents && typeof liveAgents.get === 'function' ? liveAgents.get(entry.sessionId) : undefined
1135
1135
  if (!liveAgent) {
1136
- // 会话已经不在了(被删/换机器):别开隔离区,也别假装在盯。
1136
+ // 「找不到会话」有两种:宿主刚启动还没加载(临时),或真被删了(永久)。
1137
+ // 2026-11-04 真机:重启后第一轮就报「会话已不在:请删除或重建」,可那个会话明明开着。
1138
+ // 所以先给宽限期:期内只写 lastDeferred(不记失败、不退避),过了才认定真的没了。
1139
+ const verdict = sessionMissingVerdict({ missingSince: entry.sessionMissingSince })
1140
+ if (verdict.justNow) entry.sessionMissingSince = verdict.startedAt
1141
+ if (verdict.grace) {
1142
+ entry.lastDeferred = '会话尚未就绪(宿主可能刚启动):约 ' + verdict.waitMin + ' 分钟后仍找不到才报错'
1143
+ return
1144
+ }
1145
+ // 超过宽限期仍找不到:别开隔离区,也别假装在盯。
1137
1146
  // 必须走 bumpFailure —— 否则这条会每 intervalSec 打一次 GitHub,永不退避(第四轮审核指出)。
1138
- setEntryError(entry, '会话已不在:请删除或重建这条主理鱼')
1147
+ setEntryError(entry, '会话已不在(连续 ' + verdict.waitedMin + ' 分钟找不到):确认该会话是否已被删除,再决定是否重建这条主理鱼')
1139
1148
  bumpFailure(entry, baseMs)
1140
1149
  return
1141
1150
  }
1151
+ // 找得到就清掉「缺失计时」,下次重启不会带着旧时间戳
1152
+ entry.sessionMissingSince = null
1142
1153
  const gate = decideWake(liveAgent && liveAgent.status)
1143
1154
  if (!gate.ok) {
1144
1155
  entry.lastDeferred = '会话正忙,下一轮重试'
@@ -1169,11 +1180,9 @@ async function pollOnce(ctx, entry, baseMs) {
1169
1180
  // 只读仓库要在任务书里直说,否则会话会去试写然后吃 403
1170
1181
  access: accessNote(entry.repoAccess),
1171
1182
  // 完成标准要可观测(Given-When-Then 的思路):三件事缺一不算完成
1172
- criteria: [
1173
- '改了什么:文件清单 + 一句话为什么(别只写"已修复")',
1174
- '怎么验证的:跑过的测试/命令 + 结果;跑不了就写清为什么跑不了',
1175
- iso && iso.dir ? '回写到哪:推分支并开 PR,然后在 issue 里留言 + watch_ack 打标签' : '回写到哪:在 issue 里留言 + watch_ack 打标签',
1176
- ],
1183
+ // 三条完成标准抽在 lib/watch.js 里(纯函数,可被用例覆盖):
1184
+ // 这里曾经引用过不存在的 `iso`,只在"会话空闲真的发消息"时才爆 ReferenceError。
1185
+ criteria: wakeCriteria({ isolation }),
1177
1186
  // 「为什么是这几条」:把本轮的筛选依据一并写进任务书
1178
1187
  changedTotal: fresh.length,
1179
1188
  batchLimit: listed.length,
package/lib/watch.js CHANGED
@@ -90,6 +90,25 @@ export function advanceSeen(seen, fresh) {
90
90
  * 唤醒消息 = 任务书。竞品的触发都带足上下文(类型、状态、作者、标签、是否草稿),
91
91
  * 否则 agent 醒来还得自己查一遍。这里一次给全。
92
92
  */
93
+ /**
94
+ * 唤醒消息里的「完成标准」三条。
95
+ *
96
+ * 单独抽出来是因为它曾经写错过一次:`criteria` 里引用了不存在的 `iso`(实际变量叫 `isolation`),
97
+ * 只在**会话空闲、真的走到发消息**那一步才爆 `ReferenceError: iso is not defined` ——
98
+ * 有守但一直是 304/会话忙的话,永远看不到。抽成纯函数后,它就能被用例直接覆盖。
99
+ */
100
+ export function wakeCriteria({ isolation } = {}) {
101
+ const iso = isolation || {}
102
+ const where = iso.dir
103
+ ? '回写到哪:推分支并开 PR,然后在 issue 里留言 + watch_ack 打标签'
104
+ : '回写到哪:在 issue 里留言 + watch_ack 打标签'
105
+ return [
106
+ '改了什么:文件清单 + 一句话为什么(别只写"已修复")',
107
+ '怎么验证的:跑过的测试/命令 + 结果;跑不了就写清为什么跑不了',
108
+ where,
109
+ ]
110
+ }
111
+
93
112
  export function formatWatchText(repo, fresh, options = {}) {
94
113
  const list = fresh ?? []
95
114
  const more = Number(options.more) || 0
@@ -1001,3 +1020,26 @@ export function statusView(entries, options = {}) {
1001
1020
  })),
1002
1021
  }
1003
1022
  }
1023
+
1024
+ /**
1025
+ * 「找不到会话」到底是**被删了**,还是**宿主刚启动还没加载**?
1026
+ *
1027
+ * 真机现场(2026-11-04 重启后第一轮轮询):
1028
+ * lastError: 会话已不在:请删除或重建这条主理鱼
1029
+ * 而那个会话明明还开着 —— 宿主刚启动时 agents.get() 会短暂返回 undefined。
1030
+ * 让客户看到"请删除或重建"这种不可逆建议,比什么都不说更糟。
1031
+ *
1032
+ * 判据:先给一段宽限期(默认 10 分钟,约 5 个轮询周期)。
1033
+ * 宽限期内只写 lastDeferred(不记失败、不退避);过了宽限期才认定真的没了。
1034
+ */
1035
+ export const SESSION_MISSING_GRACE_MS = 10 * 60 * 1000
1036
+
1037
+ export function sessionMissingVerdict({ missingSince, now = Date.now(), graceMs = SESSION_MISSING_GRACE_MS } = {}) {
1038
+ const since = Date.parse(String(missingSince || ''))
1039
+ if (!Number.isFinite(since)) {
1040
+ return { grace: true, startedAt: new Date(now).toISOString(), waitMin: Math.ceil(graceMs / 60000), justNow: true }
1041
+ }
1042
+ const left = graceMs - (now - since)
1043
+ if (left > 0) return { grace: true, startedAt: new Date(since).toISOString(), waitMin: Math.max(1, Math.ceil(left / 60000)) }
1044
+ return { grace: false, waitedMin: Math.max(1, Math.round((now - since) / 60000)) }
1045
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-superagent",
3
- "version": "0.9.171",
3
+ "version": "0.9.173",
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",