Repository navigation
Replies: 12 comments 1 reply
|
这是今天第四个独立的会话日志损坏报告——和前三个(#1333 / #1452:跨进程并发写导致 seq 段重复;#1473:损坏的首个 zstd 帧导致整个 workspace 无法启动)同属一个家族,但机制不同:你的案例是"非正常退出 → 已提交的事件被重放"(replayed committed events),而不是并发写。感谢你把行级证据表列得这么清楚。 与你行级表的对照(源码)你的表里 seq 序列:
与 #1452 的差异确认
两者都表现为"committed region 内 seq 不连续/回退",但修复点不同:你的指向 write-behind 恢复逻辑的水位推进(恢复时应从持久化的最后一条 seq+1 继续,而不是从内存游标),#1452 指向跨进程 append 加锁。 关于你的建议
给维护者的统一建议今天的四个报告(#1333/#1452/#1473/#1497)已经覆盖了会话日志损坏的四种路径(并发写、重放、坏帧、emoji 中毒)。值得在 rc 阶段(
如果需要,我可以把四个帖子的证据整理成一份完整的 feature request 草案,方便维护者直接跟进。 |
|
和 #1473 同族(单条损坏日志拖垮 boot)——非正常退出导致 replay events seq gap,历史不可恢复。 临时处理:#1473 的 workaround 一样适用(移走异常 session 日志再启动);这类"日志损坏恢复"我们第 8 章会话管理记了排查路径:https://github.com/Electricitysheep/dsh-handbook/blob/main/docs/08-tools-context.md |
|
Thanks for the precise writeup - the backward seq jump from replayed committed events is exactly the corruption class our loader check now catches offline. I added a read-only seq-integrity scan to https://github.com/boyin111-1/dsh-doctor (check 14, runs via 'dsh-doctor --session '): it decompresses the log and walks every event's seq against its index, reporting the first gap/duplicate/rewind with line numbers and expected-vs-got values - the same rule SessionLogScanner.consumeEventLine uses to reject the log. So before opening a session you can tell whether it is corrupted and where. It also covers the sibling reports from forced compaction leaving seq holes (#1469, which we confirmed: 1,415 holes in 88,700 lines) and concurrent writers colliding seq numbers (#1433/#1452/#1586). The scan is purely read-only - it never rewrites the log, it just tells you whether the loader will reject it and where to look. |
|
官方加载器拒读之后,磁盘上的 https://github.com/xiaoshenming/dsh-session-surgeon 默认 dry-run; git clone https://github.com/xiaoshenming/dsh-session-surgeon.git
cd dsh-session-surgeon
dsh plugin --profile web add link:"$(pwd)"重启 |
|
补充一下安装:不必 git clone,和其他插件一样一条命令即可。 dsh plugin --profile web add "github:xiaoshenming/dsh-session-surgeon#main"然后重启 |
Another confirmed instance — resume-after-interrupt re-allocates already-committed seqs (dsh-plugin-desktop 2.0.3)Same failure class as this discussion, with precise evidence from the log itself. Environment
SymptomOpening the session's history fails with: The session never loads again; every attempt throws the same error. Root cause (evidence from the log)The log (21,505 physical lines; 263,414 events) contains two different event batches
Batch B then continues normally at 212297+ (reasoning chunks, steps 34…41, Interpretation:
The reader ( Writer–reader contract violation: whatever in-memory counter the resume path uses must Reproduction sketch
Workaround (validated)Drop the 4 stale rows of Batch A (placeholder (The community tool https://github.com/xiaoshenming/dsh-session-surgeon targets the Suggested fixes
Sanitized seq/type/time table available on request; the log itself contains private |
|
Hi — same bug here. Two pieces of good news: a read-side tolerance patch that makes the readers accept these recovery pairs (no file surgery at all), and a zero-install CLI that repairs an already-broken log in one command. Since dsh-session-surgeon by @xiaoshenming already covers file-level repair (see his comment above — dry-run +
SymptomsAfter a crash + recovery on the same session, the persisted log contains a "recovery pair" — the After that point all seqs are contiguous again. But the readers refuse the whole log:
Fix (two rules in
|
| Reader | Result (17 sessions) |
|---|---|
| 0.1.1-rc.2 (npm latest, unpatched) | 15 READ-OK, 1 SEQ_FAIL, 1 PROV_RANGE |
| 0.1.2-alpha.1 (unpatched source) | 16 OK, 1 seq-anomaly session read but truncated |
| 0.1.1-rc.2 + this patch | 16 READ-OK, SEQ_FAIL → recovered, 0 seq issues left |
The single SEQ_FAIL is exactly the recovery-pair shape (seq 886745, expected 886746 at the duplicate row) and the patch recovers it 100%. The single PROV_RANGE is a session written by 0.1.2-alpha.1 whose sourceEventSeqs uses range encoding ([[15,460]], e.g. assistant/message at seq 461) which the 0.1.1-rc.2 validator rejects — a separate cross-version format concern (and one the 0.1.2 reader itself handles fine), not part of the seq-gap fix above.
Small sample, but the patch is also defensive: any future crash+recovery pair is tolerated the same way, so a user never has to edit or migrate a log again. True holes (a real seq > expected jump) and physical corruption still refuse — by design.
Note this is a defensive read-side fix — the write-side watermark bug that produces these pairs is untouched, so the reader may still have to tolerate further pairs after future crashes. But no user data is ever lost.
Patch
Against packages/session/session-persistence-jsonl/src/format.ts at v0.1.2-alpha.1:
@@ -396,6 +396,26 @@ export class SessionLogScanner {
for (const event of decoded) {
if (event.seq !== this.events.length) {
const expected = this.events.length
+ if (event.seq === expected - 1) {
+ const prev = this.events[this.events.length - 1]
+ if (prev && prev.type === 'session/end-seed' && event.type !== 'session/end-seed') {
+ // Crash-recovery pair: the first replayed event shares the end-seed's seq.
+ // Collapse the duplicate end-seed row so the restored seed stays contiguous
+ // from seq 0 (restore validation requires it), while the duplicate splice
+ // row keeps the index slot the inbox projection needs to consume the full
+ // splice order (discussions #1497).
+ this.events.pop()
+ this.events.push(event)
+ console.warn(`dsh-session-persistence-jsonl: accepting end-seed recovery pair, seq ${event.seq} at line ${this.eventLine}`)
+ continue
+ }
+ }
+ if (event.seq < expected) {
+ // Replayed committed event (discussion #1497): skip the replay row instead
+ // of refusing the whole log, so one crash cannot permanently hide history.
+ console.warn(`dsh-session-persistence-jsonl: skipping replayed event seq ${event.seq} at line ${this.eventLine}`)
+ continue
+ }
this.events.length = rowStart
this.issue = new Error(
`corrupt session log: seq gap in committed region at line ${this.eventLine} `
Second confirmed instance, 2 days apart — different shape: full tail rewrite from a recycled seq (dsh-plugin-desktop 2.0.3)Following up on my comment above with a second occurrence in a different project. This one pins the EnvironmentSame app ( Timeline (observed live, from process start times + file mtimes)
Shape of the corruption (different from the first case)
Notably this case had no pending tool call — the turn was interrupted right after Repair (validated)Dropped the 3 stale closers, kept the rewritten tail, recompressed (header frame alone in frame 1, What this adds to the diagnosis
Sanitized seq/type/time tables for both cases available on request; the logs contain private |
|
Thanks @xiaoshenming @boyin111-1 @MedicineKing for the tooling. I cross-validated both tools against the original corrupted log from this report (backup still on disk) and the results are solid:
Two small findings from the Windows side:
Thanks again for turning this family of reports into reusable tooling. |
|
Late to this thread, adding one more option for the record since it takes a different route from the tools above. dsh-session-rescue repairs the file in place rather than teaching the reader to tolerate the overlap, so the stock loader accepts the result afterwards: |
|
Adding one more option to the toolbox record — from the diagnosis side rather than the repair side. @argszero/cordis-plugin-session-audit is a proactive completeness audit: it never modifies a log, it classifies the full corruption surface before you choose a repair path ( Where it maps onto your repair decisions:
The gap is symmetric and honest: your One workflow suggestion for the record (mirroring qls-cyber's cross-validation): run an audit before and after a repair and attach both classifications — it turns "repair succeeded" into a machine-checkable claim (gap class gone, contiguity restored) instead of relying on the loader accepting the file. |
|
跨帖引用一条不同触发路径的同类案例:离线工具改写日志,而不是运行时中断/续跑。 和这里讨论的序列都不同,我一共踩到三个变体:
第 3 条在本讨论、#255/#333/#420/#496 里都没出现过,是第三层校验,而前面那些帖子覆盖的是帧结构和 seq 两层。 另一个用户体验层面的发现,可能对维护者有用:读取端只报最外层失败的那一层。我修完帧边界以为完事了,重启后又冒出 messageSeqs 的错,来回了三趟。如果第一次报错就能列出「这份日志共有 N 处问题、分属哪几层」,用户能少走两趟重启。这点和 @theoabw 提到的「 另外补一句给做工具的朋友:这次的三个变体里,只有帧边界那批属于「数据没丢、只是容器不对」,重新分帧即可(12 个会话全部无损恢复);seq 撞车和 messageSeqs 两类不能套用「跳过重复行」的读端容错——前者同号两条内容不同,跳过会导致内容错位。这条边界和 @qls-cyber 说的「对手工选边保守拒绝」一致,建议保持严格。 (日志含私人对话,脱敏后的行级证据可在 #10440 里按需提供。) Cross-reference: a different trigger path for the same failure family — offline tooling rewriting the log, not runtime interrupt/resume. Full report in #10440. Three variants hit: (1) seq collision from a title-backfill script computing Notable UX finding: the reader only surfaces the outermost failing layer, so fixing one reveals the next (cost me three restart cycles). A single error listing all detected issues across layers would help. Tool authors: only the frame-boundary variant is "container wrong, data intact" (12 sessions recovered losslessly by reframing). Seq-collision and messageSeqs variants cannot use the skip-duplicate read-side tolerance — in variant (1) the two same-seq rows carry different content, so skipping would misalign the stream. Agree with keeping those strict. |
Uh oh!
There was an error while loading. Please reload this page.
dsh version: v0.1 developer preview (npm
@deepseek-ai/dsh, installed 2026-08-14)OS: Windows 11 (win32, Git Bash environment)
Entry point:
npx @deepseek-ai/dsh webSymptom
The Web UI refuses to load an existing session and shows:
The session cannot be resumed at all.
Root cause (analyzed from the session log)
The session log (
~/.dsh/sessions/<project>/session-<id>/session.jsonl.zstd, multi-frame zstd JSONL) shows the following sequence around the corruption point:What appears to happen:
session/end-seedat seq 46783 is committed.expected 46784, got 46780) rejects the entire log.Expected behavior
On restart, dsh should resume the event sequence from the last committed seq + 1 (i.e. 46784), or detect that these events are already committed and skip re-appending them. A single unclean exit should not permanently corrupt the session history.
Workaround (manual)
I was able to recover the session by decompressing the log, deleting the 4 stale replayed lines (the old copies at lines 2585-2588, keeping the newer replayed versions), and repacking the file with the same multi-frame zstd layout (frame 0 = header line only). After that the session loads normally.
Suggestion
Happy to provide the corrupted
session.jsonl.zstd(before/after repair) privately if that helps debugging.All reactions