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.
This commit is contained in:
2026-04-30 21:17:50 -04:00
parent 1e1c92abc3
commit 8a40f6ced0

View File

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