dsh-limit-break 1.7.0 → 1.8.1

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
@@ -5,6 +5,35 @@ All notable changes to `dsh-limit-break`. Format follows
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 1.8.1 — 2026-11-12
9
+
10
+ ### Fixed
11
+ - **Republish of the 1.8.0 change set.** `1.8.0` reached the npm registry as metadata only — its
12
+ tarball (`dsh-limit-break-1.8.0.tgz`) returns 404 on every endpoint, so it cannot be installed.
13
+ The code, tests and measurements are identical; `1.8.1` is the first installable build of the
14
+ fetch-failure memory.
15
+
16
+ ## 1.8.0 — 2026-11-12 (not installable from npm; superseded by 1.8.1)
17
+
18
+ ### Changed
19
+ - **`resilient_fetch` remembers hard failures instead of re-walking the dead ladder.** A URL whose
20
+ every rung failed is cached for ten minutes: the retry returns the recorded failure immediately
21
+ (`cached: true`, `ageMs`, `retryAfterMs`) instead of paying one timeout per rung again. Measured on
22
+ `en.wikipedia.org/robots.txt` (no alternate hostname applies) with the default 12 s per-rung
23
+ timeout: cold **34.81 s**, 3 attempts → retry **0.01 s** — **3481× faster**; at 3 s per rung,
24
+ 13.26 s → 0.02 s.
25
+ - Failure entries live in `fetch-failures.json` next to the store, **not** in `facts.json`: a
26
+ transient network blip is not durable knowledge and would pollute `memory_recall`. Reads are
27
+ lock-free, writes take the same lock as `memory_save`, expired entries are pruned on write.
28
+ - Only *hard* failures are remembered (elapsed > 2 s, or a timeout/reset/DNS-class error): a fast
29
+ 404/403 says nothing about the network, so it is never cached. A different path on the same host
30
+ still gets a real attempt, and a successful call deletes that URL's entry.
31
+ - `resilient_fetch` also returns `millis` on failure, and the failed-attempt rendering shows cached
32
+ age and retry window.
33
+ - **`tools/fetch-fail-bench.mjs`** (new): cold vs cached retry, over-blocking check (different path),
34
+ TTL-expiry check, and two healing checks (expired entry must not block a live URL; success must
35
+ delete the entry). 10/10 checks PASS.
36
+
8
37
  ## 1.7.0 — 2026-11-05
9
38
 
10
39
  ### Changed
