Skip to content

Commit 81390e5

Browse files
fix: memory consolidation fails on UNSUPPORTED_REASONING_EFFORT via defaultEffort trap
resolveDreamEffort queries ctx.llm.resolveModelInfo for the exact dream/sleep route up front and forwards an effort the model actually declares, instead of relying on the withEffortFallback retry — which the harness's defaultEffort substitution makes useless when the adapter's declared default (e.g. volcano adapter defaultEffort "low") is itself rejected by the model. - configured effort supported -> forwarded verbatim - configured unsupported -> remapped to defaultEffort/first declared effort - model declares no reasoning capability -> field omitted entirely - capability query unavailable or throws -> configured value forwarded, withEffortFallback still guards the rejection path 5 regression tests cover all four branches plus the sleep path. 723 tests pass (718 + 5). Co-Authored-By: Anans-Ivresse <[email protected]>
1 parent 9480d2a commit 81390e5

5 files changed

Lines changed: 281 additions & 10 deletions

File tree

‎dsh-mneme/lib/dream.js‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { validateDecisions, applyDecisions } from "./dream/decisions.js";
22
import { clusterMemories, findPotentialConflicts } from "./dream/clustering.js";
33
import { createHash, randomUUID } from "node:crypto";
4-
export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure };
4+
export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure, resolveDreamEffort };
55

66

77
// Extract the first JSON array from LLM output, tolerating markdown fences,
@@ -373,6 +373,60 @@ async function withEffortFallback(ctx, effort, attempt, fallback, getStreamError
373373
}
374374
}
375375

