dsh-limit-break 1.6.0 → 1.8.0

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,50 @@ All notable changes to `dsh-limit-break`. Format follows
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## 1.8.0 — 2026-11-12
9
+
10
+ ### Changed
11
+ - **`resilient_fetch` remembers hard failures instead of re-walking the dead ladder.** A URL whose
12
+ every rung failed is cached for ten minutes: the retry returns the recorded failure immediately
13
+ (`cached: true`, `ageMs`, `retryAfterMs`) instead of paying one timeout per rung again. Measured on
14
+ `en.wikipedia.org/robots.txt` (no alternate hostname applies) with the default 12 s per-rung
15
+ timeout: cold **34.81 s**, 3 attempts → retry **0.01 s** — **3481× faster**; at 3 s per rung,
16
+ 13.26 s → 0.02 s.
17
+ - Failure entries live in `fetch-failures.json` next to the store, **not** in `facts.json`: a
18
+ transient network blip is not durable knowledge and would pollute `memory_recall`. Reads are
19
+ lock-free, writes take the same lock as `memory_save`, expired entries are pruned on write.
20
+ - Only *hard* failures are remembered (elapsed > 2 s, or a timeout/reset/DNS-class error): a fast
21
+ 404/403 says nothing about the network, so it is never cached. A different path on the same host
22
+ still gets a real attempt, and a successful call deletes that URL's entry.
23
+ - `resilient_fetch` also returns `millis` on failure, and the failed-attempt rendering shows cached
24
+ age and retry window.
25
+ - **`tools/fetch-fail-bench.mjs`** (new): cold vs cached retry, over-blocking check (different path),
26
+ TTL-expiry check, and two healing checks (expired entry must not block a live URL; success must
27
+ delete the entry). 10/10 checks PASS.
28
+
29
+ ## 1.7.0 — 2026-11-05
30
+
31
+ ### Changed
32
+ - **`resilient_fetch` remembers which rung worked instead of rediscovering it on every call.** A
33
+ non-direct success is written back as `network.route.<host>` (14-day TTL, written under the same
34
+ lock as `memory_save`) and the next call to that host starts at that rung; if a plain fetch starts
35
+ working again the route is deleted, so an unblocked host heals itself. Measured on
36
+ `en.wikipedia.org/wiki/Monte_Carlo_method` with the default 12 s per-rung timeout: cold **12.11 s**
37
+ with attempts `direct>alternate-host`, warm **1.08 s / 1.14 s** with a single `alternate-host`
38
+ attempt — **11.2× faster**; the tool now also reports `millis`, `route`
39
+ (`learned|reused|dropped|none`) and `cached_via`.
40
+ - **`tools/fetch-route-bench.mjs`** (new): cold-vs-warm measurement for one blocked host plus a
41
+ self-heal check (a seeded stale route must be dropped once direct works). 6/6 checks PASS.
42
+ - Route facts are ordinary facts: visible to `memory_recall`/`memory_stats`, removable with any
43
+ store edit. Only fallback successes and self-heal events write, so a working network writes nothing.
44
+
45
+ ### Notes
46
+ - No tool added, removed or renamed; store format unchanged. The tool description text now mentions
47
+ the remembered route, which an already-open session will not see until its tool snapshot refreshes.
48
+ - `maintain.py status` still prints `market listing not live yet (PR #8296 closed)` while the same
49
+ call reports `listed_in_market: true`: the check treats a merged-and-closed PR as not live. Left
50
+ as-is, documented in MAINTAIN.md so the next round does not read it as a regression.
51
+
8
52
  ## 1.6.0 — 2026-10-29
9
53
 
10
54
  ### Fixed
