Skip to content

[Bug]: 'file lock failed: Access is denied' when persisting session on Windows #434

@vanduc2514

Description

@vanduc2514

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • I am using the latest version of Moltis
  • If this happened during a chat session, I included as much full session context as possible and redacted secrets

What happened?

On Windows, when running Moltis (latest release), assistant messages sometimes fail to persist and this error appears:

file lock failed: Access is denied. (os error 5)

This happens even though no other process is accessing the session file. The error is triggered during session persistence—especially in crates/sessions/src/store.rs - SessionStore::append. The implementation uses a Rust RwLock<File> to guard file writes. However, on Windows this can cause intermittent file lock failures due to OS-level file lock semantics, RwLock poisoning, or potentially antivirus/file scanning races.

Expected behavior

Assistant messages and session state should persist reliably on Windows, without intermittent file lock failures. File lock errors ('Access is denied' or os error 5) should not occur when no other process is accessing the session file.

Steps to reproduce

  1. Run Moltis on Windows (latest binary release)
  2. Use assistant or chat features that persist session state
  3. Observe in the log messages fail to save with 'file lock failed: Access is denied' (os error 5)
  4. No other process is locking the file, anti virus (Defender) is off
  5. See logs or UI error messages for indication of failure.

Did this happen during a chat session?

Yes

Chat session context (if applicable)

Context does not contain anything except the initial SYSTEM message. No follow-up message

Error messages / logs

2026-03-14T13:48:39.645341Z  INFO moltis_agents::runner: starting streaming agent loop provider="openrouter" model="openrouter::deepseek/deepseek-chat-v3.1" native_tools=true tools_count=33 is_multimodal=false
2026-03-14T13:48:39.646128Z  INFO moltis_agents::runner: schemas_for_api prepared for streaming native_tools=true schemas_for_api_count=33 tool_schemas_count=33
2026-03-14T13:48:39.662015Z  INFO moltis_agents::runner: calling LLM (streaming) iteration=1 messages_count=2
2026-03-14T13:48:44.723642Z  INFO moltis_agents::runner: streaming LLM response complete iteration=1 has_text=true tool_calls_count=0 input_tokens=10511 output_tokens=19
2026-03-14T13:48:44.724050Z  INFO moltis_agents::runner: streaming agent loop complete — returning text iterations=1 tool_calls=0
2026-03-14T13:48:44.727410Z  INFO moltis_chat: agent run complete run_id="a668ed13-fdce-499b-a0c8-ff119a428261" iterations=1 tool_calls=0 response=Hey Duc! 👋
Good to see you. What can I help you with today? silent=false
2026-03-14T13:48:44.732274Z  INFO moltis_chat: push: checking push notification (agent mode)
2026-03-14T13:48:44.733089Z  INFO moltis_chat: push notification sent sent=0
2026-03-14T13:48:44.735535Z  WARN moltis_chat: failed to persist assistant message: file lock failed: Access is denied. (os error 5)

Is this a regression?

I don't know

Last working version

No response

Moltis version

v0.10.18

Component

Gateway / Web UI

Install method

Pre-built binary

Operating system

Other

Additional context

I run the msvc.exe binary on Windows host (not WSL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions