Skip to content

fix: add asyncio lock to context file writes#1467

Open
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/context-write-lock
Open

fix: add asyncio lock to context file writes#1467
Br1an67 wants to merge 1 commit intoMoonshotAI:mainfrom
Br1an67:fix/context-write-lock

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 17, 2026

Problem

On Windows, concurrent async writes to context.jsonl cause PermissionError due to file locking semantics. Multiple coroutines (append_message, update_token_count, checkpoint) may write simultaneously.

Fix

Add an asyncio.Lock to the Context class to serialize all file write operations (checkpoint, append_message, update_token_count).

Fixes #1429


Open with Devin

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

On Windows, concurrent async writes to the context.jsonl file
can cause PermissionError due to file locking semantics. Multiple
coroutines (append_message, update_token_count, checkpoint) may
attempt to write simultaneously.

Add an asyncio.Lock to serialize all file write operations in the
Context class, preventing concurrent access to the context file.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows 平台并发写入导致 Permission denied: [Errno 13]

1 participant