package/MAINTAIN.md CHANGED
@@ -1,146 +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
- - [ ] `resilient_fetch` 目前按"主机名别名"降级,可以继续加:`--resolve` 到已知 IP、
142
- IPv6 优先、以及把成功路径写回记忆库(现在是只读阶梯)。
143
- - [x] **`memory_save` 的并发写已有自动化覆盖**(1.6.0,2026-10-29):`tools/concurrency-selftest.mjs`
144
- 起 N 个独立进程同时写同一个 store,再读回数存活条数,另测“陈旧锁被接管”。同机 8 进程 × 6 次 × 3 轮:
145
- 修复前丢 16–17/48、且最多 25/48 直接 `EPERM`(rename 输家);加 `O_EXCL` 锁后 0 丢 0 失败,
146
- 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
@@ -43,6 +43,21 @@ IPv6 → IPv4 → a **sibling hostname of the same service** whose certificate s
43
43
  It does **not** disable certificate verification and does not route through a proxy that would
44
44
  impersonate the origin. Those are MITM, not workarounds.
45
45
 
46
+ **The ladder learns.** A fallback rung that worked is written back as `network.route.<host>` and the
47
+ next call to that host starts there; if a plain fetch starts working again the route is deleted (host
48
+ self-heals). Measured on `en.wikipedia.org/wiki/Monte_Carlo_method`, 12 s per-rung timeout: cold
49
+ **12.1 s** (rung 1 burned the timeout, rung 4 answered) → warm **1.08 s / 1.14 s**, one attempt
50
+ instead of two — **11.2× faster**. Numbers come from `tools/fetch-route-bench.mjs`.
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
+
46
61
  ## Install
47
62
 
