OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: dsh-memory-plugin 注入消息 source 仍为退役的 {kind:"plugin"},host 0.1.7-alpha.1 的 format v4 准入直接拒收,整轮运行失败

Open dzwalker opened this issue 2 months ago • 1 comments

环境

  • dsh host: 0.1.7-alpha.1(源码 tag dsh-v0.1.7-alpha.1 构建;npm latest 目前是 0.1.5-rc.2)
  • @openviking/dsh-memory-plugin: 0.5.0(npm latest)
  • profile: web,Linux x64,Node v22.22.0

现象

启用 memory 插件后,触发注入的那一轮整轮失败:

本轮运行失败
format v4 message requires a producer-owned source kind

事件在准入阶段就被拒,不落盘——所以会话 JSONL、host 日志里都查不到违规消息,排查时非常隐蔽。

根因

DSH 0.1.7 新增了会话格式 v4 的来源准入,明确拒收已退役的 {kind:"plugin"} 包装(0.1.5-rc.1 没有这条校验,所以此前一直正常):

// packages/session/session-format-v3-to-v4/src/message-sources.ts
function source(message: Readonly<Record<string, unknown>>): void {
  const value = message['source']
  if (!isSessionFormatJsonObject(value) || typeof value['kind'] !== 'string'
    || value['kind'].length === 0 || value['kind'] === 'plugin') {
    throw new SessionFormatError('format v4 message requires a producer-owned source kind')
  }
}

本插件的注入消息来自 capture.mjs 的 pluginMessage():

export const OPENVIKING_PLUGIN_SOURCE = "openviking-memory";

export function pluginMessage(content, source) {
  return createUserMessage({
    content: [{ type: "text", text: content }],
    source: {
      kind: "plugin",                       // ← 0.1.7 拒收
      plugin: OPENVIKING_PLUGIN_SOURCE,
      ...source,
    },
  });
}

影响的注入路径包括 <openviking-context source="profile">(启动 profile)与 recall 注入。

复现

  1. 安装 @openviking/[email protected],启用 profile / recall 注入;
  2. 在会话中发送任意消息;
  3. 该轮直接失败并报上述错误。

我用临时诊断(在 source() 抛错前打印消息与调用栈)抓到的完整证据:

[DIAG v4-source] message={"content":[{"type":"text","text":"<openviking-context source=\"profile\">..."}], ...}
STACK:
  at source (session-format-v3-to-v4/lib/index.js)
  at assertV4SourceRowAdmission
  at assertV4RowAdmission
  at Object.encodeEvent
  at eventLine (session-persistence-jsonl/lib/index.js)
  at Proxy.appendLines

(消息正文含用户私有 profile 内容,此处不粘贴。)

建议修法

官方 V3→V4 迁移规则是「生产者自有 kind」,非第一方生产者命名为 plugin:<名>:

// packages/session/session-format-v3-to-v4/src/sources.ts
function producerKind(plugin, role) { /* ... */ return `plugin:${plugin}` }

对应改法:

kind: `plugin:${OPENVIKING_PLUGIN_SOURCE}`   // → "plugin:openviking-memory"

准入只校验 kind(非空且不为 "plugin"),plugin 字段保留或删除都行。

⚠️ 同时需要同步插件内部的自识别判定(否则 kind 改名后行为会变):

  • capture.mjs: if (message.source?.kind === "plugin") return null;(采集过滤,改后会把其它插件的注入当人类输入采进记忆)
  • capture.mjs: promptText() 里排除自己注入的判定(改后自己的注入会混进 recall 查询)
  • runtime.mjs: isStartupProfile() 的判定

建议统一为「kind === 'plugin:<名>' 或(旧格式 kind === 'plugin' && plugin === 名)都算自己」。

本地验证

我在本机用 pnpm patch 做了同样修复,并用 host 的真实校验器验证通过:

assertV4RowAdmission({ type: 'agent/inbox/spliced', data: { inserted: [pluginMessage(...)] } })  // 修复前抛错,修复后通过

dzwalker avatar Sep 22 '26 10:09 dzwalker

Fixed by #5318 (merged): the plugin now injects with the producer-owned source kind plugin:openviking-memory, which passes DSH 0.1.7's format v4 admission. Legacy {kind: "plugin", plugin: "openviking-memory"} messages in older sessions are still recognized. The fix ships in @openviking/dsh-memory-plugin 0.5.1.

t0saki avatar Sep 23 '26 09:09 t0saki