Skip to content

Fix Windows lock ordering and config decode fallback - #874

Merged
thomwebb merged 2 commits into
mpfaffenberger:mainfrom
wkramme:fix/windows-lock-order-upstream-sync
Aug 27, 2026
Merged

Fix Windows lock ordering and config decode fallback#874
thomwebb merged 2 commits into
mpfaffenberger:mainfrom
wkramme:fix/windows-lock-order-upstream-sync

Conversation

@wkramme

@wkramme wkramme commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR includes the generic core fix set for Windows lock behavior and config decoding hardening:

  • acquire the Windows byte lock before normalizing/truncating the lock sidecar
  • normalize sidecar size only while the lock is held
  • best-effort prime for empty lock sidecars so contention errors do not leak
  • decode config using utf-8-sig (BOM-safe) with a narrow Windows locale fallback for legacy files
  • preserve strict corruption handling and quarantine behavior

Why

A review flagged a lock-ordering issue: sidecar mutation could happen before lock acquisition and potentially leak OSError under contention. This change ensures ordering is lock-first, mutate-after-acquire.

Tests

Added/updated targeted coverage for:

  • Windows lock sidecar normalization behavior
  • contention regression: sidecar is not mutated until lock acquisition
  • empty-sidecar prime path swallowing transient write error
  • UTF-8 BOM config decode acceptance
  • Windows locale fallback decode handling and warning path

Validation run

  • pytest -q -o addopts='' tests/test_atomic_io.py tests/test_config_corruption_resilience.py40 passed
  • ruff check code_puppy/atomic_io.py code_puppy/config_file.py tests/test_atomic_io.py tests/test_config_corruption_resilience.pypassed

Notes

  • Generic/open-source-safe change; no Walmart-specific behavior.

- 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
@wkramme

wkramme commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

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
thomwebb self-requested a review August 27, 2026 18:28

@thomwebb thomwebb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@thomwebb
thomwebb merged commit 904c977 into mpfaffenberger:main Aug 27, 2026
3 checks passed
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.

2 participants