Skip to content

fix(memos-local-openclaw): resolve SecretRef apiKey in OpenClaw fallb…#1345

Merged
hijzy merged 2 commits intoMemTensor:openclaw-local-plugin-20260324from
hijzy:fix/0325-llm-api
Mar 25, 2026
Merged

fix(memos-local-openclaw): resolve SecretRef apiKey in OpenClaw fallb…#1345
hijzy merged 2 commits intoMemTensor:openclaw-local-plugin-20260324from
hijzy:fix/0325-llm-api

Conversation

@hijzy
Copy link
Copy Markdown
Collaborator

@hijzy hijzy commented Mar 25, 2026

Description

loadOpenClawFallbackConfig reads openclaw.json to build the final fallback LLM config when the plugin's configured summarizer model fails. Previously, it assumed apiKey in models.providers is always a plain string. However, OpenClaw's credential system also supports SecretRef format ({ source: "env", id: "ENV_VAR_NAME" }), which was not resolved — causing either silent fallback skip (when treated as truthy object passing the check but failing HTTP auth) or incorrect availability detection in the viewer.

This PR adds resolveApiKey() to properly handle both plain string and env-sourced SecretRef API keys in three locations:

  • src/ingest/providers/index.ts — Summarizer fallback chain
  • src/shared/llm-call.ts — Skill pipeline fallback chain
  • src/viewer/server.ts — Viewer fallback model availability check

The implementation mirrors the existing resolveApiKey in src/openclaw-api.ts (used by the host model proxy path).

Related Issue (Required): Fixes #

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Unit Test
  • Test Script Or Test Steps (please provide)
  1. Configure openclaw.json with a SecretRef-style apiKey in models.providers:
    {
      "agents": { "defaults": { "model": { "primary": "anthropic/claude-3-haiku-20240307" } } },
      "models": {
        "providers": {
          "anthropic": {
            "baseUrl": "https://api.anthropic.com",
            "apiKey": { "source": "env", "id": "ANTHROPIC_API_KEY" }
          }
        }
      }
    }
  2. Set ANTHROPIC_API_KEY in environment.
  3. Configure the plugin summarizer with an intentionally invalid OpenAI-compatible endpoint so it fails.
  4. Verify the fallback chain correctly resolves the Anthropic API key from env and completes summarization via Anthropic format.

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 的人

Reviewer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed
  • Tests have been provided

@hijzy hijzy merged commit 4f1bd12 into MemTensor:openclaw-local-plugin-20260324 Mar 25, 2026
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.

1 participant