fix: handle UnicodeDecodeError race condition in copaw-worker#791
Open
nillikechatchat wants to merge 3 commits into
Open
fix: handle UnicodeDecodeError race condition in copaw-worker#791nillikechatchat wants to merge 3 commits into
nillikechatchat wants to merge 3 commits into
Conversation
…codeDecodeError race This fixes the race condition between mc mirror reporting completion and the file being fully written to disk. The race can cause partial reads of multi-byte UTF-8 characters at the end of the file, resulting in UnicodeDecodeError crashes during worker startup. Fixes: agentscope-ai#728 Changes: - Add _read_text_with_retry() helper function in both worker.py and sync.py - The function retries up to 5 times with 100ms delay on UnicodeDecodeError - Apply retry mechanism to all read_text() calls for AGENTS.md, SOUL.md, and openclaw.json - Add debug logging for retry attempts to improve observability
Contributor
📊 CI Metrics ReportSummary
By Role
Per-Test Breakdown
Trends✅ 2 test(s) improved (fewer LLM calls) Generated by HiClaw CI on 2026-05-11 10:51:04 UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix for Issue #728: UnicodeDecodeError race condition in copaw-worker.
Problem
When mc mirror completes file synchronization, there is a race condition where file reads can occur before the file is fully written to disk. This causes
UnicodeDecodeErrorwhen reading multi-byte UTF-8 characters at the end of files.Solution
Added
_read_text_with_retry()helper function in bothworker.pyandsync.pythat:UnicodeDecodeErrorduring file readsFiles Changed
copaw/src/copaw_worker/worker.py- Added retry logic for SOUL.md, AGENTS.md, HEARTBEAT.md readscopaw/src/copaw_worker/sync.py- Added retry logic for team_id.txt and team_leader.txt readsFixes #728