Skip to content

[BUG] Log rotation fails on Windows when another process holds the log file #653

Closed

Description

@cderv

Bug Description

Loguru log rotation fails with PermissionError: [WinError 32] when another basic-memory
process has the log file open. Typically happens when running a CLI command while the MCP
server is already running — both write to ~/.basic-memory/basic-memory.log.

Steps To Reproduce

  1. Start the MCP server (e.g., via Claude Desktop)
  2. Run any CLI command (e.g., bm project info)
  3. If basic-memory.log exceeds the 10 MB rotation threshold, rotation triggers

Expected Behavior

Log rotation should succeed or fail silently when another process holds the file.

Actual Behavior

Every log message produces a loguru error, flooding stderr:

PermissionError: [WinError 32] ... cannot access the file because it is being used
by another process: '...basic-memory.log' -> '...basic-memory.2026-01-07_..._821959.log'

The command itself still completes but the output is hard to read.

Environment

  • OS: Windows 11
  • Python: 3.13.9
  • Basic Memory: 0.19.1
  • Installation: uv tool

Additional Context

The log sink in utils.py uses rotation="10 MB" with no Windows-specific handling. Loguru
uses os.rename internally, which Windows blocks if another process has the file open.

Possible Solution

We could use per-process log files to avoid the contention, or suppress the rotation error
so it doesn't repeat on every message. Not sure what the best approach is for loguru
specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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