376+
/**
377+
* Resolve the reasoning effort to actually send for a dream/sleep route.
378+
*
379+
* Reasoning-effort config that the provider does not accept trips the harness's
380+
* UNSUPPORTED_REASONING_EFFORT, and the defaultEffort trap makes retrying
381+
* "without the field" useless: the harness substitutes `reasoning.defaultEffort`,
382+
* which may itself be unsupported (DSH Desktop volcano-engine adapter declares
383+
* defaultEffort=low that its model rejects). So instead of blind retries, ask
384+
* the harness for the model's declared capability and pick a value that is
385+
* actually accepted — or omit the field entirely when the model declares no
386+
* reasoning capability at all.
387+
*
388+
* @returns a supported effort id, or null when no effort should be sent, or the
389+
* configured value unchanged when the capability query is unavailable.
390+
*/
391+
async function resolveDreamEffort(ctx, route, configuredEffort, logger) {
392+
if (!configuredEffort || configuredEffort === "none") return null;
393+
// Capability query unavailable (older harness / minimal mocks): forward the
394+
// configured value as before — absence of the API proves nothing about the
395+
// model, and withEffortFallback still guards against rejection.
396+
if (typeof ctx?.llm?.resolveModelInfo !== "function") return configuredEffort;
397+
try {
398+
const info = await ctx.llm.resolveModelInfo(route.provider, route.model);
399+
const reasoning = info?.reasoning;
400+
if (!reasoning) {
401+
// Model declares no reasoning capability: the harness rejects ANY
402+
// explicit effort for such a model, and omitting the field is safe
403+
// (no reasoning capability → no defaultEffort substitution).
404+
logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} declares no reasoning capability; ignoring configured effort "${configuredEffort}"`);
405+
return null;
406+
}
407+
const supported = reasoning.efforts?.map((effort) => effort.id) ?? [];
408+
if (supported.includes(configuredEffort)) return configuredEffort;
409+
// Configured effort unsupported → pick defaultEffort if it is supported,
410+
// else the first declared effort, so the run never trips
411+
// UNSUPPORTED_REASONING_EFFORT (nor the defaultEffort trap: we always
412+
// pass an explicit value, so the harness never falls back to a poison
413+
// default).
414+
const picked = reasoning.defaultEffort && supported.includes(reasoning.defaultEffort)
415+
? reasoning.defaultEffort
416+
: supported[0];
417+
if (picked) {
418+
logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} does not support effort "${configuredEffort}" (supported: ${supported.join(", ")}); using "${picked}"`);
419+
return picked;
420+
}
421+
return null;
422+
} catch (error) {
423+
// Capability query failed — forward the configured value; withEffortFallback
424+
// still retries on rejection as before.
425+
logger?.warn?.(`dsh-mneme dream: resolveModelInfo failed (${String(error?.message ?? error)}); forwarding effort as configured`);
426+
return configuredEffort;
427+
}
428+
}
429+
376430
/**
377431
* Resolve the LLM route (Issue #25): an explicit plugin config
378432
* (dreamProvider/dreamModel) is the user's declared override and wins; the
@@ -665,7 +719,7 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
665719
// (不带该字段),避免 thinking 模型配置 low/medium 直接整单失败。解析放
666720
// 在 auditError 检查器里、闭包交回主流程,避免二次解析;解析失败同时如实
667721
// 记 audit error 并在日志带原始输出前 300 字节,便于定位"推理吞预算返回空体"。
668-
const effort = config.dreamReasoningEffort && config.dreamReasoningEffort !== "none" ? config.dreamReasoningEffort : null;
722+
const effort = await resolveDreamEffort(ctx, route, config.dreamReasoningEffort, logger);
669723
let decisions = null;
670724
let streamFailure = "";
671725
const runConsolidation = (withEffort) => {

‎dsh-mneme/lib/dream/sleep.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { randomUUID, createHash } from "node:crypto";
1818
import { validateDecisions, applyDecisions } from "./decisions.js";
1919
import { findPotentialConflicts } from "./clustering.js";
20-
import { buildReceipt, describeStreamFailure, withEffortFallback } from "../dream.js";
20+
import { buildReceipt, describeStreamFailure, resolveDreamEffort, withEffortFallback } from "../dream.js";
2121
import { computeHeat } from "../heat.js";
2222

2323
const SUMMARY_MAX = 120;
@@ -190,7 +190,7 @@ async function phaseConflicts(ctx, service, config, logger, runId, semantic = nu
190190
const listText = selected.map((p) =>
191191
`候选冲突:\nid=${p.a.id} | type=${p.a.type} | title=${p.a.title}\n${p.a.content}\n---\nid=${p.b.id} | type=${p.b.type} | title=${p.b.title}\n${p.b.content}\n(相似度 ${p.similarity.toFixed(2)})`
192192
).join("\n\n");
193-
const sleepEffort = config.sleepReasoningEffort && config.sleepReasoningEffort !== "none" ? config.sleepReasoningEffort : null;
193+
const sleepEffort = await resolveDreamEffort(ctx, route, config.sleepReasoningEffort, logger);
194194
let conflictStreamFailure = "";
195195
const runConflict = (withEffort) => {
196196
conflictStreamFailure = "";
@@ -309,7 +309,7 @@ async function phasePatterns(ctx, service, config, logger, runId, signal = null)
309309
.map((m) => `id=${m.id} | type=${m.type} | importance=${m.importance} | updated=${m.updated_at} | title=${m.title} | content=${m.content}`)
310310
.join("\n");
311311
const maxPatterns = config.sleepMaxPatternPerRun ?? 3;
312-
const sleepEffort = config.sleepReasoningEffort && config.sleepReasoningEffort !== "none" ? config.sleepReasoningEffort : null;
312+
const sleepEffort = await resolveDreamEffort(ctx, route, config.sleepReasoningEffort, logger);
313313
let patternStreamFailure = "";
314314
const runPattern = (withEffort) => {
315315
patternStreamFailure = "";

‎dsh-mneme/src/dream.js‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { validateDecisions, applyDecisions } from "./dream/decisions.js";
22
import { clusterMemories, findPotentialConflicts } from "./dream/clustering.js";
33
import { createHash, randomUUID } from "node:crypto";
4-
export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure };
4+
export { validateDecisions, applyDecisions, withEffortFallback, describeStreamFailure, resolveDreamEffort };
55

66

77
// Extract the first JSON array from LLM output, tolerating markdown fences,
@@ -373,6 +373,60 @@ async function withEffortFallback(ctx, effort, attempt, fallback, getStreamError
373373
}
374374
}
375375

376+
/**
377+
* Resolve the reasoning effort to actually send for a dream/sleep route.
378+
*
379+
* Reasoning-effort config that the provider does not accept trips the harness's
380+
* UNSUPPORTED_REASONING_EFFORT, and the defaultEffort trap makes retrying
381+
* "without the field" useless: the harness substitutes `reasoning.defaultEffort`,
382+
* which may itself be unsupported (DSH Desktop volcano-engine adapter declares
383+
* defaultEffort=low that its model rejects). So instead of blind retries, ask
384+
* the harness for the model's declared capability and pick a value that is
385+
* actually accepted — or omit the field entirely when the model declares no
386+
* reasoning capability at all.
387+
*
388+
* @returns a supported effort id, or null when no effort should be sent, or the
389+
* configured value unchanged when the capability query is unavailable.
390+
*/
391+
async function resolveDreamEffort(ctx, route, configuredEffort, logger) {
392+
if (!configuredEffort || configuredEffort === "none") return null;
393+
// Capability query unavailable (older harness / minimal mocks): forward the
394+
// configured value as before — absence of the API proves nothing about the
395+
// model, and withEffortFallback still guards against rejection.
396+
if (typeof ctx?.llm?.resolveModelInfo !== "function") return configuredEffort;
397+
try {
398+
const info = await ctx.llm.resolveModelInfo(route.provider, route.model);
399+
const reasoning = info?.reasoning;
400+
if (!reasoning) {
401+
// Model declares no reasoning capability: the harness rejects ANY
402+
// explicit effort for such a model, and omitting the field is safe
403+
// (no reasoning capability → no defaultEffort substitution).
404+
logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} declares no reasoning capability; ignoring configured effort "${configuredEffort}"`);
405+
return null;
406+
}
407+
const supported = reasoning.efforts?.map((effort) => effort.id) ?? [];
408+
if (supported.includes(configuredEffort)) return configuredEffort;
409+
// Configured effort unsupported → pick defaultEffort if it is supported,
410+
// else the first declared effort, so the run never trips
411+
// UNSUPPORTED_REASONING_EFFORT (nor the defaultEffort trap: we always
412+
// pass an explicit value, so the harness never falls back to a poison
413+
// default).
414+
const picked = reasoning.defaultEffort && supported.includes(reasoning.defaultEffort)
415+
? reasoning.defaultEffort
416+
: supported[0];
417+
if (picked) {
418+
logger?.warn?.(`dsh-mneme dream: model ${route.provider}:${route.model} does not support effort "${configuredEffort}" (supported: ${supported.join(", ")}); using "${picked}"`);
419+
return picked;
420+
}
421+
return null;
422+
} catch (error) {
423+
// Capability query failed — forward the configured value; withEffortFallback
424+
// still retries on rejection as before.
425+
logger?.warn?.(`dsh-mneme dream: resolveModelInfo failed (${String(error?.message ?? error)}); forwarding effort as configured`);
426+
return configuredEffort;
427+
}
428+
}
429+
376430
/**
377431
* Resolve the LLM route (Issue #25): an explicit plugin config
378432
* (dreamProvider/dreamModel) is the user's declared override and wins; the
@@ -665,7 +719,7 @@ export function createDreamScheduler({ onRun, thresholdCount = 10, thresholdChar
665719
// (不带该字段),避免 thinking 模型配置 low/medium 直接整单失败。解析放
666720
// 在 auditError 检查器里、闭包交回主流程,避免二次解析;解析失败同时如实
667721
// 记 audit error 并在日志带原始输出前 300 字节,便于定位"推理吞预算返回空体"。
668-
const effort = config.dreamReasoningEffort && config.dreamReasoningEffort !== "none" ? config.dreamReasoningEffort : null;
722+
const effort = await resolveDreamEffort(ctx, route, config.dreamReasoningEffort, logger);
669723
let decisions = null;
670724
let streamFailure = "";
671725
const runConsolidation = (withEffort) => {

‎dsh-mneme/src/dream/sleep.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { randomUUID, createHash } from "node:crypto";
1818
import { validateDecisions, applyDecisions } from "./decisions.js";
1919
import { findPotentialConflicts } from "./clustering.js";
20-
import { buildReceipt, describeStreamFailure, withEffortFallback } from "../dream.js";
20+
import { buildReceipt, describeStreamFailure, resolveDreamEffort, withEffortFallback } from "../dream.js";
2121
import { computeHeat } from "../heat.js";
2222

2323
const SUMMARY_MAX = 120;
@@ -190,7 +190,7 @@ async function phaseConflicts(ctx, service, config, logger, runId, semantic = nu
190190
const listText = selected.map((p) =>
191191
`候选冲突:\nid=${p.a.id} | type=${p.a.type} | title=${p.a.title}\n${p.a.content}\n---\nid=${p.b.id} | type=${p.b.type} | title=${p.b.title}\n${p.b.content}\n(相似度 ${p.similarity.toFixed(2)})`
192192
).join("\n\n");
193-
const sleepEffort = config.sleepReasoningEffort && config.sleepReasoningEffort !== "none" ? config.sleepReasoningEffort : null;
193+
const sleepEffort = await resolveDreamEffort(ctx, route, config.sleepReasoningEffort, logger);
194194
let conflictStreamFailure = "";
195195
const runConflict = (withEffort) => {
196196
conflictStreamFailure = "";
@@ -309,7 +309,7 @@ async function phasePatterns(ctx, service, config, logger, runId, signal = null)
309309
.map((m) => `id=${m.id} | type=${m.type} | importance=${m.importance} | updated=${m.updated_at} | title=${m.title} | content=${m.content}`)
310310
.join("\n");
311311
const maxPatterns = config.sleepMaxPatternPerRun ?? 3;
312-
const sleepEffort = config.sleepReasoningEffort && config.sleepReasoningEffort !== "none" ? config.sleepReasoningEffort : null;
312+
const sleepEffort = await resolveDreamEffort(ctx, route, config.sleepReasoningEffort, logger);
313313
let patternStreamFailure = "";
314314
const runPattern = (withEffort) => {
315315
patternStreamFailure = "";

0 commit comments

Comments
 (0)