refactor(opencode-plugin): migrate auto recall from chat.messages.transform to chat.message hook#1977
Merged
yangxinxin-7 merged 1 commit intoMay 12, 2026
Conversation
…nsform to chat.message hook Replace experimental.chat.messages.transform (stateless, non-persistent) with chat.message + synthetic:true parts for persistent injection. Eliminates context drift, redundant searches, and poor KV-cache hit rate across tool call continuations. Removes dead code: RecallMessagePart, RecallWithParts, extractLatestUserText, appendToLastTextPart. Adds runAutoRecall() shared function. Net -28 lines (-82/+54).
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
fdca3dc to
e509129
Compare
PR Code Suggestions ✨No code suggestions found for the PR. |
19 tasks
yangxinxin-7
approved these changes
May 12, 2026
Collaborator
yangxinxin-7
left a comment
There was a problem hiding this comment.
LGTM!这是一个很棒的重构:
- 解决了无状态钩子导致的上下文漂移和重复搜索问题
- 代码更简洁,删除了不必要的死代码
- 幂等性处理得当
- CI 全部通过
r266-tech
added a commit
to r266-tech/OpenViking
that referenced
this pull request
May 12, 2026
qin-ctx
pushed a commit
that referenced
this pull request
May 13, 2026
ZaynJarvis
pushed a commit
that referenced
this pull request
May 13, 2026
…nsform to chat.message hook (#1977) Replace experimental.chat.messages.transform (stateless, non-persistent) with chat.message + synthetic:true parts for persistent injection. Eliminates context drift, redundant searches, and poor KV-cache hit rate across tool call continuations. Removes dead code: RecallMessagePart, RecallWithParts, extractLatestUserText, appendToLastTextPart. Adds runAutoRecall() shared function. Net -28 lines (-82/+54).
ZaynJarvis
pushed a commit
that referenced
this pull request
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
将记忆召回(auto recall)钩子从
experimental.chat.messages.transform迁移到chat.message,使用synthetic: true持久化注入,解决上下文漂移与重复搜索问题。Related Issue
N/A
Type of Change
Changes Made
experimental.chat.messages.transform钩子RecallMessagePart、RecallWithParts接口、extractLatestUserText、appendToLastTextPart函数chat.message钩子,使用synthetic: true持久化注入<relevant-memories>runAutoRecall()共享函数extractMessageText()替代extractLatestUserText(),适配chat.message的input.parts签名Testing
Checklist
Additional Notes
问题根因
experimental.chat.messages.transform是无状态钩子——修改仅作用于内存中的消息拷贝,不写回会话存储。每次 LLM API 调用(含工具调用续接)都会重新触发,导致:方案
chat.message钩子在用户消息创建时触发一次,output.parts的修改持久化到会话历史。synthetic: true的 part 在 TUI 中不可见,但对 LLM 作为 synthetic context 发送。效果对比
关键约束
prt-ov-recall-{ts}-{random},必须prt-开头(OpenCode schema 校验)<relevant-memories>标记检测,防止重加载会话后重复注入chat.message仅对新消息触发