Fix Windows lock ordering and config decode fallback - #874
Conversation
- Acquire Windows byte lock before normalizing lock sidecar\n- Prime empty sidecars best-effort without leaking contention errors\n- Add contention regression coverage for lock preparation ordering\n- Add UTF-8 BOM + Windows locale fallback decode handling and tests
|
Addressed CI formatting failure by running Ruff formatter on tests/test_config_corruption_resilience.py and pushing an update (commit 21edfde).\n\nVerification after update:\n- ruff format --check . \n- ruff check on touched files \n- targeted pytest suite (tests/test_atomic_io.py + tests/test_config_corruption_resilience.py): 40 passed |
thomwebb
left a comment
There was a problem hiding this comment.
Reviewed the complete generic fix set. The Windows lock ordering issue from the internal draft is resolved: oversized sidecars are normalized only after acquisition, empty-sidecar priming preserves polling behavior, and the added contention regression verifies the sidecar remains untouched until the lock is acquired. The UTF-8/BOM and Windows locale fallback changes are appropriately scoped and covered. All four implementation/test files belong upstream; quality, macOS, and Windows encoding checks are green. Looks good to merge.
Summary
This PR includes the generic core fix set for Windows lock behavior and config decoding hardening:
utf-8-sig(BOM-safe) with a narrow Windows locale fallback for legacy filesWhy
A review flagged a lock-ordering issue: sidecar mutation could happen before lock acquisition and potentially leak
OSErrorunder contention. This change ensures ordering is lock-first, mutate-after-acquire.Tests
Added/updated targeted coverage for:
Validation run
pytest -q -o addopts='' tests/test_atomic_io.py tests/test_config_corruption_resilience.py→ 40 passedruff check code_puppy/atomic_io.py code_puppy/config_file.py tests/test_atomic_io.py tests/test_config_corruption_resilience.py→ passedNotes