dsh-log-contract 0.3.28 → 0.3.33
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/README.md +48 -38
- package/README.zh.md +38 -38
- package/bin/dsh-log-contract.mjs +67 -15
- package/docs/CONTRACTS.md +74 -60
- package/docs/interface-versioning.md +46 -0
- package/lib/archive.js +21 -21
- package/lib/checks.js +155 -66
- package/lib/compat.js +7 -7
- package/lib/contracts.js +77 -60
- package/lib/explain.js +129 -0
- package/lib/host-probes.js +4 -4
- package/lib/index.js +1 -0
- package/lib/legacy-fold.js +5 -5
- package/lib/log-reader.js +57 -23
- package/lib/prewrite.js +6 -6
- package/lib/repair.js +34 -34
- package/lib/validate.js +27 -9
- package/lib/version-support.js +4 -4
- package/lib/vocab.js +8 -8
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ plugin marker semantics).
|
|
|
36
36
|
- **`fix` / `extract` / `audit-report`** — repair primitives and read-only
|
|
37
37
|
session archaeology.
|
|
38
38
|
|
|
39
|
-
**Capabilities at a glance**: session formats **v0–v4** ·
|
|
39
|
+
**Capabilities at a glance**: session formats **v0–v4** · 57 contract rules ·
|
|
40
40
|
exit-code contract `0/1/3/4` · three-tier verdicts · pre-write validation ·
|
|
41
41
|
per-rule negative-control tests + rules self-test · tolerant reading (a single
|
|
42
42
|
damaged file degrades to structured results and is counted, never thrown).
|
|
@@ -76,7 +76,7 @@ line-by-line verification against the official Host source (each rule carries it
|
|
|
76
76
|
---
|
|
77
77
|
|
|
78
78
|
## Three-layer contract (the model)
|
|
79
|
-
>
|
|
79
|
+
> 57 rules across the layers below (`contracts` lists them all, each with its
|
|
80
80
|
> official source reference).
|
|
81
81
|
|
|
82
82
|
| Layer | Rules | What it guards |
|
|
@@ -101,7 +101,7 @@ line-by-line verification against the official Host source (each rule carries it
|
|
|
101
101
|
|---|---|---|
|
|
102
102
|
| Host package | `@deepseek-ai/dsh-session@0.2.0-rc.2` | the version this rule set is developed and CI-tested against (CI runs `pnpm check` + `pnpm test`; the four `prepublishOnly` steps are green locally on it) |
|
|
103
103
|
| Session format | **v4** (`SESSION_FORMAT_VERSION = 4`) | v4 uses the runtime vocabulary + official `foldSurface` final check |
|
|
104
|
-
| Declared range | `peerDependencies: ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1` | installable — a declared range is **not** a per-version verification |
|
|
104
|
+
| Declared range | `peerDependencies: ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.1.7-rc.2 || ^0.2.0-rc.1` | installable — a declared range is **not** a per-version verification |
|
|
105
105
|
| Known formats | 0 / 1 / 2 / 3 / 4 | 0–2 are supported by this package's **vendored** vocabulary + local equivalent fold (`legacyFoldSurface`), independent of the host |
|
|
106
106
|
|
|
107
107
|
**What happens on unverified versions (detected and reported at runtime — never silently judged by stale rules)**:
|
|
@@ -157,10 +157,10 @@ rather than by relaxing the format gate:
|
|
|
157
157
|
|
|
158
158
|
- `tool/result` is validated with the v4 shape (`role: 'tool'`, no `tool-result` wrapper block)
|
|
159
159
|
- `system/message` accepts v4's `source.kind: 'system-prompt'`
|
|
160
|
-
- validation for v3 and earlier is **unchanged** (identical verdicts on
|
|
160
|
+
- validation for v3 and earlier is **unchanged** (identical verdicts on 408 real v3 sessions before/after)
|
|
161
161
|
- the format gate still rejects **unknown** future versions (`readOnly`); v5+ remains unassessable by design
|
|
162
162
|
|
|
163
|
-
**Rules (55
|
|
163
|
+
**Rules (55 as of 0.3.28, 57 as of 0.3.32):** the five rules below were added in the
|
|
164
164
|
0.3.18 – 0.3.24 window (see above for the 0.3.28 additions):
|
|
165
165
|
|
|
166
166
|
| Rule | Checks |
|
|
@@ -171,12 +171,12 @@ rather than by relaxing the format gate:
|
|
|
171
171
|
| `P5` | two-segment carrier pairing: 2nd segment's first seq == 1st segment seq (read side accepts the legacy order) |
|
|
172
172
|
| `A1` | "in-place restorable" is judged from structured fields only (`archiveRef` / `archive` / `externalized.*`) — never from free text |
|
|
173
173
|
|
|
174
|
-
**Large sessions:** reading is line-wise (no whole-file stringification ⇒ no `ERR_STRING_TOO_LONG` above ~
|
|
174
|
+
**Large sessions:** reading is line-wise (no whole-file stringification ⇒ no `ERR_STRING_TOO_LONG` above ~536 MB),
|
|
175
175
|
and repair rebuilds `.jsonl.zstd` with streaming frames (header frame + chunked body frames, per-frame checksum + round-trip).
|
|
176
176
|
|
|
177
177
|
**Windows:** the `header.cwd` absolute-path check in `H2` is platform-aware (`win32` and `posix` both accepted).
|
|
178
178
|
|
|
179
|
-
**Compatibility:** Node ≥ 22; `@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1`; session formats v0–v4.
|
|
179
|
+
**Compatibility:** Node ≥ 22; `@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.1.7-rc.2 || ^0.2.0-rc.1`; session formats v0–v4.
|
|
180
180
|
|
|
181
181
|
## Case log — why "production-grade" is not a slogan
|
|
182
182
|
Each entry below is a **real log-corruption shape** from production sessions — the cases that
|
|
@@ -185,23 +185,23 @@ omitted.
|
|
|
185
185
|
|
|
186
186
|
| # | Date | What happened | The rule / fix it produced |
|
|
187
187
|
| --- | --- | --- | --- |
|
|
188
|
-
| 1 |
|
|
189
|
-
| 2 |
|
|
190
|
-
| 3 |
|
|
191
|
-
| 4 |
|
|
192
|
-
| 5 |
|
|
193
|
-
| 6 |
|
|
194
|
-
| 7 |
|
|
195
|
-
| 8 |
|
|
196
|
-
| 9 |
|
|
197
|
-
| 10 |
|
|
198
|
-
| 11 |
|
|
199
|
-
| 12 |
|
|
200
|
-
| 13 |
|
|
201
|
-
| 14 |
|
|
202
|
-
| 15 |
|
|
203
|
-
| 16 |
|
|
204
|
-
| 17 |
|
|
188
|
+
| 1 | 2026-08-25 | A "restore hidden content" repair wrote a replace marker with **emptied `sourceEventSeqs`** → the session refused to load (`SessionPersistenceCorruptionError`); a second attempt changed the marker to **append** → the client engine crashed. Both were **violating writes that nothing caught**. | **S5** (sourceEventSeqs must cover shadowed nodes), **M1** (turn-null assistant/message can only be replace), pre-write validation |
|
|
189
|
+
| 2 | 2026-08-27~28 | Interrupted/restarted turns replayed with a **stale in-memory cursor**, re-appending old seqs to the file tail (tail regression, duplicate batches); two writers interleaved → **file-physical order non-monotonic** (`734056 → 733539 → 735470`). Sessions failed to load with `seq gap`. | **S9** (physical-order monotonic), fix `--tail-renumber` |
|
|
190
|
+
| 3 | 2026-08-27~28 | **Fork-boundary orphan splice**: the fork's "remove parent's pending prompt" splice assumed the parent's inbox; the child's seed-relative replay has an empty inbox → `resume failed: invalid persisted inbox splice`. | **I1** (inbox seed-relative replay), fix `--neutralize-orphan` |
|
|
191
|
+
| 4 | 2026-08-28 | An oversized session (**1,052,557 tokens** vs the 1M window) could neither continue nor `/compact`; the trim budget estimator underpriced CJK by ~3.7×. | T1 (token-meter pairing) for compactability, `fix --trim-budget` guidance |
|
|
192
|
+
| 5 | 2026-08-29 | **W1/W2 wire violations**: markers shadowed an assistant with tool_calls but left the tool results dangling → strict endpoints (`INVALID_REQUEST`) reject the session's request stream. | **W1 / W2** (wire message flow) |
|
|
193
|
+
| 6 | 2026-08-30 | A single **turn-null marker** made the token-meter listener throw on **every** appended event (`consumedEvents` never advanced → full-prefix re-fold per event) → **30s / 10,008 log lines**, host event loop crushed, all sessions locked. Same session also had a **cross-step sourceEventSeqs** (steps 7/8/9 mixed in one assistant message) — offline checks were green, the live meter crashed. | **T1** (turn/step pairing), **T2** (cross-step source refs), `fix --neutralize`, `fix --clip-crossstep` |
|
|
194
|
+
| 7 | 2026-08-31 | A log was compressed as a **single zstd frame** (or the header did not form its own frame) → different readers disagreed on record boundaries ⇒ **Z4/Z5** frame-shape rules (first frame = exactly one header line; body framed) | |
|
|
195
|
+
| 8 | 2026-08-31 | A log whose **last zstd frame was torn** mid-write could not be loaded at all, with no diagnosis ⇒ **Z1** + explicit "torn tail / in-flight write" reporting | |
|
|
196
|
+
| 9 | 2026-09-09 | On **session format v4**, `tool/result` uses `role: 'tool'` and `system/message` carries a `system-prompt` source → v3-shaped checks produced **thousands of false errors on healthy v4 logs** ⇒ version dispatch + **E6/E9** v4 semantics | |
|
|
197
|
+
| 10 | 2026-09-17 | On **Windows**, `header.cwd` was judged with POSIX-only rules → **every** session flagged by **H2** ⇒ platform-aware absolute-path check | |
|
|
198
|
+
| 11 | 2026-10-20 | A **> 500 MB session** crashed the reader (`ERR_STRING_TOO_LONG`) and repair built the whole text in memory ⇒ line-wise decode + streaming frame rebuild | |
|
|
199
|
+
| 12 | 2026-10-20 | Two-segment carrier references were written with the audit segment first while an earlier convention started at the range start → readers reported hundreds of **false orphan carriers** ⇒ **P5** write-side pairing + tolerant read-side | |
|
|
200
|
+
| 13 | 2026-10-20 | `seedLength` was read as a **byte size** by some consumers (it is the number of inherited events), and `parentSession` with missing/0 was treated as corruption ⇒ **I2** semantics pinned | |
|
|
201
|
+
| 14 | 2026-10-20 | An **unknown but explicitly ignorable** event type blocked an entire migration ⇒ **G4** declarative skip + allow-list | |
|
|
202
|
+
| 15 | 2026-10-26 | A **truncated zstd frame** made the session-header reader throw `ERR_OUT_OF_RANGE`, and because there was no per-item isolation the whole enumeration/summary run failed (hundreds of failures over 33 days) — **one damaged file sank the whole batch** | **R4** (read/parse tolerance: degrade to a structured, countable result), **R5** (per-item isolation + failure counting in aggregation APIs) |
|
|
203
|
+
| 16 | 2026-10-26 | A file whose **last frame was cut mid-write** still reported `ok=true` — the check certifies only the events it actually read | **Z6** (`tailStatus: complete/interrupted/truncated/unknown`) + the documented tail-completeness boundary |
|
|
204
|
+
| 17 | 2026-10-26 | Producers **inventing `seq` on the write side**, and **deleting rows without renumbering** | **E11** (`seq` assigned by the log layer only; pre-write rejects self-invented `seq`), gap traces pinned to `E2`/`S9` |
|
|
205
205
|
|
|
206
206
|
> **Takeaway**: these rules are not synthetic theory — each one is pinned by a
|
|
207
207
|
> regression test that reproduces the corrupt shape it guards against. That is what
|
|
@@ -233,19 +233,19 @@ with the Harness read path).
|
|
|
233
233
|
### 1. Offline health check
|
|
234
234
|
|
|
235
235
|
```bash
|
|
236
|
-
dsh-log-contract check
|
|
237
|
-
dsh-log-contract check
|
|
236
|
+
dsh-log-contract check ~/.dsh/sessions/<id>.jsonl.zstd
|
|
237
|
+
dsh-log-contract check ~/.dsh/sessions/<id>.jsonl.zstd --json # machine-readable
|
|
238
238
|
```
|
|
239
239
|
|
|
240
240
|
Sample output (the CLI reports in Chinese — it is the tool's UI language):
|
|
241
241
|
|
|
242
242
|
```
|
|
243
243
|
📋 dsh-log-contract check —— backup-session-xxxx.jsonl.zstd
|
|
244
|
-
事件
|
|
244
|
+
事件 204754 | surface 节点 16 | replace 代数 5 | 帧 8620(3439.5KiB → 8191.3KiB)
|
|
245
245
|
违规 1(error 1 / warning 0)
|
|
246
246
|
|
|
247
247
|
[error] S5 @ seq <seq> / line <line> (assistant/message)
|
|
248
|
-
surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失
|
|
248
|
+
surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 121774, 121779(共 2 个)
|
|
249
249
|
|
|
250
250
|
❌ 未通过:见上方违规明细(error 级 = 会话不可读/不可写)
|
|
251
251
|
```
|
|
@@ -268,21 +268,29 @@ when the host cannot judge the file.
|
|
|
268
268
|
**Tail-completeness boundary**: `ok=true` only certifies that *the events actually
|
|
269
269
|
read* are self-consistent — see the `tailStatus` note in the 0.3.28 section above.
|
|
270
270
|
|
|
271
|
+
**Report structure versioning (`schemaVersion`)**: every `check --json` report
|
|
272
|
+
carries a top-level `schemaVersion` (currently `"1"`) that versions the **report
|
|
273
|
+
structure** itself — field set / types / meanings — not the tool version and not
|
|
274
|
+
the log format version. Within one version, reports are additive only (existing
|
|
275
|
+
top-level keys are never removed, renamed or redefined); a report **without** the
|
|
276
|
+
field is to be read as `"1"`. Full compatibility promise and bump rules:
|
|
277
|
+
[docs/interface-versioning.md](./docs/interface-versioning.md).
|
|
278
|
+
|
|
271
279
|
`check` adds **W1/W2 wire-level checks** since 0.2.0: expand the model request
|
|
272
280
|
stream in surface order and catch "dangling tool messages" (a tool result with no
|
|
273
281
|
preceding assistant tool_calls) and "user text between tool_calls and their
|
|
274
282
|
results" — tolerated by some endpoints, `INVALID_REQUEST` on strict ones
|
|
275
|
-
(MiMo, verified
|
|
283
|
+
(MiMo, verified 2026-08-27).
|
|
276
284
|
|
|
277
285
|
### 2. Repair (`fix`)
|
|
278
286
|
|
|
279
287
|
```bash
|
|
280
288
|
# Dry run (report only): strict seq scan + full contract check + removable-marker count
|
|
281
|
-
dsh-log-contract fix
|
|
289
|
+
dsh-log-contract fix ~/.dsh/sessions/<id>.jsonl.zstd --remove-markers
|
|
282
290
|
|
|
283
291
|
# Apply: backup first, then write (.zstd rebuilt in official frame format: frame1=header,
|
|
284
292
|
# frame2=rest, checksum, single trailing newline)
|
|
285
|
-
dsh-log-contract fix
|
|
293
|
+
dsh-log-contract fix ~/.dsh/sessions/<id>.jsonl.zstd --remove-markers --apply
|
|
286
294
|
```
|
|
287
295
|
|
|
288
296
|
- `--remove-markers`: remove retrace/message-editor markers and renumber everything
|
|
@@ -305,7 +313,7 @@ dsh-log-contract fix [path]<id>.jsonl.zstd --remove-markers --apply
|
|
|
305
313
|
|
|
306
314
|
```jsonc
|
|
307
315
|
// Append one event to the log tail (seq omitted = auto-assigned as nextSeq)
|
|
308
|
-
{ "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start":
|
|
316
|
+
{ "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": 121774, "end": 156421 }, "sourceEventSeqs": [121774, 121779, "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": 156430, "text": "…" } } } }
|
|
309
317
|
|
|
310
318
|
// Frame-level surgery: the complete event list after the edit (both baseline and
|
|
311
319
|
// result must be green before it may land)
|
|
@@ -313,7 +321,7 @@ dsh-log-contract fix [path]<id>.jsonl.zstd --remove-markers --apply
|
|
|
313
321
|
```
|
|
314
322
|
|
|
315
323
|
```bash
|
|
316
|
-
dsh-log-contract prewrite marker-write.json --log
|
|
324
|
+
dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>.jsonl.zstd
|
|
317
325
|
```
|
|
318
326
|
|
|
319
327
|
- A baseline with error-level violations is rejected outright (safety protocol
|
|
@@ -364,8 +372,8 @@ if (!baseline.ok) throw new Error('baseline is broken; repair it first');
|
|
|
364
372
|
const prewriter = createPreWriter({ events: log.events.map((e) => e.event) });
|
|
365
373
|
const verdict = prewriter.validateAppend({
|
|
366
374
|
type: 'assistant/message',
|
|
367
|
-
surfaceOp: { op: 'replace', start:
|
|
368
|
-
sourceEventSeqs: [
|
|
375
|
+
surfaceOp: { op: 'replace', start: 121774, end: 156421 },
|
|
376
|
+
sourceEventSeqs: [121774, 121779 /* …must fully cover shadowed nodes… */],
|
|
369
377
|
data: { turn: null, step: null, message: { /* … */ } },
|
|
370
378
|
});
|
|
371
379
|
if (!verdict.ok) {
|
|
@@ -394,6 +402,8 @@ pnpm check && pnpm test # syntax check + contract-doc drift gate + all unit t
|
|
|
394
402
|
without a control, and a control cannot reference a rule that was never
|
|
395
403
|
registered.
|
|
396
404
|
|
|
405
|
+
> The dev gate `scripts/check-tag-surface.mjs --json` also reports `clean` (the compliant tag list, mutually exclusive with `violations`), so "green" on the tag surface is an explicit list — not merely an empty `violations` array.
|
|
406
|
+
|
|
397
407
|
> **Scope of the published package**: it contains the runtime code and documentation only.
|
|
398
408
|
> Local maintainer tooling is not part of the public repository, so `pnpm check` and `pnpm test`
|
|
399
409
|
> work from a clean clone.
|
|
@@ -448,12 +458,12 @@ Rule count: 51 → 55.
|
|
|
448
458
|
Session format **v4** (host `dsh-session` 0.2.x) is supported by version dispatch (`tool/result` role,
|
|
449
459
|
`system/message` source); five rules were added (`G4` unknown-but-ignorable events, `S10` reference element
|
|
450
460
|
types, `I2` `seedLength` semantics, `P5` carrier pairing, `A1` structured-only in-place restorability);
|
|
451
|
-
large sessions (>
|
|
461
|
+
large sessions (> 500 MB) are read line-wise and repaired with streaming frames; the Windows absolute-path
|
|
452
462
|
check for `H2` is platform-aware. still **partial** — see the changelog's known-gap list). Verdicts, exit codes and `--json` fields are unchanged.
|
|
453
463
|
|
|
454
464
|
> **0.3.17 changes no behaviour.** It only adjusts the wording of comments, test titles, a few
|
|
455
465
|
> diagnostic strings and the README. Every verdict, exit code and `--json`
|
|
456
|
-
> field is unchanged from 0.3.
|
|
466
|
+
> field is unchanged from 0.3.15, so everything below applies unchanged when going from 0.3.12 to 0.3.17.
|
|
457
467
|
>
|
|
458
468
|
> 0.3.15 was a documentation-only release as well.
|
|
459
469
|
|
|
@@ -490,7 +500,7 @@ Read `coverage.uncovered` for the known gaps.
|
|
|
490
500
|
- [x] **Phase 1.5 (0.2.0)**: `fix` subcommand (strict seq scan + W1/W2 wire checks +
|
|
491
501
|
marker removal with renumbering + official frame rebuild); CI integration
|
|
492
502
|
(`dsh-log-contract check` as a scheduled guard over the Harness session dir)
|
|
493
|
-
- [x] **0.3.x (
|
|
503
|
+
- [x] **0.3.x (2026-08-30 case hardening)**: T1 token-meter pairing → 0.3.1 W1/W2
|
|
494
504
|
fold-position fix → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize` (in-place
|
|
495
505
|
turn-null neutralization) → 0.3.4 `fix --clip-crossstep` (cross-step clipping) →
|
|
496
506
|
0.3.5 **T2/S9/I1 rules** (cross-step source refs / physical order / inbox replay)
|
package/README.zh.md
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
- **`check --resume`** —— 三档结论(`loadable` / `resumable` / `compactable`,宿主判不了时另有 `not-assessable`)。
|
|
29
29
|
- **`fix` / `extract` / `audit-report`** —— 修复原语 + 只读会话考古。
|
|
30
30
|
|
|
31
|
-
**能力一览**:会话格式 **v0–v4** · 契约规则 **
|
|
31
|
+
**能力一览**:会话格式 **v0–v4** · 契约规则 **57 条** · 退出码契约 `0/1/3/4` · 三档结论 ·
|
|
32
32
|
写前校验 · 每条规则都有负对照用例 + 规则自检 · 读取容错(单文件损坏降级为结构化结果并计数,不抛出)。
|
|
33
33
|
|
|
34
34
|
---
|
|
@@ -58,7 +58,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
58
58
|
---
|
|
59
59
|
|
|
60
60
|
## 三层契约(判定模型)
|
|
61
|
-
>
|
|
61
|
+
> 57 条规则,覆盖以下各层(`contracts` 列出全部,每条附官方源码出处)。
|
|
62
62
|
|
|
63
63
|
| 层 | 规则 | 守护什么 |
|
|
64
64
|
|---|---|---|
|
|
@@ -80,7 +80,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
80
80
|
|---|---|---|
|
|
81
81
|
| 宿主包 | `@deepseek-ai/dsh-session@0.2.0-rc.2` | 本规则集开发与 CI 验证所用的版本(CI 跑 `pnpm check` + `pnpm test`;`prepublishOnly` 四步在本机该版本上全绿) |
|
|
82
82
|
| 会话格式 | **v4**(`SESSION_FORMAT_VERSION = 4`) | v4 走运行时词表 + 官方 `foldSurface` 终验 |
|
|
83
|
-
| 声明范围 | `peerDependencies: ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1` | 允许安装;**范围内不等于逐个验证过** |
|
|
83
|
+
| 声明范围 | `peerDependencies: ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.1.7-rc.2 || ^0.2.0-rc.1` | 允许安装;**范围内不等于逐个验证过** |
|
|
84
84
|
| 已知格式 | 0 / 1 / 2 / 3 / 4 | 0–2 由本包**自带** vendored 词表 + 本地等价折叠(`legacyFoldSurface`)支持,与宿主版本无关 |
|
|
85
85
|
|
|
86
86
|
**未验证的版本会发生什么(运行时检测并报告,不闷着按旧规则判)**:
|
|
@@ -98,7 +98,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
98
98
|
|
|
99
99
|
```
|
|
100
100
|
版本支持:宿主 @deepseek-ai/dsh-session@0.2.0-rc.2(基线 0.2.0-rc.2,baseline) | 文件格式 v4(header,baseline)
|
|
101
|
-
测试基线:@deepseek-ai/dsh-session@0.2.0-rc.2 | 会话格式 v4(已知 0/1/2/3/4;peer ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1)
|
|
101
|
+
测试基线:@deepseek-ai/dsh-session@0.2.0-rc.2 | 会话格式 v4(已知 0/1/2/3/4;peer ^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.1.7-rc.2 || ^0.2.0-rc.1)
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
## 🆕 0.3.28 · 读取容错 / 尾部完整性 / seq 来源
|
|
@@ -129,10 +129,10 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
129
129
|
|
|
130
130
|
- `tool/result` 按 v4 形状校验(`role: 'tool'`、无 `tool-result` 包裹块)
|
|
131
131
|
- `system/message` 接受 v4 的 `source.kind: 'system-prompt'`
|
|
132
|
-
- **v3
|
|
132
|
+
- **v3 及更早的判据零改动**(多份真实语料 v3 会话前后判定完全一致)
|
|
133
133
|
- 格式闸门仍**拒绝未知的未来版本**(`readOnly`);v5+ 按设计保持"不可评估"
|
|
134
134
|
|
|
135
|
-
**规则(0.3.28
|
|
135
|
+
**规则(0.3.28 起 55 条;0.3.32 起 57 条)**:下表五条是 0.3.18 – 0.3.24 窗口新增
|
|
136
136
|
(0.3.28 新增的四条见上一节):
|
|
137
137
|
|
|
138
138
|
| 规则 | 判据 |
|
|
@@ -143,35 +143,35 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
143
143
|
| `P5` | 两段 carrier 配对:第 2 段首元素 = 第 1 段 seq(读侧兼容早期写法) |
|
|
144
144
|
| `A1` | 「在位可还原」**只认结构化字段**(`archiveRef`/`archive`/`externalized.*`),不从自由文本推断 |
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
**大会话**:读取改为**按行解码**(不再整文件字符串化 ⇒ 约 536MB 以上不再抛 `ERR_STRING_TOO_LONG`);
|
|
147
147
|
修复采用**流式帧重建** `.jsonl.zstd`(header 帧 + 正文分块多帧,逐帧 checksum + roundtrip 校验)。
|
|
148
148
|
|
|
149
149
|
**Windows**:`H2` 的 `header.cwd` 绝对路径判断改为**平台感知**(`win32` 与 `posix` 都认)。
|
|
150
150
|
|
|
151
|
-
**兼容性**:Node ≥ 22;`@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1`;会话格式 v0–v4。
|
|
151
|
+
**兼容性**:Node ≥ 22;`@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.1.7-rc.2 || ^0.2.0-rc.1`;会话格式 v0–v4。
|
|
152
152
|
|
|
153
153
|
## 案例记录 ——「生产级保证」不是口号
|
|
154
154
|
下面每一条都来自**生产会话中实际出现的日志损坏形态**——正是这些案例促成了本工具。日期与形态真实,会话 id 与文件名省略。
|
|
155
155
|
|
|
156
156
|
| # | 日期 | 发生了什么 | 产出的规则/修复 |
|
|
157
157
|
| --- | --- | --- | --- |
|
|
158
|
-
| 1 |
|
|
159
|
-
| 2 |
|
|
160
|
-
| 3 |
|
|
161
|
-
| 4 |
|
|
162
|
-
| 5 |
|
|
163
|
-
| 6 |
|
|
164
|
-
| 7 |
|
|
165
|
-
| 8 |
|
|
166
|
-
| 9 |
|
|
167
|
-
| 10 |
|
|
168
|
-
| 11 |
|
|
169
|
-
| 12 |
|
|
170
|
-
| 13 |
|
|
171
|
-
| 14 |
|
|
172
|
-
| 15 |
|
|
173
|
-
| 16 |
|
|
174
|
-
| 17 |
|
|
158
|
+
| 1 | 2026-08-25 | 一次「恢复被隐藏内容」的修复写了**清空 `sourceEventSeqs`** 的 replace marker → 会话加载被拒(`SessionPersistenceCorruptionError`);第二次尝试把 marker 改成 **append** → 客户端引擎崩溃。两次都是**违约写入没被拦**。 | **S5**(sourceEventSeqs 必须覆盖被替换节点)、**M1**(turn-null 的 assistant/message 只能 replace)、写前校验 |
|
|
159
|
+
| 2 | 2026-08-27~28 | 中断/暂停的轮次恢复时按**过期内存光标**重放,把旧 seq 追加到文件尾(尾部回归、重复批次);两个写入者交织 → **文件物理序非单调**(`734056 → 733539 → 735470`)。会话 `seq gap` 加载失败。 | **S9**(物理序单调)、fix `--tail-renumber` |
|
|
160
|
+
| 3 | 2026-08-27~28 | **fork 边界孤儿 spliced**:fork 的「移除父待处理提示词」splice 假设父会话 inbox;子会话 seed 相对重放里 inbox 为空 → `resume failed: invalid persisted inbox splice`。 | **I1**(inbox seed 相对重放)、fix `--neutralize-orphan` |
|
|
161
|
+
| 4 | 2026-08-28 | 超限会话(**1,052,557 tokens** vs 1M 窗口)既无法继续也无法 `/compact`;裁剪预算估算对中文低估 ~3.7×。 | T1(token-meter 配对,保障可压缩)、`fix --trim-budget` 预算指引 |
|
|
162
|
+
| 5 | 2026-08-29 | **W1/W2 wire 违规**:marker 遮蔽了带 tool_calls 的 assistant 但漏盖 tool 结果 → 悬空 tool,严格端点 `INVALID_REQUEST` 拒绝请求流。 | **W1 / W2**(wire 消息流) |
|
|
163
|
+
| 6 | 2026-08-30 | 单个 **turn-null marker** 让 token-meter 监听器在**每条**追加事件上抛错(`consumedEvents` 不前进 → 每事件全前缀重折)→ **30 秒 / 10,008 行日志**、host 事件循环被压垮、全部会话锁定。同会话还有**跨 step sourceEventSeqs**(step 7/8/9 混进一条 assistant 消息)——离线 check 全绿、实机 meter 崩溃。 | **T1**(turn/step 配对)、**T2**(跨 step 源引用)、`fix --neutralize`、`fix --clip-crossstep` |
|
|
164
|
+
| 7 | 2026-08-31 | 日志被压成**单个 zstd 帧**(或 header 未单独成帧)→ 不同读取器对记录边界理解不一致 ⇒ **Z4/Z5** 帧形状规则(首帧必须恰好一行 header;正文分帧) | |
|
|
165
|
+
| 8 | 2026-08-31 | **尾帧在写入中被撕裂**的日志完全无法加载、且没有诊断 ⇒ **Z1** + 明确报「尾帧撕裂 / 写入中」 | |
|
|
166
|
+
| 9 | 2026-09-09 | **会话格式 v4** 下 `tool/result` 改用 `role:'tool'`、`system/message` 带 `system-prompt` 来源 → v3 语义的检查在**健康 v4 日志**上产出**数千条误报** ⇒ 版本分派 + **E6/E9** v4 语义 | |
|
|
167
|
+
| 10 | 2026-09-17 | **Windows** 上 `header.cwd` 用 POSIX 规则判定 → **所有**会话被 **H2** 误报 ⇒ 平台感知的绝对路径判定 | |
|
|
168
|
+
| 11 | 2026-10-20 | **超过 500MB 的会话**让读取器崩溃(`ERR_STRING_TOO_LONG`),修复时又把全文拼进内存 ⇒ 按行解码 + 流式帧重建 | |
|
|
169
|
+
| 12 | 2026-10-20 | 两段式载体引用有的把「审计段」写在前面、早期约定从区间起点开始 → 读取侧报出**数百个假孤儿载体** ⇒ **P5** 写侧成对 + 读侧容错 | |
|
|
170
|
+
| 13 | 2026-10-20 | `seedLength` 被部分消费方当作**字节数**(其语义是「继承事件条数」),且 `parentSession` 配缺失/0 被当成损坏 ⇒ **I2** 语义钉死 | |
|
|
171
|
+
| 14 | 2026-10-20 | 一种**未知但显式可忽略**的事件类型让整条迁移卡死 ⇒ **G4** 声明式跳过 + 白名单 | |
|
|
172
|
+
| 15 | 2026-10-26 | 一个**截断 zstd 帧**让会话读头抛 `ERR_OUT_OF_RANGE`,而聚合循环没有逐项隔离 ⇒ 整个枚举/汇总能力失败(33 天内数百次)——**单文件损坏 ⇒ 整表失败** | **R4**(读取容错:降级为结构化、可计数结果)、**R5**(聚合 API 逐项隔离 + 失败计数) |
|
|
173
|
+
| 16 | 2026-10-26 | **最后一帧写入中被切**的文件仍报 `ok=true`——体检只认证已读到的事件 | **Z6**(`tailStatus: complete/interrupted/truncated/unknown`)+ 明示口径边界 |
|
|
174
|
+
| 17 | 2026-10-26 | 生产者**写侧自造 seq**、以及**删行不重编号** | **E11**(seq 由日志层分配;写前拒绝自造 seq)、缺口痕迹钉到 `E2`/`S9` |
|
|
175
175
|
|
|
176
176
|
|
|
177
177
|
> **结论**:这些规则不是合成理论——每一条都有回归测试复现它守护的那种损坏形态。这就是这里「生产级」的含义。
|
|
@@ -199,19 +199,19 @@ pnpm dlx dsh-log-contract --help
|
|
|
199
199
|
### 1. 离线体检
|
|
200
200
|
|
|
201
201
|
```bash
|
|
202
|
-
dsh-log-contract check
|
|
203
|
-
dsh-log-contract check
|
|
202
|
+
dsh-log-contract check ~/.dsh/sessions/<id>.jsonl.zstd
|
|
203
|
+
dsh-log-contract check ~/.dsh/sessions/<id>.jsonl.zstd --json # 机器可读
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
输出示例:
|
|
207
207
|
|
|
208
208
|
```
|
|
209
209
|
📋 dsh-log-contract check —— backup-session-xxxx.jsonl.zstd
|
|
210
|
-
事件
|
|
210
|
+
事件 204754 | surface 节点 16 | replace 代数 5 | 帧 8620(3439.5KiB → 8191.3KiB)
|
|
211
211
|
违规 1(error 1 / warning 0)
|
|
212
212
|
|
|
213
213
|
[error] S5 @ seq <seq> / line <line> (assistant/message)
|
|
214
|
-
surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失
|
|
214
|
+
surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 121774, 121779(共 2 个)
|
|
215
215
|
|
|
216
216
|
❌ 未通过:见上方违规明细(error 级 = 会话不可读/不可写)
|
|
217
217
|
```
|
|
@@ -234,16 +234,16 @@ dsh-log-contract check [path]<id>.jsonl.zstd --json # 机器可读
|
|
|
234
234
|
`check` 自 0.2.0 起新增 **W1/W2 wire 级检查**:按 surface 顺序展开模型请求消息流,
|
|
235
235
|
捕获"悬空 tool 消息"(tool 结果没有前置 assistant tool_calls)与"user 文本插在
|
|
236
236
|
tool_calls 与其结果之间"——这类问题 DeepSeek 曾容忍,但 MiMo 等严格端点会直接
|
|
237
|
-
`INVALID_REQUEST`(
|
|
237
|
+
`INVALID_REQUEST`(2026-08-27 实锤)。
|
|
238
238
|
|
|
239
239
|
### 2. 修复(`fix`)
|
|
240
240
|
|
|
241
241
|
```bash
|
|
242
242
|
# 干跑(只报告):严格 seq 连续扫描 + 全契约体检(含 W1/W2)+ 可移除 marker 数
|
|
243
|
-
dsh-log-contract fix
|
|
243
|
+
dsh-log-contract fix ~/.dsh/sessions/<id>.jsonl.zstd --remove-markers
|
|
244
244
|
|
|
245
245
|
# 应用:备份后落盘(.zstd 走官方帧格式重建:帧1=header、帧2=其余、checksum、单个结尾换行)
|
|
246
|
-
dsh-log-contract fix
|
|
246
|
+
dsh-log-contract fix ~/.dsh/sessions/<id>.jsonl.zstd --remove-markers --apply
|
|
247
247
|
```
|
|
248
248
|
|
|
249
249
|
- `--remove-markers`:移除 retrace/message-editor marker 并全量重编号
|
|
@@ -262,14 +262,14 @@ dsh-log-contract fix [path]<id>.jsonl.zstd --remove-markers --apply
|
|
|
262
262
|
|
|
263
263
|
```jsonc
|
|
264
264
|
// 拟追加一个事件到日志尾部(seq 缺省 = 自动按 nextSeq 赋值)
|
|
265
|
-
{ "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start":
|
|
265
|
+
{ "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": 121774, "end": 156421 }, "sourceEventSeqs": [121774, 121779, "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": 156430, "text": "…" } } } }
|
|
266
266
|
|
|
267
267
|
// 帧级手术后的完整事件列表(改后确认,与改前基线双绿才允许落盘)
|
|
268
268
|
{ "edit": [ "…完整事件列表…" ] }
|
|
269
269
|
```
|
|
270
270
|
|
|
271
271
|
```bash
|
|
272
|
-
dsh-log-contract prewrite marker-write.json --log
|
|
272
|
+
dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>.jsonl.zstd
|
|
273
273
|
```
|
|
274
274
|
|
|
275
275
|
- 基线本身有 error 级违规时直接拒绝校验(安全修复协议第 2 步:**改前基线必须绿**)。
|
|
@@ -316,8 +316,8 @@ if (!baseline.ok) throw new Error('基线已坏,先修基线');
|
|
|
316
316
|
const prewriter = createPreWriter({ events: log.events.map((e) => e.event) });
|
|
317
317
|
const verdict = prewriter.validateAppend({
|
|
318
318
|
type: 'assistant/message',
|
|
319
|
-
surfaceOp: { op: 'replace', start:
|
|
320
|
-
sourceEventSeqs: [
|
|
319
|
+
surfaceOp: { op: 'replace', start: 121774, end: 156421 },
|
|
320
|
+
sourceEventSeqs: [121774, 121779 /* …必须完整覆盖被替换节点… */],
|
|
321
321
|
data: { turn: null, step: null, message: { /* … */ } },
|
|
322
322
|
});
|
|
323
323
|
if (!verdict.ok) {
|
|
@@ -385,7 +385,7 @@ git config --get core.hooksPath # 验证:应输出 .githooks
|
|
|
385
385
|
|
|
386
386
|
**会话格式 v4**(宿主 `dsh-session` 0.2.x)改为按版本分派判定(`tool/result` 的 role、`system/message` 的来源);
|
|
387
387
|
新增五条规则(`G4` 未知但可忽略事件、`S10` 引用元素类型、`I2` `seedLength` 语义、`P5` 载体配对、`A1` 只认结构化字段的在位可还原);
|
|
388
|
-
|
|
388
|
+
大会话(>500MB)按行读取 + 流式帧重建;Windows 的 `header.cwd` 判定改为平台感知。
|
|
389
389
|
> **0.3.17 不含行为变更。** 它只调整了注释、测试标题、少量诊断文案与 README 的措辞。
|
|
390
390
|
> 所有判定结果、退出码与 `--json` 字段与 0.3.15 完全一致,
|
|
391
391
|
> 因此从 0.3.12 升到 0.3.17 时,下面各条与原来完全一致。
|
|
@@ -419,7 +419,7 @@ git config --get core.hooksPath # 验证:应输出 .githooks
|
|
|
419
419
|
## Roadmap
|
|
420
420
|
- [x] **Phase 1(0.1.0)**:CLI 离线体检 + 写前校验 + 契约目录
|
|
421
421
|
- [x] **Phase 1.5(0.2.0)**:`fix` 子命令(严格 seq 扫描 + W1/W2 wire 检查 + 移除 marker 重编号 + 官方帧格式重建);CI 集成(`dsh-log-contract check` 作为 Harness 会话目录的定时守护)
|
|
422
|
-
- [x] **0.3.x(
|
|
422
|
+
- [x] **0.3.x(2026-08-30 案例固化)**:T1 token-meter 配对 → 0.3.1 W1/W2 折叠位置修复 → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize`(turn-null marker 原地中和)→ 0.3.4 `fix --clip-crossstep`(跨 step 引用裁剪)→ 0.3.5 **T2/S9/I1 规则**(跨 step 源引用 / 物理序单调 / inbox 重放)
|
|
423
423
|
- [x] **0.3.6 → 0.3.15**:按被检文件版本择路的 v0–v3 规则(T3/T4/T5、L3–L5、E8/E9/E10)、宿主能力与迁移预检的退出码 `3`/`4`,以及如实报告"哪些版本**未**验证"的版本支持说明(详见 [CHANGELOG.md](CHANGELOG.md))
|
|
424
424
|
- [ ] Phase 2:运行时守护(订阅 session append 事件流实时校验,断裂即标记 `dsh/contract-violation` 事件,策略可配 告警/拦截)——DSH 插件形态
|
|
425
425
|
- [ ] Phase 3:与 dsh-turn-guard / dsh-retrace 时间线联动
|