From 3df4f489b113e291d36da18e43e425b66212dbe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Fri, 9 Oct 2026 10:16:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(net-scope):=20region=20gate=20denial=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=B4=A7=E8=87=B4=20stream=20=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the host crash in #84. denialStream 原先写入 4 条裸 chunk(block-start/text-delta/block-end/finish)。dsh-llm firstRunMemberTime 只认 chunk/text-chunks/reasoning-chunks/tool-call-chunks,裸记录没有 .texts,append 当下 TypeError 被当成 fatal load failure,systemd Restart=always 后 web token 一直变。现包成 { type: chunk, time, chunk },与 AssistantStreamAccumulator 一致。不改写历史 session.v4.jsonl.zstd。 Co-authored-by: Cursor --- lib/net-scope.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/net-scope.js b/lib/net-scope.js index 053ec72..bb6a9cb 100644 --- a/lib/net-scope.js +++ b/lib/net-scope.js @@ -450,7 +450,14 @@ async function denialMessage() { }; } -function denialStream() { +const COMPACT_STREAM_TYPES = new Set([ + "chunk", + "text-chunks", + "reasoning-chunks", + "tool-call-chunks", +]); + +function denialChunks() { return [ { type: "block-start", index: 0, blockType: "text" }, { type: "text-delta", index: 0, text: DENIAL }, @@ -459,6 +466,22 @@ function denialStream() { ]; } +/** 宿主持久化只要 Accumulator 紧致记录;裸 chunk 会让 firstRunMemberTime 读 undefined.length(#84)。 */ +function denialStream(now = Date.now()) { + const time0 = Number.isSafeInteger(now) ? now : Date.now(); + const stream = denialChunks().map((chunk, i) => ({ + type: "chunk", + time: time0 + i, + chunk, + })); + for (const record of stream) { + if (!record || !COMPACT_STREAM_TYPES.has(record.type)) { + throw new TypeError("denial stream must use compact Assistant records"); + } + } + return stream; +} + async function appendDenial(session, turn, step) { session.append("assistant/message", { turn,