Skip to content

fix: avoid blocking OpenClaw plugin registration#2044

Merged
syzsunshine219 merged 16 commits into
MemTensor:dev-v2.0.23from
RerankerGuo:fix/openclaw-registration-rebuild-block
Jul 9, 2026
Merged

fix: avoid blocking OpenClaw plugin registration#2044
syzsunshine219 merged 16 commits into
MemTensor:dev-v2.0.23from
RerankerGuo:fix/openclaw-registration-rebuild-block

Conversation

@RerankerGuo

Copy link
Copy Markdown
Contributor

Description

Related Issue (Required): Fixes #1778

Removes the synchronous better-sqlite3 auto-rebuild path from OpenClaw plugin registration.

The plugin already has ensureSqliteBinding(ctx.log) as the central native binding preparation step. The removed registration-time fallback could run npm rebuild better-sqlite3 with a 120 second timeout before the service lifecycle was registered, which can make the plugin appear to fail loading during OpenClaw startup. Keeping binding preparation in one path avoids blocking registration and preserves the existing prebuild/rebuild handling.

A regression test guards against reintroducing a registration-time spawnSync/npm rebuild path.

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)
  • Pipeline Automated API Test (please provide)

Commands run:

node - <<'NODE'
const fs = require('fs');
const source = fs.readFileSync('apps/memos-local-openclaw/index.ts', 'utf8');
const test = fs.readFileSync('apps/memos-local-openclaw/tests/startup-registration.test.ts', 'utf8');
const prelude = source.slice(0, source.indexOf('const ctx = buildContext'));
if (prelude.includes('spawnSync')) throw new Error('spawnSync still appears before buildContext');
if (prelude.includes('npm rebuild better-sqlite3')) throw new Error('npm rebuild command still appears before buildContext');
if (prelude.includes('rebuild", "better-sqlite3')) throw new Error('rebuild args still appear before buildContext');
if (!test.includes('does not run npm rebuild during plugin registration')) throw new Error('startup registration regression test missing');
console.log('startup registration static check passed');
NODE

Result: startup registration static check passed.

Also attempted:

cd apps/memos-local-openclaw
npm test -- --run tests/startup-registration.test.ts
npm run build
make format

npm test is blocked because vitest is not installed. npm run build is blocked because tsc is not installed. make format is blocked because poetry is not installed.

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

@Memtensor-AI Memtensor-AI changed the base branch from main to dev-v2.0.22 July 2, 2026 10:57
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: QUEUED

Conflict with dev-v2.0.22 was resolved by merging the base branch into this PR head. Cloud test-engine rerun has been queued.

  • Run: tr-aed9bf13-d88 on cloud test-engine 10012
  • Branch tested: refs/pull/2044/head

I will post the final pass/fail result when the run completes.

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Automated Test Results: PASSED

Cloud test-engine rerun against dev-v2.0.22 completed successfully.

  • Run: tr-aed9bf13-d88 on cloud test-engine 10012
  • memos_local_openclaw/unit: 9 passed, 0 failed, 0 skipped

Manual code review is still required before merge.

@CarltonXiang CarltonXiang deleted the branch MemTensor:dev-v2.0.23 July 3, 2026 07:25
@syzsunshine219 syzsunshine219 reopened this Jul 3, 2026
@syzsunshine219 syzsunshine219 changed the base branch from dev-v2.0.22 to main July 3, 2026 08:20
harvey_xiang and others added 6 commits July 3, 2026 16:34
## Description

Please include a summary of the change, the problem it solves, the
implementation approach, and relevant context. List any dependencies
required for this change.

Related Issue (Required):  Fixes #issue_number

## 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?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration

