Skip to content

Hive-Mind Session Resume Does Not Restore MCP Server State #900

@chmc

Description

@chmc

Bug Report: Hive-Mind Session Resume Does Not Restore MCP Server State

Environment

  • claude-flow version: 2.7.42 (alpha)
  • Node.js version: v25.2.1
  • Platform: macOS Darwin 25.1.0 (arm64)
  • Claude Code: Latest

Summary

When resuming a hive-mind session with --claude flag, the MCP server starts with empty in-memory state instead of loading the persisted session/swarm data from .hive-mind/sessions/. This causes all mcp__claude-flow__* tool calls to fail with "Swarm not found" errors, even though the CLI correctly shows the session as active.

Steps to Reproduce

  1. Create a hive-mind session:

    claude-flow hive-mind spawn --objective "Test task" --workers 4 --claude
  2. Work with the session, then pause (Ctrl+C)

  3. Resume the session:

    claude-flow hive-mind resume session-1765101696583-uqbb9abjt --claude
  4. In the spawned Claude Code instance, try to use MCP tools:

    mcp__claude-flow__swarm_status(swarmId: "swarm-1765101696582-fbc3nfj1p")
    

Expected Behavior

The MCP server should load the persisted swarm state from .hive-mind/sessions/ so that:

  • mcp__claude-flow__swarm_status returns the active swarm info
  • mcp__claude-flow__memory_usage retrieves stored collective memory
  • All swarm coordination tools work with the resumed session

Actual Behavior

{
  "success": false,
  "error": "Swarm swarm-1765101696582-fbc3nfj1p not found",
  "timestamp": "2025-12-08T10:34:05.020Z"
}

The CLI shows the session correctly:

claude-flow hive-mind status
# Shows: hive-1765101696578 with 5 agents, status: active

But MCP tools cannot find it because:

  1. CLI stores state in .hive-mind/sessions/ directory (JSON files)
  2. MCP server maintains separate in-memory state
  3. On resume, --claude only injects context into Claude's prompt, but doesn't initialize MCP server state

Additional Issue: SQLite Module Incompatibility

The MCP server also fails to initialize the memory store due to native module version mismatch:

[ERROR] [memory-store] Failed to initialize: Error: The module
'/Users/aleksi/.npm/_npx/.../better_sqlite3.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 137. This version of Node.js requires
NODE_MODULE_VERSION 141.

This occurs because:

  • npx claude-flow@alpha caches the package with native modules compiled for an older Node.js
  • User updates Node.js but the cached native module is stale

Workaround: npm cache clean --force and reinstall

Proposed Solution

Option A: MCP Server Loads State from Disk

On startup, MCP server should:

  1. Check for active sessions in .hive-mind/sessions/
  2. Load swarm state from checkpoint JSON files
  3. Initialize in-memory state to match persisted state

Option B: CLI Initializes MCP State on Resume

The hive-mind resume --claude command should:

  1. After spawning Claude Code, send initialization commands to MCP
  2. Use MCP tools to recreate the swarm with same ID/state
  3. Populate memory namespace with persisted data

Option C: Unified State Store

Replace separate CLI/MCP state stores with a single source of truth:

  • Both CLI and MCP read/write to same SQLite database
  • Use file locking for concurrent access
  • MCP server watches for changes

Files Involved

  • .hive-mind/sessions/session-*-auto-save-*.json - Checkpoint data
  • .hive-mind/sessions/hive-mind-resume-*.txt - Resume prompt templates
  • src/mcp/mcp-server.js - MCP server (starts with empty state)
  • src/cli/ - CLI commands (manage .hive-mind/sessions/)

Workaround

Currently, users must either:

  1. Initialize a new swarm via MCP after resume (loses continuity)
  2. Use only CLI commands, not MCP tools
  3. Manually track progress outside of hive-mind (e.g., TODO.md file)

Related Issues

  • May be related to the general architecture of having separate CLI and MCP systems
  • Similar to issues with multiple MCP server instances causing state confusion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions