Skip to content

fix(deepseek-harness): emit session format v4 message sources - #2408

Closed
Pasitearko wants to merge 4 commits into
MemTensor:mainfrom
Pasitearko:patch-4
Closed

Pasitearko wants to merge 4 commits into
MemTensor:mainfrom
Pasitearko:patch-4

Conversation

@Pasitearko

Copy link
Copy Markdown

DSH 0.1.7 introduced session format v4, which retires the kind: "plugin" + plugin source shape in favour of producer-owned kinds. The DeepSeek Harness adapter still writes the retired shape in two places, so every turn fails with format v4 message requires a producer-owned source kind during agent/pre-step.

  • adapters/deepseek-harness/index.ts — recall message source → kind: `plugin:${DEEPSEEK_HARNESS_PLUGIN}` (drops the plugin field)
  • adapters/deepseek-harness/host-llm.ts — host LLM message source → kind: `plugin:${HOST_LLM_MESSAGE_SOURCE}`

This matches the shape DSH's own v3→v4 migration produces for the same rows, so it stays readable on DSH 0.1.5 as well. No other plugin-side change is needed: the v4 check only requires source.kind to be a non-empty string other than "plugin", and the plugin's own filters match on source.kind === "user".

Unit test assertions updated accordingly.

Fixes #2405

Prior automation: PR #2406 carried the same change but was closed without merging (commit 5f5d63f2), so it can be cherry-picked instead of re-applied if that is easier.

@Memtensor-AI Memtensor-AI added area:plugin OpenClaw & Hermes status:in-progress Someone or AI is working on it | 人工或 AI 正在处理 labels Sep 24, 2026
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2408
Task: db0a97825a0bf50c
Base: main
Head: patch-4

🔍 OpenCodeReview found 1 issue(s) in this PR.


1. apps/memos-local-plugin/adapters/deepseek-harness/host-llm.ts (L369)

Type safety concern: Verify that the createUserMessage function from @deepseek-ai/dsh-llm accepts a source object with only a 'kind' property. The original structure had separate 'kind' and 'plugin' properties { kind: "plugin", plugin: HOST_LLM_MESSAGE_SOURCE }. This change removes the 'plugin' property and embeds the plugin name into the 'kind' string. If the type definition expects both properties, this could cause a type error or runtime issue. Consider checking the MessageSource type definition in @deepseek-ai/dsh-llm to ensure this structure is valid.

Generated by cloud-assistant via Open Code Review.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

⚠️ Automated Test Results: ENV ISSUE

The test environment encountered an issue that requires manual attention.

Details: Environment preparation failed before any gating tests executed. Failed scopes: memos_local_plugin
Branch: patch-4

@dmitri-0

Copy link
Copy Markdown

Independent verification of this change on a live DSH 0.1.7 host

Adding field evidence for the two points that are hard to settle from the diff alone: that this PR changes the correct thing, and that the automated-test ENV ISSUE is unrelated to the code.

Environment

  • DSH 0.1.7-rc.1 (bundles @deepseek-ai/dsh-session-format-v3-to-v4@0.1.7-rc.1)
  • @memtensor/memos-local-plugin@2.0.20 from npm, patched in place with exactly this PR's change
  • Session format v4 native logs (session.v4.jsonl.zstd)

1. The PR's final shape passes the check that throws

The production error comes from the released admission validator:

// node_modules/@deepseek-ai/dsh-session-format-v3-to-v4/lib/index.js:126
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");

The same check is duplicated in the bundled persistence worker (dsh-session-persistence-jsonl/lib/worker.cjs:10722), so it gates both writing a row and re-reading the session file.

Feeding that validator four candidate sources (via assertReleasedV4Relationships on a synthetic user/message event):

REJECT released wrapper (current plugin) -> format v4 message requires a producer-owned source kind
                                                  {"kind":"plugin","plugin":"memos-local-memory","form":"recall"}
PASS   this PR's shape                           {"kind":"plugin:memos-local-memory","form":"recall"}
PASS   this PR's shape without form              {"kind":"plugin:memos-local-memory"}

So the diff is sufficient: no non-empty-string kind other than "plugin" is required.

2. form is correctly omitted in host-llm.ts

Agreed with the note already posted on #2405. ContextForm in @deepseek-ai/dsh-llm/lib/types/message.d.ts is a closed union (instructions | catalog | snapshot | notice | relay | recall) and the type explicitly allows the undeclared variant { readonly form?: never }, documented as "an undeclared context is the documented default". recall is valid, and no form at all is equally valid. Adding a form there would not be wrong, but it is not required.

3. End-to-end result on a live host

Before the change, a turn died during agent/pre-step: the session log stopped right after turn/start and nothing was persisted. After applying this PR's change and restarting the profile, two separate turns on the same session persisted their recall rows with the new source:

seq=420  user/message -> {"kind":"plugin:memos-local-memory","form":"recall"}
seq=550  user/message -> {"kind":"plugin:memos-local-memory","form":"recall"}

Scanning every session log on that host:

  • non-canonical kind:"plugin" sources inside native v4 files: 0
  • legacy kind:"plugin" rows still on disk: all 41 are inside the older v3 file, i.e. exactly the input DSH's own v3→v4 migration is built to lift (rewriteV3MessageSource → plugin:${plugin})

This confirms the change is forward-compatible with old rows: pre-existing v3 sessions keep being read through the migration, while new writes are already canonical.

Conclusion

The change is verified working against the real failing host, and the ENV ISSUE in the automated run ("Environment preparation failed before any gating tests executed", scope memos_local_plugin) is a test-harness problem, not a signal about this diff.