48
63
  ```sh
@@ -99,6 +114,13 @@ Measured, not guessed — each line is something a session actually hit.
99
114
  still cannot stop a reader from seeing the previous snapshot.
100
115
  * **The fetch ladder is hostname-level.** It does not defeat IP-level blocks, TLS interception,
101
116
  or a proxy that terminates the connection; it does not skip certificate verification.
117
+ * **A remembered route is a bet with a 14-day expiry.** The ladder trusts `network.route.<host>` for
118
+ two weeks and drops it as soon as a direct request works; if the winning rung starts failing the
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.
102
124
  * **`memory_recall` ranks by keyword overlap only** (id/topic/tags/statement/details), no
103
125
  embeddings: stopword-filtered, crudely stemmed word matching weighted by idf, so it is good at
104
126
  "which fact did I mean" and bad at paraphrase. `tools/recall-bench.mjs` states the current
package/lib/index.js CHANGED
@@ -233,6 +233,134 @@ async function withStoreLock(dir, fn) {
233
233
  }
234
234
  }
235
235
 
236
+ // A failed fetch tells you which rung of the ladder works for that host *today*; throwing that
237
+ // away means paying the same dead rungs on every call. A non-direct success is remembered per
238
+ // host (network.route.<host>) for two weeks and the ladder starts at that rung next time. When
239
+ // direct starts working again the route is dropped, so a host that unblocks heals itself.
240
+ const ROUTE_TTL_MS = 14 * 24 * 60 * 60 * 1000
241
+
242
+ function routeId(host) {
243
+ return `network.route.${String(host).toLowerCase().replace(/[^a-z0-9.-]+/g, '-')}`
244
+ }
245
+
246
+ async function readRoute(dir, host) {
247
+ const store = await loadStore(dir)
248
+ const fact = store.facts.find((f) => f && String(f.id) === routeId(host))
249
+ if (!fact) return null
250
+ const details = fact.details && typeof fact.details === 'object' ? fact.details : {}
251
+ const observed = Date.parse(String(details.observedAt || fact.timestamp || ''))
252
+ if (!Number.isFinite(observed) || Date.now() - observed > ROUTE_TTL_MS) return null
253
+ const via = typeof details.via === 'string' ? details.via : ''
254
+ if (!via || via === 'direct') return null
255
+ return { via, url: typeof details.url === 'string' ? details.url : '', observedAt: new Date(observed).toISOString() }
256
+ }
257
+
258
+ async function writeRoute(dir, host, info) {
259
+ const now = new Date().toISOString()
260
+ const id = routeId(host)
261
+ return withStoreLock(dir, async () => {
262
+ const store = await loadStore(dir)
263
+ const record = {
264
+ id,
265
+ topic: 'network',
266
+ statement: `${host} answers through the ${info.via} rung of the fetch ladder (${info.url}); a direct request to it fails today, so the ladder should start at ${info.via}.`,
267
+ value: null,
268
+ unit: null,
269
+ details: { host, via: info.via, url: info.url, observedAt: now, millis: info.millis || null },
270
+ source: 'resilient_fetch',
271
+ timestamp: now,
272
+ tags: ['network', 'fetch-route']
273
+ }
274
+ const at = store.facts.findIndex((f) => f && String(f.id) === id)
275
+ if (at >= 0) store.facts[at] = record
276
+ else store.facts.push(record)
277
+ await saveStore(dir, store)
278
+ return record
279
+ })
280
+ }
281
+
282
+ async function dropRoute(dir, host) {
283
+ const id = routeId(host)
284
+ return withStoreLock(dir, async () => {
285
+ const store = await loadStore(dir)
286
+ const before = store.facts.length
287
+ store.facts = store.facts.filter((f) => !(f && String(f.id) === id))
288
+ if (store.facts.length === before) return false
289
+ await saveStore(dir, store)
290
+ return true
291
+ })
292
+ }
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
+
236
364
  // Ranking inputs. The old scorer used raw substring counts, which let a common word
237
365
  // ("the", "how", "long") outvote the one rare word that identifies the fact. Words are
238
366
  // matched against word sets instead, suffixed words share a stem, and each query token is
@@ -655,7 +783,7 @@ export function apply(ctx, config) {
655
783
  ctx.tools.register({
656
784
  name: 'resilient_fetch',
657
785
  description:
658
- '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. 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.',
659
787
  parameters: {
660
788
  type: 'object',
661
789
  properties: {
@@ -669,8 +797,8 @@ export function apply(ctx, config) {
669
797
  schema: { type: 'object' },
670
798
  render: (_args, value) =>
671
799
  value && value.ok
672
- ? [{ type: 'text', text: `HTTP ${value.status} via ${value.via} (${value.bytes} bytes)\n${String(value.text || '').slice(0, 400)}` }]
673
- : [{ type: 'text', text: `All attempts failed: ${(value && value.attempts ? value.attempts : []).map((a) => `${a.via}=${a.error || a.status}`).join(' | ')}` }]
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)}` }]
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(' | ')}` }]
674
802
  },
675
803
  presentCall: (args) => ({
676
804
  card: 'generic',
@@ -682,11 +810,37 @@ export function apply(ctx, config) {
682
810
  const input = args && typeof args === 'object' ? args : {}
683
811
  const url = typeof input.url === 'string' ? input.url.trim() : ''
684
812
  if (!/^https?:\/\//i.test(url)) return { ok: false, code: 'fetch.invalid', attempts: [], message: 'url must start with http:// or https://' }
813
+ let host = ''
814
+ try {
815
+ host = new URL(url).hostname
816
+ } catch {
817
+ return { ok: false, code: 'fetch.invalid', attempts: [], message: 'url is not a valid absolute URL' }
818
+ }
685
819
  const per = Math.max(2000, Number(input.timeoutMs) || timeoutMs)
686
- const targets = [{ url, via: 'direct' }, ...alternatesFor(url).map((u) => ({ url: u, via: 'alternate-host' }))]
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
+ }
834
+ const cached = await readRoute(storeDir, host).catch(() => null)
835
+ let targets = [{ url, via: 'direct' }, ...alternatesFor(url).map((u) => ({ url: u, via: 'alternate-host' }))]
687
836
  if (shellFallback) {
688
837
  targets.push({ url, via: 'curl-ipv6' }, { url, via: 'curl-ipv4' })
689
838
  }
839
+ if (cached) {
840
+ const preferred = targets.filter((target) => target.via === cached.via)
841
+ if (preferred.length) targets = [...preferred, ...targets.filter((target) => target.via !== cached.via)]
842
+ }
843
+ const startedAt = Date.now()
690
844
  const attempts = []
691
845
  for (const target of targets) {
692
846
  try {
@@ -697,6 +851,21 @@ export function apply(ctx, config) {
697
851
  attempts.push({ via: target.via, url: target.url, status: result.status })
698
852
  if (result.ok && result.text) {
699
853
  const clipped = clip(result.text)
854
+ const millis = Date.now() - startedAt
855
+ let route = cached ? 'reused' : 'none'
856
+ try {
857
+ if (target.via === 'direct') {
858
+ if (cached) route = (await dropRoute(storeDir, host)) ? 'dropped' : 'none'
859
+ } else {
860
+ await writeRoute(storeDir, host, { via: target.via, url: target.url, millis })
861
+ route = cached && cached.via === target.via ? 'reused' : 'learned'
862
+ }
863
+ } catch {
864
+ route = 'unwritten'
865
+ }
866
+ if (failures[urlKey(url)]) {
867
+ await dropFailure(storeDir, url).catch(() => {})
868
+ }
700
869
  return {
701
870
  ok: true,
702
871
  status: result.status,
@@ -706,14 +875,24 @@ export function apply(ctx, config) {
706
875
  bytes: clipped.bytes,
707
876
  truncated: clipped.truncated,
708
877
  text: clipped.text,
709
- attempts
878
+ attempts,
879
+ millis,
880
+ route,
881
+ cached_via: cached ? cached.via : null
710
882
  }
711
883
  }
712
884
  } catch (error) {
713
885
  attempts.push({ via: target.via, url: target.url, error: String((error && error.message) || error).slice(0, 300) })
714
886
  }
715
887
  }
716
- return { ok: false, code: 'fetch.failed', requested: url, 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 }
717
896
  }
718
897
  }),
719
898
  'limit-break: resilient_fetch tool'
package/package.json CHANGED
@@ -1,51 +1,51 @@
1
- {
2
- "name": "dsh-limit-break",
3
- "version": "1.6.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.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
+ }
@@ -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')
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Route-cache probe: does remembering which rung of the fetch ladder works actually pay?
3
+ *
4
+ * `resilient_fetch` walks direct -> alternates -> curl IPv6 -> curl IPv4. On a host whose direct
5
+ * request is blocked (SNI-keyed), every call used to rediscover that by burning a timeout on rung 1
6
+ * before rung 4 answered. Since 1.7.0 a non-direct success is stored as `network.route.<host>` and
7
+ * the next call starts at that rung.
8
+ *
9
+ * This measures one blocked host: cold call (cache miss) vs warm calls (cache hit), printing
10
+ * attempts and seconds, then checks the store holds the route fact.
11
+ *
12
+ * Run: node tools/fetch-route-bench.mjs [url] [timeoutMs]
13
+ */
14
+ import { mkdtemp, readFile } from 'node:fs/promises'
15
+ import { tmpdir } from 'node:os'
16
+ import { join } from 'node:path'
17
+ import { fileURLToPath, pathToFileURL } from 'node:url'
18
+
19
+ const LIB = fileURLToPath(new URL('../lib/index.js', import.meta.url))
20
+ const url = process.argv[2] || 'https://en.wikipedia.org/wiki/Monte_Carlo_method'
21
+ const timeoutMs = Number(process.argv[3] || 6000)
22
+ const host = new URL(url).hostname
23
+
24
+ const { apply } = await import(pathToFileURL(LIB).href)
25
+ const mod = await import(pathToFileURL(LIB).href)
26
+ const tools = new Map()
27
+ const ctx = {
28
+ effect(fn) {
29
+ fn()
30
+ },
31
+ tools: {
32
+ register(tool) {
33
+ tools.set(tool.name, tool)
34
+ return () => tools.delete(tool.name)
35
+ }
36
+ }
37
+ }
38
+ const storeDir = join(await mkdtemp(join(tmpdir(), 'limit-break-route-')), 'memory')
39
+ apply(ctx, { storeDir })
40
+ const fetchTool = tools.get('resilient_fetch')
41
+
42
+ const call = async (label) => {
43
+ const started = Date.now()
44
+ const result = await fetchTool.execute({ url, timeoutMs })
45
+ const seconds = +((Date.now() - started) / 1000).toFixed(2)
46
+ console.log(
47
+ `${label}: ok=${result.ok} via=${result.via || '-'} route=${result.route || '-'} attempts=${(result.attempts || []).map((a) => a.via).join('>')} seconds=${seconds}`
48
+ )
49
+ return { result, seconds }
50
+ }
51
+
52
+ const cold = await call('cold')
53
+ if (!cold.result.ok || cold.result.via === 'direct') {
54
+ console.log('SKIP: direct fetch to this host works today, so there is no failed rung to remember')
55
+ process.exit(0)
56
+ }
57
+ const warm1 = await call('warm1')
58
+ const warm2 = await call('warm2')
59
+
60
+ const store = JSON.parse(await readFile(join(storeDir, 'facts.json'), 'utf8'))
61
+ const fact = store.facts.find((row) => row && row.id === `network.route.${host.toLowerCase()}`)
62
+ console.log(`route fact: ${fact ? JSON.stringify(fact.details) : 'MISSING'}`)
63
+
64
+ // Self-heal: if a host has a remembered route but a direct request now works, the stale route
65
+ // must be dropped instead of being trusted forever.
66
+ const healUrl = 'https://api.wikimedia.org/core/v1/wikipedia/en/page/Monte_Carlo_method'
67
+ const healHost = new URL(healUrl).hostname
68
+ const seeded = await mod.loadStore(storeDir)
69
+ seeded.facts.push({
70
+ id: `network.route.${healHost}`,
71
+ topic: 'network',
72
+ statement: 'seeded stale route for the self-heal check',
73
+ details: { host: healHost, via: 'alternate-host', url: healUrl, observedAt: new Date().toISOString(), millis: null },
74
+ source: 'bench',
75
+ timestamp: new Date().toISOString(),
76
+ tags: ['network']
77
+ })
78
+ await mod.saveStore(storeDir, seeded)
79
+ const heal = await fetchTool.execute({ url: healUrl, timeoutMs })
80
+ const afterHeal = await mod.loadStore(storeDir)
81
+ const healDropped = !afterHeal.facts.some((row) => row && row.id === `network.route.${healHost}`)
82
+ console.log(`self-heal: ok=${heal.ok} via=${heal.via} route=${heal.route} factDropped=${healDropped}`)
83
+
84
+ const checks = [
85
+ ['cold used a fallback rung', cold.result.via !== 'direct' && cold.result.attempts.length > 1],
86
+ ['warm call starts at the remembered rung', warm1.result.attempts.length === 1 && warm1.result.attempts[0].via === cold.result.via],
87
+ ['warm call is at least 2x faster', warm1.seconds * 2 <= cold.seconds],
88
+ ['warm call is stable', warm2.result.via === cold.result.via && warm2.result.route === 'reused'],
89
+ ['route fact written', Boolean(fact) && fact.details && fact.details.via === cold.result.via],
90
+ ['stale route dropped once direct works', heal.ok && heal.via === 'direct' && heal.route === 'dropped' && healDropped]
91
+ ]
92
+ let failed = 0
93
+ for (const [name, ok] of checks) {
94
+ console.log(`${ok ? 'PASS' : 'FAIL'} ${name}`)
95
+ if (!ok) failed += 1
96
+ }
97
+ console.log(`cold ${cold.seconds}s -> warm ${warm1.seconds}s / ${warm2.seconds}s (${(cold.seconds / Math.max(warm1.seconds, 0.01)).toFixed(1)}x faster)`)
98
+ process.exit(failed ? 1 : 0)