- [ ] 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](https://github.com/MemTensor/MemOS-Docs) (if applicable) |
我已在 [MemOS-Docs](https://github.com/MemTensor/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
Translated an untranslated JSON `description` field in
`docs/cn/open_source/modules/dream.md` from English to Chinese.
@RerankerGuo

Copy link
Copy Markdown
Contributor Author

Hi @Memtensor-AI / @CarltonXiang — friendly ping on this draft.

Quick observation: this PR still has base branch main, but MemTensor/MemOS's current merge flow is into dev-v2.0.22 (every recent PR #2065 / #2058 / #2047 / #2046 / #2042 / #2034 / #2033 / #2026 lands on dev-v2.0.22). The bot already retargeted the base SHA for testing and cloud test-engine returned PASSED against dev-v2.0.22 on every rerun.

Could a maintainer please change the base branch from maindev-v2.0.22 (Edit → base branch dropdown) so this can enter the normal merge queue? The head commit is a single focused change and does not depend on any main-only commits.

Thanks!

@RerankerGuo

Copy link
Copy Markdown
Contributor Author

Hi @syzsunshine219 — looks like you've merged 35 of the last 50 PRs on this repo. Friendly ping on this one.

This draft (and the other 21 OPEN PRs I have here) is small, single-commit, has cloud test-engine PASSED, and is fully mergeable. The only thing blocking it is that the base branch dropdown still says main — every recent merge (e.g. #2038, #2037, #2034, #2032) landed on dev-v2.0.22.

When you have a moment, would you mind one of:

  1. Flipping the base branch on this PR from maindev-v2.0.22 (Edit → base branch dropdown), or
  2. Telling me which base branch you'd prefer and I'll re-push accordingly.

Both fix and feature PRs in this batch are independent — each can be reviewed/merged on its own. Happy to rebase / split / drop any that don't fit the direction.

Thanks!

@RerankerGuo RerankerGuo force-pushed the fix/openclaw-registration-rebuild-block branch from b41dd88 to d871455 Compare July 8, 2026 07:45
@Memtensor-AI Memtensor-AI added the area:plugin OpenClaw & Hermes label Jul 8, 2026
@Memtensor-AI Memtensor-AI changed the base branch from main to dev-v2.0.23 July 8, 2026 11:36
@Memtensor-AI Memtensor-AI marked this pull request as ready for review July 8, 2026 11:36
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

🤖 Open Code Review

Target: PR #2044
Task: manual-ocr:MemTensor/MemOS#2044
Base: main
Head: fix/openclaw-registration-rebuild-block

🔍 OpenCodeReview found 2 issue(s) in this PR.


1. apps/memos-local-openclaw/index.ts (L226-L227)

Critical: pluginDir is undefined after this removal, causing a ReferenceError at runtime.

The variable pluginDir was exclusively defined inside the removed block as const pluginDir = detectPluginDir(moduleDir). It is still referenced on lines 270 and 273:

  • path.join(pluginDir, "package.json") — used to read the plugin version
  • new Telemetry(..., pluginDir) — passed as a constructor argument

Every time the plugin initializes, it will crash with ReferenceError: pluginDir is not defined before the SQLite store is opened or any tool is registered.

Fix: Replace pluginDir with moduleDir (which is already defined on the line immediately above and points to the same directory via path.dirname(fileURLToPath(import.meta.url))), or introduce a dedicated const pluginDir = moduleDir; assignment.

💡 Suggested Change

Before:

    const moduleDir = path.dirname(fileURLToPath(import.meta.url));
    let pluginCfg = (api.pluginConfig ?? {}) as Record<string, unknown>;

After:

    const moduleDir = path.dirname(fileURLToPath(import.meta.url));
    const pluginDir = moduleDir; // replaces removed detectPluginDir(moduleDir)
    let pluginCfg = (api.pluginConfig ?? {}) as Record<string, unknown>;

2. apps/memos-local-openclaw/index.ts (L226)

moduleDir is now dead code after this change. It was previously used only as the input to detectPluginDir(moduleDir), which was removed along with the sqlite auto-setup block. With pluginDir also gone (see critical issue above), moduleDir is never read by any subsequent statement. Either remove it, or repurpose it as pluginDir directly.

Generated by cloud-assistant via Open Code Review.

…oval

OCR review on MemTensor#2044 flagged that after removing detectPluginDir(moduleDir),
the local 'pluginDir' variable is still referenced on lines 270 and 273
(path.join(pluginDir, 'package.json') and new Telemetry(..., pluginDir)),
which would cause a ReferenceError at runtime.

Alias pluginDir = moduleDir at the same scope so the existing
references keep working without re-introducing the removed helper.
@Memtensor-AI

Copy link
Copy Markdown
Collaborator

✅ Automated Test Results: PASSED

All tests passed (9/9 executed). memos_local_openclaw/unit: 9/9. Duration: 3s

Branch: fix/openclaw-registration-rebuild-block

@syzsunshine219 syzsunshine219 merged commit 598b674 into MemTensor:dev-v2.0.23 Jul 9, 2026
16 checks passed
RerankerGuo added a commit to RerankerGuo/MemOS that referenced this pull request Jul 9, 2026
…oval

OCR review on MemTensor#2044 flagged that after removing detectPluginDir(moduleDir),
the local 'pluginDir' variable is still referenced on lines 270 and 273
(path.join(pluginDir, 'package.json') and new Telemetry(..., pluginDir)),
which would cause a ReferenceError at runtime.

Alias pluginDir = moduleDir at the same scope so the existing
references keep working without re-introducing the removed helper.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugin OpenClaw & Hermes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Openclaw启动时memos-local-plugin插件概率性不启动

6 participants