From 704eee142b38c843ce1c6a984e3a8bbbbe9cddbd 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 15:47:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(#84+#86):=20denial=20stream=20=E7=94=A8=20c?= =?UTF-8?q?ompact=20chunk=20+=20=E8=A1=A5=E4=B8=81=2042=20=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20plainConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #84: denialStream 之前打 type:text-chunks 带 .chunks 字段, 但宿主 firstRunMemberTime 认的是 .texts —— 字段错配继续炸。 改成逐 chunk 包成 { type:"chunk", time, chunk } 走单条路径。 #86: 补丁 42 register/commitLegacy 两个 validate 前漏 plainConfig, cosmokit volatile 字段作为 live 对象引用灌进 validate,日志爆红。 两处 replace 加 plainConfig 包裹;markers 改成 #86 新串, 再加两条升级 pattern 匹配老用户已清洗、缺 plainConfig 的产物, 确保 skipIfMarked 短路后老用户也能走升级补齐。 --- lib/core.js | 25 ++++++++++++++++++++++--- lib/net-scope.js | 23 ++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/lib/core.js b/lib/core.js index c9d7461..2d0b02d 100644 --- a/lib/core.js +++ b/lib/core.js @@ -3817,7 +3817,7 @@ const NEW_TOOL_PATCHES = [ "\t\tthis.ensureLegacyDocument();\n" + "\t\tconst stored = this.legacyDocument[ns];\n" + "\t\tconst user = isPlainObject(stored) ? stored : void 0;\n" + - "\t\tconst resolved = schema(mergeLayers(options?.base, user));\n" + + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + "\t\toptions?.validate?.(resolved);\n" + "\t\tconst registration = {\n" + "\t\t\tns,\n" + @@ -3891,7 +3891,7 @@ const NEW_TOOL_PATCHES = [ "\t\tif (registration === void 0) throw new Error(`settings namespace \"${ns}\" is not registered`);\n" + "\t\tif (expectedRevision !== void 0 && registration.revision !== expectedRevision) throw new SettingsConflictError(ns, expectedRevision, registration.revision);\n" + "\t\tconst user = change(registration.user);\n" + - "\t\tconst next = registration.schema(mergeLayers(registration.base, user));\n" + + "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + "\t\tregistration.validate?.(next);\n" + "\t\tconst prev = registration.resolved;\n" + "\t\tregistration.user = user;\n" + @@ -3958,8 +3958,27 @@ const NEW_TOOL_PATCHES = [ 'this.ownerContext.emit("settings/document-updated", previous.ns, revision);\n' + '\t\t\tthis.ownerContext.emit("settings/updated", previous.ns);', }, + { + // #86 升级:老用户早期产物没过 plainConfig,volatile 字段漏进 validate。 + pattern: + "\t\tconst resolved = schema(mergeLayers(options?.base, user));\n" + + "\t\toptions?.validate?.(resolved);", + replace: + "\t\tconst resolved = plainConfig(schema(mergeLayers(options?.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\toptions?.validate?.(resolved);", + }, + { + // #86 升级:commitLegacy 同根问题。 + pattern: + "\t\tconst next = registration.schema(mergeLayers(registration.base, user));\n" + + "\t\tregistration.validate?.(next);", + replace: + "\t\tconst next = plainConfig(registration.schema(mergeLayers(registration.base, user))); // [dsh-purge] #86 plainConfig before validate\n" + + "\t\tregistration.validate?.(next);", + }, ], - markers: ["[dsh-purge] legacy settings api"], + // #86 换 marker:老用户已带 "legacy settings api",但缺 plainConfig —— 必须进 replacements 走升级。 + markers: ["[dsh-purge] #86 plainConfig before validate"], }, { id: 45, name: "OFFICIAL_DESKTOP_UPDATE_HANDOFF", layer: "代码", layer_en: "Code", diff --git a/lib/net-scope.js b/lib/net-scope.js index 900df0e..ade9a77 100644 --- a/lib/net-scope.js +++ b/lib/net-scope.js @@ -477,21 +477,22 @@ function denialChunks() { } /** 宿主持久化只要 Accumulator 紧致记录;裸 chunk 会让 firstRunMemberTime 读 undefined.length(#84)。 - * 改为合并成一条 text-chunks 批记录,带 .length / .text,配合 firstRunMemberTime 的字段期望。 */ + * 审查「4.1 才是正解」: 每个 chunk 包成 { type: "chunk", time, chunk },走 compact chunk + * 单条路径,避免批记录 (text-chunks 需要 .texts 字段而不是 .chunks) 字段名错配再次崩溃。 */ function denialStream(now = Date.now()) { const time0 = Number.isSafeInteger(now) ? now : Date.now(); const chunks = denialChunks(); - const record = { - type: "text-chunks", - time: time0, - chunks, - length: chunks.length, - text: DENIAL, - }; - if (!COMPACT_STREAM_TYPES.has(record.type)) { - throw new TypeError(`denial stream must use compact Assistant records, got ${record.type}`); + const records = chunks.map((chunk, i) => ({ + type: "chunk", + time: time0 + i, + chunk, + })); + for (const record of records) { + if (!COMPACT_STREAM_TYPES.has(record.type)) { + throw new TypeError(`denial stream must use compact Assistant records, got ${record.type}`); + } } - return [record]; + return records; } async function appendDenial(session, turn, step) {