fix(issue-383): Resolve OpenClaw compaction delegate from runtime paths#384
Open
Veteran-ChengQin wants to merge 1 commit into
Open
Conversation
be21865 to
f54e367
Compare
Collaborator
|
Thank you for your contribution and interest! We will schedule an internal review of your code and get back to you soon. |
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.
PR 标题
Resolve OpenClaw compaction delegate from runtime paths
关联 issue
Closes #383
背景
当
memory-tencentdb作为 OpenClawcontextEngine使用时,tdai 的compact()会优先尝试调用 OpenClaw plugin SDK 暴露的delegateCompactionToRuntime(params),把 transcript compaction 委派回 OpenClaw 原生 runtime。这条路径对 OpenClaw 集成很重要:OpenClaw runtime 原生知道如何基于
sessionFile、sessionId、runtimeContext等信息执行 compaction,并返回 OpenClaw 可以采纳的新 session/transcript 元信息。当前实现主要从固定系统全局路径解析 OpenClaw SDK,例如:
在 nvm 管理 Node.js 的环境中,OpenClaw 可能实际安装在类似路径:
此时 tdai 无法解析
openclaw/plugin-sdk,会落入 self-emergency fallback:修改内容
本 PR 新增一个专用 resolver:
它会从以下位置尝试解析
openclaw/plugin-sdk:import.meta.urlNODE_PATHlib/node_modules/usr/local/lib/node_modules、/usr/lib/node_modules同时在
OffloadContextEngine.compact()中把该 resolver 放到原有固定路径解析逻辑之前:当 resolver 成功找到
delegateCompactionToRuntime时,tdai 直接委派给 OpenClaw native compaction。resolver 返回null时,继续执行原有的/usr/local、/usr/lib、direct import 探测逻辑;这些旧逻辑也都失败时,现有 self-emergency fallback 行为保持不变。非本 PR 范围
本 PR 只解决 OpenClaw native compaction delegate 的解析问题。
以下问题刻意不放入本 PR:
params.messages缺失时 fallback compaction 如何从sessionFile/sessionManager恢复 messages。这些问题应该作为后续 issue / PR 单独处理,避免把 delegate 解析修复和 fallback 压缩策略调整耦合在一起。
测试
单元测试与构建
在独立 PR worktree 中安装依赖并验证:
没有生成新的 lockfile。
单元测试:
结果:
构建验证:
结果:通过。
新增 resolver 的单元测试覆盖了三类路径:
openclaw/plugin-sdk。openclaw/plugin-sdk,覆盖 nvm/global npm root 这类安装形态。null,继续保留现有 fallback 行为。OpenClaw 集成验证
为了确认该修复不只是在单元测试中可用,也真实接入了 OpenClaw compaction runtime,本地在 WSL + OpenClaw 中运行了 40k Mid-Turn Precheck 复现实验。
环境:
关键配置:
关键计数:
关键日志片段:
后续还出现了多次 OpenClaw native compaction / safeguard 路径:
这个结果说明 patched tdai 已经成功接入 OpenClaw native compaction path:
delegateCompactionToRuntime unavailable。self_emergencyfallback。no_messages。compaction-safeguard、tool-result-truncation、post-compaction-guard均被触发。auto-compaction succeeded3 次。该 run 最终仍以非 0 退出,但原因是模型侧网络超时:
因此该 run 不能证明 SWE-bench 任务完成,但可以证明本 PR 修复的 delegate resolver 已在真实 OpenClaw 集成路径中生效,并且不再触发原先的
delegateCompactionToRuntime unavailable/self_emergency/no_messages链路。