Skip to content

[BUG] sync_changes crashes in local Docker + Postgres + streamable-http MCP with IndexError: pop from an empty deque #877

@bengreeno

Description

@bengreeno

Bug Description

In a local Docker deployment using Postgres (not SQLite), Basic Memory works for MCP requests and agent-driven edits, but local filesystem watcher/sync does not work reliably.

Manual markdown edits on disk are not picked up automatically, and enabling sync_changes causes crashes. I currently have to keep sync_changes: false to keep the setup usable.

Steps To Reproduce

  1. Run Basic Memory 0.21.5 locally in Docker with a Postgres backend (postgresql+asyncpg), with the project mounted at /app/data/main.
  2. Start MCP with:
    basic-memory mcp --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp
  3. Enable sync_changes in config.
  4. Make manual edits to markdown files in the mounted project directory.
  5. Observe watcher instability / crashes instead of reliable sync.

Expected Behavior

Manual markdown edits on disk should be detected and synced automatically when sync_changes is enabled in a local Postgres-backed deployment.

Actual Behavior

What works:

  • MCP initializes and serves requests
  • bm project info main --json works
  • agent-driven edits work

What does not work:

  • manual edits to markdown files on disk are not picked up automatically
  • enabling sync_changes causes crashes
  • I had to keep sync_changes: false to keep the setup stable

Crash signature I saw:

IndexError: pop from an empty deque

Trace lands in:

/app/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py
/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:_run_once

I also saw:

ASGI callable returned without completing response.

Relevant log snippet:

ERROR:    ASGI callable returned without completing response.

File "/app/.venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 2358, in run
    self._run_once()
File "/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 2046, in _run_once
IndexError: pop from an empty deque

There were also repeated shutdown/restart sequences around the crash:

INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [1]

Environment

  • OS: Ubuntu 24.04.4 LTS
  • Python version: 3.13.13
  • Basic Memory version: 0.21.5
  • Installation method: Docker (ghcr.io/basicmachines-co/basic-memory:latest)
  • Claude Desktop version (if applicable): N/A

Additional Context

MCP command:

basic-memory mcp --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp

Docker setup:

  • basic-memory container runs MCP over streamable-http
  • basic-memory-db is a separate postgres:16-alpine container
  • ./data is mounted to /app/data
  • ./config is mounted to /home/appuser/.basic-memory

Current config that stays mostly stable:

{
  "database_backend": "postgres",
  "sync_changes": false,
  "skip_initialization_sync": true,
  "sync_delay": 1000
}

One thing I noticed: bm project info main --json shows a SQLite-style system.database_path like:

"database_path": "/home/appuser/.basic-memory/memory.db",
"database_size": "0.00 MB"

even though this deployment is definitely using Postgres. That may just be a reporting issue, but I wanted to mention it.

Possible Solution

I don’t have a real fix yet, but my guess is this may be in the watcher / MCP server lifecycle / async shutdown path for the local Docker + Postgres + streamable-http combination, rather than in the core MCP request path itself.

The SQLite-looking database_path in bm project info may be unrelated and just a misleading status/reporting field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions