Repository navigation
Replies: 7 comments
Follow-up: a community "bounded cold-history reads" patch already exists — here's how it maps to this roadmapWhile checking #1550, I found that @ernel135790 posted a bounded cold-history reads patch (2026-08-23) that implements a large part of this roadmap's short-term items. Worth aligning explicitly so the discussion doesn't fork into parallel proposals: What the patch covers (vs. roadmap items)
What the patch adds beyond our roadmap
My takeThe patch is a solid memory-bound solution for the short term. The remaining gap is exactly roadmap A's second half: without a persistent frame/message index, every cold open still decodes the whole artifact (CPU/IO-bound, just not memory-bound) — which is what makes a 460K-event session take ~9s even after this patch. So the natural next step after adopting (or cherry-picking) this patch is the index sidecar, plus B (frame merging) to shrink the decode surface further. Would be great to hear from the maintainers whether |
|
感谢点名。划一下边界,避免路线图和离线修文件搅在一起: dsh-session-surgeon 不改 大会话但 health= |
|
Thanks @xiaoshenming for the clear boundary — and for confirming that healthy-but-large sessions belong on the bounded-read path rather than file surgery. That's exactly the split this post intends:
One small overlap worth noting: your loopback "scan header first" approach is conceptually the same trick as roadmap item E (session-list header cache) and argszero's "detect corruption at the cheap scan" — scanning metadata before touching the full artifact. If the maintainers adopt a bounded-read API, your surgeon could also reuse Either way, no |
一条跨版本的独立实例 / An independent instance across the version boundary环境:DSH 0.1.7-rc.2,
与你 §3 的实测同量级(你 8.84 MB/2.77 万事件 ⇒ 430–880 ms)⇒ 说明"逐事件成本"这一项没有随版本变差;变差的是在它之后的那一段(见下)。 This is the same order as your §3 measurement (8.84 MB / 27.7k events ⇒ 430–880 ms), so the per-event cost itself has not regressed across versions — what regressed sits after it (below). ⭐ 版本差分:这是 0.1.7 才出现的 / Version differential: new in 0.1.7同样的长会话在 0.1.5 上秒开;升到 0.1.7(v4)之后,切换会话会卡在「加载历史」数秒,而刷新同一会话立刻出来。 ⇒ 这与本讨论的 R4/#7802 指向同一条链:新事件 ⇒ 该会话投影缓存失效 ⇒ 切换时从 关于 LRU=5 的一点现场证据 / A field observation on the 5-slot LRU你 §2 提到的 prepared-session LRU 只有 5 个槽,在这里的表现正是:刚开过的会话很快(热),隔一会儿又慢(被逐出),而且切换一条就会让另一条变慢。 如果路线图里要给"短期"项排性价比,这条可能是最便宜的一档:把槽数做成可配置(哪怕只是提到与常用会话数同量级),就能把"切会话像卡死"降为偶发。 一条可复现判据 / A cheap corroborating judge
相关 / Related
说明 / Note本评论由 DSH agent 在排查自身宿主机问题时定位整理,并经人工复核后提交;上方数字均可复现。 |
Исправление бага DSH в Firefox: «Assistant stream raw chunk must be a lossless JSON object»Затрагивает: DeepSeek Harness Web UI (DSH) версия СимптомПри открытии любого чата, в котором в данный момент идёт работа ассистента, в DevTools (консоль) появляется:
Корень причиныDSH при открытии истории сверяет, что каждый объект в потоке ассистента — «обычный» plain-object без потери данных, и отбраковывает всё, что не является нативно-поддерживаемым JSON. Для этого код проверяет, что конструктор прототипа — настоящий встроенный Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`Проблема в том, что строковое представление нативных функций различается от движка к движку:
В Firefox строка не совпадает с ожидаемой точно, функция Поэтому баг:
ИсправлениеНужно заменить хрупкое сравнение по точной строке на регулярное выражение, которое допускает оба варианта форматирования (одну строку и многострочный вариант), но по-прежнему отклоняет ненативные (пользовательские) функции. Шаг 0. Определи место установки DSH и останови серверНайди, где установлен пакет DSH (обычно внутри npm root -g # например /usr/local/lib/node_modules или ~/.nvm/versions/node/vXX/lib/node_modules
ls "$(npm root -g)/@deepseek-ai/dsh/node_modules/@deepseek-ai/"Останови web-сервер DSH, чтобы запатчить файлы (обычно это systemd-сервис sudo systemctl stop dsh.service
# или, если запущен вручную, закрой его процессШаг 1. Патчим общий модуль значенийФайл: Найди функцию function hasIntrinsicConstructor(prototype, name) {
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
if (typeof constructor !== "function") return false;
try {
return constructor.name === name && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name}() { [native code] }`;
} catch {
return false;
}
}Замени её на: function hasIntrinsicConstructor(prototype, name) {
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
if (typeof constructor !== "function") return false;
try {
if (constructor.name !== name || constructor.prototype !== prototype) return false;
const source = Function.prototype.toString.call(constructor);
// Форматирование нативных функций отличается в движках:
// V8/JavaScriptCore: function Object() { [native code] }
// SpiderMonkey (Firefox): function Object() {\n [native code]\n}
// Допускаем оба варианта, но по-прежнему отклоняем ненативные функции.
const re = /^function\s+\S+\s*\(\s*\)\s*\{\s*\[native code\]\s*\}\s*$/;
return re.test(source);
} catch {
return false;
}
}Шаг 2. Патчим клиентский код контроллера сессийФайл: Этот пакет содержит свою копию той же функции (строка ~595) — её тоже нужно поправить, потому что браузер исполняет именно этот файл. Замена идентичная: function hasIntrinsicConstructor(prototype, name) {
const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
if (typeof constructor !== "function") return false;
try {
if (constructor.name !== name || constructor.prototype !== prototype) return false;
const source = Function.prototype.toString.call(constructor);
const re = /^function\s+\S+\s*\(\s*\)\s*\{\s*\[native code\]\s*\}\s*$/;
return re.test(source);
} catch {
return false;
}
}
Шаг 3. Проверь, что больше нет диагностикиВо время отладки в те же файлы могли быть добавлены временные
Проще всего: сравни Шаг 4. Перезапусти серверsudo systemctl start dsh.service
# проверь, что поднялся
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:3080/ # ожидай 200/302/401Шаг 5. Жёстко обнови страницу браузера
Шаг 6. ПроверьОткрой чат, в котором сейчас идёт работа ассистента (пока он генерирует ответ). Раньше на этом месте была ошибка — теперь должно открыться нормально. Как убедиться, что диагноз верный (без установки изменений)Если хочешь воспроизвести проблему, не трогая код, достаточно проверить строку движка: // в консоли Firefox
String(Object) // -> "function Object() {\n [native code]\n}" (с переносами)
// в консоли Chrome/Node
String(Object) // -> "function Object() { [native code] }" (одна строка)Разница в форматировании и есть причина. В Firefox точное сравнение |
Field data for §4.E / §4.C — measured on a 568-session production instance (DSH 0.2.0-rc.2)Sharing byte-level measurements of the 1. The payload is almost entirely
Inside
So ~91% of the entire response is 2. Trimming the list response moves the needle a lot; the remaining cost is server-side, not the wire Trimming each item to keep only
But after trimming, one call still burns ~930 ms of main-thread CPU, and the marginal calls in a cold window ran 1.7–11.3 s. That residue is item construction ( 3. Two smaller observations
Caveat: single host, single deployment, plugin-heavy profile — numbers are indicative, not a benchmark. Happy to re-run a specific probe if a maintainer wants a particular shape measured. |
Additional field data for §4 (R1/R2):
|
| metric | value |
|---|---|
| HTTP status | 200 (fork succeeds) |
| time to first byte / total | 57.17 s |
| main-thread CPU consumed | 51,380 ms |
| cgroup memory peak during the call | 10,631 MB (from 7,250 MB) |
| side effect | one 4 MB child session created |
| service health after | fine (fatal 0, sub-ms latency returns) |
Why the already-exists hooks don't cover this path (source-level)
dsh-api-session-controller/lib/index.js:776 async fork(request) does not call SessionStore.fork(...). It goes:
observed = await this.ctx.sessionQuery.observeSession(request.sessionId); // full materialization
boundary = atSeq ?? latestCompletedPrefixBoundary(source.events);
seed = buildForkSeed(source.events, boundary);
await this.ctx.agents.create({ sessionId: childId, seed, inheritedEventCount: ... });So third-party "zero-copy fork" patches that wrap SessionStore.prototype.fork(source, boundary, childSessionId) are reachable only from the internal/desktop call path, not from the Web API one. On this host such a patch is installed and reports zeroCopyFork: active, yet the fork counters stay at 0 across the 57 s call — i.e. the API path never reaches the wrapped method.
Implication — the Web-facing fork endpoint inherits §1 item 1 in full: it materializes the entire source log before anything is sliced, on the main thread (observeSession → decode/parse/validate/replay). maxMessages/pagination never enters this path. The §4 roadmap items that would actually help here are the same as for cold history: A (tail index + seek, or a fork-boundary that can be computed without materializing the whole prefix), B (fewer frames to decode), and generally keeping observeSession's full materialization off the list/fork paths (§4.C/E).
A bounded variant would help too: computing latestCompletedPrefixBoundary from the tail (or from the projection cache) instead of from a fully materialized source.events, since the boundary choice only needs completed-turn knowledge.
Caveat — single host, single deployment, largest session in a 857-file store; numbers indicative, not a benchmark. Happy to re-run a specific probe on request.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
中文摘要
DeepSeek Harness(DSH)首次打开一个较大的历史会话(几千条消息、大量 tool 结果,或含损坏提交历史的会话)时,Web 服务可能整体卡死数秒甚至超时。官方社区讨论 #1550(2026-08-14,报告人 wellorbetter,维护者 argszero 已确认)已经记录了这个现象与初步定位。本文不是重复报 bug,而是在 #1550 基础上做一次更系统的根因分析,并把问题从"损坏会话的 availability amplifier"扩展为所有大会话冷加载的通病:
maxMessages只限制返回 payload,不限制任何 IO/解压/解析/校验/物化成本。state.nodes.indexOf线性扫描节点数组,带 compaction 的大会话折叠为 O(n²)。本机实测(8.84MB 压缩 / 20.2MB JSON / 2.77 万事件 / 2.4 万 zstd 帧的真实日志):冷读一次(读盘+全帧解码+逐行 parse+逐事件快照)约 430ms(private decoder)/ 880ms(public),其中 JSON.parse ~200ms、事件快照 ~148ms、解码 ~78ms——而这只是"取最后 50 条消息"的前置成本。优化方向按性价比分三档:短期(A 尾部索引 sidecar+JSONL seek 冷开 <50ms、B 合并写帧减帧数 10-50x、C detached 投影接 coldSnapshot、D 事件快照按需、E 列表 header 缓存,以及社区 fork 已验证的 writer lease / yield 16ms / revision 负缓存)、中期(F 客户端骨架屏+预取、流式分页、LRU 自适应、list/inspect 隔离)、长期(G 默认 SQLite、存储格式演进、结构化损坏诊断)。预期可将冷开一个 46 万事件会话从 ~9s 降到 <100ms,并结构性消除 #1550 的全局可用性事故。
1. Problem Statement
1.1 Community anchor: Discussion #1550
Official discussion #1550 — "[Bug] Cold history loading fully materializes large/corrupt logs and can stall the entire Web server" — reported by wellorbetter on 2026-08-14 and confirmed by maintainer argszero against master, captures the community's first-hand account:
The incident: with one structurally valid large session plus one session with a committed-seq rollback in the tree, the Web server accepted TCP connections on 127.0.0.1:3080 but GET / timed out; after isolating the two session trees and restarting, it recovered. During the outage: ~163 MB working set, ~0.95 CPU-seconds per 2 wall-clock seconds, and a pile of CLOSE_WAIT sockets on port 3080.
Measured artifacts from #1550:
argszero's framing is worth quoting verbatim:
and his layered fix direction: bound the read (seekable/bounded persistence reads that stop at a page boundary instead of decode-everything-then-slice), cheap corruption detection (seq monotonicity at the frame scan level), and isolation (unreadable sessions quarantined at list/inspect time, never entering the full-scan path).
1.2 Why this document is not a duplicate bug report
#1550 was filed with corruption as the trigger and "availability amplifier" as the consequence. This document is a more systematic root-cause analysis plus an optimization roadmap that:
1.3 Scope and method
1.4 Community status (as of 2026-08-25)
The issue is live and unfixed upstream. Cross-checking #1550's own source citations against current master shows the same mechanism, with line-number drift only (see §2.2):
historySourceForgets full events before paginationhistoryPagepaginates afterwardsreadPrefix→readZstdPrefixdecodes every framestructuredClonein adoptZSTD_DECODE_YIELD_INTERVAL_MSThe reporter already prototyped a fix: wellorbetter's fork branch
fix/session-history-responsiveness(commit 159c5e4) contains (1) a cross-process writer lease (attacking the #1333/#1452 double-writer root cause), (2)ZSTD_DECODE_YIELD_INTERVAL_MS500→16 ms so large decodes yield to other requests, and (3) a revision-keyed negative cache (readFailures) so unchanged corrupt artifacts fail immediately instead of re-decoding. argszero's review: all three mechanisms pass their tests (2/2 + 152/152 + 81/81), but the patch does not cover the first valid large session's cold open — it still fully materializes; no bounded/seekable read, and the #1473 boot-block path is untouched. None of it is merged upstream as of 2026-08-25.The problem is not corruption-only: community member 7889545 reproduced a pure scale case without any corruption — 15 valid sessions (1.8–2.7 MB compressed each / ~300k tokens / 5–7k events) grew the process to ~3 GB heap within 60–90 s of boot with no client interaction; CPU profile ~60 % in
structuredClone; heap snapshot 21.6M live objects (assistant/chunk 59 MB, reasoning-delta 38 MB, …). Moving 11 session directories out ofsessions/dropped the heap to ~306 MB. NotablyarchivedSessionIdsdoes not reduce memory — archived sessions are still fully materialized, just hidden. This shows the materialization surface is not only the history RPC: the adopt path (boot-time and on-demand open) materializes just as eagerly.2. Root Cause Analysis
2.0 The full cold-load path (current master)
Key fact: pagination is applied after the full event array exists.
maxMessageslimits the returned payload only — it does not bound any I/O, decompression, parsing, validation, or materialization.2.1 Root cause R1 — Full materialization before pagination
historyRPC →historySourceFor(packages/host/apiproxy/src/api-proxy.ts:2154-2170 → 1474-1479). For a detached (cold) session this goes toinspectApiRemoteSession(packages/api/remotes/src/agent-lookup.ts:94-111), which callspersistence.list()(full enumeration) andpersistence.inspect(sessionId).inspect→prepareCore(packages/session/session-persistence/src/coordinator.ts:892-931):backend.loadStored(id)loads the entire stored log;adoptStoredEvents(coordinator.ts:560-573) migrates and deep-freezes every event;sessions.prepare(id, { seed: balanced })rebuilds the Session event-by-event (packages/core/session/src/index.ts:495-548).historyPage()applypaginate(events, beforeSeq, maxMessages)(api-proxy.ts:228-254, 745-761).Evidence that maxMessages does not bound work: the client requests history immediately on open (client/runtime/src/client/sessions/session.ts:618-648) with PAGE_MESSAGES = 50, yet the host still reads, decodes, parses, validates and materializes all 444K+ events before slicing 50 messages out.
2.2 Root cause R2 — JSONL physical read: whole file + all frames (no seek)
readStableFile(packages/session/session-persistence-jsonl/src/index.ts:292-304):stat → readFile(whole file) → stat, re-reading on revision change.readZstdPrefix(index.ts:348-419):scanZstdFramesscans frame boundaries (header-only, no decompression) then decodes every frame;SessionLogScanner(packages/session/session-persistence-jsonl/src/format.ts:272-378) JSON.parses every line and expands packed chunk rows (chunk-rows.ts:293-328).scheduler.yield()every 500 ms (index.ts:374-378) — the decode block itself is synchronous on the main thread.loadStoredFrom(fromSeq)is not implemented for JSONL (index.ts:196-197 documents "JSONL is sequential media"); the coordinator'sreadFromCore(coordinator.ts:841-870) therefore falls back toreadStoredPrefix+whole.events.slice(fromSeq)— i.e. full materialization, then slice (coordinator.ts:867-869). AnyfromSeq>0read on JSONL pays the full read/decode/parse cost.loadStoredFrom(packages/session/session-persistence-sqlite/src/store.ts:160-170, bounded suffix read via physicalSpanFrom) — but coldinspectstill calls the fullloadStored(store.ts:134-151, full-table select-events), so even the SQLite backend fully materializes on cold open; and when a suffix contains legacy shapes,readFromCore(coordinator.ts:859-861) falls back to a fullreadStoredPrefixanyway.2.3 Root cause R3 — Per-event rebuild: validation + deep copy + O(n²) surface folding
snapshotJsonValue(serialize-and-validate),assertSessionEventEnvelope,surfaceManager.validateNext; plusfreezeRestoredObjectdeep-freezing the whole JSON tree iteratively (index.ts:197-210). coordinator.ts:545-557 additionallystructuredClones each stored event on the inspect path.replacementRange(packages/core/session/src/surface.ts:337) usesstate.nodes.indexOf(op.start)/indexOf(op.end)— a linear scan of the node array per replacement. Sessions with compaction carry many replacements →foldSurface(surface.ts:387-395) becomes O(n²). With ~20K nodes and several indexOf passes, that is hundreds of millions of comparisons (hundreds of ms to seconds).2.4 Root cause R4 — Projection full re-fold on every history tail page (cache bypass)
detachedProjectionsFor→registry.restore({}, events, 0)(api-proxy.ts:810-818): with no checkpoint rows, every registered celldef.init()+ re-applies all events — O(cells × n).coldSnapshot(packages/session/session-projection-cache/src/index.ts:166-196) supports incremental restore from a floor seq — but the history path never uses it; the cache only serves session.list cold rows (api-proxy.ts:798-808). Cold history = full materialization + full projection re-fold (double O(n)).2.5 Root cause R5 — Amplifiers: 5-slot LRU, no negative cache, main-thread blocking
DEFAULT_PREPARED_SESSION_CACHE_SIZE = 5(coordinator.ts:27); a large session evicted from the LRU is re-read in full on reopen (revision re-check via stat).structuredCloneand 21.6M live objects, with no client interaction — see §1.4.archivedSessionIdsdoes not reduce this (hidden ≠ unmaterialized).2.6 What is NOT the bottleneck (client-side counter-evidence)
loadOlder50 messages per page (session.ts:380-414). The conversation assembler rebuilds incrementally per window (conversation-assembler.ts:223-248).order.maprenders the whole window; the trajectory view does use @tanstack/react-virtual). This matters only after thousands of messages are expanded, not on first open.2.7 Complexity model (summary)
3. Quantified impact (measured & estimated)
3.1 Local measurement (T2, Node v22.22.3, private zstd decoder)
Real largest session log on this machine (8.84 MB compressed / 20.2 MB JSON / 27,698 events / 24,005 zstd frames, avg ~369 B per frame):
snapshotSessionEvent— measures ~430 ms (private decoder) / ~880 ms (public one-shot fallback).3.2 Cross-validation with #1550 and the complexity model
4. Optimization roadmap (staged, prioritized by cost-effectiveness)
T2 ranked the candidates A–G by payoff/cost; the table maps them onto the staged plan (short / mid / long) together with the community-validated items from #1550 and the fork.
loadStoredFromon JSONL soreadFrom(seq)seeks to the tail framesloadStoredFromhook already exists (coordinator.ts:841-870)detachedProjectionsFor→coldSnapshotincremental instead ofrestore({}, events, 0)structuredCloneper eventZSTD_DECODE_YIELD_INTERVAL_MS500→16 ms, revision-keyedreadFailuresnegative cacheloadStoredFromseek already implemented; cold read becomes independent of log sizeAdditional #1550-aligned items folded into the plan: frame-level seq-monotonicity scan for fail-fast corruption detection (cheap scan instead of full decode; argszero #2), worker-thread decode/replay for main-thread responsiveness (#1550 suggestion 4, complements 0/yield-16ms).
5. Expected impact
6. Open questions
Sources: team T1 code-path report (tmp/20260825/team-t1-code-path.md, incl. §9 community cross-check), T2 perf analysis with local measurements (tmp/20260827/perf-analysis.md, bench-.cjs), captain's source notes & quantification (tmp/20260825/captain-notes.md, quantification.md), official discussion #1550 (raw + quotes). Inspected deepseek-ai/deepseek-harness current master 2026-08-25; finalized 2026-08-27. FINAL — ready for posting.*
All reactions