One suggestion for whoever finishes this: the adapter README still describes the recall source as plugin/memos-local-memory/recall, which matches neither the old nor the new shape, and the >=0.1.0-rc.5 <0.2.0 DSH peer range still advertises compatibility across the release that introduced this breaking v4 change. Both are worth folding into the same release.

@yangjian19930109

Copy link
Copy Markdown

@Memtensor-AI 补一份 DSH 侧的独立验证,供这个 PR 参考。

环境:DSH 0.1.7-rc.2(源码树构建,session format v4)· Windows 11 · @memtensor/memos-local-plugin@2.0.20(npm 安装于 profile web)

1. 现象与定位:升级后并非每轮都失败,而是只在自动召回真的注入消息的那一轮失败——界面「本轮运行失败」,异常为 format v4 message requires a producer-owned source kind。失败轮里模型完全没有被调用(没有 request/header、assistant/message、tool/call),因为失败发生在 agent/pre-step 组装消息阶段。

2. 落库证据:memos 自己记下了这次的 turnEndReason:

{"dshTurn":7,"turnEndReason":{"kind":"error","error":{"message":"format v4 message requires a producer-owned source kind","code":"UNKNOWN"}},"initialUserText":"继续","lastAssistantText":""}

失败轮的 v4 日志停在 turn/start 与一条 agent/inbox/spliced 撤下挂起消息,没有任何 turn/end——即该轮事件在准入被拒、整轮未能落盘。

3. 本 PR 的改动经真机验证通过:在本地按本 PR 的形状改掉两处来源后(adapters/deepseek-harness/index.ts 的 createRecallMessage、host-llm.ts 的 toDshMessage → kind: `plugin:${...}`),同一台机器上:

  • 召回消息成功落盘,来源为 plugin:memos-local-memory(form:"recall"),且该轮 turn/end.reason.kind = "completed";
  • 该会话全部 turn/end 中 error 轮为 0,全部消息来源里不存在裸 kind:"plugin";
  • 用 DSH 0.1.7-rc.2 自身的准入函数对该形状做双向校验:旧形状经 assertV4RowAdmission 与 encodeEvent 两条路径均抛该异常,新形状两条路径均通过。

4. 关于 host-llm.ts 的 OCR 意见:Open Code Review 质疑 toDshMessage 的 source 只保留 kind 是否类型安全。实测 DSH 侧 createUserMessage 只要求 source.kind 为非空字符串,且 v4 准入仅拒绝裸 "plugin";去掉 plugin 字段不影响可读性,本 PR 的处理与 DSH 自身 v3→v4 迁移对同形来源的产出完全一致。

5. 附带的运行时提醒(与本 PR 无关,但会掩盖本次修复):@huggingface/transformers@4.2.0 不再读取 HF_ENDPOINT 环境变量,只认模块自身的 env.remoteHost。在网络受限环境下,本地 embedding 冷启动会以 fetch failed 失败,memos 按设计 fail-open 返回空召回——此时根本不会注入消息,也就看不到这个 bug。若要在受限网络里稳定复现/验证,需要预置模型缓存(本机做法:先把 env.remoteHost 指向可达镜像再执行 pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2", { dtype: "q8", device: "cpu" }) 预下载;此后在 allowRemoteModels=false 下 162 ms 即可加载)。

English summary Independent live verification on DSH 0.1.7-rc.2 + plugin 2.0.20 (Windows 11). The failure is conditional: it only happens on turns where automatic recall actually injects a message, and it aborts the turn during agent/pre-step before any model call (the failed turn's v4 log ends at turn/start with no turn/end; memos recorded turnEndReason = {"kind":"error","error":{"message":"format v4 message requires a producer-owned source kind","code":"UNKNOWN"}}). After applying exactly this PR's two source changes locally (createRecallMessage in adapters/deepseek-harness/index.ts and toDshMessage in host-llm.ts), the recall row lands as kind:"plugin:memos-local-memory" (form:"recall"), the turn ends completed, the session shows zero error turns and no bare kind:"plugin" sources, and DSH's own assertV4RowAdmission / encodeEvent accept the new shape while rejecting the old one on both paths. On the OCR comment: DSH's createUserMessage only requires a non-empty string kind, and v4 admission only rejects the bare "plugin" — dropping the plugin field matches the shape DSH's own v3→v4 migration emits for the same rows. Separately, @huggingface/transformers@4.2.0 ignores HF_ENDPOINT (it reads env.remoteHost), so on restricted networks local embedding fails and recall returns empty, which hides this bug entirely; pre-seeding the model cache is required to reproduce deterministically.

@dfzsxszvs

Copy link
Copy Markdown

Verified independently here too: Windows 11, DSH Desktop 0.2.0-rc.2, @memtensor/memos-local-plugin 2.0.20. The old { kind: 'plugin', plugin: ... } source is still rejected at session-format-v3-to-v4/lib/index.js:126, and with this change applied the recall row is accepted and stored as plugin:memos-local-plugin with the form metadata preserved.

npm still ships 2.0.20, so anyone on the released plugin hits this on the first turn that produces a recall. Could a maintainer take a look? The fix has now been reproduced and verified by several independent users.

@Pasitearko Pasitearko closed this by deleting the head repository Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugin OpenClaw & Hermes status:in-progress Someone or AI is working on it | 人工或 AI 正在处理

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: DSH 0.1.7 (session format v4) rejects memos recall messages — "format v4 message requires a producer-owned source kind"

6 participants