fix(team): read and write .git/info/exclude as UTF-8 - #237
Open
Dev-next-gen wants to merge 1 commit into
Open
Dev-next-gen wants to merge 1 commit into
Dev-next-gen wants to merge 1 commit into
Conversation
The team worktree manager rewrites the repository's .git/info/exclude with Path.read_text()/write_text() and no encoding, so the locale encoding is used. On Windows (cp1252) a user rule such as "数据/" raises UnicodeDecodeError, which aborts ensure_base() and with it every isolated sub-agent run. Use UTF-8 explicitly, as the hooks config loader already does.
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.
Description
While looking at the recent fix that made the hooks loader read its config as UTF-8 (cdd2681), I noticed the same pattern in
core/team/worktree.py.WorktreeManagerinstalls and later removes its ignore block in the repository's.git/info/excludeusingPath.read_text()/write_text()with no encoding, so the locale encoding is used. On a Windows machine with the default cp1252 locale, an existing user rule such as数据/makesread_text()raiseUnicodeDecodeError: 'charmap' codec can't decode byte 0x8d.ensure_base()doesn't catch it, so every isolated sub-agent run incore/harness/agents/control.pyfails before its worktree is created.This PR reads and writes the file as UTF-8 explicitly, like the hooks loader does now. On UTF-8 locales nothing changes.
Related Issues
None that I could find.
Changes Made
core/team/worktree.py: passencoding="utf-8"to the tworead_text()and twowrite_text()calls on.git/info/exclude.tests/test_team_worktree.py: newtest_team_exclude_keeps_non_ascii_user_rules. It puts a UTF-8 rule in.git/info/exclude, then runs an install/remove cycle and checks that the rule is still there, byte for byte.Checklist
Additional Notes
Before and after results for the new test:
UnicodeDecodeError ... byte 0x8d. After the fix, the new test and the existing exclude test both pass.PYTHONUTF8=0 PYTHONCOERCECLOCALE=0 LC_ALL=Cso the locale encoding is ASCII. Before the fix:1 failed, 6 passed. After the fix:7 passed, and7 passedagain under the normal UTF-8 locale.The Windows job in python-ci should hit the same failure without the fix.
Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.