package/MAINTAIN.md CHANGED
@@ -1,152 +1,158 @@
1
- # MAINTAIN.md — 维护与进化 runbook
2
-
3
- 这份文件是给"下一个我"看的。每轮维护从一个冷启动的会话开始,不共享上一轮的上下文;
4
- 能指望的只有三样东西:**这个仓库**、**`D:\dsh-data\home\memory\facts.json`**、**`tools/maintain.py`**。
5
-
6
- 方法沿用 2026-10-20 那两轮自测:**测极限 → 突破 → 进化插件 → 同步线上 → 记录**。
7
-
8
- ---
9
-
10
- ## 0. 开工(30 秒)
11
-
12
- ```bash
13
- cd D:/deepseek-harness/default-workspace/capability-demo/plugin/dsh-limit-break
14
- PY="C:/Users/lenovo/.dsh/dsh-runtimes/dsh-primary-runtime/dependencies/python/python.exe"
15
- $PY tools/maintain.py status # 我发布的版本在哪、PR 合没合、装的是不是 latest
16
- $PY tools/maintain.py probe # 重新测一遍环境,和上次的 baseline 做 diff
17
- $PY tools/maintain.py verify # 契约测试:5 个工具是否仍然注册成功
18
- ```
19
-
20
- 先读 `facts.json` 里 `topic` 为 `maintenance` / `release` 的条目,再看 `probe` 的
21
- `diffs_vs_previous`——**diff 就是这一轮的线索**。若是空数组,说明环境没动,
22
- 那就去 backlog 里挑一条,而不是假装有进展。
23
-
24
- ## 1. 测极限
25
-
26
- `probe` 覆盖:CPU 线程/GFLOPS、GPU 名称/显存/蒙特卡洛吞吐、nvidia-smi、CuPy 可用性、
27
- PowerPoint COM、LibreOffice Kit、5 条网络探针、磁盘余量。
28
-
29
- 读数落在 `C:\Users\lenovo\.dsh\memory\baseline-limit-break.json`,下一轮自动 diff。
30
-
31
- **不要**只跑 probe 就交差。probe 的用途是发现"世界变了"(驱动升级、被封的域名活了、
32
- CUDA 掉了、Office 卸载了),任何一项变化都可能是一个新的突破点。
33
-
34
- ## 2. 找缺口
35
-
36
- 按优先级从这几个来源取一条:
37
-
38
- 1. `probe` 的 diff(环境变了 = 新机会或新故障)
39
- 2. 用户当轮的原话(最高优先级,永远压倒自己的选题)
40
- 3. 本文件末尾的 **Backlog**
41
- 4. npm / GitHub 上别人的 issue(如果有)
42
-
43
- 一轮只做**一件**。做不完的写回 Backlog,不要开第二战线。
44
-
45
- ## 3. 突破
46
-
47
- 规则和上次一样,也是这个项目唯一值得守的规则:
48
-
49
- > 结论必须是**测出来的**,不是形容出来的。
50
-
51
- - 能做就写脚本,用数字说话(秒、字节、比率、像素差、样本/秒)
52
- - 做不到也写下来:**缺什么**(缺编译器?缺凭据?缺物理接口?),以及**试过什么**
53
- - 失败要留在 Backlog 里,注明失败原因;下一轮不要重复同一个死胡同
54
-
55
- ## 4. 进化
56
-
57
- 改代码 → 跑 `verify` → 语义化版本:
58
-
59
- | 改动 | 版本 |
60
- | --- | --- |
61
- | 新工具 / 不兼容改动 | minor(1.x.0) |
62
- | 修 bug、改默认值、加参数 | patch(1.0.x) |
63
-
64
- 同步两处副本(**仓库里的**才是源头):
65
-
66
- ```
67
- capability-demo/plugin/dsh-limit-break/ <- 改这里
68
- D:\dsh-data\home\profiles\desktop\node_modules\dsh-limit-break\ <- 复制到这里才生效
69
- ```
70
-
71
- 只需重启 DSH 应用才加载新代码;**不要**替用户重启 GUI,告诉他自己重启。
72
-
73
- ## 5. 同步线上
74
-
75
- ```bash
76
- # npm(先看 http 状态,409 是 staged publishing 残留,解法:把 latest 指走再发)
77
- export PATH="/c/Users/lenovo/AppData/Local/nodejs:$PATH"
78
- npm publish --no-fund --no-audit
79
- npm view dsh-limit-break version dist-tags
80
-
81
- # git(这台机器到 GitHub 会间歇性 Recv failure,重试 3 次再判断)
82
- git add -A && git commit -m "..." && git push
83
- ```
84
-
85
- 市场目录(awesome-dsh-plugin)**不是自动同步的**:条目文件合并后才出现在市场里。
86
- - 列表没上线时,先看 PR 状态;不要重复提同一个 PR
87
- - 版本升级不需要重提条目(条目只指向仓库 URL),只有换包名/换分类才需要
88
-
89
- ## 6. 记录
90
-
91
- - `facts.json` 追加/更新 1–3 条,`topic` 用 `maintenance` 或 `release`
92
- - 更新 `CHANGELOG.md` 的 `Unreleased`
93
- - `baseline-limit-break.json` 由 probe 自动覆盖,不用手改
94
-
95
- ---
96
-
97
- ## 每轮的完成标准(DoD)
98
-
99
- 一轮算做完,必须同时满足:
100
-
101
- 1. `status` 里 `problems` 数组的每一条,要么被修掉,要么被解释成"不在我控制内"
102
- 2. 有一句可以用数字反驳的话("X 从 A 变成 B")
103
- 3. 代码有改动 → 版本升了 + `verify` PASS + npm 上是新版本
104
- 4. 没有代码改动 → `CHANGELOG.md` 记一条"本轮无发布,原因:…"
105
- 5. 有失败 → Backlog 里有一行带原因的记录
106
-
107
- **最差的结果不是失败,是一轮结束后什么都没变、也没写下来。**
108
-
109
- ---
110
-
111
- ## Backlog(按 2026-10-22 20:10 的真实状态)
112
-
113
- - [x] **1.5.0 已上线**(2026-10-22T12:20:22Z):npm `latest` = `1.5.0`(用户 OTP 发布),GitHub
114
- `origin/main` = `cd5f409`(github.com:443 被掐,改用 api.github.com + GraphQL 推送),
115
- desktop profile 已从 1.2.1 升到 **1.5.0**,`verify` PASS。四工具 ABI 未变,老会话不会 brick。
116
- - [ ] 基准里剩下的 miss(“monte carlo pi benchmark on the CPU”)是 `bench.cpu_suite` 与
117
- `bench.gpu_monte_carlo` 的真实歧义;再往上做要引入上下文/近义词表,性价比低,当作已知上限。
118
- - [x] desktop profile 版本漂移已消(1.2.1 → 1.5.0)。以后每次发布都跟一条
119
- `dsh.cmd plugin --profile desktop add dsh-limit-break@<version>`。
120
-
121
- - [x] **1.2.0 已上线**(2026-10-20T12:02:52Z):npm `latest` = `1.2.0`,GitHub `origin/main` =
122
- `fd844a4`,`verify` PASS,`test_plugin.mjs` 6/6 PASS。用户 20:04 完成了 OTP 发布和推送。
123
- `env.node_npm` 与 `release.dsh-limit-break` 两条事实已回写。
124
- - [x] 旧定时任务 `schedule-803cdbdc`(会话 5133bee1)已由用户在面板删除;`storages/schedule.json`
125
- 里只剩 `schedule-0b6c60ea`(hello world)和新的 `schedule-b3675d28`。无需再处理。
126
- - [x] 市场条目**已合并上线**(2026-10-22 之后):`awesome-dsh-plugin/awesome-dsh-plugin#8296`
127
- merged,条目文件 `data/plugins/Ma354__dsh-limit-break.yml`(category: memory);
128
- 2026-10-27 01:06 的 `#9282`(加 storefront icon,`assets/icon-180.png`)也已 merged。
129
- `maintain.py status` 现在 `listed_in_market: true`、`problems: []`。不要再提新 PR。
130
- - [ ] 本地仓库落后远端:本地 `94eafb7`,远端 `b84161a`(用户 10-25 推了 icon 等);
131
- `github.com:443` 被掐,`git fetch` 连试 3 次全失败。等网络恢复后跑
132
- `git fetch origin && git reset --hard origin/main`。在此之前文档改动走
133
- `..\_maintain\ghpush.mjs`(GraphQL,按远端 head 建提交,内容全量替换,不受分叉影响)。
134
- - [ ] npm 上还挂着占位包 `0.0.0-stage`(`stub: true`)。`npm deprecate` 也要 OTP(本轮 EOTP 失败);
135
- 用户一条命令即可:`npm deprecate dsh-limit-break@0.0.0-stage "placeholder - use 1.2.0"`。
136
- - [ ] `1.0.0` 是无元数据的旧包体(author/repository 都不在)。同样一条 `npm deprecate` 可清掉噪音(需 OTP)。
137
- - [x] `facts.json` 的 `env.gpu` 已改写成“GPU compute throughput is recorded separately in
138
- bench.gpu_monte_carlo and bench.render”(2026-10-21 的回写),陈旧描述不再存在。
139
- - [x] 插件工具对**已经打开的会话**不可见:已在 README「Known limits」第 1 条写明
140
- (tool list 是 per-session 快照,插件侧修不了)。事实 `harness.plugin-tool-visibility` 有实测。
141
- - [x] **`resilient_fetch` 会把成功路径写回记忆库**(1.7.0,2026-11-05):非 direct 成功写成
142
- `network.route.<host>`(14 天 TTL,走 `memory_save` 同一把锁),下次同主机直接从该级起步;
143
- direct 恢复后删掉路由(自愈)。实测 `en.wikipedia.org/wiki/Monte_Carlo_method`、12 s 超时:
144
- cold 12.11 s(`direct>alternate-host`)→ warm 1.08 s / 1.14 s(单次 `alternate-host`),11.2×。
145
- 跑 `node tools/fetch-route-bench.mjs <url> <timeoutMs>` 复测(约 15 s,6 项检查)。
146
- 仍可继续加:`--resolve` 到已知 IP、IPv6 优先(backlog)。
147
- - [ ] `maintain.py status` 的 `problems` 里 `market listing not live yet (PR #8296 closed)` 是误报:
148
- 同一份输出里 `listed_in_market: true`。原因未查,先记为已知噪音,别当成回归。
149
- - [x] **`memory_save` 的并发写已有自动化覆盖**(1.6.0,2026-10-29):`tools/concurrency-selftest.mjs`
150
- 起 N 个独立进程同时写同一个 store,再读回数存活条数,另测“陈旧锁被接管”。同机 8 进程 × 6 次 × 3 轮:
151
- 修复前丢 16–17/48、且最多 25/48 直接 `EPERM`(rename 输家);加 `O_EXCL` 锁后 0 丢 0 失败,
152
- 12 × 5 × 4 = 240 次同样全存活。改了 `memory_save` 的写入路径就跑一遍它(约 20 s)。
1
+ # MAINTAIN.md — 维护与进化 runbook
2
+
3
+ 这份文件是给"下一个我"看的。每轮维护从一个冷启动的会话开始,不共享上一轮的上下文;
4
+ 能指望的只有三样东西:**这个仓库**、**`D:\dsh-data\home\memory\facts.json`**、**`tools/maintain.py`**。
5
+
6
+ 方法沿用 2026-10-20 那两轮自测:**测极限 → 突破 → 进化插件 → 同步线上 → 记录**。
7
+
8
+ ---
9
+
10
+ ## 0. 开工(30 秒)
11
+
12
+ ```bash
13
+ cd D:/deepseek-harness/default-workspace/capability-demo/plugin/dsh-limit-break
14
+ PY="C:/Users/lenovo/.dsh/dsh-runtimes/dsh-primary-runtime/dependencies/python/python.exe"
15
+ $PY tools/maintain.py status # 我发布的版本在哪、PR 合没合、装的是不是 latest
16
+ $PY tools/maintain.py probe # 重新测一遍环境,和上次的 baseline 做 diff
17
+ $PY tools/maintain.py verify # 契约测试:5 个工具是否仍然注册成功
18
+ ```
19
+
20
+ 先读 `facts.json` 里 `topic` 为 `maintenance` / `release` 的条目,再看 `probe` 的
21
+ `diffs_vs_previous`——**diff 就是这一轮的线索**。若是空数组,说明环境没动,
22
+ 那就去 backlog 里挑一条,而不是假装有进展。
23
+
24
+ ## 1. 测极限
25
+
26
+ `probe` 覆盖:CPU 线程/GFLOPS、GPU 名称/显存/蒙特卡洛吞吐、nvidia-smi、CuPy 可用性、
27
+ PowerPoint COM、LibreOffice Kit、5 条网络探针、磁盘余量。
28
+
29
+ 读数落在 `C:\Users\lenovo\.dsh\memory\baseline-limit-break.json`,下一轮自动 diff。
30
+
31
+ **不要**只跑 probe 就交差。probe 的用途是发现"世界变了"(驱动升级、被封的域名活了、
32
+ CUDA 掉了、Office 卸载了),任何一项变化都可能是一个新的突破点。
33
+
34
+ ## 2. 找缺口
35
+
36
+ 按优先级从这几个来源取一条:
37
+
38
+ 1. `probe` 的 diff(环境变了 = 新机会或新故障)
39
+ 2. 用户当轮的原话(最高优先级,永远压倒自己的选题)
40
+ 3. 本文件末尾的 **Backlog**
41
+ 4. npm / GitHub 上别人的 issue(如果有)
42
+
43
+ 一轮只做**一件**。做不完的写回 Backlog,不要开第二战线。
44
+
45
+ ## 3. 突破
46
+
47
+ 规则和上次一样,也是这个项目唯一值得守的规则:
48
+
49
+ > 结论必须是**测出来的**,不是形容出来的。
50
+
51
+ - 能做就写脚本,用数字说话(秒、字节、比率、像素差、样本/秒)
52
+ - 做不到也写下来:**缺什么**(缺编译器?缺凭据?缺物理接口?),以及**试过什么**
53
+ - 失败要留在 Backlog 里,注明失败原因;下一轮不要重复同一个死胡同
54
+
55
+ ## 4. 进化
56
+
57
+ 改代码 → 跑 `verify` → 语义化版本:
58
+
59
+ | 改动 | 版本 |
60
+ | --- | --- |
61
+ | 新工具 / 不兼容改动 | minor(1.x.0) |
62
+ | 修 bug、改默认值、加参数 | patch(1.0.x) |
63
+
64
+ 同步两处副本(**仓库里的**才是源头):
65
+
66
+ ```
67
+ capability-demo/plugin/dsh-limit-break/ <- 改这里
68
+ D:\dsh-data\home\profiles\desktop\node_modules\dsh-limit-break\ <- 复制到这里才生效
69
+ ```
70
+
71
+ 只需重启 DSH 应用才加载新代码;**不要**替用户重启 GUI,告诉他自己重启。
72
+
73
+ ## 5. 同步线上
74
+
75
+ ```bash
76
+ # npm(先看 http 状态,409 是 staged publishing 残留,解法:把 latest 指走再发)
77
+ export PATH="/c/Users/lenovo/AppData/Local/nodejs:$PATH"
78
+ npm publish --no-fund --no-audit
79
+ npm view dsh-limit-break version dist-tags
80
+
81
+ # git(这台机器到 GitHub 会间歇性 Recv failure,重试 3 次再判断)
82
+ git add -A && git commit -m "..." && git push
83
+ ```
84
+
85
+ 市场目录(awesome-dsh-plugin)**不是自动同步的**:条目文件合并后才出现在市场里。
86
+ - 列表没上线时,先看 PR 状态;不要重复提同一个 PR
87
+ - 版本升级不需要重提条目(条目只指向仓库 URL),只有换包名/换分类才需要
88
+
89
+ ## 6. 记录
90
+
91
+ - `facts.json` 追加/更新 1–3 条,`topic` 用 `maintenance` 或 `release`
92
+ - 更新 `CHANGELOG.md` 的 `Unreleased`
93
+ - `baseline-limit-break.json` 由 probe 自动覆盖,不用手改
94
+
95
+ ---
96
+
97
+ ## 每轮的完成标准(DoD)
98
+
99
+ 一轮算做完,必须同时满足:
100
+
101
+ 1. `status` 里 `problems` 数组的每一条,要么被修掉,要么被解释成"不在我控制内"
102
+ 2. 有一句可以用数字反驳的话("X 从 A 变成 B")
103
+ 3. 代码有改动 → 版本升了 + `verify` PASS + npm 上是新版本
104
+ 4. 没有代码改动 → `CHANGELOG.md` 记一条"本轮无发布,原因:…"
105
+ 5. 有失败 → Backlog 里有一行带原因的记录
106
+
107
+ **最差的结果不是失败,是一轮结束后什么都没变、也没写下来。**
108
+
109
+ ---
110
+
111
+ ## Backlog(按 2026-10-22 20:10 的真实状态)
112
+
113
+ - [x] **1.5.0 已上线**(2026-10-22T12:20:22Z):npm `latest` = `1.5.0`(用户 OTP 发布),GitHub
114
+ `origin/main` = `cd5f409`(github.com:443 被掐,改用 api.github.com + GraphQL 推送),
115
+ desktop profile 已从 1.2.1 升到 **1.5.0**,`verify` PASS。四工具 ABI 未变,老会话不会 brick。
116
+ - [ ] 基准里剩下的 miss(“monte carlo pi benchmark on the CPU”)是 `bench.cpu_suite` 与
117
+ `bench.gpu_monte_carlo` 的真实歧义;再往上做要引入上下文/近义词表,性价比低,当作已知上限。
118
+ - [x] desktop profile 版本漂移已消(1.2.1 → 1.5.0)。以后每次发布都跟一条
119
+ `dsh.cmd plugin --profile desktop add dsh-limit-break@<version>`。
120
+
121
+ - [x] **1.2.0 已上线**(2026-10-20T12:02:52Z):npm `latest` = `1.2.0`,GitHub `origin/main` =
122
+ `fd844a4`,`verify` PASS,`test_plugin.mjs` 6/6 PASS。用户 20:04 完成了 OTP 发布和推送。
123
+ `env.node_npm` 与 `release.dsh-limit-break` 两条事实已回写。
124
+ - [x] 旧定时任务 `schedule-803cdbdc`(会话 5133bee1)已由用户在面板删除;`storages/schedule.json`
125
+ 里只剩 `schedule-0b6c60ea`(hello world)和新的 `schedule-b3675d28`。无需再处理。
126
+ - [x] 市场条目**已合并上线**(2026-10-22 之后):`awesome-dsh-plugin/awesome-dsh-plugin#8296`
127
+ merged,条目文件 `data/plugins/Ma354__dsh-limit-break.yml`(category: memory);
128
+ 2026-10-27 01:06 的 `#9282`(加 storefront icon,`assets/icon-180.png`)也已 merged。
129
+ `maintain.py status` 现在 `listed_in_market: true`、`problems: []`。不要再提新 PR。
130
+ - [ ] 本地仓库落后远端:本地 `94eafb7`,远端 `b84161a`(用户 10-25 推了 icon 等);
131
+ `github.com:443` 被掐,`git fetch` 连试 3 次全失败。等网络恢复后跑
132
+ `git fetch origin && git reset --hard origin/main`。在此之前文档改动走
133
+ `..\_maintain\ghpush.mjs`(GraphQL,按远端 head 建提交,内容全量替换,不受分叉影响)。
134
+ - [ ] npm 上还挂着占位包 `0.0.0-stage`(`stub: true`)。`npm deprecate` 也要 OTP(本轮 EOTP 失败);
135
+ 用户一条命令即可:`npm deprecate dsh-limit-break@0.0.0-stage "placeholder - use 1.2.0"`。
136
+ - [ ] `1.0.0` 是无元数据的旧包体(author/repository 都不在)。同样一条 `npm deprecate` 可清掉噪音(需 OTP)。
137
+ - [x] `facts.json` 的 `env.gpu` 已改写成“GPU compute throughput is recorded separately in
138
+ bench.gpu_monte_carlo and bench.render”(2026-10-21 的回写),陈旧描述不再存在。
139
+ - [x] 插件工具对**已经打开的会话**不可见:已在 README「Known limits」第 1 条写明
140
+ (tool list 是 per-session 快照,插件侧修不了)。事实 `harness.plugin-tool-visibility` 有实测。
141
+ - [x] **`resilient_fetch` 会把成功路径写回记忆库**(1.7.0,2026-11-05):非 direct 成功写成
142
+ `network.route.<host>`(14 天 TTL,走 `memory_save` 同一把锁),下次同主机直接从该级起步;
143
+ direct 恢复后删掉路由(自愈)。实测 `en.wikipedia.org/wiki/Monte_Carlo_method`、12 s 超时:
144
+ cold 12.11 s(`direct>alternate-host`)→ warm 1.08 s / 1.14 s(单次 `alternate-host`),11.2×。
145
+ 跑 `node tools/fetch-route-bench.mjs <url> <timeoutMs>` 复测(约 15 s,6 项检查)。
146
+ 仍可继续加:`--resolve` 到已知 IP、IPv6 优先(backlog)。
147
+ - [x] **`resilient_fetch` 的“三级全失败”每次重撞一遍**(1.8.0,2026-11-12):同 URL 硬失败记
148
+ `fetch-failures.json`(10 分钟 TTL、走同一把锁、只记耗时 >2 s 或 timeout/reset 类失败),
149
+ 重试直接返回缓存。实测 `en.wikipedia.org/robots.txt`、默认 12 s/级:cold 34.81 s(3 次尝试)
150
+ → 重试 0.01 s(`retryAfterMs` 给出剩余时间),3481×。跑
151
+ `node tools/fetch-fail-bench.mjs <url>` 复测(约 40 s,10 项检查)。
152
+ 仍可继续加:失败计数退避(第 2 次 10 分钟、第 3 次 1 小时)、`--resolve` 到已知 IP、IPv6 优先。
153
+ - [ ] `maintain.py status` 的 `problems` 里 `market listing not live yet (PR #8296 closed)` 是误报:
154
+ 同一份输出里 `listed_in_market: true`。原因未查,先记为已知噪音,别当成回归。
155
+ - [x] **`memory_save` 的并发写已有自动化覆盖**(1.6.0,2026-10-29):`tools/concurrency-selftest.mjs`
156
+ 起 N 个独立进程同时写同一个 store,再读回数存活条数,另测“陈旧锁被接管”。同机 8 进程 × 6 次 × 3 轮:
157
+ 修复前丢 16–17/48、且最多 25/48 直接 `EPERM`(rename 输家);加 `O_EXCL` 锁后 0 丢 0 失败,
158
+ 12 × 5 × 4 = 240 次同样全存活。改了 `memory_save` 的写入路径就跑一遍它(约 20 s)。
package/README.md CHANGED
@@ -49,6 +49,15 @@ self-heals). Measured on `en.wikipedia.org/wiki/Monte_Carlo_method`, 12 s per-ru
49
49
  **12.1 s** (rung 1 burned the timeout, rung 4 answered) → warm **1.08 s / 1.14 s**, one attempt
