Skip to content

Commit aea7e9c

Browse files
test(decay): deflake reinforced-memory guard against coarse clocks (#190)
The test simulated reinforcement by setting last_access = now_ts(), then asserted the next decay pass leaves stability bit-identical (1e-9). On hosts with coarse clock resolution (observed on Windows: consecutive time.time() calls can return the same value), last_access can equal the just-written last_decay anchor, so the strict 'last_access > anchor' guard misses and the pass legitimately decays one tick's interval (~2.1e-9 stability drift) — a race, not the compounding regression this test pins. Set last_access one second past the pass anchor so the guard condition holds deterministically on every host, and extend coverage to 50 rapid passes to pin the guard, not just the first one after the update. Reproduced: full-suite runs failed this test intermittently (stability drift 2.13e-9 vs 1e-9 threshold) while it passed in isolation; 20/20 same-tick stress trials now stable across 8 consecutive test runs.
1 parent a7a9fe4 commit aea7e9c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tests/test_decay_idempotent.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ def test_reinforced_memory_is_not_decayed_that_interval(monkeypatch, tmp_path):
6767
decayed = _stability("ns", "hot")
6868
assert decayed < 5.0
6969
# Simulate reinforcement: the memory is accessed now (last_access moves past the anchor).
70+
# Bump one second past the pass's anchor: time.time() can return the SAME
71+
# value as the anchor on coarse-clock hosts (observed on Windows), and a
72+
# last_access equal to the anchor makes the subsequent pass legitimately
73+
# decay one tick's interval — a race, not the regression this pins.
7074
conn = get_conn()
7175
conn.execute("UPDATE memories SET last_access=? WHERE namespace=? AND document_id=?",
72-
(now_ts(), "ns", "hot"))
76+
(now + 1.0, "ns", "hot"))
7377
conn.commit()
7478
# A subsequent pass must NOT decay it further — it was just accessed.
7579
mem_store.apply_decay_to_all("ns", 7.0)
7680
assert abs(_stability("ns", "hot") - decayed) < 1e-9
81+
# And the guard must hold across many rapid passes, not just one.
82+
for _ in range(50):
83+
mem_store.apply_decay_to_all("ns", 7.0)
84+
assert abs(_stability("ns", "hot") - decayed) < 1e-9

0 commit comments

Comments
 (0)