Skip to content

Fix #1639: [memos-local-openclaw] Memory Viewer (port 18799) not starting on Node 24#1823

Open
Memtensor-AI wants to merge 1 commit into
v2.0.16from
autodev/MemOS-1639
Open

Fix #1639: [memos-local-openclaw] Memory Viewer (port 18799) not starting on Node 24#1823
Memtensor-AI wants to merge 1 commit into
v2.0.16from
autodev/MemOS-1639

Conversation

@Memtensor-AI
Copy link
Copy Markdown
Collaborator

@Memtensor-AI Memtensor-AI commented May 28, 2026

Description

修复了 #1639:memos-local-openclaw 插件的 register() 在调用 api.on("before_prompt_build", ...) 时抛错(老/兼容版 OpenClaw runtime 不提供 api.on),导致后续 ViewerServer 实例化、registerService 注册、setTimeout(0) 自启动兜底都没有执行,端口 18799 永远未绑定。修复:新增 safeOn 包裹两处 api.on,并把 registerMemoryCapability / registerService 也用存在性检查 + try/catch 兜住;另加 2 个回归测试覆盖 api.on 缺失和 api.on 抛错两种场景。已 commit + push 到 autodev/MemOS-1639,scheduler 可基于此分支兜底创建 PR。

Related Issue (Required): Fixes #1639

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Executor did not report tests.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have created related documentation issue/PR in MemOS-Docs (if applicable) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

@CarltonXiang, @syzsunshine219 please review this PR.

Reviewer Checklist

…#1639)

On OpenClaw runtimes that do not expose `api.on` (or expose one that
throws), the call to `api.on("before_prompt_build", ...)` raised partway
through `register()` and aborted the rest of plugin setup. The
ViewerServer was never instantiated, `api.registerService` never ran,
and the `setTimeout(0)` self-start fallback was never scheduled — so
port 18799 stayed unbound while individual tools (registered earlier)
kept working. This matched the reported behaviour on Node 24:
register/activate succeeds, memory tools work, but the viewer HTTP
server never listens.

Make the plugin defensive against partial host APIs:

- Add a `safeOn` helper that checks for `api.on` and wraps the
  invocation in try/catch; reroute both `before_prompt_build` and
  `agent_end` through it.
- Wrap `api.registerMemoryCapability` and `api.registerService` in
  try/catch with existence checks, so missing methods log a warning
  instead of throwing.
- Track whether registerService succeeded so the existing setTimeout(0)
  fallback can log the right reason when it self-starts the viewer.

Also add two regression tests in `plugin-openclaw-wiring.test.ts`:
one for the `api.on === undefined` case and one for an `api.on` that
throws synchronously. Both assert that ViewerServer is still
constructed (and, for the missing-on variant, started) during
`register()`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants