fix: memOS一直启动多个实例
Pre-submission checklist | 提交前检查
- [x] I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
- [x] I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
- [x] This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题
Bug Description | 问题描述
🦞 OpenClaw 2026.4.9 (0512059) — iMessage green bubble energy, but for everyone.
│
◇
10:39:56+08:00 [plugins] memos-local: initialized (db: C:\Users\13268\.openclaw\memos-local\memos.db)
10:39:56+08:00 [plugins] memos-local: allowPromptInjection=true, auto-recall enabled
10:39:56+08:00 [ws] ⇄ res ✓ node.list 87ms conn=46e7af50…045c id=e493be13…e41a
10:40:58+08:00 [plugins] memos-local: service.start() not called by host, self-starting viewer...
10:40:58+08:00 [plugins] Viewer port 18799 in use, trying 18800
10:40:58+08:00 [plugins] memos-local: started (embedding: openai_compatible)
10:40:58+08:00 [plugins] ╔══════════════════════════════════════════╗
10:40:58+08:00 [plugins] ║ MemOS Memory Viewer ║
10:40:58+08:00 [plugins] ║ → http://127.0.0.1:18800 ║
10:40:58+08:00 [plugins] ║ Open in browser to manage memories ║
10:40:58+08:00 [plugins] ╚══════════════════════════════════════════╝
10:40:58+08:00 [plugins] memos-local: password reset token: 6f386c68ac6af1bc578e88d82b16d4a8
10:40:58+08:00 [plugins] memos-local: forgot password? Use the reset token on the login page.
10:41:00+08:00 [ws] ⇄ res ✓ node.list 1767ms conn=46e7af50…045c id=c5df9f08…7a27
10:41:00+08:00 [plugins] [debug] Database schema initialized
10:41:00+08:00 [plugins] [debug] OpenClaw fallback model: gemma-4-26B-A4B-it-UD-IQ4_XS.gguf via http://127.0.0.1:8080/v1 (openai_compatible)
10:41:00+08:00 [plugins] [debug] OpenClaw fallback model: gemma-4-26B-A4B-it-UD-IQ4_XS.gguf via http://127.0.0.1:8080/v1 (openai_compatible)
10:41:00+08:00 [plugins] [debug] Telemetry disabled (opt-out)
10:41:00+08:00 [plugins] memos-local: installed bundled skill memos-memory-guide → C:\Users\13268\.openclaw\workspace\skills\memos-memory-guide
10:41:00+08:00 [plugins] memos-local: installed bundled skill memos-memory-guide → C:\Users\13268\.openclaw\skills\memos-memory-guide (managed)
10:41:00+08:00 [plugins] [debug] OpenClaw fallback model: gemma-4-26B-A4B-it-UD-IQ4_XS.gguf via http://127.0.0.1:8080/v1 (openai_compatible)
10:41:00+08:00 [plugins] memos-local: initialized (db: C:\Users\13268\.openclaw\memos-local\memos.db)
10:41:00+08:00 [plugins] memos-local: allowPromptInjection=true, auto-recall enabled
10:41:06+08:00 [plugins] memos-local: service.start() not called by host, self-starting viewer...
10:41:06+08:00 [plugins] Viewer port 18799 in use, trying 18800
10:41:06+08:00 [plugins] Viewer port 18800 in use, trying 18801
10:41:06+08:00 [plugins] memos-local: started (embedding: openai_compatible)
10:41:06+08:00 [plugins] ╔══════════════════════════════════════════╗
10:41:06+08:00 [plugins] ║ MemOS Memory Viewer ║
10:41:06+08:00 [plugins] ║ → http://127.0.0.1:18801 ║
10:41:06+08:00 [plugins] ║ Open in browser to manage memories ║
10:41:06+08:00 [plugins] ╚══════════════════════════════════════════╝
10:41:06+08:00 [plugins] memos-local: password reset token: af8f99c4f6b474d7ea7544c22ae3b1b3
10:41:06+08:00 [plugins] memos-local: forgot password? Use the reset token on the login page.
How to Reproduce | 如何重现
1、安装memOS插件1.0.8
powershell -c "irm https://cdn.memtensor.com.cn/memos-local-openclaw/install.ps1 | iex"
2、启动OpenClaw 3、进行一次对话
Environment | 环境信息
PS C:\Users\13268\.openclaw> python --version
Python 3.12.13
PS C:\Users\13268\.openclaw> pip --version
pip 26.0.1 from C:\Users\13268\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\pip (python 3.13)
PS C:\Users\13268\.openclaw>
PS C:\Users\13268\.openclaw> pip show memoryos
WARNING: Package(s) not found: memoryos
PS C:\Users\13268\.openclaw>
Additional Context | 其他信息
No response
Willingness to Implement | 实现意愿
- [x] I'm willing to implement this myself | 我愿意自己解决
- [x] I would like someone else to implement this | 我希望其他人来解决
确实,尤其是openclaw gateway restart时,就得viewer没有关闭,新的viewer又启动了
翻了一下代码,问题出在 register() 里的 serviceStarted 和 viewer 都是闭包局部变量。gateway restart 或 deferred reload 重新调 register() 的时候,旧闭包里的 viewer 没人管,新的又起一个,端口就一直往上涨。
改法是在模块层面按 stateDir 追踪活跃实例,重注册的时候先 await 把旧 viewer 关干净再启动新的。顺便把 ViewerServer.stop() 改成返回 Promise 了,不然端口还没释放就 rebind 会竞态。
PR 在 #1477,有空帮忙看看。
This issue has been fixed in the latest version of the plugin. The duplicate Viewer startup and port conflict problems were resolved by introducing a global singleton state to manage the initialization lifecycle. Please update to the latest release!
Hey @IAMJOYBO! Thanks for the contribution — already solved the issue, thanks for helping us to catch the bug! 🐞
Btw if you enjoyed contributing and want to stay connected with the project, we run a Discord server for contributors, a chill space to discuss features, ask questions, or pick up new issues 👉🏻 MemOS Discord Server (Contributor Exclusive)
Thanks again for shipping this, and happy MemOSing 🧠✨