Skip to content

fix(Windows): Path format mismatch causes better-sqlite3 loading failure #1358

Closed

Description

@cower

Bug Description

Windows path format bug in index.ts causes plugin to fail loading better-sqlite3

On Windows, the plugin fails to load because of path format mismatch:

  • pluginDir from new URL(import.meta.url).pathname returns /C:/Users/... format
  • require.resolve() returns C:\Users\... format
  • The startsWith() check at line 91 always fails, causing the plugin to think better-sqlite3 is "outside plugin dir"

How to Reproduce

  1. Install plugin on Windows: openclaw plugins install @memtensor/memos-local-openclaw-plugin
  2. Manually rebuild better-sqlite3: cd ~/.openclaw-dev/extensions/memos-local-openclaw-plugin && npm rebuild better-sqlite3
  3. Start gateway: openclaw gateway start
  4. Plugin fails with: better-sqlite3 resolved outside plugin dir: C:/Users/.../better-sqlite3/lib/index.js

Environment

  • OS: Windows 10/11
  • Node.js: v22.22.0
  • Plugin version: 1.0.7

Root Cause

In index.ts line 82-92, path format mismatch causes the check to always fail on Windows.

Solution

Normalize paths before comparison by:

  1. Remove leading slash from Windows URL pathname
  2. Normalize backslashes to forward slashes for comparison

Verification

After applying this fix, the plugin loads successfully on Windows:

[plugins] memos-local: initialized (db: C:\Users\Admin\.openclaw\memos-local\memos.db)
| MemOS Local  | memos-local-openclaw-plugin | loaded | 0.1.11 |

Additional Context

This issue is related to #1201 but is a different root cause. #1201 was about Node 25+ compatibility, while this is specifically about Windows path format handling.

Activity

  1. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 29, 2026
  2. self-assigned this
    on Jun 30, 2026
  3. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

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

    Task ID: 6d7408bbcb6ffb3f
    Working branch: bugfix/autodev-1358
    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.

  4. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 6d7408bbcb6ffb3f completed.

    Summary: Fixes the Windows path mismatch in apps/memos-local-openclaw/index.ts that caused the @memtensor/memos-local-openclaw-plugin to refuse loading better-sqlite3 even when the native binding sat in its own node_modules/. The plugin's isPathInside(pluginDir, resolvedReal) sandbox guard previously compared /C:/Users/... (from new URL(import.meta.url).pathname) against C:\Users\... (from require.resolve()). The inline normalizeFsPath only stripped the \\?\ long-path prefix and lower-cased, so path.relative() returned a leading-slash absolute path and the guard always failed.

    The helpers are now extracted into apps/memos-local-openclaw/src/path-utils.ts and hardened against the five Windows path shapes the runtime can produce: plain backslash, mixed slash, URL-pathname /C:/..., \\?\C:\..., and \\?\UNC\server\share. POSIX behaviour stays case-sensitive. The sandbox semantics are preserved: hoisted-parent and sibling-dir paths still return false. Direct repro of the issue inputs flips from false → true after the fix.

    Tests: 21 new table-driven vitest cases in apps/memos-local-openclaw/tests/path-utils.test.ts covering every Windows shape plus POSIX same-dir / child / sibling / case-difference. npx vitest run tests/path-utils.test.ts → 21/21 passed. Regression sanity over the sqlite-independent suites (config, chunker, capture, policy) → 55/55 passed. tsc --noEmit clean. Pre-existing task-processor and update-install failures are environmental (better-sqlite3 native binding skipped via --ignore-scripts) and reproduce on a clean baseline — unrelated to this change.

    Files touched (3): apps/memos-local-openclaw/index.ts (import the shared helper, delete the inline copy), apps/memos-local-openclaw/src/path-utils.ts (new), apps/memos-local-openclaw/tests/path-utils.test.ts (new). Specs archived to memos-autodev-specs main (commit 0027420).

    Base branch: main
    Branch: bugfix/autodev-1358
    Commit: ee7a340
    PR: #2005
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  5. added
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:failedAI task failed | AI 任务失败
    and removed
    ai:codingAI agent is coding | AI 正在编码
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 30, 2026
  6. added a commit that references this issue on Jul 1, 2026
    70b2180
  7. added and removed
    ai:failedAI task failed | AI 任务失败
    on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:pluginOpenClaw & Hermestypes:bugSomething isn't working | 功能异常

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions