Skip to content

Commit d720e21

Browse files
modusensusAnans-Ivresse
andcommitted
fix(summarize): 审计状态随重试恢复 + AbortError 不误判 effort 拒收 + 面板补齐 off 档位
PR #316 审计修复(CodeRabbit + 自审发现): 1. effort 拒收→成功重试后审计行残留第一次 attempt 的 error 状态 ("摘要成功但审计报失败",污染 llm_audit_logs)——每次 attempt 重置 audit.status; 2. withEffortFallback catch 未先放行 AbortError,取消可能被误判为 effort 拒收 触发多余重试——catch 首查 AbortError 直接放行; 3. 面板下拉缺 off 档位(后端枚举含 off)——拆分 ENTITY_REASONING / SUMMARIZE_REASONING,补 zh/en i18n off 键。 新增回归 2 条(summarize-reasoning-effort.test.js): - effort 拒收重试成功后审计记录 success; - abort 且 message 匹配 effort 正则时不 fallback 重试。 全量 1391 pass / 0 fail。 Co-authored-by: Anans-Ivresse <[email protected]>
1 parent cbf6c0f commit d720e21

6 files changed

Lines changed: 64 additions & 7 deletions

File tree

‎dsh-mneme/lib/client.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,12 @@ window.__ModuleLoader__.load({
398398
"memory.features.entityExtractionReasoning.medium": "中",
399399
"memory.features.entityExtractionReasoning.high": "高",
400400
"memory.features.summarizeReasoningEffort": "蒸馏思考强度",
401+
"memory.features.summarizeReasoningEffort.off": "关闭思考",
401402
"memory.features.summarizeReasoningEffort.none": "跟随默认",
402403
"memory.features.summarizeReasoningEffort.low": "低",
403404
"memory.features.summarizeReasoningEffort.medium": "中",
404405
"memory.features.summarizeReasoningEffort.high": "高",
405-
"memory.features.summarizeReasoningEffort.hint": "思考型模型建议选低档,避免推理烧光输出预算导致总结失败;改后重启 DSH 生效",
406+
"memory.features.summarizeReasoningEffort.hint": "思考型模型建议选低档或关闭思考,避免推理烧光输出预算导致总结失败;改后重启 DSH 生效",
406407
"memory.features.entityExtractionModelHint": "Provider/模型留空 = 跟随主对话模型;思考强度 none = 服务商默认",
407408
"memory.features.codingRetrospect": "编码记忆蒸馏",
408409
"memory.features.codingRetrospect.hint": "用完整转录(含工具调用与报错)提炼踩坑、约束与被否决方案",
@@ -794,11 +795,12 @@ window.__ModuleLoader__.load({
794795
"memory.features.entityExtractionReasoning.medium": "Medium",
795796
"memory.features.entityExtractionReasoning.high": "High",
796797
"memory.features.summarizeReasoningEffort": "Distill reasoning effort",
798+
"memory.features.summarizeReasoningEffort.off": "No reasoning",
797799
"memory.features.summarizeReasoningEffort.none": "Follow default",
798800
"memory.features.summarizeReasoningEffort.low": "Low",
799801
"memory.features.summarizeReasoningEffort.medium": "Medium",
800802
"memory.features.summarizeReasoningEffort.high": "High",
801-
"memory.features.summarizeReasoningEffort.hint": "Prefer low for thinking models so reasoning cannot drain the output budget; takes effect after a DSH restart",
803+
"memory.features.summarizeReasoningEffort.hint": "Prefer low or No reasoning for thinking models so reasoning cannot drain the output budget; takes effect after a DSH restart",
802804
"memory.features.entityExtractionModelHint": "Provider / model empty = follow the main conversation model; reasoning none = provider default",
803805
"memory.features.codingRetrospect": "Coding retrospection",
804806
"memory.features.codingRetrospect.hint": "Distill pitfalls, constraints and rejected solutions from full transcripts (tools and errors included)",
@@ -1961,8 +1963,10 @@ window.__ModuleLoader__.load({
19611963
const FEATURE_STRINGS = ["dreamProvider", "dreamModel", "sleepProvider", "sleepModel", "entityExtractionProvider", "entityExtractionModel", "localEmbedModel", "ollamaBaseUrl", "ollamaModel"];
19621964
const EMBED_PROVIDERS = ["openai", "local", "ollama"];
19631965
// 实体抽取思考强度(issue #109):与后端 FEATURE_FLAG_ENUMS 枚举对齐。
1964-
// #315 起蒸馏思考强度共用同一组档位(后端枚举多一个 off,一样可发)。
1965-
const REASONING_OPTIONS = ["none", "low", "medium", "high"];
1966+
const ENTITY_REASONING = ["none", "low", "medium", "high"];
1967+
// 蒸馏思考强度(issue #315):比 entity 多一个 off(显式关思考,思考型模型
1968+
// 蒸馏防推理烧预算)。后端枚举含 off,面板必须能选到,否则操作者用不上。
1969+
const SUMMARIZE_REASONING = ["off", "none", "low", "medium", "high"];
19661970

19671971
function FeatureRow({ name, hint, on, disabled, onToggle, sub }) {
19681972
return h("div", { className: "mneme-featrow", style: sub ? { paddingLeft: 18, opacity: 0.86 } : undefined },
@@ -2243,7 +2247,7 @@ window.__ModuleLoader__.load({
22432247
disabled: busy,
22442248
onChange: (e) => put({ entityExtractionReasoning: e.target.value })
22452249
},
2246-
REASONING_OPTIONS.map((r) => h("option", { key: r, value: r }, t(`memory.features.entityExtractionReasoning.${r}`))))
2250+
ENTITY_REASONING.map((r) => h("option", { key: r, value: r }, t(`memory.features.entityExtractionReasoning.${r}`))))
22472251
),
22482252
h("div", { className: "mneme-featsubhint" }, t("memory.features.entityExtractionModelHint"))
22492253
);
@@ -2260,7 +2264,7 @@ window.__ModuleLoader__.load({
22602264
disabled: busy,
22612265
onChange: (e) => put({ summarizeReasoningEffort: e.target.value })
22622266
},
2263-
REASONING_OPTIONS.map((r) => h("option", { key: r, value: r }, t(`memory.features.summarizeReasoningEffort.${r}`))))
2267+
SUMMARIZE_REASONING.map((r) => h("option", { key: r, value: r }, t(`memory.features.summarizeReasoningEffort.${r}`))))
22642268
),
22652269
h("div", { className: "mneme-featsubhint" }, t("memory.features.summarizeReasoningEffort.hint"))
22662270
);

‎dsh-mneme/lib/dream.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ async function withEffortFallback(ctx, effort, attempt, fallback, getStreamError
361361
}
362362
return result;
363363
} catch (error) {
364+
// dispose/取消中止直接放行,绝不能被误判成 effort 拒收而触发 fallback
365+
//(取消后重打一次不带 effort 的调用是浪费,且可能掩盖真实的取消意图)。
366+
if (error?.name === "AbortError") throw error;
364367
const message = String(error?.message ?? error);
365368
// matches both "reasoning effort" (natural language) and the bare
366369
// "UNSUPPORTED_REASONING_EFFORT" error code (underscore).

‎dsh-mneme/lib/summarize.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,10 @@ export function createSummarizer(ctx, service, config, deps = {}) {
621621
? { ...options, reasoningEffort: summarizeEffort }
622622
: options;
623623
for (let attempt = 0; ; attempt++) {
624+
// 每次尝试重置审计状态:effort 拒收/429 的失败 attempt 会把 status 置
625+
// error,若后续重试成功,审计必须记录最终成功而不是残留第一次的失败
626+
// (否则「摘要成功但审计报失败」,污染 llm_audit_logs 统计)。
627+
if (audit) audit.status = "success";
624628
const assembler = new BlockAssembler();
625629
let text = "";
626630
let aborted = false;

‎dsh-mneme/src/dream.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ async function withEffortFallback(ctx, effort, attempt, fallback, getStreamError
361361
}
362362
return result;
363363
} catch (error) {
364+
// dispose/取消中止直接放行,绝不能被误判成 effort 拒收而触发 fallback
365+
//(取消后重打一次不带 effort 的调用是浪费,且可能掩盖真实的取消意图)。
366+
if (error?.name === "AbortError") throw error;
364367
const message = String(error?.message ?? error);
365368
// matches both "reasoning effort" (natural language) and the bare
366369
// "UNSUPPORTED_REASONING_EFFORT" error code (underscore).

‎dsh-mneme/src/summarize.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,10 @@ export function createSummarizer(ctx, service, config, deps = {}) {
621621
? { ...options, reasoningEffort: summarizeEffort }
622622
: options;
623623
for (let attempt = 0; ; attempt++) {
624+
// 每次尝试重置审计状态:effort 拒收/429 的失败 attempt 会把 status 置
625+
// error,若后续重试成功,审计必须记录最终成功而不是残留第一次的失败
626+
// (否则「摘要成功但审计报失败」,污染 llm_audit_logs 统计)。
627+
if (audit) audit.status = "success";
624628
const assembler = new BlockAssembler();
625629
let text = "";
626630
let aborted = false;

‎dsh-mneme/test/summarize-reasoning-effort.test.js‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function setup(configOver = {}, stream) {
5353
requestHeader: () => ({ config: { provider: "deepseek", model: "deepseek-chat" } }),
5454
events: [userMessage("帮我选型", 1), { seq: 2, type: "turn/end" }]
5555
};
56-
return { store, calls, handler, session };
56+
return { store, service, calls, handler, session };
5757
}
5858

5959
test("issue#315: explicit summarizeReasoningEffort is forwarded on the distill call", async () => {
@@ -148,3 +148,42 @@ test("issue#315: off works like any explicit effort (rejected → retried withou
148148
assert.equal(store.count(), 1);
149149
store.close();
150150
});
151+
152+
test("issue#315: successful effort-fallback retry records audit as success, not the first failure", async () => {
153+
const { store, service, calls, handler, session } = setup(
154+
{ summarizeReasoningEffort: "low" },
155+
(options) => (async function* () {
156+
if (options.reasoningEffort) {
157+
// first attempt is rejected (effort unsupported)…
158+
yield { type: "finish", reason: { kind: "error", failure: { code: "UNSUPPORTED_REASONING_EFFORT", message: 'reasoning effort "low" rejected' } } };
159+
return;
160+
}
161+
// …but the no-effort retry succeeds.
162+
yield { type: "text-delta", delta: ENTRIES_JSON };
163+
yield { type: "finish", kind: "ok" };
164+
})()
165+
);
166+
await handler(session, { seq: 2, type: "turn/end" });
167+
assert.equal(calls.length, 2, "effort rejection + one retry");
168+
const rows = service.listLlmAudits();
169+
const summarize = rows.find((r) => r.operation_type === "summarize_compress");
170+
assert.ok(summarize, "summarize audit row present");
171+
assert.equal(summarize.status, "success",
172+
"the retried run must record success, not the first attempt's error status");
173+
store.close();
174+
});
175+
176+
test("issue#315: abort is not misread as an effort rejection even when the message matches the pattern", async () => {
177+
const { store, calls, handler, session } = setup(
178+
{ summarizeReasoningEffort: "low" },
179+
() => (async function* () {
180+
// The message matches EFFORT_REJECT_RE on purpose: without the AbortError
181+
// guard in withEffortFallback this would be misread as an effort rejection
182+
// and trigger a wasteful no-effort retry.
183+
throw Object.assign(new Error("aborted by dispose: UNSUPPORTED_REASONING_EFFORT"), { name: "AbortError" });
184+
})()
185+
);
186+
await handler(session, { seq: 2, type: "turn/end" });
187+
assert.equal(calls.length, 1, "abort must not trigger a no-effort fallback retry");
188+
store.close();
189+
});

0 commit comments

Comments
 (0)