Skip to content

fix(openclaw): normalize better-sqlite3 bootstrap paths on Windows#1203

Open
fancyboi999 wants to merge 2 commits intoMemTensor:mainfrom
fancyboi999:fancy/issue-1192-investigate
Open

fix(openclaw): normalize better-sqlite3 bootstrap paths on Windows#1203
fancyboi999 wants to merge 2 commits intoMemTensor:mainfrom
fancyboi999:fancy/issue-1192-investigate

Conversation

@fancyboi999
Copy link
Contributor

Description

This fixes the Windows false negative in the OpenClaw plugin bootstrap for better-sqlite3.

Problem solved:

  • The runtime entry used new URL(import.meta.url).pathname and a raw startsWith check to decide whether better-sqlite3 resolved inside the plugin directory.
  • On Windows, pathname can produce /C:/... while require.resolve(...) returns C:/..., so the same path is incorrectly treated as outside the plugin dir.
  • That false negative incorrectly triggers the rebuild path and eventually surfaces as better-sqlite3 native module not found even when the module is already installed.

Implementation approach:

  • Extract the runtime bootstrap into a dedicated helper so the entry-point path logic is independently testable.
  • Convert import.meta.url to a real filesystem path with fileURLToPath(..., { windows: true }) on Windows.
  • Replace the fragile string-prefix check with a path relationship check based on path.relative(...).
  • Keep the existing auto-rebuild fallback, but run it from the normalized plugin directory.
  • Reuse the resolved plugin directory when reading package.json, removing the previous dependency on __dirname semantics.

Related Issue (Required): Fixes #1192

Type of change

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

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

Commands run locally:

  • cd apps/memos-local-openclaw && npx vitest run tests/sqlite-bootstrap.test.ts tests/shutdown-lifecycle.test.ts --reporter=dot
  • cd apps/memos-local-openclaw && npm run build

Coverage added in this PR:

  • Windows import.meta.url to filesystem path conversion
  • Windows path containment with mixed slash/case forms
  • Guard against sibling-prefix false positives
  • Rebuild retry path after an initial outside-plugin resolution

Notes:

  • tests/plugin-impl-access.test.ts showed an existing local runner-exit hang when run standalone in this environment. This PR does not change plugin-impl.ts, and the new bootstrap tests cover the runtime path logic introduced here.

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

Copilot AI review requested due to automatic review settings March 11, 2026 08:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a Windows-specific false negative when checking whether better-sqlite3 resolved within the OpenClaw plugin directory by normalizing path handling and refactoring the bootstrap logic into a testable helper.

Changes:

  • Extracted better-sqlite3 bootstrap/load/rebuild logic into src/runtime/sqlite-bootstrap.ts.
  • Replaced string-prefix path checks with a path.relative(...)-based containment check.
  • Added unit tests covering Windows path normalization and rebuild retry behavior; updated plugin entry to use the new helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
apps/memos-local-openclaw/tests/sqlite-bootstrap.test.ts Adds unit tests for Windows path conversion, containment checks, and rebuild retry logic.
apps/memos-local-openclaw/src/runtime/sqlite-bootstrap.ts Introduces a reusable/bootstrap helper for resolving/loading/rebuilding better-sqlite3 with improved path containment logic.
apps/memos-local-openclaw/index.ts Switches the plugin entrypoint to use the new bootstrap helper and reads package.json relative to the resolved plugin dir.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

fix(windows): normalize plugin path when resolving better-sqlite3 to avoid false “outside plugin dir”

2 participants