MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

fix: 本地viewer不会解析配置文件的环境变量

Open xutao0565 opened this issue 7 months ago • 3 comments

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 | 问题描述

本地插件viewer直接从配置文件读取配置,不会解析环境变量,导致Embedding等模型的key必须硬编码在配置文件中

How to Reproduce | 如何重现

以openclaw为例,openclaw.json文件Embedding 模型的key替换成变量,Viewer界面连接报错

Environment | 环境信息

  • Operating System : macos V26.4.1
  • Memos Version: memos-local-openclaw-plugin v1.0.9-beta.2

Additional Context | 其他信息

No response

Willingness to Implement | 实现意愿

  • [x] I'm willing to implement this myself | 我愿意自己解决
  • [x] I would like someone else to implement this | 我希望其他人来解决

xutao0565 avatar Apr 17 '26 11:04 xutao0565

💬 我也在做记忆系统相关的工作:CausaMem,可以来看看,说不定有能借鉴的地方 🙂

MaiHHConnect avatar Apr 19 '26 00:04 MaiHHConnect

🤖 AutoDev has picked up this issue and started working on it.

Task ID: 750b19581f7f5526 Working branch: bugfix/autodev-1490 Target branch: latest dev* branch Workflow: opsp (analysis → coding → testing → PR)

I will post the PR link here once done. If I need more information, I will ask in the comments.

Memtensor-AI avatar Jun 30 '26 08:06 Memtensor-AI

✅ AutoDev task 750b19581f7f5526 completed.

Summary: Fixes #1490: the local viewer in apps/memos-local-openclaw was reading openclaw.json directly in three paths (handleTestModel, serveFallbackModel, runMigration) without expanding ${VAR} env-var literals. Users who stored secrets in their config as "apiKey": "${MY_API_KEY}" saw 401s because the literal placeholder ended up in the Bearer header. resolveConfig() already had a deepResolveEnv() helper, but it was private and only applied to the in-memory plugin context.

The fix exports deepResolveEnv / resolveEnvVars from src/config.ts, adds readPluginConfigResolved / readOpenClawResolvedConfig helpers in ViewerServer, and routes every "about-to-call-the-network" string (apiKey/endpoint/baseUrl in the migration summarizer, fallback model probe, and embedding/chat test endpoints) through the resolver. serveConfig is intentionally left raw so the UI can still display ${VAR} literals for editing — secrets never round-trip back into the file.

Test plan: added tests/viewer-env-resolution.test.ts (4 cases) covering test-model env expansion, fallback-model env expansion, the new resolved-config helper, and the raw-passthrough property of serveConfig. All 4 pass. Full vitest suite: 226 pass / 5 fail, where the 5 failures (accuracy, skill-auto-install, task-processor, update-install) reproduce identically on unmodified dev-20260615-v2.0.20 (confirmed via git stash baseline) and depend on the local huggingface embedding cache / fake-timer process.kill timing — unrelated to this change. tsc build passes clean.

Base branch: main Branch: bugfix/autodev-1490 Commit: 5386365 PR: https://github.com/MemTensor/MemOS/pull/1984 Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

Memtensor-AI avatar Jun 30 '26 09:06 Memtensor-AI