Skip to content

Windows: config_signature unchanged after write — NTFS mtime resolution / cache #645

@memtomem

Description

@memtomem

Background

`test_web_hot_reload.py` has 17 failures on Windows — the entire file. The recurring symptom is the config signature (`(path, mtime_ns)` tuple) not changing across two writes that should have updated it.

Symptoms

```
FAILED TestSignature::test_signature_changes_on_config_write
AssertionError: assert (('C:\Users\...\config.json', 1777609014603566900), ...)
!= (('C:\Users\...\config.json', 1777609014603566900), ...)

FAILED test_concurrent_patches_are_serialised_by_lock
assert 10 in (42, 99)

FAILED test_reload_if_stale_cas_yields_to_concurrent_writer_bump
AssertionError: writer's signature was overwritten by the reader's tail
```

The `mtime_ns` value is identical across the two snapshots — meaning the second `write_text` didn't bump the modification time. Several possibilities:

  1. NTFS lazy timestamp: NTFS may defer mtime updates briefly; `os.fsync` doesn't always flush metadata immediately on Windows.
  2. Test timing: writes in the same millisecond report the same `mtime_ns` (Windows mtime resolution is finer than that, but the OS may round to FILE_ATTRIBUTE_TIMESTAMP granularity).
  3. Cache layer: `config_signature` might be cached at a level that doesn't invalidate on Windows (e.g., `stat` result caching).

Affected files

  • `packages/memtomem/tests/test_web_hot_reload.py` — 17 failures (entire file's relevant tests)
  • Possibly: `test_storage.py` (1 failure), other mtime-sensitive tests

Investigation needed

  1. Confirm whether the issue is (a) production code's mtime read missing a flush, (b) test timing assumption (writes-too-fast-to-distinguish), or (c) Windows file-attribute cache not invalidating.
  2. If (a): fix `config_signature` to read mtime via `os.stat(path)` after `fsync` in the writer, or via `Path.stat()` with `follow_symlinks=False` consistently.
  3. If (b): tests should sleep `time.sleep(0.01)` between writes, or use a monotonic counter instead of mtime for tests.
  4. If (c): may need `FlushFileBuffers` (via `ctypes` to `kernel32`) on Windows, but that's a heavy hammer.

Refs

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions