Replies: 1 comment
|
Verified every claim against Mechanism confirmed (alpha.4):
Your proposed guard is right — The family finding: the same unguarded pattern exists at three more runtime sites:
Durable fix option (recommend alongside the one-liner): every Test alignment: Want me to shape this into a concrete diff for the core, or is your fork already carrying it? |
Uh oh!
There was an error while loading. Please reload this page.
问题描述 / Problem
在
dsh 0.1.2-alpha.2(master 与最新 tagdsh-v0.1.2-alpha.4同样存在)上,由第三方插件以「鸭子类型」注册 LLM 适配器(普通对象,不带基类可选方法)后,运行/compact抛:触发插件:
@liustack/modlens(dsh/index.js约 L750 用llm.registerAdapter([providerId], {providerInfo, providerRetryPolicy, listModels, resolveModel, prepareCall, stream, ...})注册,没有imageRequestPricing——该方法晚于插件诞生)。影响 / Impact(一个根因,三个症状)
/compact直接command/done kind=error崩溃;agent/pre-step监听器 catch 所有错误后只打 warnstep compaction failed: ...; continuing the turn,继续回合——会话一路涨到 ~143K totalTokens(contextWindow 131072)从不压缩;CONTEXT_WINDOW_EXCEEDED后compactIfNeeded同样炸,无法压缩,会话被截断。调用链 / Call chain
根因 / Root cause
LlmRuntime.registerAdapter存储原始适配器对象,支持鸭子类型注册(prepareRoutes只校验providerInfo/providerRetryPolicy);LlmAdapter.imageRequestPricing是基类可选方法(默认返回 undefined),但鸭子类型对象未继承基类,等于没有该方法;this.adapters.get(provider)?.adapter.imageRequestPricing(provider, model)的?.只防「适配器不存在」,不防「方法不存在」→ 直接 TypeError。与先前同类问题同根:modlens 曾缺失
prepareCall导致registration.adapter.prepareCall is not a function(适配器契约演进后,鸭子类型注册的第三方插件未跟上)。建议修复 / Proposed fix
packages/llm/llm/src/index.tsLlmRuntime.imageRequestPricing(L659)改为方法存在性守卫,语义为「适配器未声明该方法 → 按无图片定价降级」:该模式建议推广到
LlmRuntime上所有「取适配器可选方法」的调用点。回归测试 / Regression test
packages/llm/llm/tests/topology.spec.ts的imageRequestPricing resolution用例新增鸭子类型分支:注册['duck'](普通对象,须带providerRetryPolicy(),否则先炸在prepareRoutes),断言ctx.llm.imageRequestPricing('duck','vision')为undefined。环境 / Environment
modlens-deepseekgongsi/deepseek-v4-flash(contextWindow 131072)@liustack/modlens3.25.3All reactions