From 8a40f6ced08139de9d1e0b54cb4bd2f920b4dca8 Mon Sep 17 00:00:00 2001 From: anti Date: Thu, 30 Apr 2026 21:17:50 -0400 Subject: [PATCH] fix(personas_pool): re-stat after read to avoid caching stale mtime The initial stat and read happened without a lock between them. A file change mid-window stored the mtime of the pre-change stat against the post-change content, suppressing the next reload. Re-stat after read_text; fall back to the pre-read stat only on OSError. --- decnet/realism/personas_pool.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/decnet/realism/personas_pool.py b/decnet/realism/personas_pool.py index 9c7a29fe..9202c730 100644 --- a/decnet/realism/personas_pool.py +++ b/decnet/realism/personas_pool.py @@ -120,11 +120,19 @@ def load(*, language_default: str = "en") -> list[EmailPersona]: logger.warning("realism global pool: read failed path=%s: %s", path, exc) return [] + # Re-stat after the read so the stored mtime reflects what we actually + # parsed — a file change between the initial stat and read would otherwise + # cache a stale mtime and suppress the next reload. + try: + st2 = path.stat() + except OSError: + st2 = st + parsed = parse_personas(raw, language_default=language_default) with _lock: _cache = parsed _cache_path = path - _cache_mtime = st.st_mtime + _cache_mtime = st2.st_mtime if parsed: logger.info( "realism global pool: loaded %d personas from %s", len(parsed), path,