Skip to content

[Bug]: No graceful degradation when native modules fail to load — entire plugin becomes unusable #74

@kevintseng

Description

@kevintseng

Component

MCP Server

Bug Description

Summary

When any native C++ module (better-sqlite3, onnxruntime-node, sqlite-vec) fails to load, the entire MCP server crashes and all memesh tools become completely unavailable. There is no fallback mechanism or graceful degradation.

What Happened

In Claude Desktop Cowork environment (Ubuntu 22 ARM64 sandbox), better-sqlite3 cannot compile due to:

  1. Plugin directory is read-only filesystem (sandbox security)
  2. node-gyp cannot download Node.js headers (network restriction, HTTP 403)

Because ConnectionPool.ts has a hard import Database from 'better-sqlite3' at the top level, the import fails immediately and the entire MCP server process crashes before any tool can register.

Expected Behavior

The MCP server should start with reduced functionality when native modules are unavailable:

  • Core MCP tools should still register (even if some features are limited)
  • Clear warning/error message explaining which features are degraded
  • Suggest user actions (e.g., "Run npm rebuild" or "Set MEMESH_API_KEY for cloud-only mode")

Impact

  • 100% of plugin functionality lost when a single native module fails
  • Affects all users in sandboxed/restricted environments (Cowork, Docker, CI/CD)
  • No error message visible to user — tools simply don't appear

Steps to Reproduce

  1. Install memesh plugin in Claude Desktop Cowork mode
  2. Start a new Cowork session
  3. The MCP server fails silently during bootstrap (server-bootstrap.js)
  4. No memesh tools appear in the available tools list
  5. User has no indication of what went wrong

Root cause chain:

server-bootstrap.js
  → ServerInitializer.ts → KnowledgeGraph.createSync()
    → ConnectionPool.ts → import Database from 'better-sqlite3'
      → Native .node binary not found → CRASH

Error Output

Error: Cannot find module 'better-sqlite3'
  or: Error: The module was compiled against a different Node.js version

node-gyp rebuild errors:
gyp ERR! stack Error: 403 response downloading https://nodejs.org/download/release/v22.22.0/node-v22.22.0-headers.tar.gz
gyp ERR! System Linux 6.8.0-94-generic
gyp ERR! node -v v22.22.0

Also: .claude-plugin/memesh/ is read-only filesystem:
mkdir: cannot create directory 'node_modules': Read-only file system

MeMesh Version

2.8.10

Claude Code Client

Other

Node.js Version

v22.22.0

Operating System

Linux

MCP Configuration

{
  "memesh": {
    "command": "node",
    "args": ["${CLAUDE_PLUGIN_ROOT}/dist/mcp/server-bootstrap.js"],
    "env": {
      "NODE_ENV": "production",
      "MEMESH_DISABLE_DAEMON": "1"
    }
  }
}

Additional Context

Suggested Fix (backward compatible)

Option 1: Dynamic import with try/catch (recommended)

Wrap the better-sqlite3 import in a dynamic import with fallback:

// src/db/ConnectionPool.ts
let Database: any;
let nativeModuleAvailable = false;

try {
  Database = (await import('better-sqlite3')).default;
  nativeModuleAvailable = true;
} catch (e) {
  logger.warn('[memesh] better-sqlite3 not available. Memory features will be limited.');
}

Option 2: Ship prebuild binaries

Include prebuilt binaries for common platforms in the npm package (see issue #73 for details).

Option 3: Add sql.js as pure-JS fallback

Add sql.js (WebAssembly SQLite) as optional fallback when native module unavailable.

Related

Environment

  • Plugin: @pcircle/memesh v2.8.10
  • Platform: Claude Desktop Cowork (Ubuntu 22.04 ARM64 sandbox)
  • Node.js: v22.22.0
  • All native build tools present (gcc, g++, make, python3) but blocked by sandbox

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNeeds triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions