Repository navigation
Bug: 每次工具调用崩溃 reading 'prepare' — profile 内独立 dsh-tools 副本分裂 Symbol #1418
yinsang0910-star
started this conversation in
General
Replies: 1 comment
|
更正(08-16):我之前(08-15)在这条里说「relink 治标、
抱歉之前的误导。完整的避坑地图和自评在 #2130。 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Bug: 每次工具调用崩溃
Cannot read properties of undefined (reading 'prepare')— 根因是 profile 内独立 dsh-tools 副本分裂 Symbol(Reading CONTRIBUTING.md 知悉外部 PR 暂不被接受,故以此 Discussion 形式报告 bug + 附上根因与已验证的修复方案,供团队采纳。)
现象
当 web profile 的
package.json声明了@deepseek-ai/dsh-tools依赖时,每次 agent 工具调用(pwsh / read / glob / web_search …)都崩溃:崩溃表达式是
ctx.tools[TOOL_RUNTIME_SCHEDULER].prepare(),其中ctx.tools[TOOL_RUNTIME_SCHEDULER]为undefined。turn 以code: UNKNOWN结束。根因
同一进程里加载了两份物理上不同的
@deepseek-ai/dsh-tools:.../node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-tools~/.dsh/profiles/<name>/node_modules/@deepseek-ai/dsh-toolsdsh plugin(pnpm)装进 profile 的独立副本@deepseek-ai/dsh-tools导出了模块级TOOL_RUNTIME_SCHEDULERSymbol。每份副本持有各自互不相等的 Symbol:dsh-agent-loop从宿主闭包解析 dsh-tools,用它那份 Symbol 做查找;ctx.tools(ToolRuntime 服务)由 profile 副本构造,其实例字段[TOOL_RUNTIME_SCHEDULER]用自己那份 Symbol 写入。两份 Symbol 不等 → agent-loop 的查找读不到 →
undefined→ 每次工具调用必崩。我用模块加载探针确认了两份都在启动时被加载;把 profile 副本指向宿主实例后,该查找恢复可解析。为什么现有防护没拦住
healProfilesModuleFallback(packages/boot/app-boot/src/profile.ts)已确立"单一模块实例"契约:把应用依赖闭包里的每个包 symlink 进$DSH_HOME/profiles/node_modules,注释也写明 "every plugin shares the installation's single cordis instance instead of a duplicate"。但这只覆盖经由 fallback 目录的解析。一旦 profile 自己package.json声明了@deepseek-ai/dsh-tools(dsh plugin add、pnpm peer 提升、或手改),pnpm 会在 profile 的node_modules下落一份真实副本,Node 从 profile 目录向上查找时先命中这份副本,fallback 根本轮不到 → 重复实例存活。复现
npm i -g @deepseek-ai/dsh@0.1.0-rc.6~/.dsh/profiles/web/package.json含"@deepseek-ai/dsh-tools": "0.1.0-rc.6",并在 profile 目录跑pnpm install(独立 dsh-tools 落进node_modules/@deepseek-ai/)。dsh web→ 新建/恢复会话 → 让 agent 调任意工具。reading 'prepare'结束。影响
任何让 profile 积累了带共享模块级 Symbol 的 harness 包(dsh-tools 是最明确的;其它共享 Symbol 的包同理)的 profile,工具调用即不可用。
dsh plugin是裸 pnpm 转发器、对无 bundle 依赖只打 warning,很容易无意间把 harness 包装进 profile。建议修复(已在本地验证)
在
apps/cli/src/plugin.ts的runPlugin成功路径(reconcilePlugins之后)新增一步relinkHostPackages:审计 profile 依赖,凡是从宿主安装解析(resolveBundleDir已按 installAnchor 优先)但 profile 侧又持有独立真实副本的包,把 profile 侧替换成指向宿主安装的 junction/symlink,恢复单一模块实例(单一 Symbol)。宿主闭包外的第三方插件从 profile 侧解析、不受影响;幂等(realpath 相等即跳过)。配套在
runPlugin成功后调用reconcilePlugins(before, dir); relinkHostPackages(dir)。这样每次dsh plugin add/update/install/remove既修复既有 profile,也自愈转发器可能引入的重复。我已把该改动落在
apps/cli/src/plugin.ts(分支fix/plugin-relink-host-packages,位于我的 forkyinsang0910-star/deepseek-harness),因官方暂不收外部 PR 而未发起 PR。若团队愿意采纳,可直接取用或联系我调整。附带验证
ctx.tools[TOOL_RUNTIME_SCHEDULER](用 agent-loop 同款 Symbol 查)恢复可解析。lstatSync().isSymbolicLink()为 true ✓。All reactions