dsh-limit-break 1.5.0 → 1.6.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 +21 -0
- package/MAINTAIN.md +17 -9
- package/README.md +8 -4
- package/lib/index.js +79 -19
- package/package.json +1 -1
- package/tools/concurrency-selftest.mjs +112 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ All notable changes to `dsh-limit-break`. Format follows
|
|
|
5
5
|
|
|
6
6
|
## Unreleased
|
|
7
7
|
|
|
8
|
+
## 1.6.0 — 2026-10-29
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- **`memory_save` no longer loses writes when two sessions save at the same time.** Saving was
|
|
12
|
+
load → mutate → write-temp → rename with nothing serialising it, so concurrent writers each
|
|
13
|
+
wrote a store missing the other's fact, and on Windows the losing `rename` often failed outright
|
|
14
|
+
with `EPERM`. Saves now take a lock file created with `O_EXCL` around the whole read-modify-write,
|
|
15
|
+
released in a `finally`; a lock left behind by a dead process is stolen after 15 s, and a writer
|
|
16
|
+
that cannot get in within 8 s returns `{ ok: false, code: 'memory.locked' }` instead of throwing.
|
|
17
|
+
A failed `stat` is never read as "stale" — that is exactly how two writers end up inside at once.
|
|
18
|
+
- **`tools/concurrency-selftest.mjs`** (new): spawns N worker processes that each save M facts,
|
|
19
|
+
reads the store back, and counts what survived; it also checks stale-lock recovery.
|
|
20
|
+
8 workers × 6 saves × 3 rounds on the same machine: **16–17 of 48 saves lost** and **up to 25 of
|
|
21
|
+
48 saves failed with `EPERM`** before; **0 lost, 0 failed** after (also clean at 12 × 5 × 4 = 240
|
|
22
|
+
saves, and a 60 s-old lock is recovered with 6/6 saves kept).
|
|
23
|
+
|
|
24
|
+
### Notes
|
|
25
|
+
- No tool added, removed or renamed: the four-tool ABI is untouched. Store format unchanged, and
|
|
26
|
+
single-writer behaviour is identical (the lock is uncontended: one `open` + one `rm` per save).
|
|
27
|
+
- Read paths (`memory_recall`, `memory_stats`) do not take the lock.
|
|
28
|
+
|
|
8
29
|
## 1.5.0 — 2026-10-22
|
|
9
30
|
|
|
10
31
|
### Changed
|
package/MAINTAIN.md
CHANGED
|
@@ -110,22 +110,27 @@ git add -A && git commit -m "..." && git push
|
|
|
110
110
|
|
|
111
111
|
## Backlog(按 2026-10-22 20:10 的真实状态)
|
|
112
112
|
|
|
113
|
-
- [x] **1.5.0
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
四工具 ABI 未变,1.4.0 的“工具集冻结”规则仍然成立。
|
|
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。
|
|
117
116
|
- [ ] 基准里剩下的 miss(“monte carlo pi benchmark on the CPU”)是 `bench.cpu_suite` 与
|
|
118
117
|
`bench.gpu_monte_carlo` 的真实歧义;再往上做要引入上下文/近义词表,性价比低,当作已知上限。
|
|
119
|
-
- [
|
|
120
|
-
`dsh.cmd plugin --profile desktop add dsh-limit-break@<version
|
|
118
|
+
- [x] desktop profile 版本漂移已消(1.2.1 → 1.5.0)。以后每次发布都跟一条
|
|
119
|
+
`dsh.cmd plugin --profile desktop add dsh-limit-break@<version>`。
|
|
121
120
|
|
|
122
121
|
- [x] **1.2.0 已上线**(2026-10-20T12:02:52Z):npm `latest` = `1.2.0`,GitHub `origin/main` =
|
|
123
122
|
`fd844a4`,`verify` PASS,`test_plugin.mjs` 6/6 PASS。用户 20:04 完成了 OTP 发布和推送。
|
|
124
123
|
`env.node_npm` 与 `release.dsh-limit-break` 两条事实已回写。
|
|
125
124
|
- [x] 旧定时任务 `schedule-803cdbdc`(会话 5133bee1)已由用户在面板删除;`storages/schedule.json`
|
|
126
125
|
里只剩 `schedule-0b6c60ea`(hello world)和新的 `schedule-b3675d28`。无需再处理。
|
|
127
|
-
- [
|
|
128
|
-
`
|
|
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 建提交,内容全量替换,不受分叉影响)。
|
|
129
134
|
- [ ] npm 上还挂着占位包 `0.0.0-stage`(`stub: true`)。`npm deprecate` 也要 OTP(本轮 EOTP 失败);
|
|
130
135
|
用户一条命令即可:`npm deprecate dsh-limit-break@0.0.0-stage "placeholder - use 1.2.0"`。
|
|
131
136
|
- [ ] `1.0.0` 是无元数据的旧包体(author/repository 都不在)。同样一条 `npm deprecate` 可清掉噪音(需 OTP)。
|
|
@@ -135,4 +140,7 @@ git add -A && git commit -m "..." && git push
|
|
|
135
140
|
(tool list 是 per-session 快照,插件侧修不了)。事实 `harness.plugin-tool-visibility` 有实测。
|
|
136
141
|
- [ ] `resilient_fetch` 目前按"主机名别名"降级,可以继续加:`--resolve` 到已知 IP、
|
|
137
142
|
IPv6 优先、以及把成功路径写回记忆库(现在是只读阶梯)。
|
|
138
|
-
- [
|
|
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)。
|
package/README.md
CHANGED
|
@@ -75,7 +75,10 @@ package the profile does not declare is silently ignored.
|
|
|
75
75
|
```
|
|
76
76
|
|
|
77
77
|
Plain JSON on purpose: anything that can read a file can use it, with or without this plugin.
|
|
78
|
-
Writes are tmp-file + rename.
|
|
78
|
+
Writes are tmp-file + rename, and a save takes a `.facts.lock` (created `O_EXCL`, stolen after
|
|
79
|
+
15 s if its writer died) around the whole read-modify-write, so two sessions saving at the same
|
|
80
|
+
moment both keep their facts. `tools/concurrency-selftest.mjs` states the numbers: 16–17 of 48
|
|
81
|
+
saves lost before the lock, 0 after.
|
|
79
82
|
|
|
80
83
|
## Disable / remove
|
|
81
84
|
|
|
@@ -90,9 +93,10 @@ Measured, not guessed — each line is something a session actually hit.
|
|
|
90
93
|
* **Tools are visible only to sessions opened after the mount.** A session created before the
|
|
91
94
|
plugin mounted keeps its tool snapshot; new tools do not appear until a new session. Not fixable
|
|
92
95
|
from the plugin side (the tool list is materialised per session).
|
|
93
|
-
* **
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
* **Concurrent saves serialise, and wait at most 8 s.** A second session saving at the same moment
|
|
97
|
+
waits for the lock instead of losing its fact; if the holder is wedged, the save returns
|
|
98
|
+
`{ ok: false, code: "memory.locked" }` rather than hanging. Read paths take no lock, so a save
|
|
99
|
+
still cannot stop a reader from seeing the previous snapshot.
|
|
96
100
|
* **The fetch ladder is hostname-level.** It does not defeat IP-level blocks, TLS interception,
|
|
97
101
|
or a proxy that terminates the connection; it does not skip certificate verification.
|
|
98
102
|
* **`memory_recall` ranks by keyword overlap only** (id/topic/tags/statement/details), no
|
package/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import { execFile } from 'node:child_process'
|
|
20
20
|
import { appendFileSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
21
|
-
import { mkdir, readFile, rename, stat, writeFile } from 'node:fs/promises'
|
|
21
|
+
import { mkdir, open, readFile, rename, rm, stat, writeFile } from 'node:fs/promises'
|
|
22
22
|
import { homedir } from 'node:os'
|
|
23
23
|
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
24
24
|
import { fileURLToPath } from 'node:url'
|
|
@@ -182,6 +182,57 @@ async function saveStore(dir, store) {
|
|
|
182
182
|
return { file, bytes: Buffer.byteLength(body) }
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
// memory_save is load -> mutate -> save, and every DSH window is its own process, so two sessions
|
|
186
|
+
// that save at the same moment both write a store that is missing the other's fact (and on Windows
|
|
187
|
+
// the loser's rename can fail outright with EPERM). A lock file created with O_EXCL is enough:
|
|
188
|
+
// writes are tiny and rare, and a crashed writer is recovered by stealing a lock older than
|
|
189
|
+
// LOCK_STALE_MS. A failed stat is treated as "still held", never as "stale" — stealing on a
|
|
190
|
+
// transient EPERM is exactly how two writers end up in the critical section at once.
|
|
191
|
+
const LOCK_STALE_MS = 15000
|
|
192
|
+
const LOCK_WAIT_MS = 8000
|
|
193
|
+
|
|
194
|
+
async function withStoreLock(dir, fn) {
|
|
195
|
+
const lock = join(dir, '.facts.lock')
|
|
196
|
+
await mkdir(dir, { recursive: true })
|
|
197
|
+
const started = Date.now()
|
|
198
|
+
for (;;) {
|
|
199
|
+
let handle = null
|
|
200
|
+
try {
|
|
201
|
+
handle = await open(lock, 'wx')
|
|
202
|
+
await handle.writeFile(`${process.pid} ${new Date().toISOString()}\n`)
|
|
203
|
+
await handle.close()
|
|
204
|
+
break
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (handle) await handle.close().catch(() => {})
|
|
207
|
+
// On Windows a create that races a delete comes back as EPERM, not EEXIST, so both mean
|
|
208
|
+
// "somebody else is inside the critical section, or just left it".
|
|
209
|
+
if (!error || (error.code !== 'EEXIST' && error.code !== 'EPERM')) throw error
|
|
210
|
+
const info = await stat(lock).catch((problem) => problem)
|
|
211
|
+
if (!info || info.code) {
|
|
212
|
+
// The lock vanished or is pending deletion: that is a released lock, retry promptly.
|
|
213
|
+
await new Promise((resolve) => setTimeout(resolve, 5))
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
const age = typeof info.mtimeMs === 'number' ? Date.now() - info.mtimeMs : 0
|
|
217
|
+
if (age > LOCK_STALE_MS) {
|
|
218
|
+
await rm(lock, { force: true }).catch(() => {})
|
|
219
|
+
continue
|
|
220
|
+
}
|
|
221
|
+
if (Date.now() - started > LOCK_WAIT_MS) {
|
|
222
|
+
const err = new Error(`memory store is locked by another process (${lock}); gave up after ${LOCK_WAIT_MS} ms`)
|
|
223
|
+
err.code = 'memory.locked'
|
|
224
|
+
throw err
|
|
225
|
+
}
|
|
226
|
+
await new Promise((resolve) => setTimeout(resolve, 10 + Math.random() * 30))
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
return await fn()
|
|
231
|
+
} finally {
|
|
232
|
+
await rm(lock, { force: true }).catch(() => {})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
185
236
|
// Ranking inputs. The old scorer used raw substring counts, which let a common word
|
|
186
237
|
// ("the", "how", "long") outvote the one rare word that identifies the fact. Words are
|
|
187
238
|
// matched against word sets instead, suffixed words share a stem, and each query token is
|
|
@@ -565,25 +616,34 @@ export function apply(ctx, config) {
|
|
|
565
616
|
if (id.length > MAX_ID_CHARS || statement.length > MAX_TEXT) {
|
|
566
617
|
return { ok: false, code: 'memory.invalid', message: `id must be <= ${MAX_ID_CHARS} chars and statement <= ${MAX_TEXT} chars.` }
|
|
567
618
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
619
|
+
try {
|
|
620
|
+
return await withStoreLock(storeDir, async () => {
|
|
621
|
+
const store = await loadStore(storeDir)
|
|
622
|
+
const now = new Date().toISOString()
|
|
623
|
+
const record = {
|
|
624
|
+
id,
|
|
625
|
+
topic: String(id).includes('.') ? String(id).split('.')[0] : 'general',
|
|
626
|
+
statement,
|
|
627
|
+
value: input.value === undefined ? null : input.value,
|
|
628
|
+
unit: input.unit === undefined ? null : input.unit,
|
|
629
|
+
details: input.details && typeof input.details === 'object' ? input.details : null,
|
|
630
|
+
source: input.source ? String(input.source) : null,
|
|
631
|
+
timestamp: now,
|
|
632
|
+
tags: Array.isArray(input.tags) ? input.tags.map(String) : []
|
|
633
|
+
}
|
|
634
|
+
const at = store.facts.findIndex((f) => f && String(f.id) === id)
|
|
635
|
+
const action = at >= 0 ? 'updated' : 'created'
|
|
636
|
+
if (at >= 0) store.facts[at] = record
|
|
637
|
+
else store.facts.push(record)
|
|
638
|
+
const written = await saveStore(storeDir, store)
|
|
639
|
+
return { ok: true, id, action, total: store.facts.length, bytes: written.bytes, file: written.file }
|
|
640
|
+
})
|
|
641
|
+
} catch (error) {
|
|
642
|
+
if (error && error.code === 'memory.locked') {
|
|
643
|
+
return { ok: false, code: 'memory.locked', message: error.message }
|
|
644
|
+
}
|
|
645
|
+
throw error
|
|
580
646
|
}
|
|
581
|
-
const at = store.facts.findIndex((f) => f && String(f.id) === id)
|
|
582
|
-
const action = at >= 0 ? 'updated' : 'created'
|
|
583
|
-
if (at >= 0) store.facts[at] = record
|
|
584
|
-
else store.facts.push(record)
|
|
585
|
-
const written = await saveStore(storeDir, store)
|
|
586
|
-
return { ok: true, id, action, total: store.facts.length, bytes: written.bytes, file: written.file }
|
|
587
647
|
}
|
|
588
648
|
}),
|
|
589
649
|
'limit-break: memory_save tool'
|
package/package.json
CHANGED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concurrency probe: do simultaneous memory_save calls lose facts?
|
|
3
|
+
*
|
|
4
|
+
* memory_save is load -> mutate -> save (tmp file + rename). Without a lock, two processes that
|
|
5
|
+
* load the same store each write their own version back and the later rename wins, so the other
|
|
6
|
+
* process' fact disappears. On Windows the losing writer can even fail the rename outright
|
|
7
|
+
* (EPERM: the target is open in the other process).
|
|
8
|
+
*
|
|
9
|
+
* This test makes the damage visible in plain numbers: N worker processes each attempt M saves,
|
|
10
|
+
* then the store is read back and the surviving ids are counted.
|
|
11
|
+
*
|
|
12
|
+
* Run: node tools/concurrency-selftest.mjs [workers] [saves-per-worker] [rounds]
|
|
13
|
+
*/
|
|
14
|
+
import { execFile } from 'node:child_process'
|
|
15
|
+
import { mkdir, mkdtemp, readdir, readFile, rm, utimes, writeFile } from 'node:fs/promises'
|
|
16
|
+
import { tmpdir } from 'node:os'
|
|
17
|
+
import { join } from 'node:path'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
import { promisify } from 'node:util'
|
|
20
|
+
|
|
21
|
+
const exec = promisify(execFile)
|
|
22
|
+
const LIB = fileURLToPath(new URL('../lib/index.js', import.meta.url))
|
|
23
|
+
const workers = Number(process.argv[2] || 8)
|
|
24
|
+
const perWorker = Number(process.argv[3] || 6)
|
|
25
|
+
const rounds = Number(process.argv[4] || 3)
|
|
26
|
+
|
|
27
|
+
const worker = `
|
|
28
|
+
import(process.env.LIB).then(async (m) => {
|
|
29
|
+
const tools = new Map()
|
|
30
|
+
const ctx = {
|
|
31
|
+
effect(fn) { fn() },
|
|
32
|
+
tools: { register(d) { tools.set(d.name, d); return () => tools.delete(d.name) } }
|
|
33
|
+
}
|
|
34
|
+
m.apply(ctx, { storeDir: process.env.STORE_DIR })
|
|
35
|
+
const save = tools.get('memory_save')
|
|
36
|
+
const w = Number(process.env.WORKER)
|
|
37
|
+
let ok = 0
|
|
38
|
+
const errors = []
|
|
39
|
+
for (let i = 0; i < ${perWorker}; i += 1) {
|
|
40
|
+
try {
|
|
41
|
+
const res = await save.execute({ id: 'race.w' + w + '_' + i, statement: 'concurrent write w' + w + ' i' + i + ' from a separate process' })
|
|
42
|
+
if (res && res.ok) ok += 1
|
|
43
|
+
else errors.push((res && res.code ? res.code : 'not-ok') + ' ' + JSON.stringify(res))
|
|
44
|
+
} catch (e) {
|
|
45
|
+
const detail = [e && e.code, e && e.syscall, e && e.path, e && e.message].filter(Boolean).join(' | ')
|
|
46
|
+
errors.push(detail || String(e))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
console.log('RESULT ' + JSON.stringify({ worker: w, ok, errors }))
|
|
50
|
+
process.exit(0)
|
|
51
|
+
}).catch((e) => { console.error(e); process.exit(1) })
|
|
52
|
+
`
|
|
53
|
+
|
|
54
|
+
const results = []
|
|
55
|
+
for (let round = 1; round <= rounds; round += 1) {
|
|
56
|
+
const dir = await mkdtemp(join(tmpdir(), 'limit-break-race-'))
|
|
57
|
+
const storeDir = join(dir, 'memory')
|
|
58
|
+
const replies = await Promise.all(
|
|
59
|
+
Array.from({ length: workers }, (_, w) =>
|
|
60
|
+
exec(process.execPath, ['--input-type=module', '-e', worker], {
|
|
61
|
+
env: { ...process.env, LIB: `file:///${LIB.replaceAll('\\', '/')}`, STORE_DIR: storeDir, WORKER: String(w) },
|
|
62
|
+
timeout: 120000
|
|
63
|
+
}).then((r) => r.stdout)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
const reports = replies.flatMap((out) =>
|
|
67
|
+
out.split('\n').filter((line) => line.startsWith('RESULT ')).map((line) => JSON.parse(line.slice(7)))
|
|
68
|
+
)
|
|
69
|
+
const succeeded = reports.reduce((sum, r) => sum + r.ok, 0)
|
|
70
|
+
const errorCodes = reports.flatMap((r) => r.errors)
|
|
71
|
+
const store = JSON.parse(await readFile(join(storeDir, 'facts.json'), 'utf8'))
|
|
72
|
+
const kept = store.facts.filter((f) => f && /^race\.w/.test(String(f.id))).length
|
|
73
|
+
const leftover = (await readdir(storeDir)).filter((name) => name !== 'facts.json' && name !== 'plugin-load.log')
|
|
74
|
+
results.push({ round, attempted: workers * perWorker, succeeded, kept, lost: succeeded - kept, failed: workers * perWorker - succeeded, errorCodes, leftover })
|
|
75
|
+
await rm(dir, { recursive: true, force: true })
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
for (const r of results) {
|
|
79
|
+
const codes = r.errorCodes.length ? ` (errors: ${[...new Set(r.errorCodes)].join(',')})` : ''
|
|
80
|
+
console.log(`round ${r.round}: attempted ${r.attempted}, save-ok ${r.succeeded}, kept ${r.kept}, lost ${r.lost}${codes}${r.leftover.length ? ` leftover: ${r.leftover.join(',')}` : ''}`)
|
|
81
|
+
}
|
|
82
|
+
// A writer that dies while holding the lock must not wedge the store forever: a lock older than
|
|
83
|
+
// the stale window is stolen, and the save goes through.
|
|
84
|
+
const staleDir = await mkdtemp(join(tmpdir(), 'limit-break-stale-'))
|
|
85
|
+
const staleStore = join(staleDir, 'memory')
|
|
86
|
+
await mkdir(staleStore, { recursive: true })
|
|
87
|
+
await writeFile(join(staleStore, '.facts.lock'), '999999 2020-01-01T00:00:00.000Z\n')
|
|
88
|
+
const past = new Date(Date.now() - 60000)
|
|
89
|
+
await utimes(join(staleStore, '.facts.lock'), past, past)
|
|
90
|
+
const staleOut = await exec(process.execPath, ['--input-type=module', '-e', worker], {
|
|
91
|
+
env: { ...process.env, LIB: `file:///${LIB.replaceAll('\\', '/')}`, STORE_DIR: staleStore, WORKER: '99' },
|
|
92
|
+
timeout: 120000
|
|
93
|
+
})
|
|
94
|
+
const stale = JSON.parse(staleOut.stdout.split('\n').filter((line) => line.startsWith('RESULT ')).map((line) => line.slice(7))[0])
|
|
95
|
+
const staleStoreJson = JSON.parse(await readFile(join(staleStore, 'facts.json'), 'utf8'))
|
|
96
|
+
const staleKept = staleStoreJson.facts.filter((f) => f && /^race\.w99/.test(String(f.id))).length
|
|
97
|
+
const staleLeftover = (await readdir(staleStore)).filter((name) => name !== 'facts.json' && name !== 'plugin-load.log')
|
|
98
|
+
await rm(staleDir, { recursive: true, force: true })
|
|
99
|
+
console.log(`stale lock: save-ok ${stale.ok}/${perWorker}, kept ${staleKept}, leftover ${staleLeftover.length ? staleLeftover.join(',') : 'none'}`)
|
|
100
|
+
|
|
101
|
+
const lost = results.map((r) => r.lost)
|
|
102
|
+
const failed = results.map((r) => r.failed)
|
|
103
|
+
const worstLost = Math.max(...lost)
|
|
104
|
+
const avgLost = +(lost.reduce((a, b) => a + b, 0) / lost.length).toFixed(1)
|
|
105
|
+
const worstFailed = Math.max(...failed)
|
|
106
|
+
console.log(`${workers} workers x ${perWorker} saves x ${rounds} rounds -> lost facts: worst ${worstLost}, average ${avgLost}; failed saves: worst ${worstFailed}`)
|
|
107
|
+
const staleBad = stale.ok !== perWorker || staleKept !== perWorker || staleLeftover.length > 0
|
|
108
|
+
if (worstLost > 0 || worstFailed > 0 || staleBad) {
|
|
109
|
+
console.log('FAIL: concurrent saves lose facts or fail outright')
|
|
110
|
+
process.exit(1)
|
|
111
|
+
}
|
|
112
|
+
console.log('PASS: every concurrent save survived and none failed')
|