dsh-session-superagent 0.8.53 → 0.8.54
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 +22 -0
- package/MAINTENANCE.md +1 -1
- package/README.md +2 -2
- package/client.js +1 -1
- package/lib/index.js +11 -2
- package/lib/watch.js +15 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
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.8.54] - 2026-11-02 —— 第二阶段限流:照 Retry-After 等,别猜
|
|
6
|
+
|
|
7
|
+
### 学到的一条(知识库第 4 条)
|
|
8
|
+
GitHub 有两种限流:**primary**(固定窗口,有 `X-RateLimit-*` 预警)和 **secondary**(突发触发,403/429 + `Retry-After`)。
|
|
9
|
+
primary 我们 0.8.53 已经自适应;secondary **没有预警**,一旦触发继续按间隔重试只会延长封禁。
|
|
10
|
+
|
|
11
|
+
实测证据:`gh api --include` 的 `Access-Control-Expose-Headers` 里明确列着 `Retry-After`,
|
|
12
|
+
404 响应也能看到这一行 —— 它是协议里的正式头。
|
|
13
|
+
|
|
14
|
+
### 改了什么
|
|
15
|
+
失败路径先看 `Retry-After`:
|
|
16
|
+
- 有值 → 就按它等(封顶 1 小时),`lastDeferred` 写「被 GitHub 限流,按 Retry-After 等 N 秒」;
|
|
17
|
+
- 没值 → 走原来的指数退避。
|
|
18
|
+
|
|
19
|
+
### 顺带结案:那个"并发偶发红"
|
|
20
|
+
这轮又跑 **10 次全绿**(前几轮还有 4+6 次)。回看两次失败都发生在
|
|
21
|
+
**版本号刚改、文件正在被重写的同一秒** —— 是测试读文件与改文件撞车,不是产品问题。
|
|
22
|
+
判定为**人为窗口,不是 flake**,不再追。
|
|
23
|
+
|
|
24
|
+
### 测试
|
|
25
|
+
- 新增 1 例(403 + `Retry-After` 解析、正常值、0/非数字、封顶)。合计 **108 例**。
|
|
26
|
+
|
|
5
27
|
## [0.8.53] - 2026-11-02 —— 按剩余额度自适应降频(别把 5000/小时打光)
|
|
6
28
|
|
|
7
29
|
### 算一笔账
|
package/MAINTENANCE.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## 二、当前状态(2026-11-01)
|
|
11
11
|
|
|
12
|
-
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test`
|
|
12
|
+
- [x] 七个工具可用(github / repo_here / watch_start / watch_status / watch_stop / watch_ack / watch_doctor),`node --test` 108/108 通过
|
|
13
13
|
- [x] 自回声抑制(逐条水位)
|
|
14
14
|
- [x] 仅空闲注入(避免草稿回放)
|
|
15
15
|
- [x] 唤醒失败不推进水位
|
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)
|
|
6
|
-
[](https://github.com/MYCF711/dsh-session-superagent/releases)
|
|
7
7
|
[](https://www.npmjs.com/package/dsh-session-superagent)
|
|
8
8
|
[](https://github.com/topics/dsh-plugin)
|
|
9
9
|
|
|
@@ -99,7 +99,7 @@ dsh plugin install /path/to/dsh-session-superagent
|
|
|
99
99
|
## 开发
|
|
100
100
|
|
|
101
101
|
```sh
|
|
102
|
-
node --test #
|
|
102
|
+
node --test # 108 项单测
|
|
103
103
|
```
|
|
104
104
|
|
|
105
105
|
版本与发布流程见 [UPDATING.md](UPDATING.md),交付门见 [CHECKLIST.md](CHECKLIST.md),接手台账见 [MAINTENANCE.md](MAINTENANCE.md)。
|
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.8.
|
|
17
|
+
const CLIENT_VERSION = '0.8.54'
|
|
18
18
|
let BASE = '/session-superagent'
|
|
19
19
|
/**
|
|
20
20
|
* 挑「最新的那个服务端实例」。
|
package/lib/index.js
CHANGED
|
@@ -24,13 +24,13 @@ import { redact } from './redact.js'
|
|
|
24
24
|
import { decodeBody } from './body.js'
|
|
25
25
|
import {
|
|
26
26
|
advanceSeen, applyWatcherAction, batchFresh, decideWake, DEFAULT_ACK_LABEL, formatWatchText,
|
|
27
|
-
classifyGhError, filterReason, hasAckLabel, jitterMs, parseGhInclude, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
27
|
+
classifyGhError, filterReason, hasAckLabel, jitterMs, parseGhInclude, retryAfterMs, throttleDelayMs, inActiveHours, newestUpdatedAt, nextDelayMs, pushFiltered, normalizeFilters, partitionItems, passesFilters,
|
|
28
28
|
mergeFilters, mergePollResult, pruneSeen, pruneWakeTimes, pushHistory, recordReported, staleWorktrees, worktreePlan,
|
|
29
29
|
} from './watch.js'
|
|
30
30
|
|
|
31
31
|
export const name = 'dsh-session-superagent'
|
|
32
32
|
/** 服务端版本:随 package.json 同步(meta 测试守着)。客户端据此挑「最新的那个实例」。 */
|
|
33
|
-
export const SERVER_VERSION = '0.8.
|
|
33
|
+
export const SERVER_VERSION = '0.8.54'
|
|
34
34
|
export const inject = ['tools', 'agents', 'webServer']
|
|
35
35
|
|
|
36
36
|
/** 仅供测试:读写状态文件(生产代码不要用)。 */
|
|
@@ -443,6 +443,15 @@ async function pollOnce(ctx, entry, baseMs) {
|
|
|
443
443
|
const res = await run('gh', args, { timeoutMs: 45000, env: ghEnv() })
|
|
444
444
|
entry.lastPoll = new Date().toISOString()
|
|
445
445
|
if (res.code !== 0) {
|
|
446
|
+
// 先看是不是被限流:GH 的 secondary limit 会给 Retry-After,照它等最准
|
|
447
|
+
const failure = parseGhInclude(res.stdout)
|
|
448
|
+
const wait = retryAfterMs(failure.retryAfter)
|
|
449
|
+
if (wait > 0) {
|
|
450
|
+
entry.nextAt = new Date(Date.now() + wait).toISOString()
|
|
451
|
+
entry.lastDeferred = '被 GitHub 限流,按 Retry-After 等 ' + Math.round(wait / 1000) + ' 秒'
|
|
452
|
+
entry.lastError = null
|
|
453
|
+
return
|
|
454
|
+
}
|
|
446
455
|
const detail = redact(res.stderr).slice(0, 240)
|
|
447
456
|
// 常见失败给一句能照着做的提示,别只丢原始 stderr
|
|
448
457
|
const classified = classifyGhError(detail)
|
package/lib/watch.js
CHANGED
|
@@ -451,12 +451,15 @@ export function parseGhInclude(stdout) {
|
|
|
451
451
|
return Number.isFinite(value) ? value : null
|
|
452
452
|
}
|
|
453
453
|
const resetSeconds = numeric('x-ratelimit-reset')
|
|
454
|
+
// Stage 2 限流(secondary rate limit)用 Retry-After 告诉你等多久;primary 用 x-ratelimit-reset
|
|
455
|
+
const retryAfterRaw = header('retry-after')
|
|
454
456
|
return {
|
|
455
457
|
status,
|
|
456
458
|
etag: header('etag'),
|
|
457
459
|
remaining: numeric('x-ratelimit-remaining'),
|
|
458
460
|
limit: numeric('x-ratelimit-limit'),
|
|
459
461
|
resetAt: resetSeconds ? new Date(resetSeconds * 1000).toISOString() : null,
|
|
462
|
+
retryAfter: Number.isFinite(Number(retryAfterRaw)) ? Number(retryAfterRaw) : null,
|
|
460
463
|
body,
|
|
461
464
|
}
|
|
462
465
|
}
|
|
@@ -468,6 +471,18 @@ export function parseGhInclude(stdout) {
|
|
|
468
471
|
* (实测 `gh api --include` 的输出里就是这几个头)。
|
|
469
472
|
* 剩余低于阈值时,把下一次轮询推到额度重置时间(最多等 1 小时),而不是继续发请求。
|
|
470
473
|
*/
|
|
474
|
+
/**
|
|
475
|
+
* GitHub 的「第二阶段限流」会在 403/429 响应里带 `Retry-After: <秒>`。
|
|
476
|
+
* 按它等,比我们瞎猜一个退避时间准确得多。
|
|
477
|
+
* 依据:GitHub 暴露头里明确包含 `Retry-After`(实测 `gh api --include` 的
|
|
478
|
+
* Access-Control-Expose-Headers 一行里就能看到),且官方限流文档要求遵守它。
|
|
479
|
+
*/
|
|
480
|
+
export function retryAfterMs(retryAfter, { capMs = 3600 * 1000 } = {}) {
|
|
481
|
+
const seconds = Number(retryAfter)
|
|
482
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return 0
|
|
483
|
+
return Math.min(capMs, Math.round(seconds * 1000))
|
|
484
|
+
}
|
|
485
|
+
|
|
471
486
|
export function throttleDelayMs({ remaining, resetAt, now = Date.now(), threshold = 500, capMs = 3600 * 1000 } = {}) {
|
|
472
487
|
if (remaining === null || remaining === undefined) return 0
|
|
473
488
|
if (Number(remaining) >= Number(threshold)) return 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-superagent",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.54",
|
|
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",
|