50
50
  instead of two — **11.2× faster**. Numbers come from `tools/fetch-route-bench.mjs`.
51
51
 
52
+ **The ladder remembers failures too.** A URL whose every rung died is not retried for ten minutes: the
53
+ same call returns the recorded failure in milliseconds instead of burning another timeout per rung.
54
+ Measured on `en.wikipedia.org/robots.txt` (no alternate hostname applies there), default 12 s per
55
+ rung: cold **34.81 s** (3 dead rungs) → retry **0.01 s** (cached, `retryAfterMs` tells you when) —
56
+ **3481× faster**. Only *slow* failures are remembered (a fast 404/403 is not a network verdict), the
57
+ entry lives in a sidecar next to the store rather than `facts.json` (a transient blip is not durable
58
+ knowledge), a different path on the same host still gets a real attempt, and the entry is deleted as
59
+ soon as the URL answers. Numbers come from `tools/fetch-fail-bench.mjs`.
60
+
52
61
  ## Install
53
62
 
54
63
  ```sh
@@ -108,6 +117,10 @@ Measured, not guessed — each line is something a session actually hit.
108
117
  * **A remembered route is a bet with a 14-day expiry.** The ladder trusts `network.route.<host>` for
109
118
  two weeks and drops it as soon as a direct request works; if the winning rung starts failing the
110
119
  call still walks the rest of the ladder, it just pays that one rung first.
120
+ * **A remembered failure blinds that one URL for ten minutes.** If a host recovers faster than that,
121
+ the exact URL still reports the cached failure (with `retryAfterMs`) until the entry expires — the
122
+ deliberate trade for not paying ~35 s on every retry of a dead URL. A different path on the same
123
+ host, or a different host, is still attempted normally.
111
124
  * **`memory_recall` ranks by keyword overlap only** (id/topic/tags/statement/details), no
112
125
  embeddings: stopword-filtered, crudely stemmed word matching weighted by idf, so it is good at
113
126
  "which fact did I mean" and bad at paraphrase. `tools/recall-bench.mjs` states the current
package/lib/index.js CHANGED
@@ -291,6 +291,76 @@ async function dropRoute(dir, host) {
291
291
  })
292
292
  }
293
293
 
294
+ // A URL that just failed every rung will fail the same way ten seconds later, but the ladder
295
+ // still pays a full timeout per rung (~36 s at the default 12 s). Hard failures are therefore
296
+ // remembered for ten minutes in a sidecar next to the store — deliberately *not* in facts.json:
297
+ // a transient network failure is not durable knowledge and would pollute memory_recall.
298
+ const FAIL_TTL_MS = 10 * 60 * 1000
299
+ const FAIL_FILE = 'fetch-failures.json'
300
+
301
+ function urlKey(url) {
302
+ return String(url)
303
+ .replace(/#.*$/, '')
304
+ .replace(/[^a-zA-Z0-9]+/g, '-')
305
+ .replace(/^-|-$/g, '')
306
+ .slice(0, 120)
307
+ }
308
+
309
+ async function readFailures(dir) {
310
+ try {
311
+ const doc = JSON.parse(await readFile(join(dir, FAIL_FILE), 'utf8'))
312
+ return doc && typeof doc === 'object' && doc.failures && typeof doc.failures === 'object' ? doc.failures : {}
313
+ } catch {
314
+ return {}
315
+ }
316
+ }
317
+
318
+ function freshFailure(entries, url) {
319
+ const entry = entries && entries[urlKey(url)]
320
+ if (!entry || entry.url !== url) return null
321
+ const at = Date.parse(String(entry.lastFailedAt || ''))
322
+ if (!Number.isFinite(at)) return null
323
+ const age = Date.now() - at
324
+ if (age > FAIL_TTL_MS) return null
325
+ return { entry, ageMs: age, retryAfterMs: FAIL_TTL_MS - age }
326
+ }
327
+
328
+ async function writeFailure(dir, url, info) {
329
+ const now = new Date().toISOString()
330
+ return withStoreLock(dir, async () => {
331
+ const entries = await readFailures(dir)
332
+ const key = urlKey(url)
333
+ const before = entries[key] && Date.parse(String(entries[key].lastFailedAt || '')) > Date.now() - FAIL_TTL_MS ? Number(entries[key].count) || 0 : 0
334
+ entries[key] = {
335
+ url,
336
+ host: info.host || '',
337
+ lastFailedAt: now,
338
+ count: before + 1,
339
+ millis: info.millis || null,
340
+ attempts: Array.isArray(info.attempts) ? info.attempts.slice(0, 8) : []
341
+ }
342
+ const kept = {}
343
+ for (const [k, v] of Object.entries(entries)) {
344
+ const at = Date.parse(String(v && v.lastFailedAt))
345
+ if (Number.isFinite(at) && Date.now() - at <= FAIL_TTL_MS) kept[k] = v
346
+ }
347
+ const trimmed = Object.entries(kept).slice(-50)
348
+ await writeFile(join(dir, FAIL_FILE), JSON.stringify({ updated_at: now, failures: Object.fromEntries(trimmed) }, null, 2))
349
+ return entries[key]
350
+ })
351
+ }
352
+
353
+ async function dropFailure(dir, url) {
354
+ return withStoreLock(dir, async () => {
355
+ const entries = await readFailures(dir)
356
+ const key = urlKey(url)
357
+ if (!entries[key]) return false
358
+ delete entries[key]
359
+ await writeFile(join(dir, FAIL_FILE), JSON.stringify({ updated_at: new Date().toISOString(), failures: entries }, null, 2))
360
+ return true
361
+ })
362
+ }
363
+
294
364
  // Ranking inputs. The old scorer used raw substring counts, which let a common word
295
365
  // ("the", "how", "long") outvote the one rare word that identifies the fact. Words are
296
366
  // matched against word sets instead, suffixed words share a stem, and each query token is
@@ -713,7 +783,7 @@ export function apply(ctx, config) {
713
783
  ctx.tools.register({
714
784
  name: 'resilient_fetch',
715
785
  description:
716
- 'Fetch a URL through a 4-step ladder for hosts whose block is keyed on the TLS hostname (SNI) rather than the IP: plain fetch -> IPv6 -> IPv4 -> a same-service alternate hostname. A host that only answered on a later rung is remembered in the memory store for two weeks and the next call starts at that rung. Use when web_fetch or a plain request fails with a timeout, a connection reset, or "resolves to a non-public IP", and you still need the content.',
786
+ 'Fetch a URL through a 4-step ladder for hosts whose block is keyed on the TLS hostname (SNI) rather than the IP: plain fetch -> IPv6 -> IPv4 -> a same-service alternate hostname. A host that only answered on a later rung is remembered in the memory store for two weeks and the next call starts at that rung; a URL that just failed every rung is remembered for ten minutes, so an immediate retry returns the same failure instantly instead of paying the timeouts again. Use when web_fetch or a plain request fails with a timeout, a connection reset, or "resolves to a non-public IP", and you still need the content.',
717
787
  parameters: {
718
788
  type: 'object',
719
789
  properties: {
@@ -728,7 +798,7 @@ export function apply(ctx, config) {
728
798
  render: (_args, value) =>
729
799
  value && value.ok
730
800
  ? [{ type: 'text', text: `HTTP ${value.status} via ${value.via} in ${(Number(value.millis) / 1000).toFixed(1)}s [route ${value.route}] (${value.bytes} bytes)\n${String(value.text || '').slice(0, 400)}` }]
731
- : [{ type: 'text', text: `All attempts failed: ${(value && value.attempts ? value.attempts : []).map((a) => `${a.via}=${a.error || a.status}`).join(' | ')}` }]
801
+ : [{ type: 'text', text: `All attempts failed${value && value.cached ? ` (cached ${Math.round(Number(value.ageMs) / 1000)}s ago; retry in ${Math.ceil(Number(value.retryAfterMs) / 60000)} min)` : ''}: ${(value && value.attempts ? value.attempts : []).map((a) => `${a.via}=${a.error || a.status}`).join(' | ')}` }]
732
802
  },
733
803
  presentCall: (args) => ({
734
804
  card: 'generic',
@@ -747,6 +817,20 @@ export function apply(ctx, config) {
747
817
  return { ok: false, code: 'fetch.invalid', attempts: [], message: 'url is not a valid absolute URL' }
748
818
  }
749
819
  const per = Math.max(2000, Number(input.timeoutMs) || timeoutMs)
820
+ const failures = await readFailures(storeDir).catch(() => ({}))
821
+ const prior = freshFailure(failures, url)
822
+ if (prior) {
823
+ return {
824
+ ok: false,
825
+ code: 'fetch.failed',
826
+ cached: true,
827
+ requested: url,
828
+ cachedAt: prior.entry.lastFailedAt,
829
+ ageMs: prior.ageMs,
830
+ retryAfterMs: prior.retryAfterMs,
831
+ attempts: Array.isArray(prior.entry.attempts) ? prior.entry.attempts : []
832
+ }
833
+ }
750
834
  const cached = await readRoute(storeDir, host).catch(() => null)
751
835
  let targets = [{ url, via: 'direct' }, ...alternatesFor(url).map((u) => ({ url: u, via: 'alternate-host' }))]
752
836
  if (shellFallback) {
@@ -779,6 +863,9 @@ export function apply(ctx, config) {
779
863
  } catch {
780
864
  route = 'unwritten'
781
865
  }
866
+ if (failures[urlKey(url)]) {
867
+ await dropFailure(storeDir, url).catch(() => {})
868
+ }
782
869
  return {
783
870
  ok: true,
784
871
  status: result.status,
@@ -798,7 +885,14 @@ export function apply(ctx, config) {
798
885
  attempts.push({ via: target.via, url: target.url, error: String((error && error.message) || error).slice(0, 300) })
799
886
  }
800
887
  }
801
- return { ok: false, code: 'fetch.failed', requested: url, cached_via: cached ? cached.via : null, attempts }
888
+ const elapsed = Date.now() - startedAt
889
+ // Only "hard" failures are worth remembering: a fast 404/403 says nothing about the
890
+ // network, and caching it would hide a real fix (or a different path) for ten minutes.
891
+ const hard =
892
+ elapsed > 2000 ||
893
+ attempts.some((a) => /timeout|aborted|reset|ECONN|ETIMEDOUT|EPIPE|EHOSTUNREACH|ENETUNREACH|EAI_AGAIN/i.test(String(a.error || '')))
894
+ if (hard) await writeFailure(storeDir, url, { host, millis: elapsed, attempts }).catch(() => {})
895
+ return { ok: false, code: 'fetch.failed', requested: url, cached: false, millis: elapsed, cached_via: cached ? cached.via : null, attempts }
802
896
  }
803
897
  }),
804
898
  'limit-break: resilient_fetch tool'
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
- {
2
- "name": "dsh-limit-break",
3
- "version": "1.7.0",
4
- "description": "Durable cross-session memory and a fetch ladder that survives hostname-keyed blocking — four small tools for DeepSeek Harness.",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "exports": {
8
- ".": "./lib/index.js",
9
- "./package.json": "./package.json"
10
- },
11
- "files": [
12
- "lib/",
13
- "cordis.patch.yml",
14
- "README.md",
15
- "LICENSE",
16
- "tools/",
17
- "MAINTAIN.md",
18
- "CHANGELOG.md"
19
- ],
20
- "keywords": [
21
- "deepseek",
22
- "deepseek-harness",
23
- "dsh",
24
- "dsh-plugin",
25
- "memory",
26
- "long-term-memory",
27
- "fetch",
28
- "network"
29
- ],
30
- "engines": {
31
- "node": ">=22.6"
32
- },
33
- "license": "MIT",
34
- "author": {
35
- "name": "mapingyue",
36
- "email": "2067984403@qq.com"
37
- },
38
- "repository": {
39
- "type": "git",
40
- "url": "git+https://github.com/Ma354/dsh-limit-break.git"
41
- },
42
- "homepage": "https://github.com/Ma354/dsh-limit-break#readme",
43
- "bugs": {
44
- "url": "https://github.com/Ma354/dsh-limit-break/issues"
45
- },
46
- "dsh": {
47
- "bundle": {
48
- "patch": "./cordis.patch.yml"
49
- }
50
- }
51
- }
1
+ {
2
+ "name": "dsh-limit-break",
3
+ "version": "1.8.1",
4
+ "description": "Durable cross-session memory and a fetch ladder that survives hostname-keyed blocking — four small tools for DeepSeek Harness.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./package.json": "./package.json"
10
+ },
11
+ "files": [
12
+ "lib/",
13
+ "cordis.patch.yml",
14
+ "README.md",
15
+ "LICENSE",
16
+ "tools/",
17
+ "MAINTAIN.md",
18
+ "CHANGELOG.md"
19
+ ],
20
+ "keywords": [
21
+ "deepseek",
22
+ "deepseek-harness",
23
+ "dsh",
24
+ "dsh-plugin",
25
+ "memory",
26
+ "long-term-memory",
27
+ "fetch",
28
+ "network"
29
+ ],
30
+ "engines": {
31
+ "node": ">=22.6"
32
+ },
33
+ "license": "MIT",
34
+ "author": {
35
+ "name": "mapingyue",
36
+ "email": "2067984403@qq.com"
37
+ },
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/Ma354/dsh-limit-break.git"
41
+ },
42
+ "homepage": "https://github.com/Ma354/dsh-limit-break#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/Ma354/dsh-limit-break/issues"
45
+ },
46
+ "dsh": {
47
+ "bundle": {
48
+ "patch": "./cordis.patch.yml"
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Benchmark: does remembering a hard failure actually save the ladder?
3
+ *
4
+ * A blocked host costs one timeout per rung (~3 s per rung at timeoutMs=3000). Before 1.8.0 a
5
+ * second call to the same dead URL paid that again in full; now it should come back in ~0 ms
6
+ * from the ten-minute failure memory, while a *different* URL on the same host still gets a real
7
+ * attempt (no over-blocking), and an expired entry stops short-circuiting.
8
+ *
9
+ * Usage: node tools/fetch-fail-bench.mjs [url]
10
+ */
11
+ import { apply } from '../lib/index.js'
12
+ import { mkdtemp, readFile, writeFile, rm } from 'node:fs/promises'
13
+ import { tmpdir } from 'node:os'
14
+ import { join } from 'node:path'
15
+
16
+ const URL_DEAD = process.argv[2] || 'https://en.wikipedia.org/robots.txt'
17
+ const PER = 3000
18
+
19
+ function register(dir) {
20
+ const tools = new Map()
21
+ const ctx = {
22
+ effect(fn) {
23
+ fn()
24
+ },
25
+ tools: {
26
+ register(def) {
27
+ tools.set(def.name, def)
28
+ return () => tools.delete(def.name)
29
+ }
30
+ }
31
+ }
32
+ apply(ctx, { storeDir: dir })
33
+ return tools
34
+ }
35
+
36
+ async function timed(tool, url) {
37
+ const t0 = Date.now()
38
+ const res = await tool.execute({ url, timeoutMs: PER })
39
+ return { res, seconds: (Date.now() - t0) / 1000 }
40
+ }
41
+
42
+ const dir = await mkdtemp(join(tmpdir(), 'dsh-fail-bench-'))
43
+ const tools = register(dir)
44
+ const tool = tools.get('resilient_fetch')
45
+ if (!tool) throw new Error('resilient_fetch was not registered')
46
+
47
+ const first = await timed(tool, URL_DEAD)
48
+ const second = await timed(tool, URL_DEAD)
49
+
50
+ const sidecar = JSON.parse(await readFile(join(dir, 'fetch-failures.json'), 'utf8').catch(() => '{"failures":{}}'))
51
+ const entries = Object.values(sidecar.failures || {})
52
+
53
+ const other = await timed(tool, URL_DEAD.replace(/[^/]+$/, 'index.html'))
54
+
55
+ // Expire the entry by hand: an old failure must not keep short-circuiting.
56
+ if (entries.length) {
57
+ const key = Object.keys(sidecar.failures)[0]
58
+ sidecar.failures[key].lastFailedAt = new Date(Date.now() - 11 * 60 * 1000).toISOString()
59
+ await writeFile(join(dir, 'fetch-failures.json'), JSON.stringify(sidecar, null, 2))
60
+ }
61
+ const expired = await timed(tool, URL_DEAD)
62
+
63
+ // 10 minutes of blindness is the designed cost of the cache, so the cached reply has to say when
64
+ // to retry. Separately: an *expired* entry must be cleaned up when the URL finally answers, so
65
+ // the sidecar does not accumulate dead entries for hosts that came back.
66
+ import { createServer } from 'node:http'
67
+ const server = createServer((_req, res) => {
68
+ res.writeHead(200, { 'content-type': 'text/plain' })
69
+ res.end('ok')
70
+ })
71
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
72
+ const liveUrl = `http://127.0.0.1:${server.address().port}/ok`
73
+ const keyOf = (u) => String(u).replace(/#.*$/, '').replace(/[^a-zA-Z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 120)
74
+ const planted = JSON.parse(await readFile(join(dir, 'fetch-failures.json'), 'utf8').catch(() => '{"failures":{}}'))
75
+ planted.failures[keyOf(liveUrl)] = {
76
+ url: liveUrl,
77
+ host: '127.0.0.1',
78
+ lastFailedAt: new Date(Date.now() - 11 * 60 * 1000).toISOString(),
79
+ count: 1,
80
+ millis: 9000,
81
+ attempts: []
82
+ }
83
+ await writeFile(join(dir, 'fetch-failures.json'), JSON.stringify(planted, null, 2))
84
+ const healed = await timed(tool, liveUrl)
85
+ const afterHeal = JSON.parse(await readFile(join(dir, 'fetch-failures.json'), 'utf8').catch(() => '{"failures":{}}'))
86
+ server.close()
87
+
88
+ const rows = [
89
+ ['first call (cold, really walks the ladder)', first.seconds, first.res.cached === true ? 'CACHED?!' : `${first.res.attempts.length} attempts`],
90
+ ['second call, same URL', second.seconds, second.res.cached ? 'cached failure' : 'NOT CACHED'],
91
+ ['different path, same host', other.seconds, other.res.cached ? 'CACHED (over-blocking!)' : `${other.res.attempts.length} attempts`],
92
+ ['same URL after the 10 min TTL', expired.seconds, expired.res.cached ? 'STILL CACHED' : `${expired.res.attempts.length} attempts`],
93
+ ['expired entry, host works again', healed.seconds, healed.res.ok ? `ok via ${healed.res.via}` : 'FAILED']
94
+ ]
95
+ console.log('url:', URL_DEAD, 'timeoutMs:', PER)
96
+ for (const [label, seconds, note] of rows) console.log(` ${label.padEnd(44)} ${seconds.toFixed(2).padStart(7)}s ${note}`)
97
+
98
+ const saved = first.seconds - second.seconds
99
+ const checks = [
100
+ ['failure recorded in sidecar', entries.length === 1],
101
+ ['first call really failed hard', first.res.ok === false && first.seconds > 2],
102
+ ['second call served from memory', second.res.cached === true && second.seconds < 0.5],
103
+ ['second call saves the ladder time', second.seconds < first.seconds / 3],
104
+ ['different path is not blocked by the cache', other.res.cached !== true],
105
+ ['expired entry is retried', expired.res.cached !== true],
106
+ ['cached reply says when to retry', Number(second.res.retryAfterMs) > 0 && Number(second.res.retryAfterMs) <= 10 * 60 * 1000],
107
+ ['an expired entry does not block a working URL', healed.res.ok === true],
108
+ ['the healed URL forgets its failure', !(afterHeal.failures && afterHeal.failures[keyOf(liveUrl)])],
109
+ ['no fake success', second.res.ok === false]
110
+ ]
111
+ let failed = 0
112
+ for (const [name, ok] of checks) {
113
+ console.log(` ${ok ? 'PASS' : 'FAIL'} ${name}`)
114
+ if (!ok) failed++
115
+ }
116
+ console.log(`saved ${saved.toFixed(2)}s on the retry (${first.seconds > 0 ? (first.seconds / Math.max(second.seconds, 0.001)).toFixed(0) : '?'}x)`)
117
+ await rm(dir, { recursive: true, force: true })
118
+ if (failed) {
119
+ console.log(`FAILED: ${failed} check(s)`)
120
+ process.exit(1)
121
+ }
122
+ console.log('PASS: fetch failure memory')